package com.huaheng.pc.system.user.controller; import java.util.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.abel533.echarts.Option; import com.github.abel533.echarts.axis.Axis; import com.github.abel533.echarts.axis.CategoryAxis; import com.github.abel533.echarts.axis.ValueAxis; import com.github.abel533.echarts.code.*; import com.github.abel533.echarts.json.GsonUtil; import com.github.abel533.echarts.series.Line; import com.github.abel533.echarts.series.Pie; import com.github.abel533.echarts.style.itemstyle.Normal; import com.huaheng.common.support.Convert; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper; import com.huaheng.pc.system.notice.domain.SysNotice; import com.huaheng.pc.system.notice.service.SysNoticeService; import com.huaheng.pc.system.user.domain.ChartData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import com.huaheng.framework.config.HuaHengConfig; import com.huaheng.framework.web.controller.BaseController; import com.huaheng.pc.system.menu.domain.Menu; import com.huaheng.pc.system.menu.service.IMenuService; import com.huaheng.pc.system.user.domain.User; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; /** * 首页 业务处理 * * @author huaheng */ @Controller public class IndexController extends BaseController { @Autowired private IMenuService menuService; @Autowired private HuaHengConfig huahengConfig; @Resource private SysNoticeService noticeService; @Resource ExcelReportMapper mapper; @GetMapping("index/getInventoryStatus") @ResponseBody public String getInventoryStatus(){ Option option = new Option(); // option.title("库存状态分布").title().x("center"); option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)"); option.legend().setOrient(Orient.vertical); option.legend().setRight(10); option.legend().setTop(20); option.legend().setBottom(10); option.legend().setData(new ArrayList<String>()); Pie pie = new Pie(); pie.setName("库存状态"); pie.setType(SeriesType.pie); pie.setRadius("70%"); pie.setCenter(new String[]{"40%","50%"}); Normal normal = new Normal(); normal.setFormatter("{b} \n {c} ({d}%)"); normal.setBarBorderColor("#eee"); normal.setBorderWidth(1); normal.setBorderRadius(4); pie.label().normal(normal); pie.itemStyle().emphasis().setShadowBlur(10); pie.itemStyle().emphasis().setShadowOffsetX(0); pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)"); String sql = "SELECT d.dictLabel '状态', i.qty '库存' FROM (SELECT inventorySts ,SUM(qty) qty FROM inventory_detail WHERE warehouseCode = '" + ShiroUtils.getWarehouseCode()+"' GROUP BY inventorySts) i INNER JOIN sys_dict_data d ON i.inventorySts= d.dictValue AND d.warehouseCode = '" + ShiroUtils.getWarehouseCode()+"' ;"; List<LinkedHashMap<String, Object>> results = mapper.selectCommon(sql); for(LinkedHashMap<String, Object> item : results){ ChartData chartData = new ChartData(); for(Map.Entry<String, Object> entries : item.entrySet()){ if("状态".equals(entries.getKey())){ option.legend().getData().add(entries.getValue()); chartData.setName(entries.getValue().toString()); }else{ chartData.setValue(Convert.toDouble(entries.getValue())); } } pie.data().add(chartData); } option.series().add(pie); return GsonUtil.format(option); } @GetMapping("index/getCommonData") @ResponseBody public AjaxResult getCommonData(){ String condition = " and warehouseCode = '" + ShiroUtils.getWarehouseCode() +"'"; String bllCount = "SELECT ifnull(sum(t.a),0) 'total' from (\n" + "SELECT COUNT(*) 'a' FROM receipt_header WHERE DATEDIFF(NOW(), created)=0 " + condition + " UNION \n" + "SELECT COUNT(*) 'a' FROM shipment_header WHERE DATEDIFF(NOW(), created)=0 " + condition + ") t"; String receiptTotal = "SELECT IFNULL(SUM(d.qty),0) 'total' FROM receipt_container_detail d join receipt_container_header h on d.receiptContainerId = h.id WHERE DATEDIFF(NOW(), h.created) = 0 AND d.status > 19 AND h.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ;"; String shipmentTotal = "SELECT IFNULL(SUM(d.qty),0) 'total' from shipment_container_detail d JOIN shipment_container_header h on d.shippingContainerId = h.id WHERE DATEDIFF(NOW(), h.created) = 0 AND h.status > 19 AND h.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ;"; String inventoryTotal = "SELECT IFNULL(SUM(totalQty),0) 'total' from inventory_header where 1=1 " + condition; String materialCount = "SELECT count(DISTINCT materialSkuQty) 'total' from inventory_header WHERE 1=1" + condition; String taskUncompletedTotal = "SELECT COUNT(*) 'total' from task_detail WHERE status < 100 " + condition; Map<String, Object> map = new HashMap<>(); List<LinkedHashMap<String, Object>> temp1 = mapper.selectCommon(bllCount); map.put("bllCount",temp1.get(0).entrySet().iterator().next().getValue()); List<LinkedHashMap<String, Object>> temp2 = mapper.selectCommon(receiptTotal); map.put("receiptTotal",temp2.get(0).entrySet().stream().findFirst().get().getValue()); List<LinkedHashMap<String, Object>> temp3 = mapper.selectCommon(shipmentTotal); map.put("shipmentTotal",temp3.get(0).entrySet().stream().findFirst().get().getValue()); List<LinkedHashMap<String, Object>> temp4 = mapper.selectCommon(inventoryTotal); map.put("inventoryTotal",temp4.get(0).entrySet().stream().findFirst().get().getValue()); List<LinkedHashMap<String, Object>> temp5 = mapper.selectCommon(materialCount); map.put("materialCount",temp5.get(0).entrySet().stream().findFirst().get().getValue()); List<LinkedHashMap<String, Object>> temp6 = mapper.selectCommon(taskUncompletedTotal); map.put("taskUncompletedTotal",temp6.get(0).entrySet().stream().findFirst().get().getValue()); return AjaxResult.success(map); } @GetMapping("index/getShipmentsLast7Days") @ResponseBody public String getShipmentsLast7Days(){ String sql = "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" + "from (\n" + " SELECT curdate() as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 1 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 2 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 3 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 4 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 5 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 6 day) as click_date\n" + ") a left join (\n" + "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from shipment_container_detail d join shipment_container_header h on d.shippingContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND h.status=30 GROUP BY DATE(h.created)\n" + ") b on a.click_date = b.created ORDER BY a.click_date;"; List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql); sql = "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" + "from (\n" + " SELECT curdate() as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 1 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 2 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 3 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 4 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 5 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 6 day) as click_date\n" + ") a left join (\n" + "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from receipt_container_detail d join receipt_container_header h on d.receiptContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND d.status=30 GROUP BY DATE(h.created)\n" + ") b on a.click_date = b.created ORDER BY a.click_date;"; List<LinkedHashMap<String, Object>> list2 = mapper.selectCommon(sql); Option option = new Option(); // option.title("七日发货量"); option.tooltip().trigger(Trigger.axis).axisPointer().type(PointerType.cross); option.grid().setLeft("3%"); option.grid().setRight("4%"); option.grid().setBottom("3%"); option.grid().containLabel(true); option.legend().data().add("收货量"); option.legend().data().add("发货量"); Map<Object, Object> map = new HashMap<>(); Axis axis = new CategoryAxis() ; axis.boundaryGap(false); Line line = new Line(); line.setName("发货量"); for(LinkedHashMap<String, Object> item : list){ Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator(); Object o1 = iterator.next().getValue(); Object o2 = iterator.next().getValue(); axis.data().add(o1); line.data().add(o2); } Line line2 = new Line(); line2.setName("收货量"); for(LinkedHashMap<String, Object> item : list2){ Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator(); Object o1 = iterator.next().getValue(); Object o2 = iterator.next().getValue(); line2.data().add(o2); } option.setxAxis(Arrays.asList(axis)); ValueAxis yAxis = new ValueAxis(); option.setyAxis(Arrays.asList(yAxis)); option.series(line,line2); return GsonUtil.format(option); } @GetMapping("index/getInventoryProp") @ResponseBody public String getInventoryProp(){ String sql = "SELECT m.`name`,sum(i.qty) as total from inventory_detail i join material m on i.materialCode = m.`code` and i.warehouseCode = m.warehouseCode AND i.warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' \n" + "GROUP BY m.`name` ORDER BY total desc;"; List<LinkedHashMap<String, Object>> results = mapper.selectCommon(sql); Option option = new Option(); // option.title("库存状态分布").title().x("center"); option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)"); option.legend().setOrient(Orient.vertical); option.legend().setRight(10); option.legend().setTop(10); option.legend().setBottom(10); option.legend().setData(new ArrayList<String>()); option.legend().setType(LegendType.scroll); // option.legend().setType("scroll"); Pie pie = new Pie(); pie.setName("库存"); pie.setType(SeriesType.pie); pie.setRadius("55%"); pie.setCenter(new String[]{"40%","50%"}); pie.itemStyle().emphasis().setShadowBlur(10); pie.itemStyle().emphasis().setShadowOffsetX(0); pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)"); Normal normal = new Normal(); normal.setFormatter("{b} \n {c} ({d}%)"); normal.setBarBorderColor("#eee"); normal.setBorderWidth(1); normal.setBorderRadius(4); pie.label().normal(normal); int i = 0; Map<String, Boolean> map = new HashMap<>(); for(LinkedHashMap<String,Object> item : results){ Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator(); Object o1 = iterator.next().getValue(); Object o2 = iterator.next().getValue(); option.legend().data().add(o1); pie.data().add(new ChartData(o1.toString(), Convert.toDouble(o2))); if(i<6){ map.put(o1.toString(),true); }else{ map.put(o1.toString(),false); } i++; } option.series(pie); option.legend().setSelected(map); return GsonUtil.format(option); } @GetMapping("index/getLocationProp") @ResponseBody public String getLocationProp(){ String sql = "SELECT (SELECT count(1) FROM location WHERE\tIFNULL(containerCode,'') !='' AND warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ) as '有货', (SELECT count(1) FROM location WHERE\tIFNULL(containerCode,'') ='' AND warehouseCode = '"+ShiroUtils.getWarehouseCode()+"' ) as '无货' from DUAL"; List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql); Option option = new Option(); // option.title("库存状态分布").title().x("center"); option.tooltip(Trigger.item).tooltip().formatter("{a} <br/>{b} : {c} ({d}%)"); option.legend().setOrient(Orient.vertical); option.legend().setRight(10); option.legend().setTop(20); option.legend().setBottom(20); option.legend().setData(new ArrayList<String>()); Pie pie = new Pie(); pie.setName("货位状态"); pie.setType(SeriesType.pie); pie.setRadius("55%"); pie.setCenter(new String[]{"40%","50%"}); Normal normal = new Normal(); normal.setFormatter("{b} \n {c} ({d}%)"); normal.setBarBorderColor("#eee"); normal.setBorderWidth(1); normal.setBorderRadius(4); pie.label().normal(normal); pie.itemStyle().emphasis().setShadowBlur(10); pie.itemStyle().emphasis().setShadowOffsetX(0); pie.itemStyle().emphasis().setShadowColor("rgba(0, 0, 0, 0.4)"); for(LinkedHashMap<String,Object> item : list){ Iterator<Map.Entry<String, Object>> iterator = item.entrySet().iterator(); Map.Entry<String, Object> next = iterator.next(); option.legend().data().add(next.getKey()); pie.data().add(new ChartData(next.getKey(), Convert.toDouble(next.getValue()))); next = iterator.next(); option.legend().data().add(next.getKey()); pie.data().add(new ChartData(next.getKey(), Convert.toDouble(next.getValue()))); } option.series(pie); return GsonUtil.format(option); } // 系统首页 @GetMapping("/index") public String index(ModelMap mmap) { // 取身份信息 User user = getUser(); // 根据用户id取出菜单 List<Menu> menus = menuService.selectPCMenusByUserId(user.getId()); mmap.put("menus", menus); System.out.println(menus); mmap.put("user", user); mmap.put("copyrightYear", huahengConfig.getCopyrightYear()); mmap.put("notices", noticeService.getMyNotice(0)); return "index"; } // 系统介绍 @GetMapping("/system/main") public String main(ModelMap mmap) { mmap.put("version", huahengConfig.getVersion()); return "main"; } }