123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736 |
- /**
- * Date:2019-09-23 17:09:15
- * author:吴洪双
- */
- package com.shawn.web.controller;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.shawn.model.Bean.Child;
- import com.shawn.model.Bean.Childlast;
- import com.shawn.model.Bean.Children2;
- import com.shawn.model.Bean.Children3;
- import com.shawn.model.dto.TAdminDTO;
- import com.shawn.model.dto.TEquipmentDTO;
- import com.shawn.model.entity.*;
- import com.shawn.model.param.StatisticsParam;
- import com.shawn.model.param.TAreaParam;
- import com.shawn.repository.TAreaMapper;
- import com.shawn.repository.TEquipmentMapper;
- import com.shawn.repository.TOrderMapper;
- import com.shawn.service.interfac.*;
- import com.shawn.util.BeanUtils;
- import com.shawn.util.PushUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.*;
- import com.shawn.model.dto.ResultMessage;
- 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("/openDoor")
- public ResponseEntity<?> openDoor(@RequestBody StatisticsParam param) {
- String equipmentId = param.getEquipmentId();
- Long id = Long.valueOf(equipmentId);
- TEquipment equipment = tEquipmentService.selectEntityById(id);
- PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("openDoor", "0").toString());
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("SUCCESS"));
- }
- //查看是否远程来关机成功
- @PostMapping("/checkStatus")
- public ResponseEntity<?> checkStatus(@RequestBody StatisticsParam param) {
- String equipmentId = param.getEquipmentId();
- Long id = Long.valueOf(equipmentId);
- TEquipment equipment = tEquipmentService.selectEntityById(id);
- String network = equipment.getNetwork();
- Long nowTime2 = getNetworkTime();
- // Long nowTime2 = new Date().getTime();
- if(network!=null){
- Long old = Long.valueOf(network);
- if (nowTime2==null){
- nowTime2 = getNetworkTime();
- }
- if(nowTime2==null){
- nowTime2 = new Date().getTime();
- }
- if(nowTime2-old<15000){
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("网络良好"));
- }else {
- if(equipment.getEqeStatus()==0){
- equipment.setEqeStatus(1);
- tEquipmentService.updateById(equipment);
- }else {
- equipment.setEqeStatus(0);
- tEquipmentService.updateById(equipment);
- }
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("fail")
- .setMessage("网络不好,操作失败"));
- }
- }else {
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("该机器尚未更新系统"));
- }
- }
- public static Long getNetworkTime() {
- Long time = null;
- URL url= null;//取得资源对象http://time.tianqi.com/
- try {
- url = new URL("http://time.tianqi.com");
- URLConnection uc=url.openConnection();//生成连接对象
- uc.connect(); //发出连接
- long ld=uc.getDate(); //取得网站日期时间
- Date date=new Date(ld); //转换为标准时间对象
- time = date.getTime();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return time;
- }
- //机器睡眠
- @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("/onoffStatus")
- public ResponseEntity<?> onoffStatus(@RequestBody StatisticsParam param) {
- String equipmentId = param.getEquipmentId();
- Long id = Long.valueOf(equipmentId);
- TEquipment equipments = tEquipmentService.selectEntityById(id);
- PushUtils.push(equipments.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("SUCCESS"));
- }
- // 获取所有机器开关机状态
- @PostMapping("/equipmentStatus")
- public ResponseEntity<?> equipmentStatus(@RequestBody StatisticsParam param) {
- String adminId = param.getAdminId();
- TEquipmentExample example = new TEquipmentExample();
- TEquipmentExample.Criteria criteria = example.createCriteria();
- criteria.andAdminIdEqualTo(Long.valueOf(adminId));
- List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
- if(equipmentList.size()>0){
- for (TEquipment equipment:equipmentList) {
- PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
- }
- }
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("SUCCESS"));
- }
- //机器开关机
- @PostMapping("/onOff")
- public ResponseEntity<?> onOff(@RequestBody StatisticsParam param) {
- String equipmentId = param.getEquipmentId();
- Long id = Long.valueOf(equipmentId);
- // TEquipment equipments = tEquipmentService.selectEntityById(id);
- // PushUtils.push(equipments.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
- TEquipment equipment = tEquipmentService.selectEntityById(id);
- if (equipment == null) {
- // return ERROR_MESSAGE;
- }
- String eqeStatus = "1";
- String code = param.getAdminId();
- //开机为1,关机为0
- Integer intcode = Integer.valueOf(code);
- Integer eqeStatus1 = equipment.getEqeStatus();
- if(intcode==eqeStatus1){
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(false)
- .setData("ERROT")
- .setMessage("操作异常"));
- }
- if (code.equals("0")) {
- eqeStatus = "0";
- equipment.setEqeStatus(0);
- } else {
- equipment.setEqeStatus(1);
- }
- Long time = getNetworkTime();
- // long time = new Date().getTime();
- // PushUtils.push(equipment.getGtClientId(), String.valueOf(time), "", PushUtils.buildJson("eqeStatus", eqeStatus).toString());
- if(time==null){
- time = getNetworkTime();
- }
- if(time==null){
- time = new Date().getTime();
- }
- if(time!=null){
- // System.out.println("time=="+time);
- PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("eqeStatus", eqeStatus,String.valueOf(time),"http://time.tianqi.com").toString());
- tEquipmentService.updateById(equipment);
- }else {
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(false)
- .setData("error")
- .setMessage("error"));
- }
- 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<>();
- 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"));
- }
- //修改机器的清洗规则
- @PostMapping("/updateRule")
- public ResponseEntity<?> updateRule(@RequestBody StatisticsParam param) {
- List<TEquipment> equipmentList = new ArrayList<>();
- if(param.getEquipmentId()!=""&¶m.getEquipmentId()!=null){
- TEquipmentExample example = new TEquipmentExample();
- TEquipmentExample.Criteria criteria = example.createCriteria();
- criteria.andIdEqualTo(Long.valueOf(param.getEquipmentId()));
- equipmentList = tEquipmentService.selectByOption(example);
- }
- if(equipmentList.size()>0){
- TEquipment equipment = equipmentList.get(0);
- if(param.getRule()!=""&¶m.getRule()!=null){
- equipment.setRule(param.getRule());
- boolean b = tEquipmentService.updateById(equipment);
- if(b){
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("SUCCESS")
- .setMessage("SUCCESS"));
- }else {
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("ERROR")
- .setMessage("ERROR"));
- }
- }
- }
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(new ResultMessage()
- .setCode(true)
- .setData("")
- .setMessage(""));
- }
- 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);
- // System.out.println("所在周星期一的日期:" + weekBegin);
- 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;
- }
- }
|