TEquipmentController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /**
  2. * Date:2019-09-23 17:09:15
  3. * author:吴洪双
  4. */
  5. package com.shawn.web.controller;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9. import java.text.SimpleDateFormat;
  10. import java.util.*;
  11. import java.util.stream.Collectors;
  12. import com.shawn.model.Bean.Child;
  13. import com.shawn.model.Bean.Childlast;
  14. import com.shawn.model.Bean.Children2;
  15. import com.shawn.model.Bean.Children3;
  16. import com.shawn.model.dto.TAdminDTO;
  17. import com.shawn.model.dto.TEquipmentDTO;
  18. import com.shawn.model.entity.*;
  19. import com.shawn.model.param.StatisticsParam;
  20. import com.shawn.model.param.TAreaParam;
  21. import com.shawn.repository.TAreaMapper;
  22. import com.shawn.repository.TEquipmentMapper;
  23. import com.shawn.repository.TOrderMapper;
  24. import com.shawn.service.interfac.*;
  25. import com.shawn.util.BeanUtils;
  26. import com.shawn.util.PushUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.http.HttpStatus;
  29. import org.springframework.http.ResponseEntity;
  30. import org.springframework.web.bind.annotation.*;
  31. import com.shawn.model.dto.ResultMessage;
  32. import com.shawn.web.controller.base.BaseController;
  33. import com.shawn.model.param.TEquipmentParam;
  34. import lombok.extern.apachecommons.CommonsLog;
  35. @CommonsLog
  36. @RestController
  37. @RequestMapping("TEquipment")
  38. public class TEquipmentController extends BaseController<TEquipment, TEquipmentExample, TEquipmentParam, Long> {
  39. @Autowired
  40. private TEquipmentServiceInterface tEquipmentService;
  41. @Autowired
  42. private TAdminServiceInterface tAdminService;
  43. @Autowired
  44. private TAlarmRecordServiceInterface tAlarmRecordService;
  45. @Autowired
  46. private TAreaServiceInterface tAreaServiceInterface;
  47. @Autowired
  48. private TOrderServiceInterface tOrderServiceInterface;
  49. @Autowired
  50. private TEquipmentMapper tEquipmentMapper;
  51. @Autowired
  52. private TAreaMapper tAreaMapper;
  53. @Autowired
  54. private TOrderMapper tOrderMapper;
  55. @Autowired
  56. public TEquipmentController(TEquipmentServiceInterface service) {
  57. super(service);
  58. }
  59. @Override
  60. protected TEquipmentExample createNewExample() {
  61. return new TEquipmentExample();
  62. }
  63. @PostMapping("/getEquipmentListByUser")
  64. public ResponseEntity<?> getEquipmentListByUser(@RequestBody TAdmin param) {
  65. List<TAdminDTO> resultList = new ArrayList<>();
  66. if ("admin".equals(param.getUsername())) { // 管理员查所有商家
  67. List<TAdmin> adminList = tAdminService.selectByOption(null);
  68. List<TEquipment> equipmentList = tEquipmentService.selectByOption(null);
  69. List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(null);
  70. //获取当前用户今天所有机器的所以警报信息
  71. List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(null);
  72. resultList = adminList.stream().map(e -> {
  73. TAdminDTO dto = new TAdminDTO();
  74. BeanUtils.copyPropertiesIgnoreNull(e, dto, true);
  75. List<TEquipmentDTO> selList = equipmentList.stream()
  76. .filter(equipment -> e.getId().equals(equipment.getAdminId())) // 查对应的设备
  77. .map(equipment -> {
  78. TEquipmentDTO equipmentDTO = new TEquipmentDTO();
  79. BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
  80. Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
  81. if (op.isPresent()) {
  82. equipmentDTO.setAlarmContent(op.get().getAlarmContent());
  83. equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
  84. }
  85. //获取该机器的所有警报信息
  86. List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
  87. equipmentDTO.setAlarmList(eqAlarmList);
  88. return equipmentDTO;
  89. }).collect(Collectors.toList());
  90. dto.setEquipmentList(selList);
  91. return dto;
  92. }).collect(Collectors.toList());
  93. } else { // 只查当前商家的设备列表
  94. TAdminDTO dto = new TAdminDTO();
  95. BeanUtils.copyPropertiesIgnoreNull(param, dto, true);
  96. TEquipmentExample example = new TEquipmentExample();
  97. TEquipmentExample.Criteria criteria = example.createCriteria();
  98. criteria.andAdminIdEqualTo(param.getId());
  99. List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
  100. List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(param.getId());
  101. //获取当前用户今天所有机器的所以警报信息
  102. List<TAlarmRecord> alarmList = tAlarmRecordService.getAlarmList(param.getId());
  103. List<TEquipmentDTO> equipmentDTOList = equipmentList.stream().map(equipment -> {
  104. TEquipmentDTO equipmentDTO = new TEquipmentDTO();
  105. BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
  106. Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
  107. if (op.isPresent()) {
  108. equipmentDTO.setAlarmContent(op.get().getAlarmContent());
  109. equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
  110. }
  111. //获取该机器的所有警报信息
  112. List<TAlarmRecord> eqAlarmList = alarmList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).collect(Collectors.toList());
  113. equipmentDTO.setAlarmList(eqAlarmList);
  114. return equipmentDTO;
  115. }).collect(Collectors.toList());
  116. dto.setEquipmentList(equipmentDTOList);
  117. resultList.add(dto);
  118. }
  119. return ResponseEntity.status(HttpStatus.OK)
  120. .body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
  121. }
  122. @PostMapping("/updateName")
  123. public ResponseEntity<?> updateName(@RequestBody TEquipment equipment) {
  124. Boolean t = tEquipmentService.updateById(equipment);
  125. if (t == true) {
  126. return ResponseEntity.status(HttpStatus.OK)
  127. .body(new ResultMessage().setCode(true).setData(t).setMessage("修改成功"));
  128. } else {
  129. return ResponseEntity.status(HttpStatus.OK)
  130. .body(new ResultMessage().setCode(false).setData(t).setMessage("修改失败"));
  131. }
  132. }
  133. //根据机器id获取用户信息
  134. @PostMapping("/findByEquipment")
  135. public ResponseEntity<?> findByEquipment(@RequestBody TEquipment equipment) {
  136. TEquipment tEquipment = tEquipmentService.selectEntityById(equipment.getId());
  137. TAdmin tAdmin = tAdminService.selectEntityById(tEquipment.getAdminId());
  138. return ResponseEntity.status(HttpStatus.OK)
  139. .body(new ResultMessage().setCode(false).setData(tAdmin).setMessage(""));
  140. }
  141. //获取机器数量
  142. @PostMapping("/getMachineNum")
  143. public ResponseEntity<?> getMachineNum(@RequestBody StatisticsParam param) {
  144. String machineTotalNum = "";
  145. String machineUseNum = "";
  146. String equipmentId = param.getEquipmentId();
  147. //判断是否有机器id传入
  148. if (equipmentId != null && equipmentId != "") {
  149. Long id = Long.valueOf(equipmentId);
  150. TEquipment equipment = tEquipmentService.selectEntityById(id);
  151. Long adminId = equipment.getAdminId();
  152. String dminId = String.valueOf(adminId);
  153. param.setAdminId(dminId);
  154. machineTotalNum = tEquipmentService.findMachineTotalNum(param);
  155. machineUseNum = tEquipmentService.findMachineUseNum(param);
  156. } else {
  157. machineTotalNum = tEquipmentService.findMachineTotalNum(param);
  158. machineUseNum = tEquipmentService.findMachineUseNum(param);
  159. }
  160. List<String> list = new ArrayList<>();
  161. list.add(machineTotalNum);
  162. list.add(machineUseNum);
  163. return ResponseEntity
  164. .status(HttpStatus.OK)
  165. .body(new ResultMessage()
  166. .setCode(true)
  167. .setData(list)
  168. .setMessage("SUCCESS"));
  169. }
  170. //远程开门
  171. @PostMapping("/openDoor")
  172. public ResponseEntity<?> openDoor(@RequestBody StatisticsParam param) {
  173. String equipmentId = param.getEquipmentId();
  174. Long id = Long.valueOf(equipmentId);
  175. TEquipment equipment = tEquipmentService.selectEntityById(id);
  176. PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("openDoor", "0").toString());
  177. return ResponseEntity
  178. .status(HttpStatus.OK)
  179. .body(new ResultMessage()
  180. .setCode(true)
  181. .setData("SUCCESS")
  182. .setMessage("SUCCESS"));
  183. }
  184. //查看是否远程来关机成功
  185. @PostMapping("/checkStatus")
  186. public ResponseEntity<?> checkStatus(@RequestBody StatisticsParam param) {
  187. String equipmentId = param.getEquipmentId();
  188. Long id = Long.valueOf(equipmentId);
  189. TEquipment equipment = tEquipmentService.selectEntityById(id);
  190. String network = equipment.getNetwork();
  191. Long nowTime2 = getNetworkTime();
  192. // Long nowTime2 = new Date().getTime();
  193. if(network!=null){
  194. Long old = Long.valueOf(network);
  195. if (nowTime2==null){
  196. nowTime2 = getNetworkTime();
  197. }
  198. if(nowTime2==null){
  199. nowTime2 = new Date().getTime();
  200. }
  201. if(nowTime2-old<15000){
  202. return ResponseEntity
  203. .status(HttpStatus.OK)
  204. .body(new ResultMessage()
  205. .setCode(true)
  206. .setData("SUCCESS")
  207. .setMessage("网络良好"));
  208. }else {
  209. if(equipment.getEqeStatus()==0){
  210. equipment.setEqeStatus(1);
  211. tEquipmentService.updateById(equipment);
  212. }else {
  213. equipment.setEqeStatus(0);
  214. tEquipmentService.updateById(equipment);
  215. }
  216. return ResponseEntity
  217. .status(HttpStatus.OK)
  218. .body(new ResultMessage()
  219. .setCode(true)
  220. .setData("fail")
  221. .setMessage("网络不好,操作失败"));
  222. }
  223. }else {
  224. return ResponseEntity
  225. .status(HttpStatus.OK)
  226. .body(new ResultMessage()
  227. .setCode(true)
  228. .setData("SUCCESS")
  229. .setMessage("该机器尚未更新系统"));
  230. }
  231. }
  232. public static Long getNetworkTime() {
  233. Long time = null;
  234. URL url= null;//取得资源对象http://time.tianqi.com/
  235. try {
  236. url = new URL("http://time.tianqi.com");
  237. URLConnection uc=url.openConnection();//生成连接对象
  238. uc.connect(); //发出连接
  239. long ld=uc.getDate(); //取得网站日期时间
  240. Date date=new Date(ld); //转换为标准时间对象
  241. time = date.getTime();
  242. } catch (Exception e) {
  243. e.printStackTrace();
  244. }
  245. return time;
  246. }
  247. //机器睡眠
  248. @PostMapping("/sleep")
  249. public ResponseEntity<?> sleep(@RequestBody StatisticsParam param) {
  250. String equipmentId = param.getEquipmentId();
  251. Long id = Long.valueOf(equipmentId);
  252. TEquipment equipment = tEquipmentService.selectEntityById(id);
  253. if (equipment == null) {
  254. // return ERROR_MESSAGE;
  255. }
  256. String eqeStatus = "0";
  257. String code = param.getAdminId();
  258. if (code.equals("1")) {
  259. eqeStatus = "1";
  260. equipment.setIsSleep(true);
  261. } else {
  262. equipment.setIsSleep(false);
  263. }
  264. tEquipmentService.updateById(equipment);
  265. PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("is_sleep", eqeStatus).toString());
  266. return ResponseEntity
  267. .status(HttpStatus.OK)
  268. .body(new ResultMessage()
  269. .setCode(true)
  270. .setData("SUCCESS")
  271. .setMessage("SUCCESS"));
  272. }
  273. // 获取机器开关机状态
  274. @PostMapping("/onoffStatus")
  275. public ResponseEntity<?> onoffStatus(@RequestBody StatisticsParam param) {
  276. String equipmentId = param.getEquipmentId();
  277. Long id = Long.valueOf(equipmentId);
  278. TEquipment equipments = tEquipmentService.selectEntityById(id);
  279. PushUtils.push(equipments.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
  280. return ResponseEntity
  281. .status(HttpStatus.OK)
  282. .body(new ResultMessage()
  283. .setCode(true)
  284. .setData("SUCCESS")
  285. .setMessage("SUCCESS"));
  286. }
  287. // 获取所有机器开关机状态
  288. @PostMapping("/equipmentStatus")
  289. public ResponseEntity<?> equipmentStatus(@RequestBody StatisticsParam param) {
  290. String adminId = param.getAdminId();
  291. TEquipmentExample example = new TEquipmentExample();
  292. TEquipmentExample.Criteria criteria = example.createCriteria();
  293. criteria.andAdminIdEqualTo(Long.valueOf(adminId));
  294. List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
  295. if(equipmentList.size()>0){
  296. for (TEquipment equipment:equipmentList) {
  297. PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
  298. }
  299. }
  300. return ResponseEntity
  301. .status(HttpStatus.OK)
  302. .body(new ResultMessage()
  303. .setCode(true)
  304. .setData("SUCCESS")
  305. .setMessage("SUCCESS"));
  306. }
  307. //机器开关机
  308. @PostMapping("/onOff")
  309. public ResponseEntity<?> onOff(@RequestBody StatisticsParam param) {
  310. String equipmentId = param.getEquipmentId();
  311. Long id = Long.valueOf(equipmentId);
  312. // TEquipment equipments = tEquipmentService.selectEntityById(id);
  313. // PushUtils.push(equipments.getGtClientId(), "", "", PushUtils.buildJson("onoffstatus", "0").toString());
  314. TEquipment equipment = tEquipmentService.selectEntityById(id);
  315. if (equipment == null) {
  316. // return ERROR_MESSAGE;
  317. }
  318. String eqeStatus = "1";
  319. String code = param.getAdminId();
  320. //开机为1,关机为0
  321. Integer intcode = Integer.valueOf(code);
  322. Integer eqeStatus1 = equipment.getEqeStatus();
  323. if(intcode==eqeStatus1){
  324. return ResponseEntity
  325. .status(HttpStatus.OK)
  326. .body(new ResultMessage()
  327. .setCode(false)
  328. .setData("ERROT")
  329. .setMessage("操作异常"));
  330. }
  331. if (code.equals("0")) {
  332. eqeStatus = "0";
  333. equipment.setEqeStatus(0);
  334. } else {
  335. equipment.setEqeStatus(1);
  336. }
  337. Long time = getNetworkTime();
  338. // long time = new Date().getTime();
  339. // PushUtils.push(equipment.getGtClientId(), String.valueOf(time), "", PushUtils.buildJson("eqeStatus", eqeStatus).toString());
  340. if(time==null){
  341. time = getNetworkTime();
  342. }
  343. if(time==null){
  344. time = new Date().getTime();
  345. }
  346. if(time!=null){
  347. // System.out.println("time=="+time);
  348. PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("eqeStatus", eqeStatus,String.valueOf(time),"http://time.tianqi.com").toString());
  349. tEquipmentService.updateById(equipment);
  350. }else {
  351. return ResponseEntity
  352. .status(HttpStatus.OK)
  353. .body(new ResultMessage()
  354. .setCode(false)
  355. .setData("error")
  356. .setMessage("error"));
  357. }
  358. return ResponseEntity
  359. .status(HttpStatus.OK)
  360. .body(new ResultMessage()
  361. .setCode(true)
  362. .setData("SUCCESS")
  363. .setMessage("SUCCESS"));
  364. }
  365. @PostMapping("/getEquipmentListByProvince")
  366. public ResponseEntity<?> getEquipmentListByProvince(@RequestBody TAdmin param) {
  367. List<TAdminDTO> resultList = new ArrayList<>();
  368. if ("admin".equals(param.getUsername())) { // 管理员查所有商家
  369. //获取有多少个省份
  370. List<TArea> list1 = tAreaServiceInterface.getProvinceList();
  371. Map<Long, String> map1 = new HashMap<>();
  372. for (TArea area : list1) {
  373. String fullname = area.getFullName();
  374. String provinceName = fullname.substring(0, 3);
  375. String treePath = area.getTreePath();
  376. String[] str = treePath.split(",");
  377. Long s = null;
  378. if (str.length > 1) {
  379. s = Long.valueOf(str[1]);
  380. }
  381. if (str.length <= 1) {
  382. s = area.getId();
  383. }
  384. map1.put(s, provinceName);
  385. }
  386. List<Children3> children3List = new ArrayList<>();
  387. for (Long key : map1.keySet()) {
  388. Children3 children3 = new Children3();
  389. children3.setId(key);
  390. // children3.setName(map1.get(key));
  391. int pday = 0;
  392. int pweek = 0;
  393. int pmonth = 0;
  394. int pyear = 0;
  395. Set<Long> province = new HashSet<>();
  396. //本省有多少个市
  397. Map<Long, String> cityMap = new HashMap<>();
  398. for (TArea carea : list1) {
  399. String fullName = carea.getFullName();
  400. if (fullName.substring(0, 3).equals(map1.get(key))) {
  401. province.add(carea.getId());
  402. if (key.equals(carea.getParent())) {
  403. cityMap.put(carea.getId(), carea.getName());
  404. } else {
  405. TArea cityArea = tAreaServiceInterface.selectEntityById(carea.getParent());
  406. cityMap.put(cityArea.getId(), cityArea.getName());
  407. }
  408. }
  409. }
  410. List<Children2> children2List = new ArrayList<>();
  411. //有多少个市,市有多少个商家
  412. for (Long citykey : cityMap.keySet()) {
  413. for (TArea area : list1) {
  414. String fullName = area.getFullName();
  415. if (fullName.substring(0, 3).equals(map1.get(key))) {
  416. //市级
  417. Children2 children2 = new Children2();
  418. //市级下所有商家集合
  419. List<Child> Children = new ArrayList<>();
  420. //属于这个市的所以设备的areaid
  421. Set<Long> city = new HashSet<>();
  422. //添加市级
  423. if ((area.getId()).equals(citykey) || (area.getParent()).equals(citykey)) {
  424. children2.setId(citykey);
  425. for (TArea cityArea2 : list1) {
  426. if ((cityArea2.getId()).equals(citykey) || (cityArea2.getParent()).equals(citykey)) {
  427. city.add(cityArea2.getId());
  428. }
  429. }
  430. children2.setCity(city);
  431. int i = 0;
  432. for (Children2 children21 : children2List) {
  433. if (children21.getId().equals(citykey)) {
  434. i++;
  435. }
  436. }
  437. if (i == 0) {
  438. for (Long id : city) {
  439. // List<Childlast> childlasts = new ArrayList<>();
  440. Set<Long> adminIds = new HashSet<>();
  441. List<TEquipment> equipments = tEquipmentMapper.findByArea(id);
  442. for (TEquipment tEquipment : equipments) {
  443. adminIds.add(tEquipment.getAdminId());
  444. }
  445. for (Long adminId3 : adminIds) {
  446. TAdmin tAdmin = tAdminService.selectEntityById(adminId3);
  447. int k = 0;
  448. for (Child child : Children) {
  449. if (child.getId().equals(tAdmin.getId())) {
  450. k++;
  451. }
  452. }
  453. if (k == 0) {
  454. //new
  455. Child child = new Child();
  456. child.setId(adminId3);
  457. child.setName(tAdmin.getName());
  458. List<Childlast> children = new ArrayList<>();
  459. Childlast childlast1 = new Childlast();
  460. childlast1.setId(adminId3);
  461. childlast1.setName("总销售情况");
  462. children.add(0, childlast1);
  463. List<TEquipment> tEquipmentList = tEquipmentMapper.findByAdmin(adminId3);
  464. for (TEquipment tEquipment : tEquipmentList) {
  465. Long areaId = tEquipment.getAreaId();
  466. for (Long idd : city) {
  467. if (idd.equals(areaId)) {
  468. Childlast childlast2 = new Childlast();
  469. childlast2.setId(tEquipment.getId());
  470. childlast2.setName(tEquipment.getName());
  471. children.add(childlast2);
  472. }
  473. }
  474. }
  475. child.setChildren(children);
  476. Children.add(child);
  477. }
  478. }
  479. }
  480. children2.setChildren(Children);
  481. //这个市的销售数据 日 周 月 年
  482. List<Long> cityIds = new ArrayList();
  483. for (Long cityid : city) {
  484. cityIds.add(cityid);
  485. }
  486. StringBuffer namelast = new StringBuffer();
  487. namelast.append(cityMap.get(citykey)).append(" ");
  488. String day = "";
  489. String week = "";
  490. String month = "";
  491. String year = "";
  492. //数据为空时要处理
  493. for (int s = 1; s < 5; s++) {
  494. String startDate = null;
  495. String endDate = null;
  496. if (s == 1) {
  497. //日
  498. Date date = new Date();
  499. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
  500. String format = dateFormat.format(date);
  501. startDate = format;
  502. endDate = format;
  503. Map<String, Object> params = new HashMap<String, Object>();
  504. params.put("areaIds", cityIds);
  505. params.put("startDate", startDate);
  506. params.put("endDate", endDate);
  507. Double day1 = tOrderServiceInterface.getAreaPrice(params);
  508. if (day1 != null) {
  509. double ceil = Math.ceil(day1);
  510. int ceil1 = (int) ceil;
  511. pday += ceil1;
  512. day = String.valueOf(ceil1);
  513. namelast.append("-----日:").append(day);
  514. } else {
  515. namelast.append("-----日:0 ");
  516. }
  517. }
  518. if (s == 2) {
  519. //周
  520. Map<String, String> weekDate = getWeekDate();
  521. startDate = weekDate.get("mondayDate");
  522. endDate = weekDate.get("sundayDate");
  523. Map<String, Object> params = new HashMap<String, Object>();
  524. params.put("areaIds", cityIds);
  525. params.put("startDate", startDate);
  526. params.put("endDate", endDate);
  527. Double day1 = tOrderServiceInterface.getAreaPrice(params);
  528. if (day1 != null) {
  529. double ceil = Math.ceil(day1);
  530. int ceil1 = (int) ceil;
  531. pweek += ceil1;
  532. week = String.valueOf(ceil1);
  533. namelast.append(" 周:").append(week);
  534. } else {
  535. namelast.append(" 周:0 ");
  536. }
  537. }
  538. if (s == 3) {
  539. //月
  540. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
  541. //获取当前月第一天:
  542. Calendar c = Calendar.getInstance();
  543. c.add(Calendar.MONTH, 0);
  544. c.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
  545. String first = dateFormat.format(c.getTime());
  546. //获取当前月最后一天
  547. Calendar ca = Calendar.getInstance();
  548. ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
  549. String last = dateFormat.format(ca.getTime());
  550. startDate = first;
  551. endDate = last;
  552. Map<String, Object> params = new HashMap<String, Object>();
  553. params.put("areaIds", cityIds);
  554. params.put("startDate", startDate);
  555. params.put("endDate", endDate);
  556. Double day1 = tOrderServiceInterface.getAreaPrice(params);
  557. if (day1 != null) {
  558. double ceil = Math.ceil(day1);
  559. int ceil1 = (int) ceil;
  560. pmonth += ceil1;
  561. month = String.valueOf(ceil1);
  562. namelast.append(" 月:").append(month);
  563. } else {
  564. namelast.append(" 月:0 ");
  565. }
  566. }
  567. if (s == 4) {
  568. //年
  569. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
  570. Calendar cale = Calendar.getInstance();
  571. int year1 = cale.get(Calendar.YEAR);
  572. String y = String.valueOf(year1);
  573. StringBuffer st = new StringBuffer();
  574. st.append(y).append("/01/01");
  575. startDate = st.toString();
  576. StringBuffer e = new StringBuffer();
  577. e.append(y).append("/12/30");
  578. endDate = e.toString();
  579. Map<String, Object> params = new HashMap<String, Object>();
  580. params.put("areaIds", cityIds);
  581. params.put("startDate", startDate);
  582. params.put("endDate", endDate);
  583. Double day1 = tOrderServiceInterface.getAreaPrice(params);
  584. if (day1 != null) {
  585. double ceil = Math.ceil(day1);
  586. int ceil1 = (int) ceil;
  587. pyear += ceil1;
  588. year = String.valueOf(ceil1);
  589. namelast.append(" 年:").append(year);
  590. } else {
  591. namelast.append(" 年:0 ");
  592. }
  593. }
  594. }
  595. children2.setName(namelast.toString());
  596. children2List.add(children2);
  597. } else {
  598. i = 0;
  599. }
  600. }
  601. }
  602. }
  603. }
  604. children3.setChildren(children2List);
  605. children3.setProvince(province);
  606. StringBuffer pnameLast = new StringBuffer();
  607. pnameLast.append(map1.get(key)).append("-----日:").append(pday).append(" 周:").append(pweek).append(" 月:").append(pmonth).append(" 年:").append(pyear);
  608. children3.setName(pnameLast.toString());
  609. children3List.add(children3);
  610. }
  611. return ResponseEntity.status(HttpStatus.OK)
  612. .body(new ResultMessage().setCode(true).setData(children3List).setMessage("SUCCESS"));
  613. } else { // 只查当前商家的设备列表
  614. return ResponseEntity.status(HttpStatus.OK)
  615. .body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
  616. }
  617. // return ResponseEntity.status(HttpStatus.OK)
  618. // .body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
  619. }
  620. //修改机器的清洗规则
  621. @PostMapping("/updateRule")
  622. public ResponseEntity<?> updateRule(@RequestBody StatisticsParam param) {
  623. List<TEquipment> equipmentList = new ArrayList<>();
  624. if(param.getEquipmentId()!=""&&param.getEquipmentId()!=null){
  625. TEquipmentExample example = new TEquipmentExample();
  626. TEquipmentExample.Criteria criteria = example.createCriteria();
  627. criteria.andIdEqualTo(Long.valueOf(param.getEquipmentId()));
  628. equipmentList = tEquipmentService.selectByOption(example);
  629. }
  630. if(equipmentList.size()>0){
  631. TEquipment equipment = equipmentList.get(0);
  632. if(param.getRule()!=""&&param.getRule()!=null){
  633. equipment.setRule(param.getRule());
  634. boolean b = tEquipmentService.updateById(equipment);
  635. if(b){
  636. return ResponseEntity
  637. .status(HttpStatus.OK)
  638. .body(new ResultMessage()
  639. .setCode(true)
  640. .setData("SUCCESS")
  641. .setMessage("SUCCESS"));
  642. }else {
  643. return ResponseEntity
  644. .status(HttpStatus.OK)
  645. .body(new ResultMessage()
  646. .setCode(true)
  647. .setData("ERROR")
  648. .setMessage("ERROR"));
  649. }
  650. }
  651. }
  652. return ResponseEntity
  653. .status(HttpStatus.OK)
  654. .body(new ResultMessage()
  655. .setCode(true)
  656. .setData("")
  657. .setMessage(""));
  658. }
  659. public static Map<String, String> getWeekDate() {
  660. Map<String, String> map = new HashMap();
  661. SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
  662. Calendar cal = Calendar.getInstance();
  663. cal.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
  664. int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
  665. if (dayWeek == 1) {
  666. dayWeek = 8;
  667. }
  668. // System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
  669. cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek);// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
  670. Date mondayDate = cal.getTime();
  671. String weekBegin = sdf.format(mondayDate);
  672. // System.out.println("所在周星期一的日期:" + weekBegin);
  673. cal.add(Calendar.DATE, 4 + cal.getFirstDayOfWeek());
  674. Date sundayDate = cal.getTime();
  675. String weekEnd = sdf.format(sundayDate);
  676. // System.out.println("所在周星期日的日期:" + weekEnd);
  677. map.put("mondayDate", weekBegin);
  678. map.put("sundayDate", weekEnd);
  679. return map;
  680. }
  681. }