123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- /*
- *
- *
- *
- */
- package com.hboxs.control.admin;
- import com.hboxs.common.Filter;
- import com.hboxs.common.Message;
- import com.hboxs.common.Pageable;
- import com.hboxs.dto.AlarmStatisticsDTO;
- import com.hboxs.dto.CleanStatisticsDTO;
- import com.hboxs.entity.*;
- import com.hboxs.entity.BaseEntity.Save;
- import com.hboxs.service.*;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.context.request.RequestAttributes;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.servlet.mvc.support.RedirectAttributes;
- import javax.annotation.Resource;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * Controller -
- */
- @Controller("indexController")
- @RequestMapping("/asl-admin/index")
- public class IndexController extends BaseController {
- @Resource(name = "adminServiceImpl")
- private AdminService adminService;
- @Resource(name = "roleServiceImpl")
- private RoleService roleService;
- @Resource(name = "globalConfigServiceImpl")
- private GlobalConfigService globalConfigService;
- @Resource(name = "equipmentServiceImpl")
- private EquipmentService equipmentService;
- @Resource(name = "cleanHistoryServiceImpl")
- private CleanHistoryService cleanHistoryService;
- @Resource(name = "alarmRecordServiceImpl")
- private AlarmRecordService alarmRecordService;
- /**
- *今日人流量
- */
- @RequestMapping(value = "/peopleCounting", method = RequestMethod.GET)
- public Integer peopleCounting(ModelMap model , RedirectAttributes redirectAttributes) {
- int number = 0;
- Admin admin = adminService.getCurrent();
- List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
- for(Equipment equipment:equipmentList){
- //今日人流量
- if(equipment.getPeopleCounting()!=null){
- number+=equipment.getPeopleCounting();
- }
- }
- model.addAttribute("peopleCounting", number);
- return number;
- }
- /**
- *机器启动数量/机器总数量
- */
- @RequestMapping(value = "/equipmentNumber", method = RequestMethod.GET)
- public Map<String,Integer> equipmentNumber(ModelMap model , RedirectAttributes redirectAttributes) {
- Map<String,Integer> map = new HashMap<>();
- Admin admin = adminService.getCurrent();
- List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
- int on = 0;
- for(Equipment equipment:equipmentList){
- //开启的机器数量
- if(equipment.getEqeStatus()!=null&&equipment.getEqeStatus()==1){
- on++;
- }
- }
- map.put("totalNum",equipmentList.size());
- map.put("openNum",on);
- model.addAttribute("equipmentNumber", map);
- return map;
- }
- /**
- *今日定时清洗次数/随机清洗次数
- */
- @RequestMapping(value = "/cleanNumber", method = RequestMethod.GET)
- public Map<String,Integer> cleanNumber(ModelMap model , RedirectAttributes redirectAttributes) {
- Map<String,Integer> map = new HashMap<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- List<Filter> fs1 = new ArrayList<>();
- String beginEndDate = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date();
- String startToday = simpleDateFormat.format(date);
- SimpleDateFormat _format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- String endToday = _format.format(date);
- beginEndDate = startToday + " - " + endToday;
- Date begin = null;
- Date end = null;
- if (!StringUtils.isEmpty(beginEndDate)) {
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- begin = simpleDateFormat1.parse(beginEndDate.split(" - ")[0].trim());
- end = simpleDateFormat1.parse(beginEndDate.split(" - ")[1].trim());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- fs.add(Filter.eq("type", 0));
- fs.add(Filter.eq("adminId", admin.getId()));
- fs.add(Filter.geDate("createDate", begin));
- fs.add(Filter.leDate("createDate", end));
- List<CleanHistory> list1 = cleanHistoryService.findList(99999, fs, null);
- fs1.add(Filter.eq("type", 1));
- fs1.add(Filter.eq("adminId", admin.getId()));
- fs1.add(Filter.geDate("createDate", begin));
- fs1.add(Filter.leDate("createDate", end));
- List<CleanHistory> list2 = cleanHistoryService.findList(99999, fs1, null);
- int random = 0;
- if(list2!=null){
- random+=list2.size();
- }
- int regular = 0;
- if(list1!=null){
- regular+=list1.size();
- }
- map.put("random",random);
- map.put("regular",regular);
- model.addAttribute("cleanNumber", map);
- return map;
- }
- /**
- *机器的状态,温度,湿度,清洗剂的剩余用量
- */
- @RequestMapping(value = "/equipmentStatus", method = RequestMethod.GET)
- public List<Equipment> equipmentStatus(ModelMap model , RedirectAttributes redirectAttributes) {
- List<Equipment> equipmentList = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- equipmentList = equipmentService.findByAdminId(admin.getId());
- model.addAttribute("equipmentList", equipmentList);
- return equipmentList;
- }
- /**
- *机器今日的报警记录,故障处理
- */
- @RequestMapping(value = "/alarmRecordList", method = RequestMethod.GET)
- public List<AlarmRecord> alarmRecordList(ModelMap model , RedirectAttributes redirectAttributes) {
- List<AlarmRecord> alarmRecordList = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- String beginEndDate = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date();
- String startToday = simpleDateFormat.format(date);
- SimpleDateFormat _format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- String endToday = _format.format(date);
- beginEndDate = startToday + " - " + endToday;
- Date begin = null;
- Date end = null;
- if (!StringUtils.isEmpty(beginEndDate)) {
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- begin = simpleDateFormat1.parse(beginEndDate.split(" - ")[0].trim());
- end = simpleDateFormat1.parse(beginEndDate.split(" - ")[1].trim());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- fs.add(Filter.eq("adminId", admin.getId()));
- fs.add(Filter.geDate("createDate", begin));
- fs.add(Filter.leDate("createDate", end));
- alarmRecordList = alarmRecordService.findList(999, fs, null);
- return alarmRecordList;
- }
- /**
- *机器全年的使用统计
- */
- @RequestMapping(value = "/allCleanNumber", method = RequestMethod.GET)
- @ResponseBody
- public List<CleanStatisticsDTO> allCleanNumber(ModelMap model , RedirectAttributes redirectAttributes) {
- List<CleanStatisticsDTO> list = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- list = cleanHistoryService.findByTime(admin.getId());
- model.addAttribute("allCleanNumber", list);
- return list;
- }
- /**
- *机器消耗的资源,水电
- */
- @RequestMapping(value = "/consumedResources", method = RequestMethod.GET)
- public Map<String,Integer> consumedResources(String time,ModelMap model , RedirectAttributes redirectAttributes) {
- Map<String,Integer> map = new HashMap<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- fs.add(Filter.eq("adminId", admin.getId()));
- int electricity = 0;
- int water = 0;
- if(time.equals("All")){
- List<CleanHistory> cleanHistoryList = cleanHistoryService.findList(99999,fs,null);
- for(CleanHistory cleanHistory:cleanHistoryList){
- if(cleanHistory.getElectricity()!=null){
- electricity+=cleanHistory.getElectricity();
- }
- if(cleanHistory.getWater()!=null){
- water+=cleanHistory.getWater();
- }
- }
- }else if(time.length()==4){
- Date begin = null;
- Date end = null;
- begin = beginY(time);
- end = endY(time);
- fs.add(Filter.geDate("createDate", begin));
- fs.add(Filter.leDate("createDate", end));
- List<CleanHistory> list = cleanHistoryService.findList(99999, fs, null);
- for(CleanHistory cleanHistory:list){
- if(cleanHistory.getElectricity()!=null){
- electricity+=cleanHistory.getElectricity();
- }
- if(cleanHistory.getWater()!=null){
- water+=cleanHistory.getWater();
- }
- }
- }else {
- Date begin = null;
- Date end = null;
- begin = beginM(time);
- end = endM(time);
- fs.add(Filter.geDate("createDate", begin));
- fs.add(Filter.leDate("createDate", end));
- List<CleanHistory> list = cleanHistoryService.findList(99999, fs, null);
- for(CleanHistory cleanHistory:list){
- if(cleanHistory.getElectricity()!=null){
- electricity+=cleanHistory.getElectricity();
- }
- if(cleanHistory.getWater()!=null){
- water+=cleanHistory.getWater();
- }
- }
- }
- map.put("electricity",electricity);
- map.put("water",water);
- model.addAttribute("consumedResources", map);
- return map;
- }
- /**
- *报警的类型统计,问题占比
- */
- @RequestMapping(value = "/alarmRecordType", method = RequestMethod.GET)
- public List<AlarmStatisticsDTO> alarmRecordType(String time, ModelMap model , RedirectAttributes redirectAttributes) {
- List<AlarmStatisticsDTO> list = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- Date begin = null;
- Date end = null;
- if(time.equals("All")){
- }else if(time.length()==4){
- begin = beginY(time);
- end = endY(time);
- } else {
- begin = beginM(time);
- end = endM(time);
- }
- list = alarmRecordService.findByType(admin.getId(),begin,end);
- model.addAttribute("alarmRecordType", list);
- return list;
- }
- /**
- *机器故障排行
- */
- @RequestMapping(value = "/alarmRecordLine", method = RequestMethod.GET)
- public List<AlarmStatisticsDTO> alarmRecordLine(String time, ModelMap model , RedirectAttributes redirectAttributes) {
- List<AlarmStatisticsDTO> list = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- Date begin = null;
- Date end = null;
- if(time.equals("All")){
- }else if(time.length()==4){
- begin = beginY(time);
- end = endY(time);
- } else {
- begin = beginM(time);
- end = endM(time);
- }
- list = alarmRecordService.findLine(admin.getId(),begin,end);
- model.addAttribute("alarmRecordLine", list);
- return list;
- }
- /**
- *机器清洗排行
- */
- @RequestMapping(value = "/cleanLine", method = RequestMethod.GET)
- public List<AlarmStatisticsDTO> cleanLine(String time, ModelMap model , RedirectAttributes redirectAttributes) {
- List<AlarmStatisticsDTO> list = new ArrayList<>();
- Admin admin = adminService.getCurrent();
- List<Filter> fs = new ArrayList<>();
- Date begin = null;
- Date end = null;
- if(time.equals("All")){
- }else if(time.length()==4){
- begin = beginY(time);
- end = endY(time);
- } else {
- begin = beginM(time);
- end = endM(time);
- }
- list = cleanHistoryService.findLine(admin.getId(),begin,end);
- model.addAttribute("cleanLine", list);
- return list;
- }
- private Date beginY(String time) {
- Date dater = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
- Date date = null;
- try {
- date = simpleDateFormat.parse(time);
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String startToday = simpleDateFormat1.format(date);
- dater = simpleDateFormat1.parse(startToday);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return dater;
- }
- private Date endY(String time) {
- Date dater = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
- Date date = null;
- try {
- date = simpleDateFormat.parse(time);
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-12-31 23:59:59");
- String startToday = simpleDateFormat1.format(date);
- SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dater = simpleDateFormat2.parse(startToday);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return dater;
- }
- private Date beginM(String time) {
- Date dater = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
- Date date = null;
- try {
- date = simpleDateFormat.parse(time);
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String startToday = simpleDateFormat1.format(date);
- dater = simpleDateFormat1.parse(startToday);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return dater;
- }
- private Date endM(String time) {
- String[] split = time.split("-");
- int year = Integer.parseInt(split[0]);
- int month = Integer.parseInt(split[1]);
- Calendar cal = Calendar.getInstance();
- //设置年份
- cal.set(Calendar.YEAR,year);
- //设置月份
- cal.set(Calendar.MONTH, month-1);
- //获取某月最大天数
- int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
- //设置日历中月份的最大天数
- cal.set(Calendar.DAY_OF_MONTH, lastDay);
- //格式化日期
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String lastDayOfMonth = sdf.format(cal.getTime());
- Date dater = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
- Date date = null;
- try {
- date = simpleDateFormat.parse(lastDayOfMonth);
- SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- String startToday = simpleDateFormat1.format(date);
- SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dater = simpleDateFormat2.parse(startToday);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return dater;
- }
- }
|