From 203250cd8eca569cc51499058c2a602d192c7e39 Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期二, 31 十月 2023 18:04:30 +0800 Subject: [PATCH] zjh 2023/10/31--1 --- ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjHomePageController.java | 22 +++++++ ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java | 140 ++++++++++++++++++++++++++++++++++++++++++++++ ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java | 9 +++ 3 files changed, 171 insertions(+), 0 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java index f006bfd..2bb9d0c 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java @@ -12,6 +12,7 @@ import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; import com.ltkj.hosp.vodomain.AddNewReservationConfirm; +import com.ltkj.hosp.vodomain.PieChartVo; import com.ltkj.hosp.vodomain.QjDomainVo; import com.ltkj.mall.mallOrderUtils.TjConstants; import com.ltkj.system.service.ISysUserService; @@ -945,6 +946,145 @@ } + @Override + @Async("async") + public void getLineChart() { + redisCache.setCacheObject("getLineChart",getLineCharts()); + } + + @Override + @Async("async") + public void getPieChart() { + redisCache.setCacheObject("getPieChart",getPieCharts()); + } + + //棣栭〉楗肩姸鍥剧櫥璁颁汉鏁版帴鍙� + private AjaxResult getPieCharts() { + Map<String, Object> map = new HashMap<>(); + + //鑾峰彇浣撴鐧昏鏁� + LambdaQueryWrapper<TjOrder> wq0 = new LambdaQueryWrapper<>(); + wq0.between(TjOrder::getCreateTime, DateUtil.lastMonth(), DateUtil.now()); + List<TjOrder> orderCountList = orderService.list(wq0); + if (null != orderCountList && orderCountList.size() > 0) { + List<PieChartVo> pieChartVoList = getTjorderCountMap(orderCountList); + map.put("tjdj", pieChartVoList); + } else { + map.put("tjdj", 0); + } + //鑾峰彇浣撴寮傚父鏁� + LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>(); + wq1.between(TjOrder::getFinishTime, DateUtil.lastMonth(), DateUtil.now()); + wq1.eq(TjOrder::getCheckStatus, 1); + List<TjOrder> orderAbnormalCountList = orderService.list(wq1); + if (null != orderAbnormalCountList && orderAbnormalCountList.size() > 0) { + List<PieChartVo> pieChartVoList = getTjorderAbnormalCountMap(orderAbnormalCountList); + map.put("tjyc", pieChartVoList); + } else { + map.put("tjyc", 0); + } + + return AjaxResult.success(map); + } + + //棣栭〉鎶樼嚎鍥炬暟鎹� + private AjaxResult getLineCharts() { + List<Map<Object, Object>> line = orderService.getLine(); + Collections.reverse(line); + return AjaxResult.success("鎶樼嚎鍥炬暟鎹�", line); + } + + + //鑾峰彇浣撴鐧昏鏁� + private List<PieChartVo> getTjorderCountMap(List<TjOrder> orderList) { + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int e = 0; + Map<String, Object> map = null; + for (TjOrder tjOrder : orderList) { + map = new HashMap<>(); + TjCustomer customer = tjCustomerService.getById(tjOrder.getUserId()); + if (null != customer) { + int age = DateUtil.ageOfNow(customer.getCusBrithday()); + if (age >= 0 && age <= 3) { + a += 1; + } else if (age > 3 && age <= 16) { + b += 1; + } else if (age > 16 && age <= 40) { + c += 1; + } else if (age > 40 && age <= 60) { + d += 1; + } else { + e += 1; + } + } + map.put("0-3宀�", a); + map.put("3-16宀�", b); + map.put("16-40宀�", c); + map.put("40-60宀�", d); + map.put("60宀佷互涓�", e); + } + List<PieChartVo> pieChartVoList = new ArrayList<>(); + assert map != null; + for (Map.Entry<String, Object> entry : map.entrySet()) { + PieChartVo pieChartVo = new PieChartVo(); + pieChartVo.setName(entry.getKey()); + pieChartVo.setCount((Integer) entry.getValue()); + pieChartVoList.add(pieChartVo); + } + return pieChartVoList; + } + + //鑾峰彇浣撴寮傚父鏁� + private List<PieChartVo> getTjorderAbnormalCountMap(List<TjOrder> orderList) { + int a = 0; + int b = 0; + int c = 0; + int d = 0; + int e = 0; + Map<String, Object> map = null; + for (TjOrder tjOrder : orderList) { + map = new HashMap<>(); + LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>(); + wq.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId()); + wq.eq(TjOrderDetail::getExceptionDesc, 1); + List<TjOrderDetail> list = tjOrderDetailService.list(wq); + if (null != list && list.size() > 0) { + TjCustomer customer = tjCustomerService.getById(tjOrder.getUserId()); + if (null != customer) { + int age = DateUtil.ageOfNow(customer.getCusBrithday()); + if (age >= 0 && age <= 3) { + a += 1; + } else if (age > 3 && age <= 16) { + b += 1; + } else if (age > 16 && age <= 40) { + c += 1; + } else if (age > 40 && age <= 60) { + d += 1; + } else { + e += 1; + } + } + map.put("0-3宀�", a); + map.put("3-16宀�", b); + map.put("16-40宀�", c); + map.put("40-60宀�", d); + map.put("60宀佷互涓�", e); + } + } + List<PieChartVo> pieChartVoList = new ArrayList<>(); + assert map != null; + for (Map.Entry<String, Object> entry : map.entrySet()) { + PieChartVo pieChartVo = new PieChartVo(); + pieChartVo.setName(entry.getKey()); + pieChartVo.setCount((Integer) entry.getValue()); + pieChartVoList.add(pieChartVo); + } + return pieChartVoList; + } + private List<DictSfxm> getDictSfxm() { List<DictSfxm> dictSfxms = dictSfxmService.getYjDictSfxmList(); if (null != dictSfxms && dictSfxms.size() > 0) { diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjHomePageController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjHomePageController.java index 0db4807..b82c16a 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjHomePageController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjHomePageController.java @@ -6,6 +6,7 @@ import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.core.domain.entity.SysDept; import com.ltkj.common.core.domain.entity.SysUser; +import com.ltkj.common.core.redis.RedisCache; import com.ltkj.common.utils.DateUtils; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; @@ -42,6 +43,10 @@ private ITjCustomerService customerService; @Resource private ITjProjectService projectService; + @Resource + private RedisCache redisCache; + @Resource + private TjAsyncService asyncService; @Resource private ISysDeptService deptService; @Resource @@ -446,6 +451,14 @@ @GetMapping("/getLineChart") @ApiOperation(value = "棣栭〉鎶樼嚎鍥炬暟鎹�") public AjaxResult getLineChart() { + asyncService.getLineChart(); + if(redisCache.hasKey("getLineChart")){ + return redisCache.getCacheObject("getLineChart"); + } + return getResult(); + } + + private AjaxResult getResult() { List<Map<Object, Object>> line = orderService.getLine(); Collections.reverse(line); return AjaxResult.success("鎶樼嚎鍥炬暟鎹�", line); @@ -454,6 +467,14 @@ @GetMapping("/getPieChart") @ApiOperation(value = "棣栭〉楗肩姸鍥剧櫥璁颁汉鏁版帴鍙�") public AjaxResult getPieChart() { + asyncService.getPieChart(); + if(redisCache.hasKey("getPieChart")){ + return redisCache.getCacheObject("getPieChart"); + } + return getAjaxResult(); + } + + private AjaxResult getAjaxResult() { Map<String, Object> map = new HashMap<>(); //鑾峰彇浣撴鐧昏鏁� @@ -477,6 +498,7 @@ } else { map.put("tjyc", 0); } + return AjaxResult.success(map); } diff --git a/ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java b/ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java index f83896b..d733a29 100644 --- a/ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java +++ b/ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java @@ -86,4 +86,13 @@ void getDictSfxms(); void getOrderDetailByProParentId(String tjNumber,Map<String, Object> map,String proParentId); + + + //棣栭〉鎶樼嚎鍥炬暟鎹� + void getLineChart(); + + //棣栭〉楗肩姸鍥剧櫥璁颁汉鏁版帴鍙� + void getPieChart(); + + } -- Gitblit v1.8.0