Explorar o código

修复机器销售页面的BUG

李天标 %!s(int64=5) %!d(string=hai) anos
pai
achega
75ae17a557

+ 24 - 0
src/main/java/com/shawn/model/Bean/Child.java

@@ -23,4 +23,28 @@ public class Child {
     private String name;
     @ApiModelProperty(value="机器列表")
     private List<Childlast> children;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List<Childlast> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<Childlast> children) {
+        this.children = children;
+    }
 }

+ 16 - 0
src/main/java/com/shawn/model/Bean/Childlast.java

@@ -20,4 +20,20 @@ public class Childlast {
     private Long id;
     @ApiModelProperty(value="名称")
     private String name;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }

+ 465 - 457
src/main/java/com/shawn/web/controller/TEquipmentController.java

@@ -1,7 +1,7 @@
 /**
  * Date:2019-09-23 17:09:15
  * author:吴洪双
-*/
+ */
 
 package com.shawn.web.controller;
 
@@ -37,477 +37,485 @@ import com.shawn.web.controller.base.BaseController;
 import com.shawn.model.param.TEquipmentParam;
 
 import lombok.extern.apachecommons.CommonsLog;
+
 @CommonsLog
 @RestController
 @RequestMapping("TEquipment")
-public class TEquipmentController extends BaseController<TEquipment,TEquipmentExample,TEquipmentParam,Long>{
-	@Autowired
-	private TEquipmentServiceInterface tEquipmentService;
-	@Autowired
-	private TAdminServiceInterface tAdminService;
-	@Autowired
-	private TAlarmRecordServiceInterface tAlarmRecordService;
-	@Autowired
-	private TAreaServiceInterface tAreaServiceInterface;
-	@Autowired
-	private TOrderServiceInterface tOrderServiceInterface;
-
-	@Autowired
-	private TEquipmentMapper tEquipmentMapper;
-
-	@Autowired
-	private TAreaMapper tAreaMapper;
-
-	@Autowired
-	private TOrderMapper tOrderMapper;
-
-	@Autowired
-	public TEquipmentController(TEquipmentServiceInterface service) {
-		super(service);
-	}
-
-	@Override
-	protected TEquipmentExample createNewExample() {
-		return new TEquipmentExample();
-	}
-
-	@PostMapping("/getEquipmentListByUser")
-	public ResponseEntity<?> getEquipmentListByUser(@RequestBody TAdmin param) {
-
-		List<TAdminDTO> resultList = new ArrayList<>();
-
-		if("admin".equals(param.getUsername())){ // 管理员查所有商家
-			List<TAdmin> adminList = tAdminService.selectByOption(null);
-			List<TEquipment> equipmentList = tEquipmentService.selectByOption(null);
-			List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(null);
-			//获取当前用户今天所有机器的所以警报信息
-			List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(null);
-
-			resultList = adminList.stream().map(e ->{
-				TAdminDTO dto = new TAdminDTO();
-				BeanUtils.copyPropertiesIgnoreNull(e,dto,true);
-
-				List<TEquipmentDTO> selList =  equipmentList.stream()
-						.filter(equipment ->e.getId().equals(equipment.getAdminId())) // 查对应的设备
-						.map(equipment -> {
-							TEquipmentDTO equipmentDTO = new TEquipmentDTO();
-							BeanUtils.copyPropertiesIgnoreNull(equipment,equipmentDTO,true);
-							Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
-							if(op.isPresent()){
-								equipmentDTO.setAlarmContent(op.get().getAlarmContent());
-								equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
-							}
-							//获取该机器的所有警报信息
-							List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
-							equipmentDTO.setAlarmList(eqAlarmList);
-							return equipmentDTO;
-						}).collect(Collectors.toList());
-				dto.setEquipmentList(selList);
-				return dto;
-			}).collect(Collectors.toList());
-		}else{ // 只查当前商家的设备列表
-			TAdminDTO dto = new TAdminDTO();
-			BeanUtils.copyPropertiesIgnoreNull(param,dto,true);
-			TEquipmentExample example = new TEquipmentExample();
-			TEquipmentExample.Criteria criteria = example.createCriteria();
-			criteria.andAdminIdEqualTo(param.getId());
-			List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
-			List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(param.getId());
-			//获取当前用户今天所有机器的所以警报信息
-			List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(param.getId());
-
-			List<TEquipmentDTO> equipmentDTOList = equipmentList.stream().map(equipment -> {
-				TEquipmentDTO equipmentDTO = new TEquipmentDTO();
-				BeanUtils.copyPropertiesIgnoreNull(equipment,equipmentDTO,true);
-				Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
-				if(op.isPresent()){
-					equipmentDTO.setAlarmContent(op.get().getAlarmContent());
-					equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
-				}
-				//获取该机器的所有警报信息
-				List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
-				equipmentDTO.setAlarmList(eqAlarmList);
-				return equipmentDTO;
-			}).collect(Collectors.toList());
-
-
-			dto.setEquipmentList(equipmentDTOList);
-			resultList.add(dto);
-		}
-
-		return ResponseEntity.status(HttpStatus.OK)
-				.body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
-
-	}
-	@PostMapping("/updateName")
-	public ResponseEntity<?> updateName(@RequestBody TEquipment equipment){
-		Boolean t=tEquipmentService.updateById(equipment);
-		if(t==true){
-			return  ResponseEntity.status(HttpStatus.OK)
-					.body(new ResultMessage().setCode(true).setData(t).setMessage("修改成功"));
-		}else {
-			return  ResponseEntity.status(HttpStatus.OK)
-					.body(new ResultMessage().setCode(false).setData(t).setMessage("修改失败"));
-		}
-
-	}
-	//根据机器id获取用户信息
-	@PostMapping("/findByEquipment")
-	public ResponseEntity<?> findByEquipment(@RequestBody TEquipment equipment){
-		TEquipment tEquipment = tEquipmentService.selectEntityById(equipment.getId());
-		TAdmin tAdmin = tAdminService.selectEntityById(tEquipment.getAdminId());
-		return  ResponseEntity.status(HttpStatus.OK)
-					.body(new ResultMessage().setCode(false).setData(tAdmin).setMessage(""));
-	}
-	//获取机器数量
-	@PostMapping("/getMachineNum")
-	public ResponseEntity<?> getMachineNum(@RequestBody StatisticsParam param) {
-		String machineTotalNum ="";
-		String machineUseNum = "";
-		String equipmentId = param.getEquipmentId();
-		//判断是否有机器id传入
-		if(equipmentId!=null && equipmentId!=""){
-			Long id = Long.valueOf(equipmentId);
-			TEquipment equipment = tEquipmentService.selectEntityById(id);
-			Long adminId = equipment.getAdminId();
-			String dminId = String.valueOf(adminId);
-			param.setAdminId(dminId);
-			 machineTotalNum = tEquipmentService.findMachineTotalNum(param);
-			 machineUseNum = tEquipmentService.findMachineUseNum(param);
-		}else{
-			 machineTotalNum = tEquipmentService.findMachineTotalNum(param);
-			 machineUseNum = tEquipmentService.findMachineUseNum(param);
-		}
-
-			List<String> list = new ArrayList<>();
-			list.add(machineTotalNum);
-			list.add(machineUseNum);
-		return ResponseEntity
-				.status(HttpStatus.OK)
-				.body(new ResultMessage()
-						.setCode(true)
-						.setData(list)
-						.setMessage("SUCCESS"));
-	}
-	//机器睡眠
-	@PostMapping("/sleep")
-	public ResponseEntity<?> sleep(@RequestBody StatisticsParam param) {
-		String equipmentId = param.getEquipmentId();
-			Long id = Long.valueOf(equipmentId);
-			TEquipment equipment = tEquipmentService.selectEntityById(id);
-		if (equipment == null) {
+public class TEquipmentController extends BaseController<TEquipment, TEquipmentExample, TEquipmentParam, Long> {
+    @Autowired
+    private TEquipmentServiceInterface tEquipmentService;
+    @Autowired
+    private TAdminServiceInterface tAdminService;
+    @Autowired
+    private TAlarmRecordServiceInterface tAlarmRecordService;
+    @Autowired
+    private TAreaServiceInterface tAreaServiceInterface;
+    @Autowired
+    private TOrderServiceInterface tOrderServiceInterface;
+
+    @Autowired
+    private TEquipmentMapper tEquipmentMapper;
+
+    @Autowired
+    private TAreaMapper tAreaMapper;
+
+    @Autowired
+    private TOrderMapper tOrderMapper;
+
+    @Autowired
+    public TEquipmentController(TEquipmentServiceInterface service) {
+        super(service);
+    }
+
+    @Override
+    protected TEquipmentExample createNewExample() {
+        return new TEquipmentExample();
+    }
+
+    @PostMapping("/getEquipmentListByUser")
+    public ResponseEntity<?> getEquipmentListByUser(@RequestBody TAdmin param) {
+
+        List<TAdminDTO> resultList = new ArrayList<>();
+
+        if ("admin".equals(param.getUsername())) { // 管理员查所有商家
+            List<TAdmin> adminList = tAdminService.selectByOption(null);
+            List<TEquipment> equipmentList = tEquipmentService.selectByOption(null);
+            List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(null);
+            //获取当前用户今天所有机器的所以警报信息
+            List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(null);
+
+            resultList = adminList.stream().map(e -> {
+                TAdminDTO dto = new TAdminDTO();
+                BeanUtils.copyPropertiesIgnoreNull(e, dto, true);
+
+                List<TEquipmentDTO> selList = equipmentList.stream()
+                        .filter(equipment -> e.getId().equals(equipment.getAdminId())) // 查对应的设备
+                        .map(equipment -> {
+                            TEquipmentDTO equipmentDTO = new TEquipmentDTO();
+                            BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
+                            Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
+                            if (op.isPresent()) {
+                                equipmentDTO.setAlarmContent(op.get().getAlarmContent());
+                                equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
+                            }
+                            //获取该机器的所有警报信息
+                            List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
+                            equipmentDTO.setAlarmList(eqAlarmList);
+                            return equipmentDTO;
+                        }).collect(Collectors.toList());
+                dto.setEquipmentList(selList);
+                return dto;
+            }).collect(Collectors.toList());
+        } else { // 只查当前商家的设备列表
+            TAdminDTO dto = new TAdminDTO();
+            BeanUtils.copyPropertiesIgnoreNull(param, dto, true);
+            TEquipmentExample example = new TEquipmentExample();
+            TEquipmentExample.Criteria criteria = example.createCriteria();
+            criteria.andAdminIdEqualTo(param.getId());
+            List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
+            List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(param.getId());
+            //获取当前用户今天所有机器的所以警报信息
+            List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(param.getId());
+
+            List<TEquipmentDTO> equipmentDTOList = equipmentList.stream().map(equipment -> {
+                TEquipmentDTO equipmentDTO = new TEquipmentDTO();
+                BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
+                Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
+                if (op.isPresent()) {
+                    equipmentDTO.setAlarmContent(op.get().getAlarmContent());
+                    equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
+                }
+                //获取该机器的所有警报信息
+                List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
+                equipmentDTO.setAlarmList(eqAlarmList);
+                return equipmentDTO;
+            }).collect(Collectors.toList());
+
+
+            dto.setEquipmentList(equipmentDTOList);
+            resultList.add(dto);
+        }
+
+        return ResponseEntity.status(HttpStatus.OK)
+                .body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
+
+    }
+
+    @PostMapping("/updateName")
+    public ResponseEntity<?> updateName(@RequestBody TEquipment equipment) {
+        Boolean t = tEquipmentService.updateById(equipment);
+        if (t == true) {
+            return ResponseEntity.status(HttpStatus.OK)
+                    .body(new ResultMessage().setCode(true).setData(t).setMessage("修改成功"));
+        } else {
+            return ResponseEntity.status(HttpStatus.OK)
+                    .body(new ResultMessage().setCode(false).setData(t).setMessage("修改失败"));
+        }
+
+    }
+
+    //根据机器id获取用户信息
+    @PostMapping("/findByEquipment")
+    public ResponseEntity<?> findByEquipment(@RequestBody TEquipment equipment) {
+        TEquipment tEquipment = tEquipmentService.selectEntityById(equipment.getId());
+        TAdmin tAdmin = tAdminService.selectEntityById(tEquipment.getAdminId());
+        return ResponseEntity.status(HttpStatus.OK)
+                .body(new ResultMessage().setCode(false).setData(tAdmin).setMessage(""));
+    }
+
+    //获取机器数量
+    @PostMapping("/getMachineNum")
+    public ResponseEntity<?> getMachineNum(@RequestBody StatisticsParam param) {
+        String machineTotalNum = "";
+        String machineUseNum = "";
+        String equipmentId = param.getEquipmentId();
+        //判断是否有机器id传入
+        if (equipmentId != null && equipmentId != "") {
+            Long id = Long.valueOf(equipmentId);
+            TEquipment equipment = tEquipmentService.selectEntityById(id);
+            Long adminId = equipment.getAdminId();
+            String dminId = String.valueOf(adminId);
+            param.setAdminId(dminId);
+            machineTotalNum = tEquipmentService.findMachineTotalNum(param);
+            machineUseNum = tEquipmentService.findMachineUseNum(param);
+        } else {
+            machineTotalNum = tEquipmentService.findMachineTotalNum(param);
+            machineUseNum = tEquipmentService.findMachineUseNum(param);
+        }
+
+        List<String> list = new ArrayList<>();
+        list.add(machineTotalNum);
+        list.add(machineUseNum);
+        return ResponseEntity
+                .status(HttpStatus.OK)
+                .body(new ResultMessage()
+                        .setCode(true)
+                        .setData(list)
+                        .setMessage("SUCCESS"));
+    }
+
+    //机器睡眠
+    @PostMapping("/sleep")
+    public ResponseEntity<?> sleep(@RequestBody StatisticsParam param) {
+        String equipmentId = param.getEquipmentId();
+        Long id = Long.valueOf(equipmentId);
+        TEquipment equipment = tEquipmentService.selectEntityById(id);
+        if (equipment == null) {
 //			return ERROR_MESSAGE;
-		}
-		String eqeStatus = "0";
-		String code = param.getAdminId();
-		if (code.equals("1")) {
-			eqeStatus = "1";
-			equipment.setIsSleep(true);
-		}else {
-			equipment.setIsSleep(false);
-		}
-
-
-		tEquipmentService.updateById(equipment);
-		PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("is_sleep", eqeStatus).toString());
-		return ResponseEntity
-				.status(HttpStatus.OK)
-				.body(new ResultMessage()
-						.setCode(true)
-						.setData("SUCCESS")
-						.setMessage("SUCCESS"));
-	}
-
-	@PostMapping("/getEquipmentListByProvince")
-	public ResponseEntity<?> getEquipmentListByProvince(@RequestBody TAdmin param) {
-		List<TAdminDTO> resultList = new ArrayList<>();
-		if("admin".equals(param.getUsername())){ // 管理员查所有商家
-			//获取有多少个省份
-			List<TArea> list1 = tAreaServiceInterface.getProvinceList();
-			Map<Long, String> map1 = new HashMap<>();
-			for (TArea area : list1) {
-				String fullname = area.getFullName();
-				String provinceName = fullname.substring(0, 3);
-				String treePath = area.getTreePath();
-				String[] str = treePath.split(",");
-				Long s = null;
-				if (str.length > 1) {
-					s = Long.valueOf(str[1]);
-				}
-				if (str.length <= 1) {
-					s = area.getId();
-				}
-				map1.put(s, provinceName);
-			}
-
-			List<Children3> children3List = new ArrayList<>();
-			for (Long key : map1.keySet()) {
-				Children3 children3 = new Children3();
-				children3.setId(key);
+        }
+        String eqeStatus = "0";
+        String code = param.getAdminId();
+        if (code.equals("1")) {
+            eqeStatus = "1";
+            equipment.setIsSleep(true);
+        } else {
+            equipment.setIsSleep(false);
+        }
+
+
+        tEquipmentService.updateById(equipment);
+        PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("is_sleep", eqeStatus).toString());
+        return ResponseEntity
+                .status(HttpStatus.OK)
+                .body(new ResultMessage()
+                        .setCode(true)
+                        .setData("SUCCESS")
+                        .setMessage("SUCCESS"));
+    }
+
+    @PostMapping("/getEquipmentListByProvince")
+    public ResponseEntity<?> getEquipmentListByProvince(@RequestBody TAdmin param) {
+        List<TAdminDTO> resultList = new ArrayList<>();
+        if ("admin".equals(param.getUsername())) { // 管理员查所有商家
+            //获取有多少个省份
+            List<TArea> list1 = tAreaServiceInterface.getProvinceList();
+            Map<Long, String> map1 = new HashMap<>();
+            for (TArea area : list1) {
+                String fullname = area.getFullName();
+                String provinceName = fullname.substring(0, 3);
+                String treePath = area.getTreePath();
+                String[] str = treePath.split(",");
+                Long s = null;
+                if (str.length > 1) {
+                    s = Long.valueOf(str[1]);
+                }
+                if (str.length <= 1) {
+                    s = area.getId();
+                }
+                map1.put(s, provinceName);
+            }
+
+            List<Children3> children3List = new ArrayList<>();
+            for (Long key : map1.keySet()) {
+                Children3 children3 = new Children3();
+                children3.setId(key);
 //				children3.setName(map1.get(key));
-				int pday = 0 ;
-				int pweek = 0 ;
-				int pmonth = 0 ;
-				int pyear = 0 ;
-				Set<Long> province = new HashSet<>();
-				//本省有多少个市
-				Map<Long,String> cityMap = new HashMap<>();
-				for (TArea carea : list1) {
-					String fullName = carea.getFullName();
-					if(fullName.substring(0,3).equals(map1.get(key))){
-						province.add(carea.getId());
-						if(key.equals(carea.getParent())){
-							cityMap.put(carea.getId(),carea.getName());
-						}else{
-							TArea cityArea = tAreaServiceInterface.selectEntityById(carea.getParent());
-							cityMap.put(cityArea.getId(),cityArea.getName());
-						}
-					}
-				}
-				List<Children2> children2List = new ArrayList<>();
-				//有多少个市,市有多少个商家
-				for (Long citykey : cityMap.keySet()) {
-					for (TArea area : list1) {
-
-					  String fullName = area.getFullName();
-					  if(fullName.substring(0,3).equals(map1.get(key))){
-							//市级
-							Children2 children2 = new Children2();
-							//市级下所有商家集合
-							List<Child> Children = new ArrayList<>();
-							//属于这个市的所以设备的areaid
-							Set<Long> city = new HashSet<>();
-						  		//添加市级
-								if((area.getId()).equals(citykey)||(area.getParent()).equals(citykey)){
-									children2.setId(citykey);
-									for (TArea cityArea2 : list1) {
-										if((cityArea2.getId()).equals(citykey)||(cityArea2.getParent()).equals(citykey)){
-											city.add(cityArea2.getId());
-										}
-									}
-									children2.setCity(city);
-									int i = 0;
-									for(Children2 children21:children2List){
-										if(children21.getId().equals(citykey)){
-											i++;
-										}
-									}
-									if(i==0){
-										for(Long id:city){
-											List<Childlast> childlasts = new ArrayList<>();
-
-											List<TEquipment> equipments =tEquipmentMapper.findByArea(id);
-											TAdmin tAdmin = tAdminService.selectEntityById(equipments.get(0).getAdminId());
-											int k = 0;
-											for(Child child:Children){
-												if(child.getId().equals(tAdmin.getId())){
-													k++;
-												}
-											}
-											if(k==0){
-												//商家的机器
-												Child child =new Child();
-												child.setId(tAdmin.getId());
-												child.setName(tAdmin.getName());
-												Childlast childlast1 = new Childlast();
-												childlast1.setId(tAdmin.getId());
-												childlast1.setName("总销售情况");
-												Long adminId  = tAdmin.getId();
-												List<TEquipment> tEquipmentList=tEquipmentMapper.findByAdmin(adminId);
-												for(TEquipment tEquipment:tEquipmentList){
-													int j =0;
-													for(Long id1:city){
-														Long areaId=tEquipment.getAreaId();
-														if(areaId!=null&&areaId.equals(id1)){
-															j++;
-														}
-													}
-													if(j>0){
-														Childlast childlast2 = new Childlast();
-														childlast2.setId(tEquipment.getId());
-														childlast2.setName(tEquipment.getName());
-														childlasts.add(childlast2);
-													}
-												}
-												if(childlasts!=null){
-													childlasts.add(0,childlast1);
-												}
-												child.setChildren(childlasts);
-												Children.add(child);
-											}
-
-										}
-										children2.setChildren(Children);
-										//这个市的销售数据  日 周 月 年
-										List<Long> cityIds = new ArrayList();
-										for(Long cityid:city){
-											cityIds.add(cityid);
-										}
-										StringBuffer namelast = new StringBuffer();
-										namelast.append(cityMap.get(citykey)).append("  ");
-										String day = "";
-										String week = "";
-										String month = "";
-										String year = "";
-										//数据为空时要处理
-										for(int s=1;s<5;s++){
-											String startDate = null;
-											String endDate = null;
-											if(s==1){
-												//日
-												Date date = new Date();
-												SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy/MM/dd");
-												String format = dateFormat.format(date);
-												startDate = format;
-												endDate = format;
-												Map<String, Object> params = new HashMap<String, Object>();
-												params.put("areaIds",cityIds);
-												params.put("startDate",startDate);
-												params.put("endDate",endDate);
-												Double day1 = tOrderServiceInterface.getAreaPrice(params);
-													if(day1!=null){
-														double ceil = Math.ceil(day1);
-														int ceil1 = (int) ceil;
-														pday +=ceil1;
-														day = String.valueOf(ceil1);
-														namelast.append("-----日:").append(day);
-													}else{
-														namelast.append("-----日:0 ");
-													}
-											}
-											if(s==2){
-												//周
-												Map<String, String> weekDate = getWeekDate();
-												startDate = weekDate.get("mondayDate");
-												endDate = weekDate.get("sundayDate");
-												Map<String, Object> params = new HashMap<String, Object>();
-												params.put("areaIds",cityIds);
-												params.put("startDate",startDate);
-												params.put("endDate",endDate);
-												Double day1 = tOrderServiceInterface.getAreaPrice(params);
-												if(day1!=null){
-													double ceil = Math.ceil(day1);
-													int ceil1 = (int) ceil;
-													pweek +=ceil1;
-													week = String.valueOf(ceil1);
-													namelast.append(" 周:").append(week);
-												}else{
-													namelast.append(" 周:0 ");
-												}
-											}
-											if(s==3){
-												//月
-												SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy/MM/dd");
-												//获取当前月第一天:
-												Calendar c = Calendar.getInstance();
-												c.add(Calendar.MONTH, 0);
-												c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
-												String first = dateFormat.format(c.getTime());
-												//获取当前月最后一天
-												Calendar ca = Calendar.getInstance();
-												ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
-												String last = dateFormat.format(ca.getTime());
-												startDate = first;
-												endDate = last;
-												Map<String, Object> params = new HashMap<String, Object>();
-												params.put("areaIds",cityIds);
-												params.put("startDate",startDate);
-												params.put("endDate",endDate);
-												Double day1 = tOrderServiceInterface.getAreaPrice(params);
-												if(day1!=null){
-													double ceil = Math.ceil(day1);
-													int ceil1 = (int) ceil;
-													pmonth+=ceil1;
-													month = String.valueOf(ceil1);
-													namelast.append(" 月:").append(month);
-												}else{
-													namelast.append(" 月:0 ");
-												}
-											}
-											if(s==4){
-												//年
-												SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy/MM/dd");
-												Calendar cale = Calendar.getInstance();
-												int year1 = cale.get(Calendar.YEAR);
-												String y = String.valueOf(year1);
-												StringBuffer st = new StringBuffer();
-												st.append(y).append("/01/01");
-												startDate = st.toString();
-												StringBuffer e = new StringBuffer();
-												e.append(y).append("/12/30");
-												endDate = e.toString();
-												Map<String, Object> params = new HashMap<String, Object>();
-												params.put("areaIds",cityIds);
-												params.put("startDate",startDate);
-												params.put("endDate",endDate);
-												Double day1 = tOrderServiceInterface.getAreaPrice(params);
-												if(day1!=null){
-													double ceil = Math.ceil(day1);
-													int ceil1 = (int) ceil;
-													pyear +=ceil1;
-													year = String.valueOf(ceil1);
-													namelast.append(" 年:").append(year);
-												}else{
-													namelast.append(" 年:0 ");
-												}
-											}
-										}
-										children2.setName(namelast.toString());
-										children2List.add(children2);
-									}else{
-										i=0;
-									}
-								}
-						}
-					}
-				}
-				children3.setChildren(children2List);
-				children3.setProvince(province);
-
-				StringBuffer pnameLast = new StringBuffer();
-				pnameLast.append(map1.get(key)).append("-----日:").append(pday).append(" 周:").append(pweek).append(" 月:").append(pmonth).append(" 年:").append(pyear);
-				children3.setName(pnameLast.toString());
-				children3List.add(children3);
-
-			}
-			return ResponseEntity.status(HttpStatus.OK)
-					.body(new ResultMessage().setCode(true).setData(children3List).setMessage("SUCCESS"));
-
-		}else{ // 只查当前商家的设备列表
-			return ResponseEntity.status(HttpStatus.OK)
-					.body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
-		}
+                int pday = 0;
+                int pweek = 0;
+                int pmonth = 0;
+                int pyear = 0;
+                Set<Long> province = new HashSet<>();
+                //本省有多少个市
+                Map<Long, String> cityMap = new HashMap<>();
+                for (TArea carea : list1) {
+                    String fullName = carea.getFullName();
+                    if (fullName.substring(0, 3).equals(map1.get(key))) {
+                        province.add(carea.getId());
+                        if (key.equals(carea.getParent())) {
+                            cityMap.put(carea.getId(), carea.getName());
+                        } else {
+                            TArea cityArea = tAreaServiceInterface.selectEntityById(carea.getParent());
+                            cityMap.put(cityArea.getId(), cityArea.getName());
+                        }
+                    }
+                }
+                List<Children2> children2List = new ArrayList<>();
+                //有多少个市,市有多少个商家
+                for (Long citykey : cityMap.keySet()) {
+                    for (TArea area : list1) {
+
+                        String fullName = area.getFullName();
+                        if (fullName.substring(0, 3).equals(map1.get(key))) {
+                            //市级
+                            Children2 children2 = new Children2();
+                            //市级下所有商家集合
+                            List<Child> Children = new ArrayList<>();
+                            //属于这个市的所以设备的areaid
+                            Set<Long> city = new HashSet<>();
+                            //添加市级
+                            if ((area.getId()).equals(citykey) || (area.getParent()).equals(citykey)) {
+                                children2.setId(citykey);
+                                for (TArea cityArea2 : list1) {
+                                    if ((cityArea2.getId()).equals(citykey) || (cityArea2.getParent()).equals(citykey)) {
+                                        city.add(cityArea2.getId());
+                                    }
+                                }
+                                children2.setCity(city);
+                                int i = 0;
+                                for (Children2 children21 : children2List) {
+                                    if (children21.getId().equals(citykey)) {
+                                        i++;
+                                    }
+                                }
+                                if (i == 0) {
+                                    for (Long id : city) {
+//                                        List<Childlast> childlasts = new ArrayList<>();
+                                        Set<Long> adminIds = new HashSet<>();
+                                        List<TEquipment> equipments = tEquipmentMapper.findByArea(id);
+                                        for (TEquipment tEquipment : equipments) {
+                                            adminIds.add(tEquipment.getAdminId());
+                                        }
+                                        for (Long adminId3 : adminIds) {
+                                            TAdmin tAdmin = tAdminService.selectEntityById(adminId3);
+                                            int k = 0;
+                                            for (Child child : Children) {
+                                                if (child.getId().equals(tAdmin.getId())) {
+                                                    k++;
+                                                }
+                                            }
+                                            if (k == 0) {
+                                                //new
+                                                Child child = new Child();
+                                                child.setId(adminId3);
+                                                child.setName(tAdmin.getName());
+
+                                                List<Childlast> children = new ArrayList<>();
+                                                Childlast childlast1 = new Childlast();
+                                                childlast1.setId(adminId3);
+                                                childlast1.setName("总销售情况");
+                                                children.add(0, childlast1);
+
+                                                List<TEquipment> tEquipmentList = tEquipmentMapper.findByAdmin(adminId3);
+                                                for (TEquipment tEquipment : tEquipmentList) {
+                                                    Long areaId = tEquipment.getAreaId();
+                                                    for (Long idd : city) {
+                                                        if (idd.equals(areaId)) {
+                                                            Childlast childlast2 = new Childlast();
+                                                            childlast2.setId(tEquipment.getId());
+                                                            childlast2.setName(tEquipment.getName());
+                                                            children.add(childlast2);
+                                                        }
+                                                    }
+                                                }
+
+                                                child.setChildren(children);
+                                                Children.add(child);
+                                            }
+
+                                        }
+                                    }
+                                    children2.setChildren(Children);
+                                    //这个市的销售数据  日 周 月 年
+                                    List<Long> cityIds = new ArrayList();
+                                    for (Long cityid : city) {
+                                        cityIds.add(cityid);
+                                    }
+                                    StringBuffer namelast = new StringBuffer();
+                                    namelast.append(cityMap.get(citykey)).append("  ");
+                                    String day = "";
+                                    String week = "";
+                                    String month = "";
+                                    String year = "";
+                                    //数据为空时要处理
+                                    for (int s = 1; s < 5; s++) {
+                                        String startDate = null;
+                                        String endDate = null;
+                                        if (s == 1) {
+                                            //日
+                                            Date date = new Date();
+                                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
+                                            String format = dateFormat.format(date);
+                                            startDate = format;
+                                            endDate = format;
+                                            Map<String, Object> params = new HashMap<String, Object>();
+                                            params.put("areaIds", cityIds);
+                                            params.put("startDate", startDate);
+                                            params.put("endDate", endDate);
+                                            Double day1 = tOrderServiceInterface.getAreaPrice(params);
+                                            if (day1 != null) {
+                                                double ceil = Math.ceil(day1);
+                                                int ceil1 = (int) ceil;
+                                                pday += ceil1;
+                                                day = String.valueOf(ceil1);
+                                                namelast.append("-----日:").append(day);
+                                            } else {
+                                                namelast.append("-----日:0 ");
+                                            }
+                                        }
+                                        if (s == 2) {
+                                            //周
+                                            Map<String, String> weekDate = getWeekDate();
+                                            startDate = weekDate.get("mondayDate");
+                                            endDate = weekDate.get("sundayDate");
+                                            Map<String, Object> params = new HashMap<String, Object>();
+                                            params.put("areaIds", cityIds);
+                                            params.put("startDate", startDate);
+                                            params.put("endDate", endDate);
+                                            Double day1 = tOrderServiceInterface.getAreaPrice(params);
+                                            if (day1 != null) {
+                                                double ceil = Math.ceil(day1);
+                                                int ceil1 = (int) ceil;
+                                                pweek += ceil1;
+                                                week = String.valueOf(ceil1);
+                                                namelast.append(" 周:").append(week);
+                                            } else {
+                                                namelast.append(" 周:0 ");
+                                            }
+                                        }
+                                        if (s == 3) {
+                                            //月
+                                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
+                                            //获取当前月第一天:
+                                            Calendar c = Calendar.getInstance();
+                                            c.add(Calendar.MONTH, 0);
+                                            c.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
+                                            String first = dateFormat.format(c.getTime());
+                                            //获取当前月最后一天
+                                            Calendar ca = Calendar.getInstance();
+                                            ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
+                                            String last = dateFormat.format(ca.getTime());
+                                            startDate = first;
+                                            endDate = last;
+                                            Map<String, Object> params = new HashMap<String, Object>();
+                                            params.put("areaIds", cityIds);
+                                            params.put("startDate", startDate);
+                                            params.put("endDate", endDate);
+                                            Double day1 = tOrderServiceInterface.getAreaPrice(params);
+                                            if (day1 != null) {
+                                                double ceil = Math.ceil(day1);
+                                                int ceil1 = (int) ceil;
+                                                pmonth += ceil1;
+                                                month = String.valueOf(ceil1);
+                                                namelast.append(" 月:").append(month);
+                                            } else {
+                                                namelast.append(" 月:0 ");
+                                            }
+                                        }
+                                        if (s == 4) {
+                                            //年
+                                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
+                                            Calendar cale = Calendar.getInstance();
+                                            int year1 = cale.get(Calendar.YEAR);
+                                            String y = String.valueOf(year1);
+                                            StringBuffer st = new StringBuffer();
+                                            st.append(y).append("/01/01");
+                                            startDate = st.toString();
+                                            StringBuffer e = new StringBuffer();
+                                            e.append(y).append("/12/30");
+                                            endDate = e.toString();
+                                            Map<String, Object> params = new HashMap<String, Object>();
+                                            params.put("areaIds", cityIds);
+                                            params.put("startDate", startDate);
+                                            params.put("endDate", endDate);
+                                            Double day1 = tOrderServiceInterface.getAreaPrice(params);
+                                            if (day1 != null) {
+                                                double ceil = Math.ceil(day1);
+                                                int ceil1 = (int) ceil;
+                                                pyear += ceil1;
+                                                year = String.valueOf(ceil1);
+                                                namelast.append(" 年:").append(year);
+                                            } else {
+                                                namelast.append(" 年:0 ");
+                                            }
+                                        }
+                                    }
+                                    children2.setName(namelast.toString());
+                                    children2List.add(children2);
+                                } else {
+                                    i = 0;
+                                }
+                            }
+                        }
+                    }
+                }
+                children3.setChildren(children2List);
+                children3.setProvince(province);
+
+                StringBuffer pnameLast = new StringBuffer();
+                pnameLast.append(map1.get(key)).append("-----日:").append(pday).append(" 周:").append(pweek).append(" 月:").append(pmonth).append(" 年:").append(pyear);
+                children3.setName(pnameLast.toString());
+                children3List.add(children3);
+
+            }
+            return ResponseEntity.status(HttpStatus.OK)
+                    .body(new ResultMessage().setCode(true).setData(children3List).setMessage("SUCCESS"));
+
+        } else { // 只查当前商家的设备列表
+            return ResponseEntity.status(HttpStatus.OK)
+                    .body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
+        }
 
 //		return ResponseEntity.status(HttpStatus.OK)
 //				.body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
 
-	}
-	public static Map<String,String> getWeekDate() {
-		Map<String,String> map = new HashMap();
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
-
-		Calendar cal = Calendar.getInstance();
-		cal.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
-		int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
-		if(dayWeek==1){
-			dayWeek = 8;
-		}
+    }
+
+    public static Map<String, String> getWeekDate() {
+        Map<String, String> map = new HashMap();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+
+        Calendar cal = Calendar.getInstance();
+        cal.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
+        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
+        if (dayWeek == 1) {
+            dayWeek = 8;
+        }
 //		System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
 
-		cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek);// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
-		Date mondayDate = cal.getTime();
-		String weekBegin = sdf.format(mondayDate);
+        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek);// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
+        Date mondayDate = cal.getTime();
+        String weekBegin = sdf.format(mondayDate);
 //		System.out.println("所在周星期一的日期:" + weekBegin);
 
 
-		cal.add(Calendar.DATE, 4 +cal.getFirstDayOfWeek());
-		Date sundayDate = cal.getTime();
-		String weekEnd = sdf.format(sundayDate);
+        cal.add(Calendar.DATE, 4 + cal.getFirstDayOfWeek());
+        Date sundayDate = cal.getTime();
+        String weekEnd = sdf.format(sundayDate);
 //		System.out.println("所在周星期日的日期:" + weekEnd);
 
-		map.put("mondayDate", weekBegin);
-		map.put("sundayDate", weekEnd);
-		return map;
-	}
+        map.put("mondayDate", weekBegin);
+        map.put("sundayDate", weekEnd);
+        return map;
+    }
 
 }