From ceecebe477faf5a45b19f3b258f7add8f93b4583 Mon Sep 17 00:00:00 2001 From: futian.liu <liufutianyoo@163.com> Date: 星期二, 05 十二月 2023 10:00:24 +0800 Subject: [PATCH] 代码优化 结构调整 --- consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java | 167 +++++++++++++++++++++++-------------------------------- 1 files changed, 69 insertions(+), 98 deletions(-) diff --git a/consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java b/consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java index 8659f28..b60f2c7 100644 --- a/consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java +++ b/consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java @@ -1,13 +1,28 @@ package com.consum.base.controller; -import cn.afterturn.easypoi.excel.ExcelExportUtil; -import cn.afterturn.easypoi.excel.entity.TemplateExportParams; -import cn.hutool.core.util.ReflectUtil; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.Lists; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import com.consum.base.BaseController; import com.consum.base.core.utils.CommonUtil; import com.consum.base.core.utils.IdUtil; -import com.consum.base.core.utils.MapUtils; -import com.consum.base.core.utils.MapperUtil; import com.consum.base.pojo.GoodsUseRecordVO; import com.consum.base.pojo.LWhFormTransferGoodsInfoParam; import com.consum.base.pojo.RecordUserInfoVO; @@ -19,14 +34,14 @@ import com.consum.base.pojo.request.ProcureModelInfoParam; import com.consum.base.pojo.request.RecordInfoParam; import com.consum.base.pojo.response.FormTransferVO; -import com.consum.base.pojo.response.FromTransferTemplateInfoVO; +import com.consum.base.pojo.response.GoodsTemplateCountVO; import com.consum.base.pojo.response.LWHFromTransferExtendVO; import com.consum.base.pojo.response.TransferInfoVO; import com.consum.base.service.BaseWarehouseService; import com.consum.base.service.LWhFormTransferCoreService; import com.consum.base.service.LWhFormTransferService; import com.consum.base.service.LWhProcureModelService; -import com.consum.base.service.LWhProcureModelUserRecordServiceImpl; +import com.consum.base.service.LWhProcureModelUserRecordService; import com.consum.base.service.LWhProcureModelUserServiceImpl; import com.consum.model.po.BaseWarehouse; import com.consum.model.po.FinSysTenantUser; @@ -38,27 +53,14 @@ import com.walker.infrastructure.utils.CollectionUtils; import com.walker.infrastructure.utils.DateUtils; import com.walker.web.ResponseValue; + +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.TemplateExportParams; +import cn.hutool.core.util.ReflectUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.compress.utils.Lists; -import org.apache.poi.ss.usermodel.Workbook; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; /** * @Description 璋冩嫧绠$悊 @@ -79,7 +81,7 @@ @Autowired private LWhProcureModelUserServiceImpl lWhProcureModelUserService; @Autowired - private LWhProcureModelUserRecordServiceImpl lWhProcureModelUserRecordService; + private LWhProcureModelUserRecordService lWhProcureModelUserRecordService; @Autowired private BaseWarehouseService baseWarehouseService; @@ -106,13 +108,14 @@ long id = this.lWhFormTransferService.add(param, this.getSysInfo()); Integer transferBusinessType = param.getTransferBusinessType(); - //閮ㄩ棬鍒嗗彂涓氬姟闇�瑕佸鐞� + // 閮ㄩ棬鍒嗗彂涓氬姟闇�瑕佸鐞� if (transferBusinessType == 1) { // 鍏堝嚭搴擄紝鍐嶅叆搴� // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 FinSysTenantUser sysTenantUser = this.getSysInfo(); String agencyId = sysTenantUser.getTenantId(); - List<BaseWarehouse> baseWarehouseList = baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short) 1, (short) 1); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short)1, (short)1); if (CollectionUtils.isEmpty(baseWarehouseList)) { return ResponseValue.error("鏈烘瀯鏃犻粯璁や粨搴擄紒"); } @@ -135,17 +138,15 @@ * @Description 鍒楄〃鏌ヨ(璋冩嫧鏄庣粏) * @Author 鍗㈠簡闃� * @Date 2023/10/30 - * <p> - * 1.鏌ヨ璋冩嫧鍗� - * <p> - * 2.鏌ヨ鐗╁搧鍨嬪彿 + * <p> + * 1.鏌ヨ璋冩嫧鍗� + * <p> + * 2.鏌ヨ鐗╁搧鍨嬪彿 */ @ApiOperation(value = "鍗曟嵁鍒楄〃鏌ヨ", notes = "鍗曟嵁鍒楄〃鏌ヨ") - @ApiImplicitParams({ - @ApiImplicitParam(name = "page", value = "椤电爜", required = true, dataType = "int"), + @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "椤电爜", required = true, dataType = "int"), @ApiImplicitParam(name = "size", value = "姣忛〉鏉℃暟", required = true, dataType = "int"), - @ApiImplicitParam(name = "param", value = "鏉′欢鍙傛暟", required = true, dataType = "TransferQry"), - }) + @ApiImplicitParam(name = "param", value = "鏉′欢鍙傛暟", required = true, dataType = "TransferQry"),}) @GetMapping("/list") public ResponseValue queryFormTransferList() { TransferQry param = CommonUtil.getObjFromReq(TransferQry.class); @@ -166,29 +167,18 @@ FormTransferVO formTransferVO = new FormTransferVO(); BeanUtils.copyProperties(item, formTransferVO); - List<FromTransferTemplateInfoVO> templateInfoList = Lists.newArrayList(); - // 鏌ヨ鍨嬪彿鏁伴噺 - String sql = "SELECT bgt.id,bgm.GOODS_TEMPLATES_ID,GOODS_NAME,sum( counts ) count FROM " - + "l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON pm.BASE_GOODS_MODELS_ID = bgm.id " - + "LEFT JOIN base_goods_template bgt ON bgm.GOODS_TEMPLATES_ID = bgt.id " - + "WHERE pm.BUSINESS_ID =:id GROUP BY bgm.GOODS_TEMPLATES_ID"; - Map<String, Object> paramMap = new HashMap<>(); - paramMap.put("id", item.getId()); - List<Map<String, Object>> procureModelList = lWhProcureModelService.select(sql, paramMap, new MapperUtil()); - for (Map<String, Object> map : procureModelList) { - FromTransferTemplateInfoVO procureTemplateInfoVO = MapUtils.convertMapToObj(map, FromTransferTemplateInfoVO.class); - templateInfoList.add(procureTemplateInfoVO); - } - formTransferVO.setFromTransferTemplateInfoList(templateInfoList); + List<GoodsTemplateCountVO> goodsTemplateCount = + lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); + formTransferVO.setFromTransferTemplateInfoList(goodsTemplateCount); result.add(formTransferVO); }); } try { Field fieldDatas = GenericPager.class.getDeclaredField("datas"); -// fieldDatas.setAccessible(true); -// fieldDatas.set(genericPager, result); + // fieldDatas.setAccessible(true); + // fieldDatas.set(genericPager, result); ReflectUtil.setFieldValue(genericPager, fieldDatas, result); } catch (Exception e) { @@ -203,9 +193,7 @@ * @Date 2023/10/30 */ @ApiOperation(value = "鏍规嵁id鏌ヨ璇︽儏", notes = "鏍规嵁id鏌ヨ璇︽儏") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @GetMapping("/detail") public ResponseValue getById(Long id) { if (id == null) { @@ -216,9 +204,7 @@ } @ApiOperation(value = "璋冩嫧鏄庣粏鍒楄〃", notes = "璋冩嫧鏄庣粏鍒楄〃") - @ApiImplicitParams({ - @ApiImplicitParam(name = "param", value = "鏉′欢", required = true, dataType = "TransferQry"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鏉′欢", required = true, dataType = "TransferQry"),}) @GetMapping("/detail/list") public ResponseValue queryFormTransferDetailList() { TransferQry param = CommonUtil.getObjFromReq(TransferQry.class); @@ -242,9 +228,7 @@ * @date 2023/10/31 */ @ApiOperation(value = "鎾ら攢", notes = "鎾ら攢") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @PostMapping("/updStatus") public ResponseValue updateStatus(Long id) { if (id == null) { @@ -261,9 +245,7 @@ * @Date 2023/10/31 */ @ApiOperation(value = "璋冩嫧鍏ュ簱", notes = "璋冩嫧鍏ュ簱") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @PostMapping("/income") public ResponseValue income(Long id) { lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser()); @@ -276,15 +258,14 @@ * @Date 2023/10/31 */ @ApiOperation(value = "璋冩嫧鍑哄簱", notes = "璋冩嫧鍑哄簱") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @PostMapping("/output") public ResponseValue output(Long id) { // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 FinSysTenantUser sysTenantUser = this.getSysInfo(); String agencyId = sysTenantUser.getTenantId(); - List<BaseWarehouse> baseWarehouseList = baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short) 1, (short) 1); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short)1, (short)1); if (CollectionUtils.isEmpty(baseWarehouseList)) { return ResponseValue.error("鏈烘瀯鏃犻粯璁や粨搴擄紒"); } @@ -299,12 +280,9 @@ return ResponseValue.success(); } - @ApiOperation(value = "璋冩嫧鍗曞鍑�", notes = "璋冩嫧鍗曞鍑�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), - @ApiImplicitParam(name = "type", value = "瀵煎嚭绫诲瀷 1 鍏ュ簱 2 鍑哄簱", required = true, dataType = "Integer"), - }) + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"), + @ApiImplicitParam(name = "type", value = "瀵煎嚭绫诲瀷 1 鍏ュ簱 2 鍑哄簱", required = true, dataType = "Integer"),}) @GetMapping("/list/export") public void export(Long id, Integer type, HttpServletResponse response) throws Exception { @@ -320,8 +298,10 @@ params.setHeadingStartRow(2); List<TransferExcelTemplate> export = this.lWhFormTransferService.export(id, type); - int countNum = export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); - double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null).mapToDouble(TransferExcelTemplate::getAmount).sum(); + int countNum = + export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); + double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null) + .mapToDouble(TransferExcelTemplate::getAmount).sum(); Optional<TransferExcelTemplate> first = export.stream().findFirst(); TransferExcelTemplate entity = first.get(); String businessFormCode = entity.getBusinessFormCode(); @@ -342,7 +322,6 @@ } - /** * 閮ㄩ棬鐗╁搧鍒嗗彂鍒楄〃鏄庣粏 * @@ -350,9 +329,7 @@ * @return */ @ApiOperation(value = "閮ㄩ棬鐗╁搧鍒嗗彂鍒楄〃鏄庣粏", notes = "閮ㄩ棬鐗╁搧鍒嗗彂鍒楄〃鏄庣粏") - @ApiImplicitParams({ - @ApiImplicitParam(name = "transferQryDto", value = "璋冩嫧鍗曟煡璇㈡潯浠�", required = true) - }) + @ApiImplicitParams({@ApiImplicitParam(name = "transferQryDto", value = "璋冩嫧鍗曟煡璇㈡潯浠�", required = true)}) @GetMapping("/department/list") public ResponseValue departmentTransferList() { TransferQry param = CommonUtil.getObjFromReq(TransferQry.class); @@ -364,15 +341,13 @@ if (currentUser == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } - GenericPager<Map<String, Object>> transferInfoDetailsVoGenericPager = this.lWhFormTransferService.queryTransferInfo(param); + GenericPager<Map<String, Object>> transferInfoDetailsVoGenericPager = + this.lWhFormTransferService.queryTransferInfo(param); return ResponseValue.success(transferInfoDetailsVoGenericPager); } - @ApiOperation(value = "浣跨敤浜轰慨鏀�", notes = "浣跨敤浜轰慨鏀�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "procureModelInfoDto", value = "浣跨敤淇℃伅", required = true) - }) + @ApiImplicitParams({@ApiImplicitParam(name = "procureModelInfoDto", value = "浣跨敤淇℃伅", required = true)}) @PostMapping("/useInfo/update") public ResponseValue infoUpdate() { @@ -438,9 +413,7 @@ * @return */ @ApiOperation(value = "閮ㄩ棬鐗╁搧浣跨敤浜鸿褰�", notes = "閮ㄩ棬鐗╁搧浣跨敤浜鸿褰�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "transferOrderId", value = "璋冩嫧鍗昳d", required = true) - }) + @ApiImplicitParams({@ApiImplicitParam(name = "transferOrderId", value = "璋冩嫧鍗昳d", required = true)}) @GetMapping("/use/record") public ResponseValue useRecord(Long transferOrderId) { @@ -453,14 +426,14 @@ return ResponseValue.error("鏈煡璇㈠埌浣跨敤璁板綍"); } List<GoodsUseRecordVO> goodsUseRecordList = Lists.newArrayList(); - //鍒嗙粍 - Map<Long, Map<Long, List<UseRecordDTO>>> collect = useRecordDTOList.stream() - .collect(Collectors.groupingBy(UseRecordDTO::getId, Collectors.groupingBy(UseRecordDTO::getBaseGoodsModelsId))); - //寮�濮嬪惊鐜痗ollect + // 鍒嗙粍 + Map<Long, Map<Long, List<UseRecordDTO>>> collect = useRecordDTOList.stream().collect( + Collectors.groupingBy(UseRecordDTO::getId, Collectors.groupingBy(UseRecordDTO::getBaseGoodsModelsId))); + // 寮�濮嬪惊鐜痗ollect for (Map.Entry<Long, Map<Long, List<UseRecordDTO>>> entry : collect.entrySet()) { Long id = entry.getKey(); Map<Long, List<UseRecordDTO>> value = entry.getValue(); - //寮�濮嬪惊鐜痸alue + // 寮�濮嬪惊鐜痸alue List<UseRecordSkuVO> useRecordSkuList = Lists.newArrayList(); for (Map.Entry<Long, List<UseRecordDTO>> item : value.entrySet()) { List<UseRecordDTO> list = item.getValue(); @@ -490,19 +463,17 @@ } } } - //鍒嗙粍涔嬪悗閲嶆柊鎺掑簭 - List<GoodsUseRecordVO> result = goodsUseRecordList.stream() - .sorted(Comparator.comparing(GoodsUseRecordVO::getUpdateTime - , Comparator.nullsFirst(Long::compareTo)).reversed()) + // 鍒嗙粍涔嬪悗閲嶆柊鎺掑簭 + List<GoodsUseRecordVO> result = goodsUseRecordList + .stream().sorted(Comparator + .comparing(GoodsUseRecordVO::getUpdateTime, Comparator.nullsFirst(Long::compareTo)).reversed()) .collect(Collectors.toList()); return ResponseValue.success(result); } - @ApiOperation(value = "鏌ヨ閮ㄩ棬涓嬬殑鍒嗗彂鍗�", notes = "鏌ヨ閮ㄩ棬涓嬬殑鍒嗗彂鍗�") @ApiImplicitParams({ - @ApiImplicitParam(name = "agencyId", value = "鏈烘瀯id", required = true, dataType = "Long", paramType = "query") - }) + @ApiImplicitParam(name = "agencyId", value = "鏈烘瀯id", required = true, dataType = "Long", paramType = "query")}) @GetMapping("/query/transfList") public ResponseValue queryDepartmentTransferOrderList() { -- Gitblit v1.9.1