| package com.zy.asrs.wms.asrs.controller;  | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;  | 
| import com.zy.asrs.framework.common.DateUtils;  | 
| import com.zy.asrs.framework.common.R;  | 
| import com.zy.asrs.wms.asrs.entity.Loc;  | 
| import com.zy.asrs.wms.asrs.entity.TaskLog;  | 
| import com.zy.asrs.wms.asrs.entity.echart.EChartLineBean;  | 
| import com.zy.asrs.wms.asrs.entity.echart.EChartPieBean;  | 
| import com.zy.asrs.wms.asrs.entity.enums.LocStsType;  | 
| import com.zy.asrs.wms.asrs.entity.statistics.InformationTop;  | 
| import com.zy.asrs.wms.asrs.entity.statistics.ViewInOut;  | 
| import com.zy.asrs.wms.asrs.mapper.statistics.ViewInOutMapper;  | 
| import com.zy.asrs.wms.asrs.service.LocService;  | 
| import com.zy.asrs.wms.asrs.service.MatService;  | 
| import com.zy.asrs.wms.asrs.service.TaskDetlLogService;  | 
| import com.zy.asrs.wms.asrs.service.TaskLogService;  | 
| import com.zy.asrs.wms.common.annotation.CacheData;  | 
| import com.zy.asrs.wms.system.controller.BaseController;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.web.bind.annotation.PostMapping;  | 
| import org.springframework.web.bind.annotation.RequestMapping;  | 
| import org.springframework.web.bind.annotation.RestController;  | 
|   | 
| import java.text.SimpleDateFormat;  | 
| import java.util.*;  | 
|   | 
| @RestController  | 
| @RequestMapping("/api")  | 
| public class EChartController extends BaseController {  | 
|   | 
|     @Autowired  | 
|     private LocService locService;  | 
|     @Autowired  | 
|     private TaskLogService taskLogService;  | 
|     @Autowired  | 
|     private TaskDetlLogService taskDetlLogService;  | 
|     @Autowired  | 
|     private ViewInOutMapper viewInOutMapper;  | 
|     @Autowired  | 
|     private MatService matService;  | 
|   | 
|     @PostMapping("/charts/loc/use")  | 
|     @CacheData(tableName = {"man_loc"})  | 
|     public R locUse(){  | 
|         List<EChartPieBean> list = new ArrayList<>();  | 
|   | 
|         long fqty = locService.count(new LambdaQueryWrapper<Loc>().in(Loc::getLocStsId, LocStsType.F.val(), LocStsType.D.val()));  | 
|         long oqty = locService.count(new LambdaQueryWrapper<Loc>().in(Loc::getLocStsId, LocStsType.O.val()));  | 
|         long uqty = locService.count(new LambdaQueryWrapper<Loc>().in(Loc::getLocStsId, LocStsType.S.val(), LocStsType.R.val()));  | 
|         long xqty = locService.count(new LambdaQueryWrapper<Loc>().in(Loc::getLocStsId, LocStsType.X.val()));  | 
|   | 
|         EChartPieBean fbean = new EChartPieBean();  | 
|         fbean.setName("在库库位");  | 
|         fbean.setValue(fqty);  | 
|         list.add(fbean);  | 
|   | 
|         EChartPieBean obean = new EChartPieBean();  | 
|         obean.setName("空库位");  | 
|         obean.setValue(oqty);  | 
|         list.add(obean);  | 
|   | 
|         EChartPieBean ubean = new EChartPieBean();  | 
|         ubean.setName("使用库位");  | 
|         ubean.setValue(uqty);  | 
|         list.add(ubean);  | 
|   | 
|         EChartPieBean xbean = new EChartPieBean();  | 
|         xbean.setName("禁用库位");  | 
|         xbean.setValue(xqty);  | 
|         list.add(xbean);  | 
|         return R.ok(list);  | 
|     }  | 
|   | 
|     @PostMapping("/charts/loc/line")  | 
|     @CacheData(tableName = {"man_task_log"})  | 
|     public R locIoLineCharts(){  | 
|         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");  | 
|         Calendar calendar = Calendar.getInstance();  | 
|         calendar.add(Calendar.DATE, -12);  | 
|   | 
|         ArrayList<String> days = new ArrayList<>();  | 
|         ArrayList<Long> inData = new ArrayList<>();  | 
|         ArrayList<Long> outData = new ArrayList<>();  | 
|         for (int i = 0; i < 12; i++) {  | 
|             calendar.add(Calendar.DATE, 1);  | 
|             Date time = calendar.getTime();  | 
|             days.add(sf.format(time));  | 
|   | 
|             Date startOfDay = DateUtils.getStartOfDay(time);  | 
|             Date endOfDay = DateUtils.getEndOfDay(time);  | 
|   | 
|             LambdaQueryWrapper<TaskLog> inWrapper = new LambdaQueryWrapper<TaskLog>()  | 
|                     .ge(TaskLog::getCreateTime, startOfDay)  | 
|                     .le(TaskLog::getCreateTime, endOfDay)  | 
|                     .eq(TaskLog::getTaskSts, 100)  | 
|                     .in(TaskLog::getTaskType, 1, 53, 57);  | 
|   | 
|             LambdaQueryWrapper<TaskLog> outWrapper = new LambdaQueryWrapper<TaskLog>()  | 
|                     .ge(TaskLog::getCreateTime, startOfDay)  | 
|                     .le(TaskLog::getCreateTime, endOfDay)  | 
|                     .eq(TaskLog::getTaskSts, 200)  | 
|                     .in(TaskLog::getTaskType, 101, 103, 107);  | 
|   | 
|             long inCount = taskLogService.count(inWrapper);  | 
|             long outCount = taskLogService.count(outWrapper);  | 
|   | 
|             inData.add(inCount);  | 
|             outData.add(outCount);  | 
|         }  | 
|   | 
|         EChartLineBean inBean = new EChartLineBean();  | 
|         inBean.setName("入库数量");  | 
|         inBean.setValue(inData);  | 
|   | 
|         EChartLineBean outBean = new EChartLineBean();  | 
|         outBean.setName("出库数量");  | 
|         outBean.setValue(outData);  | 
|   | 
|         HashMap<String, Object> map = new HashMap<>();  | 
|         map.put("in", inBean);  | 
|         map.put("out", outBean);  | 
|         map.put("days", days);  | 
|   | 
|         return R.ok().add(map);  | 
|     }  | 
|   | 
|     @PostMapping("/charts/information")  | 
|     @CacheData(tableName = {"man_mat", "man_task", "man_task_log"})  | 
|     public R information() {  | 
|         HashMap<String, Object> data = new HashMap<>();  | 
|         long matCount = matService.count();  | 
|         Long inQty = 0L;  | 
|         Long outQty = 0L;  | 
|         Long totalQty = 0L;  | 
|   | 
|         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  | 
|         ViewInOut viewInOut = viewInOutMapper.selectOne(new LambdaQueryWrapper<ViewInOut>().eq(ViewInOut::getYmd, format.format(new Date())).orderByDesc(ViewInOut::getYmd).last("limit 0,1"));  | 
|         if (viewInOut != null) {  | 
|             inQty = viewInOut.getInQty();  | 
|             outQty = viewInOut.getOutQty();  | 
|             totalQty = viewInOut.getTotalQty();  | 
|         }  | 
|   | 
|         data.put("inCount", inQty);  | 
|         data.put("outCount", outQty);  | 
|         data.put("totalCount", totalQty);  | 
|         data.put("matCount", matCount);  | 
|         return R.ok().add(data);  | 
|     }  | 
|   | 
|     @PostMapping("/charts/information/top")  | 
|     @CacheData(tableName = {"man_task_detl_log"})  | 
|     public R informationTop() {  | 
|         List<InformationTop> topIn = taskDetlLogService.getInformationTopIn(10);  | 
|         List<InformationTop> topOut = taskDetlLogService.getInformationTopOut(10);  | 
|   | 
|         HashMap<String, Object> data = new HashMap<>();  | 
|         data.put("topIn", topIn);  | 
|         data.put("topOut", topOut);  | 
|         return R.ok().add(data);  | 
|     }  | 
|   | 
| }  |