package cn.exrick.xboot.your.controller.pc; import cn.exrick.xboot.core.common.redis.RedisTemplateHelper; import cn.exrick.xboot.core.common.utils.PageUtil; import cn.exrick.xboot.core.common.utils.ResultUtil; import cn.exrick.xboot.core.common.utils.SecurityUtil; import cn.exrick.xboot.core.common.vo.PageVo; import cn.exrick.xboot.core.common.vo.Result; import cn.exrick.xboot.core.entity.User; import cn.exrick.xboot.core.service.UserService; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import cn.exrick.xboot.your.util.HaiKangPost; import cn.exrick.xboot.your.vo.AlarmVo; import cn.exrick.xboot.your.vo.PreviewURLsVo; import cn.exrick.xboot.your.vo.TalkURLsVo; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.text.SimpleDateFormat; import java.util.*; /** * @author whj */ @Slf4j @RestController @Api(tags = "大屏统计接口") @RequestMapping("/xboot/pcStatistic") @Transactional public class StatisticController { @Autowired private RedisTemplateHelper redisTemplateHelper; @Autowired private IOrderTaskService iOrderTaskService; @Autowired private IEventLogService iEventLogService; @Autowired private ICarService iCarService; @Autowired private HaiKangPost haiKangPost; @Autowired private IAreaService iAreaService; @Autowired private IAreaSectionService iAreaSectionService; @Autowired private IEquipmentService iEquipmentService; @Autowired private IAlarmService iAlarmService; @Autowired private ICustomerService iCustomerService; @Autowired private IOrderTask2Service iOrderTask2Service; @Autowired private UserService userService; @Autowired private IDuoZhengService iDuoZhengService; @RequestMapping(value = "/getLoginInfo", method = RequestMethod.GET) @ApiOperation(value = "获取登录信息") public Result getLoginInfo() { Map map = new HashMap<>(); map.put("name","实时调度"); map.put("url","indexIframe"); Map map1 = new HashMap<>(); map1.put("name","安全管理"); map1.put("url","aqglIframe"); Map map2 = new HashMap<>(); map2.put("name","配送分析"); map2.put("url","psfxIframe"); Map map3 = new HashMap<>(); map3.put("name","综合分析"); map3.put("url","zhfxIframe"); Map map4 = new HashMap<>(); map4.put("name","一户多证"); map4.put("url","yhdzIframe"); List> list = new ArrayList<>(); list.add(map); list.add(map1); list.add(map2); list.add(map3); list.add(map4); return new ResultUtil().setData(list,"登录成功"); } @RequestMapping(value = "/getIndex1", method = RequestMethod.GET) @ApiOperation(value = "获取首页数据") public Result getIndex1() { Map map = new HashMap<>(); Set scan = redisTemplateHelper.scan("*statistic1::*"); for (String str : scan) { map.put(str.substring(12),redisTemplateHelper.get(str)); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("kstatus",0); map.put("taKan",iCustomerService.count(wrapper)); return new ResultUtil().setData(map); } @RequestMapping(value = "/getTaKanList", method = RequestMethod.GET) @ApiOperation(value = "获取踏勘商户列表") public Result getTaKanList() { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("kstatus",0); return new ResultUtil().setData(iCustomerService.list(wrapper)); } @RequestMapping(value = "/getTodayTask", method = RequestMethod.GET) @ApiOperation(value = "获取今日配送任务") public Result getTodayTask(String sendTime) { //QueryWrapper wrapper2 = new QueryWrapper(); String format = ""; if(StrUtil.isNotEmpty(sendTime)){ format = sendTime; }else{ format = DateUtil.format(new Date(), "yyyy-MM-dd"); } //wrapper2.eq("a.send_date",format); //wrapper2.orderByAsc("a.seq"); List list = iOrderTaskService.list3(format); return new ResultUtil().setData(list); } @RequestMapping(value = "/getEventLog", method = RequestMethod.GET) @ApiOperation(value = "获取事件日志") public Result getEventLog() { QueryWrapper wrapper2 = new QueryWrapper(); PageVo page = new PageVo(); page.setPageNumber(1); page.setPageSize(20); page.setOrder("desc"); page.setSort("createTime"); IPage data = iEventLogService.page(PageUtil.initMpPage(page),wrapper2); return new ResultUtil().setData(data.getRecords()); } @RequestMapping(value = "/getCars", method = RequestMethod.GET) @ApiOperation(value = "获取车辆定位信息") public Result getCars() { List list = iCarService.list(); List list2 = new ArrayList<>(); for(int i=0;i().setData(JSONUtil.parseObj(latestGps)); } @RequestMapping(value = "/getAnalysis", method = RequestMethod.GET) @ApiOperation(value = "获取配送分析") public Result getAnalysis() { List list = iAreaService.list2(); for(Area area:list){ double sum = 0; int flag = 0; for(AreaSection areaSection: area.getChildren()){ sum+=areaSection.getStability(); flag++; } if(flag>0){ double v = sum / flag; area.setVariance(trans2(v)); } } return new ResultUtil().setData(list); } @RequestMapping(value = "/getAnalysisDetail", method = RequestMethod.GET) @ApiOperation(value = "获取配送分析详情") public Result getAnalysisDetail(String areaName,String selectName) { QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("name",areaName); Area one = iAreaService.getOne(wrapper); QueryWrapper wrapper2 = new QueryWrapper(); wrapper2.eq("area_id",one.getId()); wrapper2.eq("name",selectName); AreaSection one1 = iAreaSectionService.getOne(wrapper2); List list = iOrderTaskService.groupByTime(one.getId(),one1.getId()); List list1 = new ArrayList<>(); List list2 = new ArrayList<>(); List list3 = new ArrayList<>(); List list4 = new ArrayList<>(); for(OrderTask obj:list){ list1.add(obj.getCustomerName()); list2.add(Integer.valueOf(obj.getTime()/60000)); list3.add(Integer.valueOf(obj.getNum()/60000)); list4.add(Integer.valueOf(obj.getLevel()/60000)); } Map map = new HashMap<>(); map.put("name",list1); map.put("avg",list2); map.put("min",list3); map.put("max",list4); return new ResultUtil().setData(map); } @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET) @ApiOperation(value = "获取某辆车的配送情况") public Result getOrderStatus(String carNo) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("car_no",carNo); Car car = iCarService.getOne(wrapper); if(car==null){ return ResultUtil.error("车辆不存在,请先添加车辆信息"); } QueryWrapper wrapper2 = new QueryWrapper(); String format = DateUtil.format(new Date(), "yyyy-MM-dd"); wrapper2.eq("a.send_date",format); wrapper2.eq("a.car_id",car.getId()); List list = iOrderTaskService.list4(wrapper2); return new ResultUtil().setData(list); } @RequestMapping(value = "/getVideoByCarId", method = RequestMethod.GET) @ApiOperation(value = "获取视频信息 1:前置 4:车内") public Result getVideoByCarId(String carCode,int type) { QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("code",carCode); Car car = iCarService.getOne(wrapper); if(car==null){ return ResultUtil.error("车辆编号错误"); } QueryWrapper wrapper1 = new QueryWrapper<>(); wrapper1.eq("car_id",car.getId()); wrapper1.eq("type",type); Equipment one = iEquipmentService.getOne(wrapper1); if(one==null){ return ResultUtil.error("设备未找到"); } PreviewURLsVo previewURLsVo = new PreviewURLsVo(); previewURLsVo.setCameraIndexCode(one.getCode()); String s = haiKangPost.previewURLs(previewURLsVo); return new ResultUtil().setData(JSONUtil.parseObj(s)); } @RequestMapping(value = "/getYuYinByCarId", method = RequestMethod.GET) @ApiOperation(value = "获取对讲信息") public Result getYuYinByCarId(String carCode,int type,int transmode) { QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("code",carCode); Car car = iCarService.getOne(wrapper); if(car==null){ return ResultUtil.error("车辆编号错误"); } QueryWrapper wrapper1 = new QueryWrapper<>(); wrapper1.eq("car_id",car.getId()); wrapper1.eq("type",type); Equipment one = iEquipmentService.getOne(wrapper1); if(one==null){ return ResultUtil.error("设备未找到"); } TalkURLsVo talkURLsVo =new TalkURLsVo(); talkURLsVo.setCameraIndexCode(one.getCode()); talkURLsVo.setTransmode(transmode); String s = haiKangPost.talkURLs(talkURLsVo); return new ResultUtil().setData(JSONUtil.parseObj(s)); } @RequestMapping(value = "/getAlarmByCarId", method = RequestMethod.GET) @ApiOperation(value = "获取报警图片") public Result getAlarmByCarId(String alarmId) { QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("alarm_id",alarmId); Alarm alarm = iAlarmService.getOne(wrapper); if(alarm==null){ return ResultUtil.error("报警id错误"); } AlarmVo alarmVo = new AlarmVo(); alarmVo.setAlarmId(alarm.getAlarmId()); String[] s1 = alarm.getAlarmTime().split(" "); alarmVo.setAlarmTime(s1[0]+"T"+s1[1]+".000+08:00"); String s = haiKangPost.findPicturesByAlarmId(alarmVo); return new ResultUtil().setData(JSONUtil.parseObj(s)); } public double trans2(double v2){ return (double) Math.round(v2 * 100) / 100; } @RequestMapping(value = "/getYiHuDuoZheng", method = RequestMethod.GET) @ApiOperation(value = "获取配送分析详情") public Result getYiHuDuoZheng() { // List list = iCustomerService.getYiHuDuoZheng(); // Map map = new HashMap<>(); // map.put("name","一户多证"); // List childrens = new ArrayList<>(); // for(Customer c:list){ // Map map2 = new HashMap<>(); // map2.put("name",c.getName()); // // List names = new ArrayList<>(); // Map map3 = new HashMap<>(); // map3.put("name",c.getCode()); // names.add(map3); // // map2.put("children",names); // // childrens.add(map2); // } // map.put("children",childrens); List list = iDuoZhengService.getNames(); Map map = new HashMap<>(); map.put("name","一户多证"); List childrens = new ArrayList<>(); for(String c:list){ Map map2 = new HashMap<>(); map2.put("name",c); List names = new ArrayList<>(); QueryWrapper wp = new QueryWrapper<>(); wp.eq("name",c); List list1 = iDuoZhengService.list(wp); for(DuoZheng dz:list1){ Map map3 = new HashMap<>(); map3.put("name",dz.getCustomerName()); names.add(map3); } map2.put("children",names); childrens.add(map2); } map.put("children",childrens); return new ResultUtil().setData(map); } @RequestMapping(value = "/test", method = RequestMethod.GET) @ApiOperation(value = "测试接口,没用") public String test(){ List list = iOrderTaskService.list(); List list2 = new ArrayList<>(); for(OrderTask orderTask:list){ OrderTask2 orderTask2 = new OrderTask2(); BeanUtil.copyProperties(orderTask,orderTask2); if(StrUtil.isNotEmpty(orderTask.getUserId())){ orderTask2.setUserName(getUser(orderTask.getUserId())); } if(StrUtil.isNotEmpty(orderTask.getCustomerId())){ orderTask2.setCustomerName(getCustomer(orderTask.getCustomerId())); } list2.add(orderTask2); } iOrderTask2Service.saveBatch(list2); return list.size()+"ok"; } private String getUser(String id){ User user = userService.get(id); if(user!=null){ return user.getNickname(); }else{ return null; } } private String getCustomer(String id){ Customer customer = iCustomerService.getById(id); if(customer!=null){ return customer.getName(); }else{ return null; } } }