diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java index 1d4654ab..e2fbca02 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java @@ -2564,7 +2564,6 @@ public class DepositoryRecordController { */ @PostMapping("/getSunBurstDataForApplication") public RestResponse getSunBurstDataForApplication(@RequestBody Map map, HttpServletRequest request) { -// String dateName, String type, Long start, Long end, List materialTypeAll if (!map.containsKey("type")) { throw new MyException("错误,请指定图表类型"); } @@ -2609,4 +2608,46 @@ public class DepositoryRecordController { Map data = depositoryRecordService.getSunBurstDataByForApplication(dateName, type, start, end, materialTypeNoParent,depositoryId); return new RestResponse(data); } + + + /** + * 用于获取出入库的旭日图的数据 + * @param map 查询数据 + * @return + */ + @PostMapping("/getSunBurstDataForMtName") + public RestResponse getSunBurstDataForMtName(@RequestBody Map map){ + if(!map.containsKey("depositoryId")){ + throw new MyException("错误,未选择查看的仓库"); + } + Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); + // 获取图表类型 + String type = map.get("type"); + // 获取要查看的日期 + String dateName = null; + int month = -1; + if (map.containsKey("dateName")) { + dateName = map.get("dateName"); + month = ObjectFormatUtil.toInteger(dateName.split("月")[0]); + } else { + Calendar instance = Calendar.getInstance(); + month = instance.get(Calendar.MONTH) + 1; + dateName = month + "月"; + } + // 获取当前month月与下个月的月初 + Map timeSpaceMap = DateUtil.getThisMonthTimeSpace(month); + Long start = timeSpaceMap.get("start"); + Long end = timeSpaceMap.get("end"); + Map data = new HashMap<>(); + if(map.containsKey("mtName")){ + // 如果包含名称 + String mtName = map.get("mtName"); + data = depositoryRecordService.getSunBurstDataByMtName(mtName,type,start,end,mtName,depositoryId); + }else{ + // 如果不包含名称 + List materialTypeNoParent = materialTypeService.findMaterialTypeNoParent(); + data = depositoryRecordService.getSunBurstDataByForApplication(dateName,type,start,end,materialTypeNoParent,depositoryId); + } + return new RestResponse(data); + } } diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java b/src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java index 30b2613e..7f2c2e15 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java @@ -65,7 +65,7 @@ public class MaterialController { public RestResponse findMaterial(@RequestParam Map map) { if (map.containsKey("materialTypeId")) { Long materialTypeId = ObjectFormatUtil.toLong(map.get("materialTypeId")); - List childForMaterialTypeByParent = materialTypeService.findChildForMaterialTypeByParent(materialTypeId); + List childForMaterialTypeByParent = materialTypeService.findAllChildForMaterialTypeByParent(materialTypeId); map.put("materialTypeIds", childForMaterialTypeByParent); map.remove("materialTypeId"); } @@ -180,7 +180,7 @@ public class MaterialController { } if (map.containsKey("materialTypeId")) { Long materialTypeId = ObjectFormatUtil.toLong(map.get("materialTypeId")); - List childForMaterialTypeByParent = materialTypeService.findChildForMaterialTypeByParent(materialTypeId); + List childForMaterialTypeByParent = materialTypeService.findAllChildForMaterialTypeByParent(materialTypeId); if (childForMaterialTypeByParent.size() > 0) { map.put("materialTypeIds", childForMaterialTypeByParent); map.remove("materialTypeId"); diff --git a/src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java b/src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java index 4e06ed80..43242aed 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java @@ -512,14 +512,26 @@ public interface DepositoryRecordService { /** * 用于获取出入库的旭日图数据 - * @param dateName 当前月份名称 + * @param name 当前旭日图名称 * @param type 查看类型 * @param start 开始时间 * @param end 结束时间 * @param materialTypeAll 当前查看物料类型 * @return */ - Map getSunBurstDataByForApplication(String dateName, String type, Long start, Long end, List materialTypeAll,Integer depositoryId); + Map getSunBurstDataByForApplication(String name, String type, Long start, Long end, List materialTypeAll,Integer depositoryId); + + /** + * 用于获取当前类别名称下当前月份的出入库的旭日图数据 + * + * @param name 当前旭日图名称 + * @param type 类型(1入库2出库) + * @param start 开始 + * @param end 结束 + * @param mtName 类别名称 + * @return + */ + Map getSunBurstDataByMtName(String name, String type, Long start, Long end, String mtName,Integer depositoryId); } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/MaterialTypeService.java b/src/main/java/com/dreamchaser/depository_manage/service/MaterialTypeService.java index 66efc63f..ef146fda 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/MaterialTypeService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/MaterialTypeService.java @@ -7,43 +7,51 @@ import java.util.Map; /** * 物料的服务层接口 + * * @author 金昊霖 */ public interface MaterialTypeService { /** * 插入一条物料类型记录 + * * @param map 参数map * @return 受影响的数量 */ - Integer insertMaterialType(Map map); + Integer insertMaterialType(Map map); /** * 根据条件查询对应记录数目 + * * @param map * @return 对应数目 */ - Integer findMaterialTypeCountByCondition(Map map); + Integer findMaterialTypeCountByCondition(Map map); /** * 根据条件查询物料类型 + * * @param map * @return 符合条件的记录 */ - List findMaterialTypeByCondition(Map map); + List findMaterialTypeByCondition(Map map); /** * 查询所有物料类型 + * * @return 所有记录 */ List findMaterialTypeAll(); + /** * 查询所有顶级类型 + * * @return 所有记录 */ List findMaterialTypeNoParent(); /** * 根据主键id完全删除记录 + * * @param id * @return 受影响数目 */ @@ -51,6 +59,7 @@ public interface MaterialTypeService { /** * 根据多个主键id删除记录 + * * @param ids * @return 受影响数目 */ @@ -58,13 +67,15 @@ public interface MaterialTypeService { /** * 修改物料类型 + * * @param map * @return 受影响条数 */ - Integer updateMaterialType(Map map); + Integer updateMaterialType(Map map); /** * 根据主键id查询对应物料类型 + * * @param id * @return 对应记录 */ @@ -72,12 +83,15 @@ public interface MaterialTypeService { /** * 根据类型名称查询物料类型 + * * @param name * @return */ List findMaterialTypeByName(String name); + /** * 根据OldId查询对应物料类型 + * * @param OldId * @return 对应记录 */ @@ -85,6 +99,7 @@ public interface MaterialTypeService { /** * 根据主键id将物料类型状态修改为删除 + * * @param id * @return 受影响条数 */ @@ -92,6 +107,7 @@ public interface MaterialTypeService { /** * 根据多个主键ids将物料类型状态修改为删除 + * * @param ids * @return 受影响条数 */ @@ -99,20 +115,30 @@ public interface MaterialTypeService { /** * 根据条件修改状态 + * * @param map * @return */ - Integer updateStateByParam(Map map); + Integer updateStateByParam(Map map); /** - * 获取当前类别下的所有类别 + * 获取当前类别下的所有类别(含最底层) + * * @param mtId 待查询类别Id * @return */ - List findChildForMaterialTypeByParent(Long mtId); + List findAllChildForMaterialTypeByParent(Long mtId); + + /** + * 获取当前类别下的所有类别(仅子集) + * @param mtId 带查询id + * @return + */ + List findChildForMaterialTypeByParent(Long mtId); /** * 构造树形选择框 + * * @return */ List InitTreeMenus(); diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java index f6d7ea43..6293245f 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java @@ -5,6 +5,7 @@ import com.dreamchaser.depository_manage.config.PublicConfig; import com.dreamchaser.depository_manage.config.QyWxConfig; import com.dreamchaser.depository_manage.entity.*; import com.dreamchaser.depository_manage.entity.MaterialAndPlace; +import com.dreamchaser.depository_manage.exception.MyException; import com.dreamchaser.depository_manage.mapper.*; import com.dreamchaser.depository_manage.pojo.*; import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.ApprovalInfo_Details; @@ -751,7 +752,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, null, null); for (UserByPort userByPort : userByPortList) { int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } approverId.append(userByPort.getId()).append(","); @@ -790,7 +791,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, null, null); for (UserByPort userByPort : userByPortList) { int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } approverId.append(userByPort.getId()).append(","); @@ -2104,7 +2105,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { String materialUnit = inventoryById.getUnit(); // 声明用于查询的map Map paramForSelect = new HashMap<>(); - paramForSelect.put("depositoryId",inventoryById.getDepositoryId()); + paramForSelect.put("depositoryId", inventoryById.getDepositoryId()); if (type == 1) { paramForSelect.put("mid", inventoryById.getMid()); } else { @@ -2196,7 +2197,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { // 获取当前物料的单价 double price = ObjectFormatUtil.divide(inventoryById.getPrice(), 100.0, 2); - if(flagForSplit){ + if (flagForSplit) { price = ObjectFormatUtil.divide(price, scale, 2); } // 获取当前物料的总额 @@ -2537,7 +2538,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort1 : userByPortList) { int emptype = userByPort1.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId1 = userByPort1.getId(); @@ -2620,7 +2621,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort1 : userByPortList) { int emptype = userByPort1.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId1 = userByPort1.getId(); @@ -2706,8 +2707,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { // 将当前redis中存储的spno删除 redisPool.getRedisTemplateByDb(14).delete("wms_QyWxMessage_" + spNo); } - } - else { + } else { // 如果是前两个审批节点 //定义处理时间 @@ -3336,7 +3336,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort depositoryManage = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(depositorymanager), userKey, token); // 获取用户的用工关系 int emptype = depositoryManage.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String departmentHeadWorkwechat = depositoryManage.getWorkwechat(); @@ -3395,7 +3395,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort userByPort = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(s), userKey, token); // 获取用户的用工关系 int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String workwechat = userByPort.getWorkwechat(); @@ -3433,7 +3433,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { for (UserByPort userByPort : departmentHeadByUser) { depositoryManager.append(userByPort.getId()).append(","); int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String workwechat = userByPort.getWorkwechat(); @@ -3456,7 +3456,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort depositoryManage = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(depositorymanager), userKey, token); // 获取用户的用工关系 int emptype = depositoryManage.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String departmentHeadWorkwechat = depositoryManage.getWorkwechat(); @@ -3515,7 +3515,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort userByPort = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(s), userKey, token); // 获取用户的用工关系 int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String workwechat = userByPort.getWorkwechat(); @@ -3634,7 +3634,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort : userByPortList) { int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId = userByPort.getId(); @@ -3657,7 +3657,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort manager = PublicConfig.FindUserById(integer, userKey, token); // 获取用户的用工关系 int emptype = manager.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } updateRedisDataForUserManager(integer, minRecordKey); @@ -3721,7 +3721,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort : userByPortList) { int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId = userByPort.getId(); @@ -3746,7 +3746,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort manager = PublicConfig.FindUserById(integer, userKey, token); // 获取用户的用工关系 int emptype = manager.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } minRecordManage.append(integer).append(","); @@ -3784,7 +3784,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort userByPort = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(s), userKey, token); // 获取用户的用工关系 int emptype = userByPort.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String workwechat = userByPort.getWorkwechat(); @@ -3831,7 +3831,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort departHead = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(record.getDepartmenthead()), userKey, token); // 获取用户的用工关系 int emptype = departHead.getEmptype(); - if(emptype <= 10){ + if (emptype <= 10) { String key = "user:" + departHead.getNumber() + ":QyWxOutId:" + id; String responseCode = (String) redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "responseCode"); qyWxOperationService.updateButtonTemplateCardToUnEnable(responseCode, userToken.getName(), finalResult, userAgent); @@ -4026,7 +4026,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort userById = PublicConfig.FindUserById(ObjectFormatUtil.toInteger(s), null, null); // 获取用户的用工关系 int emptype = userById.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } String workwechat = userById.getWorkwechat(); @@ -4149,7 +4149,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort1 : userByPortList) { int emptype = userByPort1.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId = userByPort1.getId(); @@ -4172,7 +4172,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort manager = PublicConfig.FindUserById(integer, userKey, token); // 获取用户的用工关系 int emptype = manager.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } updateRedisDataForUserManager(integer, minRecordKey); @@ -4235,7 +4235,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List userByPortList = PublicConfig.FindUserByMap(paramForGetUserByPost, userKey, token); for (UserByPort userByPort1 : userByPortList) { int emptype = userByPort1.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } Integer userId = userByPort1.getId(); @@ -4260,7 +4260,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { UserByPort manager = PublicConfig.FindUserById(integer, userKey, token); // 获取用户的用工关系 int emptype = manager.getEmptype(); - if(emptype > 10){ + if (emptype > 10) { continue; } minRecordManage.append(integer).append(","); @@ -5297,7 +5297,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { double sumCount = 0; if (type == 1) { // 如果入库 - sumCount = ObjectFormatUtil.divide(depositoryRecordMapper.findApplicationInByMonthTest(map) , 100.0,2); + sumCount = ObjectFormatUtil.divide(depositoryRecordMapper.findApplicationInByMonthTest(map), 100.0, 2); } else { // 如果出库 sumCount = ObjectFormatUtil.divide(depositoryRecordMapper.findApplicationOutByMonth(map), 100.0, 2); @@ -5818,68 +5818,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { return result; } - - - - /** - * 用于计算当前主记录下的总额与数量 - */ - class CalcApplicationOutInfo implements Callable { - - ApplicationOutRecord mainRecord; - - CalcApplicationOutInfo(ApplicationOutRecord mainRecord) { - this.mainRecord = mainRecord; - } - - @Override - public Object call() throws Exception { - Map result = new HashMap<>(); - // 获取当前订单的子订单 - List minList = depositoryRecordMapper.findApplicationOutRecordMinByParent(mainRecord.getId()); - // 额度 - double price = 0.0; - // 数量 - double count = 0; - for (ApplicationOutRecordMin recordMin : minList) { - double quantity = (double) recordMin.getQuantity() / 100; - count += quantity; - // 获取当前出库物料 - Inventory materialById = materialMapper.findInventoryById(recordMin.getMid()); - // 计算当前出库金额 - double price_out = 0.0; - if (recordMin.getUnit().equals(materialById.getUnit()) || "-1".equals(recordMin.getUnit())) { - if (materialById.getPrice() != null) { - price_out = materialById.getPrice() * quantity; - } - } else { - Map paramForSplitInfo = new HashMap<>(); - paramForSplitInfo.put("newUnit", recordMin.getUnit()); - paramForSplitInfo.put("mid", materialById.getMid()); - SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); - int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); - if (materialById.getPrice() != null) { - price_out = materialById.getPrice() / scale * quantity; - } - } - - - BigDecimal bg = new BigDecimal(price_out / 100); - price_out = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - price = ObjectFormatUtil.sum(price, price_out); - } - result.put("count", count); - result.put("price", price); - return result; - } - } - - /** * 获取折线图数据 + * * @param depositoryId 待获取仓库Id - * @param type 查看类型(1入库2出库) - * @param dateType 日期类型(day按天month按月) + * @param type 查看类型(1入库2出库) + * @param dateType 日期类型(day按天month按月) * @return */ public Map getLineOrBarChartData(Integer depositoryId, String type, String dateType, String echartType) { @@ -5911,26 +5855,27 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { } // 每天仓库出入库数目 Map show_data = new HashMap<>(); - Map applicationRecordByDate = getLineOrBarChartDataForApplicationRecord(type, dayTimeSpaces, depositoryId,echartType); - show_data.put("data",applicationRecordByDate); - show_data.put("dayNames",dayNames); + Map applicationRecordByDate = getLineOrBarChartDataForApplicationRecord(type, dayTimeSpaces, depositoryId, echartType); + show_data.put("data", applicationRecordByDate); + show_data.put("dayNames", dayNames); return show_data; } /** * 获取当前折线图的具体数据 - * @param type 查看类型(1入库2出库) - * @param days 查询日期 + * + * @param type 查看类型(1入库2出库) + * @param days 查询日期 * @param depositoryId 仓库id * @return */ public Map getLineOrBarChartDataForApplicationRecord(String type, List days, Integer depositoryId, String echartType) { Map map = new HashMap<>(); - if("line".equals(echartType)){ + if ("line".equals(echartType)) { map.put("type", "line"); Map areaStyleItem = new HashMap<>(); map.put("areaStyle", areaStyleItem); - }else if("bar".equals(echartType)){ + } else if ("bar".equals(echartType)) { map.put("type", "bar"); Map emphasisItem = new HashMap<>(); emphasisItem.put("focus", "series"); @@ -5952,17 +5897,17 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { return map; } - /** * 用于获取出入库的旭日图数据 - * @param dateName 当前月份名称 - * @param type 查看类型 - * @param start 开始时间 - * @param end 结束时间 + * + * @param name 当前月份名称 + * @param type 查看类型 + * @param start 开始时间 + * @param end 结束时间 * @param materialTypeAll 当前查看物料类型 * @return */ - public Map getSunBurstDataByForApplication(String dateName, String type, Long start, Long end, List materialTypeAll,Integer depositoryId) { + public Map getSunBurstDataByForApplication(String name, String type, Long start, Long end, List materialTypeAll, Integer depositoryId) { Map result = new HashMap<>(); @@ -5981,7 +5926,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List resultForData = new ArrayList<>(); for (MaterialType materialType : materialTypeAll) { // 测试 - Future future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType,depositoryId)); + Future future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType, depositoryId)); futureList.add(future); } double sum = 0.0; @@ -5998,7 +5943,88 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { } } result.put("children", resultForData); - result.put("name", dateName); + result.put("name", name); + result.remove("month"); + result.put("value", sum); + // 用于生产随机的颜色 + Random random = new Random(); + Map itemStyle = new HashMap<>(); + int r = random.nextInt(256); + int g = random.nextInt(256); + int b = random.nextInt(256); + itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); + result.put("itemStyle", itemStyle); + return result; + } + + /** + * 用于获取当前类别名称下当前月份的出入库的旭日图数据 + * + * @param name 当前月份 + * @param type 类型(1入库2出库) + * @param start 开始 + * @param end 结束 + * @param mtName 类别名称 + * @return + */ + public Map getSunBurstDataByMtName(String name, String type, Long start, Long end, String mtName, Integer depositoryId) { + List materialTypeByNames = materialTypeMapper.findMaterialTypeByName(mtName); + MaterialType materialType = null; + if (materialTypeByNames.size() > 0) { + materialType = materialTypeByNames.get(0); + } else { + throw new MyException("错误,不存在当前名称的类型"); + } + List childMaterialTypeList = materialTypeMapper.findMaterialTypeByParent(materialType.getOldId()); + + + double sum = 0.0; + Map result = new HashMap<>(); + if (childMaterialTypeList != null && childMaterialTypeList.size() > 0) { + int threadSize = PublicConfig.availableVirtualMachine; + + int maxThreadSize = childMaterialTypeList.size(); + if (maxThreadSize < threadSize) { + maxThreadSize = threadSize * 2; + } + ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); + + // 结果集 + List> futureList = new ArrayList>(); + // 1.定义CompletionService + CompletionService completionService = new ExecutorCompletionService(exs); + + int runThreadSize = 0; + for (MaterialType value : childMaterialTypeList) { + Future submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value, depositoryId)); + runThreadSize++; + futureList.add(submit); + } + + + List resultForData = new ArrayList<>(); + for (int i = 0; i < runThreadSize; i++) { + Object obj = null; + try { + obj = completionService.take().get(); + resultForData.add(obj); + sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"))); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + result.put("children", resultForData); + }else{ + try { + Object call = new getSunBurstDataForApplicationByDepository(type, start, end, materialType, depositoryId).call(); + sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(call, String.class, Object.class).get("value"))); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + result.put("name", name); result.remove("month"); result.put("value", sum); // 用于生产随机的颜色 @@ -6012,6 +6038,59 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { return result; } + /** + * 用于计算当前主记录下的总额与数量 + */ + class CalcApplicationOutInfo implements Callable { + + ApplicationOutRecord mainRecord; + + CalcApplicationOutInfo(ApplicationOutRecord mainRecord) { + this.mainRecord = mainRecord; + } + + @Override + public Object call() throws Exception { + Map result = new HashMap<>(); + // 获取当前订单的子订单 + List minList = depositoryRecordMapper.findApplicationOutRecordMinByParent(mainRecord.getId()); + // 额度 + double price = 0.0; + // 数量 + double count = 0; + for (ApplicationOutRecordMin recordMin : minList) { + double quantity = (double) recordMin.getQuantity() / 100; + count += quantity; + // 获取当前出库物料 + Inventory materialById = materialMapper.findInventoryById(recordMin.getMid()); + // 计算当前出库金额 + double price_out = 0.0; + if (recordMin.getUnit().equals(materialById.getUnit()) || "-1".equals(recordMin.getUnit())) { + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() * quantity; + } + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", recordMin.getUnit()); + paramForSplitInfo.put("mid", materialById.getMid()); + SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() / scale * quantity; + } + } + + + BigDecimal bg = new BigDecimal(price_out / 100); + price_out = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + price = ObjectFormatUtil.sum(price, price_out); + } + result.put("count", count); + result.put("price", price); + return result; + } + } + /** * 用于具体执行查询旭日图的多线程类 */ @@ -6024,7 +6103,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { MaterialType materialType; Integer depositoryId; - public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType,Integer depositoryId) { + public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType, Integer depositoryId) { this.type = type; this.start = start; this.end = end; @@ -6057,7 +6136,4 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { } - - - } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java index 52c7ab6c..19be7cfa 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java @@ -230,7 +230,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { * @param mtId 待查询类别Id * @return */ - public List findChildForMaterialTypeByParent(Long mtId) { + public List findAllChildForMaterialTypeByParent(Long mtId) { List result = new ArrayList<>(); result.add(mtId); List parentIdList = new ArrayList<>(); @@ -245,6 +245,16 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { return result; } + /** + * 获取当前类别下的所有类别(仅子集) + * @param mtId 带查询id + * @return + */ + @Override + public List findChildForMaterialTypeByParent(Long mtId) { + return materialTypeMapper.findMaterialTypeByParent(mtId); + } + /** * 构造树形选择框 * diff --git a/src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html b/src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html index 6c4754f5..bee023da 100644 --- a/src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html +++ b/src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html @@ -94,42 +94,30 @@ type: 'sunburst', data: [], radius: [0, '95%'], - sort: undefined, + itemStyle: { + borderWidth: 1, + borderColor: "white", + borderType: "solid", + shadowBlur: 0, + shadowColor: 'rgba(0, 0, 0, 0.2)', + shadowOffsetX: 0, + shadowOffsetY: 0, + opacity: 1 + }, emphasis: { focus: 'ancestor' }, - levels: [ - {}, - { - r0: '15%', - r: '35%', - itemStyle: { - borderWidth: 2 - }, - label: { - rotate: 'tangential' - } + blue: { + itemStyle: { + opacity: 0.2 }, - { - r0: '35%', - r: '70%', - label: { - align: 'right' - } - }, - { - r0: '70%', - r: '72%', - label: { - position: 'outside', - padding: 3, - silent: false - }, - itemStyle: { - borderWidth: 3 - } + label: { + opacity: 0.1 } - ] + }, + label: { + rotate: '0' + } }, toolbox: { feature: { @@ -178,7 +166,7 @@ initSunburstChart(req); }); - $("#selectMonthForChart").on('change',function(obj) { + $("#selectMonthForChart").on('change', function (obj) { let value = obj.target.value; let req = {}; req.dateName = value; @@ -226,17 +214,79 @@ } } }) - } + }; // 设置点击事件 - echartSunburstChart.on('click', function(params) { - let name = params.name; - if(name !== ""){ + echartSunburstChart.on('click', function (params) { + let name = params.name.trim(); + let dataType = params.dataType; + let clickData = params.data; + if (dataType === undefined) { + } else { + if (name !== "") { + let req = {}; + req.depositoryId = $("#selectDepositoryForChart").val(); + req.dateName = $("#selectMonthForChart").val(); + req.type = type; + req.mtName = name; + $.ajax({ + url: '/depositoryRecord/getSunBurstDataForMtName', + type: 'post', + dataType: "json", + data: JSON.stringify(req), + contentType: "application/json;charset=utf-8", + beforeSend: function () { + this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']}); + }, + success: function (result) { + layer.close(this.layerIndex); + let data = result.data; + // 当前点击的数据在option中的下标(减二后为data中的下标) + let clickDataNum = params.dataIndex; + let seriesDataList = optionSunburstChart.series.data[0].children; + let seriesData = seriesDataList[clickDataNum - 2]; + if (seriesData !== undefined && seriesData.name === clickData.name) { + // 如果当前获取到series的数据是点击的数据则覆盖 + seriesDataList[clickDataNum - 2] = data; + } else { + // 如果不是,则代表点击的更深一层的数据 + updateSeriesData(seriesDataList, clickData, clickDataNum,data); + optionSunburstChart.series.data[0].children = seriesDataList; + } + echartSunburstChart.setOption(optionSunburstChart); + } + }) + + } } + }); + function updateSeriesData(seriesDataList, data, clickNum,updateData) { + for (let i = 0; i < seriesDataList.length; i++) { + clickNum--; + let seriesData = seriesDataList[i]; + if (seriesData.name === data.name) { + seriesDataList[i] = updateData; + return true; + } else { + let seriesDataChildren = seriesData.children; + if (seriesDataChildren !== undefined) { + let returnResult = updateSeriesData(seriesDataChildren, data, clickNum,updateData); + if (!returnResult) { + clickNum -= seriesDataChildren.length; + } else { + return true; + } + } + } + + } + return false; + } + }); diff --git a/src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java b/src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java index d5fb1e48..a852d989 100644 --- a/src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java +++ b/src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java @@ -1,13 +1,16 @@ package com.dreamchaser.depository_manage; import com.alibaba.fastjson.JSONObject; +import com.dreamchaser.depository_manage.config.PublicConfig; import com.dreamchaser.depository_manage.entity.MaterialType; +import com.dreamchaser.depository_manage.exception.MyException; import com.dreamchaser.depository_manage.service.DepositoryRecordService; import com.dreamchaser.depository_manage.service.DepositoryService; import com.dreamchaser.depository_manage.service.MaterialService; import com.dreamchaser.depository_manage.service.MaterialTypeService; import com.dreamchaser.depository_manage.utils.DateUtil; import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; +import org.apache.ibatis.jdbc.Null; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -46,44 +49,30 @@ public class SunburstChartTest { // 获取月份名称 List sourceList = ObjectFormatUtil.objToList(previousMonth.get("sourceList"), Object.class); // 结果集 - List materialTypeNoParent = materialTypeService.findMaterialTypeNoParent(); +// List materialTypeNoParent = materialTypeService.findMaterialTypeNoParent(); // 1.定义CompletionService - Map map = ObjectFormatUtil.objToMap(sourceList.get(4), String.class, Object.class); - Map sourceListTask = getSunBurstDataByForApplication("map", type, months.get(2), months.get(1), materialTypeNoParent); - System.out.println(JSONObject.toJSONString(sourceListTask)); +// Map map = ObjectFormatUtil.objToMap(sourceList.get(4), String.class, Object.class); +// Map sourceListTask = getSunBurstDataForApplication("map", type, months.get(2), months.get(1), materialTypeNoParent); +// System.out.println(JSONObject.toJSONString(sourceListTask)); // 用于返回结果 - } - @Test - public void a(){ - int month = 7; - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); - Calendar instance = Calendar.getInstance(); - instance.set(Calendar.MONTH, month - 1); - String end = formatter.format(instance.getTime()); - Long endTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(end); - System.out.println("end:"+end); - System.out.println("endTimeSpace:"+endTimeSpace); - instance.add(Calendar.MONTH, 1); - String start = formatter.format(instance.getTime()); - Long startTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime())); - System.out.println("start:"+start); - System.out.println("startTimeSpace:"+startTimeSpace); + Map sunBurstDataByMtName = getSunBurstDataByMtName("7月", "1", months.get(2), months.get(1), "化验器具"); + System.out.println(sunBurstDataByMtName); } - /** * 用于获取出入库的旭日图数据 - * @param dayName 当前月份名称 - * @param type 查看类型 - * @param start 开始时间 - * @param end 结束时间 + * + * @param dayName 当前月份名称 + * @param type 查看类型 + * @param start 开始时间 + * @param end 结束时间 * @param materialTypeAll 当前查看物料类型 * @return */ - public Map getSunBurstDataByForApplication(String dayName, String type, Long start, Long end, List materialTypeAll) { + public Map getSunBurstDataForApplication(String dayName, String type, Long start, Long end, List materialTypeAll) { Map result = new HashMap<>(); @@ -109,6 +98,7 @@ public class SunburstChartTest { Object obj = null; try { obj = completionService.take().get(); + sum = ObjectFormatUtil.sum(sum,ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj,String.class,Object.class).get("value"))); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -129,6 +119,77 @@ public class SunburstChartTest { return result; } + /** + * 用于获取当前类别名称下当前月份的出入库的旭日图数据 + * + * @param dayName 当前月份 + * @param type 类型(1入库2出库) + * @param start 开始 + * @param end 结束 + * @param mtName 类别名称 + * @return + */ + public Map getSunBurstDataByMtName(String dayName, String type, Long start, Long end, String mtName) { + List materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); + MaterialType materialType = null; + if (materialTypeByNames.size() > 0) { + materialType = materialTypeByNames.get(0); + } else { + throw new MyException("错误,不存在当前名称的类型"); + } + List childMaterialTypeList = materialTypeService.findChildForMaterialTypeByParent(materialType.getOldId()); + + + int threadSize = PublicConfig.availableVirtualMachine; + + int maxThreadSize = childMaterialTypeList.size(); + if (maxThreadSize < threadSize) { + maxThreadSize = threadSize * 2; + } + ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); + + // 结果集 + List> futureList = new ArrayList>(); + // 1.定义CompletionService + CompletionService completionService = new ExecutorCompletionService(exs); + + int runThreadSize = 0; + for (MaterialType value : childMaterialTypeList) { + Future submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value)); + runThreadSize++; + futureList.add(submit); + } + + double sum = 0.0; + List resultForData = new ArrayList<>(); + for (int i = 0; i < runThreadSize; i++) { + Object obj = null; + try { + obj = completionService.take().get(); + resultForData.add(obj); + sum = ObjectFormatUtil.sum(sum,ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj,String.class,Object.class).get("value"))); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + Map result = new HashMap<>(); + result.put("children", resultForData); + result.put("name", dayName); + result.remove("month"); + result.put("value", sum); + // 用于生产随机的颜色 + Random random = new Random(); + Map itemStyle = new HashMap<>(); + int r = random.nextInt(256); + int g = random.nextInt(256); + int b = random.nextInt(256); + itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); + result.put("itemStyle", itemStyle); + return result; + } + + + /** * 用于具体执行查询旭日图的多线程类 */ @@ -175,5 +236,4 @@ public class SunburstChartTest { return result; } } - }