IndexController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. *
  3. *
  4. *
  5. */
  6. package com.hboxs.control.admin;
  7. import com.hboxs.common.Filter;
  8. import com.hboxs.common.Message;
  9. import com.hboxs.common.Pageable;
  10. import com.hboxs.dto.AlarmStatisticsDTO;
  11. import com.hboxs.dto.CleanStatisticsDTO;
  12. import com.hboxs.entity.*;
  13. import com.hboxs.entity.BaseEntity.Save;
  14. import com.hboxs.service.*;
  15. import org.apache.commons.codec.digest.DigestUtils;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.ui.ModelMap;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. import org.springframework.web.context.request.RequestAttributes;
  23. import org.springframework.web.context.request.RequestContextHolder;
  24. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  25. import javax.annotation.Resource;
  26. import java.text.ParseException;
  27. import java.text.SimpleDateFormat;
  28. import java.util.*;
  29. /**
  30. * Controller -
  31. */
  32. @Controller("indexController")
  33. @RequestMapping("/asl-admin/index")
  34. public class IndexController extends BaseController {
  35. @Resource(name = "adminServiceImpl")
  36. private AdminService adminService;
  37. @Resource(name = "roleServiceImpl")
  38. private RoleService roleService;
  39. @Resource(name = "globalConfigServiceImpl")
  40. private GlobalConfigService globalConfigService;
  41. @Resource(name = "equipmentServiceImpl")
  42. private EquipmentService equipmentService;
  43. @Resource(name = "cleanHistoryServiceImpl")
  44. private CleanHistoryService cleanHistoryService;
  45. @Resource(name = "alarmRecordServiceImpl")
  46. private AlarmRecordService alarmRecordService;
  47. /**
  48. *今日人流量
  49. */
  50. @RequestMapping(value = "/peopleCounting", method = RequestMethod.GET)
  51. public Integer peopleCounting(ModelMap model , RedirectAttributes redirectAttributes) {
  52. int number = 0;
  53. Admin admin = adminService.getCurrent();
  54. List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
  55. for(Equipment equipment:equipmentList){
  56. //今日人流量
  57. if(equipment.getPeopleCounting()!=null){
  58. number+=equipment.getPeopleCounting();
  59. }
  60. }
  61. model.addAttribute("peopleCounting", number);
  62. return number;
  63. }
  64. /**
  65. *机器启动数量/机器总数量
  66. */
  67. @RequestMapping(value = "/equipmentNumber", method = RequestMethod.GET)
  68. public Map<String,Integer> equipmentNumber(ModelMap model , RedirectAttributes redirectAttributes) {
  69. Map<String,Integer> map = new HashMap<>();
  70. Admin admin = adminService.getCurrent();
  71. List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
  72. int on = 0;
  73. for(Equipment equipment:equipmentList){
  74. //开启的机器数量
  75. if(equipment.getEqeStatus()!=null&&equipment.getEqeStatus()==1){
  76. on++;
  77. }
  78. }
  79. map.put("totalNum",equipmentList.size());
  80. map.put("openNum",on);
  81. model.addAttribute("equipmentNumber", map);
  82. return map;
  83. }
  84. /**
  85. *今日定时清洗次数/随机清洗次数
  86. */
  87. @RequestMapping(value = "/cleanNumber", method = RequestMethod.GET)
  88. public Map<String,Integer> cleanNumber(ModelMap model , RedirectAttributes redirectAttributes) {
  89. Map<String,Integer> map = new HashMap<>();
  90. Admin admin = adminService.getCurrent();
  91. List<Filter> fs = new ArrayList<>();
  92. List<Filter> fs1 = new ArrayList<>();
  93. String beginEndDate = null;
  94. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  95. Date date = new Date();
  96. String startToday = simpleDateFormat.format(date);
  97. SimpleDateFormat _format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
  98. String endToday = _format.format(date);
  99. beginEndDate = startToday + " - " + endToday;
  100. Date begin = null;
  101. Date end = null;
  102. if (!StringUtils.isEmpty(beginEndDate)) {
  103. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  104. try {
  105. begin = simpleDateFormat1.parse(beginEndDate.split(" - ")[0].trim());
  106. end = simpleDateFormat1.parse(beginEndDate.split(" - ")[1].trim());
  107. } catch (ParseException e) {
  108. e.printStackTrace();
  109. }
  110. }
  111. fs.add(Filter.eq("type", 0));
  112. fs.add(Filter.eq("adminId", admin.getId()));
  113. fs.add(Filter.geDate("createDate", begin));
  114. fs.add(Filter.leDate("createDate", end));
  115. List<CleanHistory> list1 = cleanHistoryService.findList(99999, fs, null);
  116. fs1.add(Filter.eq("type", 1));
  117. fs1.add(Filter.eq("adminId", admin.getId()));
  118. fs1.add(Filter.geDate("createDate", begin));
  119. fs1.add(Filter.leDate("createDate", end));
  120. List<CleanHistory> list2 = cleanHistoryService.findList(99999, fs1, null);
  121. int random = 0;
  122. if(list2!=null){
  123. random+=list2.size();
  124. }
  125. int regular = 0;
  126. if(list1!=null){
  127. regular+=list1.size();
  128. }
  129. map.put("random",random);
  130. map.put("regular",regular);
  131. model.addAttribute("cleanNumber", map);
  132. return map;
  133. }
  134. /**
  135. *机器的状态,温度,湿度,清洗剂的剩余用量
  136. */
  137. @RequestMapping(value = "/equipmentStatus", method = RequestMethod.GET)
  138. public List<Equipment> equipmentStatus(ModelMap model , RedirectAttributes redirectAttributes) {
  139. List<Equipment> equipmentList = new ArrayList<>();
  140. Admin admin = adminService.getCurrent();
  141. equipmentList = equipmentService.findByAdminId(admin.getId());
  142. model.addAttribute("equipmentList", equipmentList);
  143. return equipmentList;
  144. }
  145. /**
  146. *机器今日的报警记录,故障处理
  147. */
  148. @RequestMapping(value = "/alarmRecordList", method = RequestMethod.GET)
  149. public List<AlarmRecord> alarmRecordList(ModelMap model , RedirectAttributes redirectAttributes) {
  150. List<AlarmRecord> alarmRecordList = new ArrayList<>();
  151. Admin admin = adminService.getCurrent();
  152. List<Filter> fs = new ArrayList<>();
  153. String beginEndDate = null;
  154. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  155. Date date = new Date();
  156. String startToday = simpleDateFormat.format(date);
  157. SimpleDateFormat _format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
  158. String endToday = _format.format(date);
  159. beginEndDate = startToday + " - " + endToday;
  160. Date begin = null;
  161. Date end = null;
  162. if (!StringUtils.isEmpty(beginEndDate)) {
  163. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  164. try {
  165. begin = simpleDateFormat1.parse(beginEndDate.split(" - ")[0].trim());
  166. end = simpleDateFormat1.parse(beginEndDate.split(" - ")[1].trim());
  167. } catch (ParseException e) {
  168. e.printStackTrace();
  169. }
  170. }
  171. fs.add(Filter.eq("adminId", admin.getId()));
  172. fs.add(Filter.geDate("createDate", begin));
  173. fs.add(Filter.leDate("createDate", end));
  174. alarmRecordList = alarmRecordService.findList(999, fs, null);
  175. return alarmRecordList;
  176. }
  177. /**
  178. *机器全年的使用统计
  179. */
  180. @RequestMapping(value = "/allCleanNumber", method = RequestMethod.GET)
  181. @ResponseBody
  182. public List<CleanStatisticsDTO> allCleanNumber(ModelMap model , RedirectAttributes redirectAttributes) {
  183. List<CleanStatisticsDTO> list = new ArrayList<>();
  184. Admin admin = adminService.getCurrent();
  185. list = cleanHistoryService.findByTime(admin.getId());
  186. model.addAttribute("allCleanNumber", list);
  187. return list;
  188. }
  189. /**
  190. *机器消耗的资源,水电
  191. */
  192. @RequestMapping(value = "/consumedResources", method = RequestMethod.GET)
  193. public Map<String,Integer> consumedResources(String time,ModelMap model , RedirectAttributes redirectAttributes) {
  194. Map<String,Integer> map = new HashMap<>();
  195. Admin admin = adminService.getCurrent();
  196. List<Filter> fs = new ArrayList<>();
  197. fs.add(Filter.eq("adminId", admin.getId()));
  198. int electricity = 0;
  199. int water = 0;
  200. if(time.equals("All")){
  201. List<CleanHistory> cleanHistoryList = cleanHistoryService.findList(99999,fs,null);
  202. for(CleanHistory cleanHistory:cleanHistoryList){
  203. if(cleanHistory.getElectricity()!=null){
  204. electricity+=cleanHistory.getElectricity();
  205. }
  206. if(cleanHistory.getWater()!=null){
  207. water+=cleanHistory.getWater();
  208. }
  209. }
  210. }else if(time.length()==4){
  211. Date begin = null;
  212. Date end = null;
  213. begin = beginY(time);
  214. end = endY(time);
  215. fs.add(Filter.geDate("createDate", begin));
  216. fs.add(Filter.leDate("createDate", end));
  217. List<CleanHistory> list = cleanHistoryService.findList(99999, fs, null);
  218. for(CleanHistory cleanHistory:list){
  219. if(cleanHistory.getElectricity()!=null){
  220. electricity+=cleanHistory.getElectricity();
  221. }
  222. if(cleanHistory.getWater()!=null){
  223. water+=cleanHistory.getWater();
  224. }
  225. }
  226. }else {
  227. Date begin = null;
  228. Date end = null;
  229. begin = beginM(time);
  230. end = endM(time);
  231. fs.add(Filter.geDate("createDate", begin));
  232. fs.add(Filter.leDate("createDate", end));
  233. List<CleanHistory> list = cleanHistoryService.findList(99999, fs, null);
  234. for(CleanHistory cleanHistory:list){
  235. if(cleanHistory.getElectricity()!=null){
  236. electricity+=cleanHistory.getElectricity();
  237. }
  238. if(cleanHistory.getWater()!=null){
  239. water+=cleanHistory.getWater();
  240. }
  241. }
  242. }
  243. map.put("electricity",electricity);
  244. map.put("water",water);
  245. model.addAttribute("consumedResources", map);
  246. return map;
  247. }
  248. /**
  249. *报警的类型统计,问题占比
  250. */
  251. @RequestMapping(value = "/alarmRecordType", method = RequestMethod.GET)
  252. public List<AlarmStatisticsDTO> alarmRecordType(String time, ModelMap model , RedirectAttributes redirectAttributes) {
  253. List<AlarmStatisticsDTO> list = new ArrayList<>();
  254. Admin admin = adminService.getCurrent();
  255. List<Filter> fs = new ArrayList<>();
  256. Date begin = null;
  257. Date end = null;
  258. if(time.equals("All")){
  259. }else if(time.length()==4){
  260. begin = beginY(time);
  261. end = endY(time);
  262. } else {
  263. begin = beginM(time);
  264. end = endM(time);
  265. }
  266. list = alarmRecordService.findByType(admin.getId(),begin,end);
  267. model.addAttribute("alarmRecordType", list);
  268. return list;
  269. }
  270. /**
  271. *机器故障排行
  272. */
  273. @RequestMapping(value = "/alarmRecordLine", method = RequestMethod.GET)
  274. public List<AlarmStatisticsDTO> alarmRecordLine(String time, ModelMap model , RedirectAttributes redirectAttributes) {
  275. List<AlarmStatisticsDTO> list = new ArrayList<>();
  276. Admin admin = adminService.getCurrent();
  277. List<Filter> fs = new ArrayList<>();
  278. Date begin = null;
  279. Date end = null;
  280. if(time.equals("All")){
  281. }else if(time.length()==4){
  282. begin = beginY(time);
  283. end = endY(time);
  284. } else {
  285. begin = beginM(time);
  286. end = endM(time);
  287. }
  288. list = alarmRecordService.findLine(admin.getId(),begin,end);
  289. model.addAttribute("alarmRecordLine", list);
  290. return list;
  291. }
  292. /**
  293. *机器清洗排行
  294. */
  295. @RequestMapping(value = "/cleanLine", method = RequestMethod.GET)
  296. public List<AlarmStatisticsDTO> cleanLine(String time, ModelMap model , RedirectAttributes redirectAttributes) {
  297. List<AlarmStatisticsDTO> list = new ArrayList<>();
  298. Admin admin = adminService.getCurrent();
  299. List<Filter> fs = new ArrayList<>();
  300. Date begin = null;
  301. Date end = null;
  302. if(time.equals("All")){
  303. }else if(time.length()==4){
  304. begin = beginY(time);
  305. end = endY(time);
  306. } else {
  307. begin = beginM(time);
  308. end = endM(time);
  309. }
  310. list = cleanHistoryService.findLine(admin.getId(),begin,end);
  311. model.addAttribute("cleanLine", list);
  312. return list;
  313. }
  314. private Date beginY(String time) {
  315. Date dater = null;
  316. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
  317. Date date = null;
  318. try {
  319. date = simpleDateFormat.parse(time);
  320. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  321. String startToday = simpleDateFormat1.format(date);
  322. dater = simpleDateFormat1.parse(startToday);
  323. } catch (ParseException e) {
  324. e.printStackTrace();
  325. }
  326. return dater;
  327. }
  328. private Date endY(String time) {
  329. Date dater = null;
  330. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
  331. Date date = null;
  332. try {
  333. date = simpleDateFormat.parse(time);
  334. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-12-31 23:59:59");
  335. String startToday = simpleDateFormat1.format(date);
  336. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  337. dater = simpleDateFormat2.parse(startToday);
  338. } catch (ParseException e) {
  339. e.printStackTrace();
  340. }
  341. return dater;
  342. }
  343. private Date beginM(String time) {
  344. Date dater = null;
  345. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
  346. Date date = null;
  347. try {
  348. date = simpleDateFormat.parse(time);
  349. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  350. String startToday = simpleDateFormat1.format(date);
  351. dater = simpleDateFormat1.parse(startToday);
  352. } catch (ParseException e) {
  353. e.printStackTrace();
  354. }
  355. return dater;
  356. }
  357. private Date endM(String time) {
  358. String[] split = time.split("-");
  359. int year = Integer.parseInt(split[0]);
  360. int month = Integer.parseInt(split[1]);
  361. Calendar cal = Calendar.getInstance();
  362. //设置年份
  363. cal.set(Calendar.YEAR,year);
  364. //设置月份
  365. cal.set(Calendar.MONTH, month-1);
  366. //获取某月最大天数
  367. int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  368. //设置日历中月份的最大天数
  369. cal.set(Calendar.DAY_OF_MONTH, lastDay);
  370. //格式化日期
  371. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  372. String lastDayOfMonth = sdf.format(cal.getTime());
  373. Date dater = null;
  374. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
  375. Date date = null;
  376. try {
  377. date = simpleDateFormat.parse(lastDayOfMonth);
  378. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
  379. String startToday = simpleDateFormat1.format(date);
  380. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  381. dater = simpleDateFormat2.parse(startToday);
  382. } catch (ParseException e) {
  383. e.printStackTrace();
  384. }
  385. return dater;
  386. }
  387. }