From 58a518f8bc23ed382f4da2a86b09024b063a620c Mon Sep 17 00:00:00 2001 From: 黎星凯 <13949086503@163.com> Date: 星期一, 13 五月 2024 15:40:47 +0800 Subject: [PATCH] 20240511修改: 分发单优化, 分类,物品,分发单明细,采购单明细数据导入 --- consum-base/src/main/java/com/consum/base/controller/LWhFormTransferController.java | 738 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 630 insertions(+), 108 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 160179e..dd2a671 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,33 +1,48 @@ package com.consum.base.controller; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; - import javax.servlet.http.HttpServletResponse; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.exception.ExcelAnalysisException; +import com.alibaba.excel.exception.ExcelDataConvertException; +import com.alibaba.fastjson.JSONObject; +import com.consum.base.pojo.*; +import com.consum.base.pojo.excel.ImportProcureOrderTemplate; +import com.consum.base.pojo.excel.LWhFormTransferTemplate; +import com.consum.base.pojo.query.WarehouseQry; +import com.consum.base.service.*; +import com.consum.base.util.DateUtil; +import com.consum.base.util.ExcelStyleUtil; +import com.consum.model.po.*; import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.ObjectUtils; 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 org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; import com.consum.base.BaseController; +import com.consum.base.core.WhBusinessEnum; +import com.consum.base.core.type.StatesType; +import com.consum.base.core.type.TransferStatesType; import com.consum.base.core.utils.CommonUtil; import com.consum.base.core.utils.IdUtil; -import com.consum.base.pojo.GoodsUseRecordVO; -import com.consum.base.pojo.LWhFormTransferGoodsInfoParam; -import com.consum.base.pojo.RecordUserInfoVO; -import com.consum.base.pojo.UseRecordSkuVO; +import com.consum.base.pojo.dto.GoodsInfoDTO; import com.consum.base.pojo.dto.UseRecordDTO; import com.consum.base.pojo.excel.TransferExcelTemplate; import com.consum.base.pojo.query.TransferQry; @@ -38,24 +53,12 @@ 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.LGoodsUserRecordCoreService; -import com.consum.base.service.LWhFormTransferService; -import com.consum.base.service.LWhProcureModelService; -import com.consum.base.service.LWhProcureModelUserRecordService; -import com.consum.base.service.LWhProcureModelUserService; -import com.consum.base.service.impl.LWhFormTransferCoreService; -import com.consum.model.po.BaseWarehouse; -import com.consum.model.po.FinSysTenantUser; -import com.consum.model.po.LWhFormTransfer; -import com.consum.model.po.LWhProcureModelUser; -import com.consum.model.po.LWhProcureModelUserRecord; +import com.consum.base.service.core.LWhFormTransferCoreService; import com.iplatform.model.po.S_user_core; import com.walker.db.page.GenericPager; 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; @@ -63,6 +66,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.web.multipart.MultipartFile; /** * @Description 璋冩嫧绠$悊 @@ -85,9 +89,19 @@ @Autowired private LWhProcureModelUserRecordService lWhProcureModelUserRecordService; @Autowired + private LGoodsUserRecordCoreService lGoodsUserRecordCoreService; + @Autowired + private LWhGoodsService lWhGoodsService; + @Autowired private BaseWarehouseService baseWarehouseService; @Autowired - private LGoodsUserRecordCoreService lGoodsUserRecordCoreService; + private FinSysTenantDepartmentService departmentService; + @Autowired + private BaseCategoryService baseCategoryService; + @Autowired + private BaseGoodsTemplateService baseGoodsTemplateService; + @Autowired + private BaseGoodsModelsService baseGoodsModelsService; /** * @Description 鏂板 @@ -95,6 +109,7 @@ @ApiOperation(value = "鍗曟嵁鏂板", notes = "鍗曟嵁鏂板") @ApiImplicitParam(name = "param", value = "鍗曟嵁鏂板", required = true, dataType = "LWhFormTransferParam") @PostMapping("/add") + @Transactional(rollbackFor = Exception.class) public ResponseValue add() throws Exception { LWhFormTransferParam param = CommonUtil.getObjFromReqBody(LWhFormTransferParam.class); LWhFormTransferParam param2 = new LWhFormTransferParam(); @@ -109,48 +124,196 @@ if (CollectionUtils.isEmpty(transferGoods)) { return ResponseValue.error("璋冩嫧鍗曚笉鑳戒负绌�"); } - long id = this.lWhFormTransferService.add(param, this.getSysInfo()); + long id = this.lWhFormTransferService.add(param, this.getSysInfo(), StrUtil.isEmpty(param.getProcureDoc())); + if (id == -1L) { + return ResponseValue.error("鎮ㄤ笉鏄簱绠″憳"); + } + if (id == -2L) { + return ResponseValue.error("浠撳簱涓嶅瓨鍦�"); + } Integer transferBusinessType = param.getTransferBusinessType(); // 閮ㄩ棬鍒嗗彂涓氬姟闇�瑕佸鐞� - if (transferBusinessType == 1) { + // 鎷嗗垎 鏂伴�昏緫 + if (transferBusinessType == 1 && !StrUtil.isEmpty(param.getProcureDoc())) { // 鍏堝嚭搴擄紝鍐嶅叆搴� // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 + List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.BUMENFENFA, id); + Set<Long> baseModelIds = + modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); + FinSysTenantUser sysTenantUser = this.getSysInfo(); String agencyId = sysTenantUser.getTenantId(); List<BaseWarehouse> baseWarehouseList = - baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short)1, (short)1); - if (CollectionUtils.isEmpty(baseWarehouseList)) { - return ResponseValue.error("鏈烘瀯鏃犻粯璁や粨搴擄紒"); + baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); + Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); + // 閫氳繃璋冩嫧鍗曚腑鐨勫瀷鍙穒d鏌ヨ鍑鸿鍨嬪彿鐗╁搧鎵�鍦ㄧ殑浠撳簱浣嶇疆 + List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, null); + GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); + if (ObjectUtils.isEmpty(goodsInfoDTO)) { + return ResponseValue.error("璇ュ瀷鍙锋病鏈夊簱瀛樺彲浣跨敤"); } - BaseWarehouse baseWarehouse = baseWarehouseList.get(0); - Long wareHouseId = baseWarehouse.getId(); - String warehouseName = baseWarehouse.getWarehouseName(); + + Long wareHouseId = goodsInfoDTO.getWarehouseId(); + String warehouseName = goodsInfoDTO.getWarehouseName(); LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); lWhFormTransfer.setOutWarehouseId(wareHouseId); lWhFormTransfer.setOutWarehouseName(warehouseName); lWhFormTransferService.update(lWhFormTransfer); - lWhFormTransferCoreService.doTransferOutPut(id, getCurrentUser()); - - lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser()); + Long l = lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); + if (l == -1L) { + return ResponseValue.error("浠撳簱鏁伴噺涓嶈冻"); + } + lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), param.getOperatorName()); } return ResponseValue.success(); } + + public ResponseValue add2(LWhFormTransferParam param) throws Exception { + S_user_core currentUser = this.getCurrentUser(); + if (currentUser == null) { + return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); + } + List<LWhFormTransferGoodsInfoParam> transferGoods = param.getTransferGoods(); + if (CollectionUtils.isEmpty(transferGoods)) { + return ResponseValue.error("璋冩嫧鍗曚笉鑳戒负绌�"); + } + + FinSysTenantUser sysInfo = this.getSysInfo(); + + long id = this.lWhFormTransferService.add(param, sysInfo, true); + if (id == -1L) { + return ResponseValue.error("鎮ㄤ笉鏄簱绠″憳"); + } + if (id == -2L) { + return ResponseValue.error("浠撳簱涓嶅瓨鍦�"); + } + + Integer transferBusinessType = param.getTransferBusinessType(); + // 閮ㄩ棬鍒嗗彂涓氬姟闇�瑕佸鐞� + // todo 鎷嗗垎 鏂伴�昏緫 + if (transferBusinessType == 1 && !StrUtil.isEmpty(param.getProcureDoc())) { + // 鍏堝嚭搴擄紝鍐嶅叆搴� + // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 + List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.BUMENFENFA, id); + Set<Long> baseModelIds = + modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); + + FinSysTenantUser sysTenantUser = this.getSysInfo(); + String agencyId = sysTenantUser.getTenantId(); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); + Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); + // 閫氳繃璋冩嫧鍗曚腑鐨勫瀷鍙穒d鏌ヨ鍑鸿鍨嬪彿鐗╁搧鎵�鍦ㄧ殑浠撳簱浣嶇疆 + List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, null); + GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); + if (ObjectUtils.isEmpty(goodsInfoDTO)) { + return ResponseValue.error("璇ュ瀷鍙锋病鏈夊簱瀛樺彲浣跨敤"); + } + + Long wareHouseId = goodsInfoDTO.getWarehouseId(); + String warehouseName = goodsInfoDTO.getWarehouseName(); + LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); + lWhFormTransfer.setOutWarehouseId(wareHouseId); + lWhFormTransfer.setOutWarehouseName(warehouseName); + lWhFormTransferService.update(lWhFormTransfer); + Long l = lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); + if (l == -1L) { + return ResponseValue.error("浠撳簱鏁伴噺涓嶈冻"); + } + lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), param.getOperatorName()); + } + + return ResponseValue.success(); + } + + + /** + * 涓婁紶鍒嗗彂鍗曪紙娴佺▼淇敼锛� + * + * @param idStr 璋冩嫧鍗昳d json + * @return + * @throws Exception + */ + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) + @Transactional(rollbackFor = Exception.class) + @PostMapping("import") + public ResponseValue upload(@RequestBody String idStr) throws Exception { + Map<String, Object> map = JSONObject.parseObject(idStr, Map.class); + String type = map.get("type").toString(); + Long id = Convert.toLong(map.get("idStr")); + String procureDoc = map.get("procureDoc").toString(); + // [璋冩嫧] + if ("0".equals(type)) { + // 淇敼 + LWhFormTransfer addLWhFormTransfer = new LWhFormTransfer(); + addLWhFormTransfer.setId(id); + addLWhFormTransfer.setProcureDoc(procureDoc); + int update = lWhFormTransferService.update(addLWhFormTransfer); + if (update < 1) { + return ResponseValue.error(); + } + return ResponseValue.success(); + } + + // [鍒嗗彂] + Long opTime = Convert.toLong(map.get("opTime")); + // 淇敼琛ㄧ殑鏂囦欢閫昏緫 + LWHFromTransferExtendVO lwhFromTransferExtendVO = lWhFormTransferService.getById(id); + // 淇敼 + LWhFormTransfer addLWhFormTransfer = new LWhFormTransfer(); + addLWhFormTransfer.setId(id); + addLWhFormTransfer.setProcureDoc(procureDoc); + addLWhFormTransfer.setInTime(opTime); + addLWhFormTransfer.setOutputTime(opTime); + int update = lWhFormTransferService.update(addLWhFormTransfer); + if (update < 1) { + return ResponseValue.error(); + } + // 涓诲垎鍙戦�昏緫 + // 鍏堝嚭搴擄紝鍐嶅叆搴� + // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 + List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.BUMENFENFA, id); + Set<Long> baseModelIds = + modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); + FinSysTenantUser sysTenantUser = this.getSysInfo(); + String agencyId = sysTenantUser.getTenantId(); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); + Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); + // 閫氳繃璋冩嫧鍗曚腑鐨勫瀷鍙穒d鏌ヨ鍑鸿鍨嬪彿鐗╁搧鎵�鍦ㄧ殑浠撳簱浣嶇疆 + List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, null); + GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); + if (ObjectUtils.isEmpty(goodsInfoDTO)) { + return ResponseValue.error("璇ュ瀷鍙锋病鏈夊簱瀛樺彲浣跨敤"); + } + Long wareHouseId = goodsInfoDTO.getWarehouseId(); + String warehouseName = goodsInfoDTO.getWarehouseName(); + LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); + lWhFormTransfer.setOutWarehouseId(wareHouseId); + lWhFormTransfer.setOutWarehouseName(warehouseName); + lWhFormTransferService.update(lWhFormTransfer); + lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.BUMENFENFA); + lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), lwhFromTransferExtendVO.getOperatorName()); + return ResponseValue.success(); + } + + /** * @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"), - @ApiImplicitParam(name = "size", value = "姣忛〉鏉℃暟", required = true, dataType = "int"), - @ApiImplicitParam(name = "param", value = "鏉′欢鍙傛暟", required = true, dataType = "TransferQry"),}) + @ApiImplicitParam(name = "size", value = "姣忛〉鏉℃暟", required = true, dataType = "int"), + @ApiImplicitParam(name = "param", value = "鏉′欢鍙傛暟", required = true, dataType = "TransferQry"),}) @GetMapping("/list") public ResponseValue queryFormTransferList() { TransferQry param = CommonUtil.getObjFromReq(TransferQry.class); @@ -173,7 +336,7 @@ // 鏌ヨ鍨嬪彿鏁伴噺 List<GoodsTemplateCountVO> goodsTemplateCount = - lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); + lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); formTransferVO.setFromTransferTemplateInfoList(goodsTemplateCount); result.add(formTransferVO); @@ -220,6 +383,10 @@ if (sysInfo == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } + String tenantId = sysInfo.getTenantId(); + if (param.getInAgencyId() == null) { + param.setInAgencyId(Long.valueOf(tenantId)); + } GenericPager<Map<String, Object>> mapGenericPager = lWhFormTransferService.queryFormTransferDetailList(param); return ResponseValue.success(mapGenericPager); @@ -238,6 +405,10 @@ if (id == null) { return ResponseValue.error("鍙傛暟閿欒"); } + LWhFormTransfer lWhFormTransfer = lWhFormTransferService.selectById(id); + if (lWhFormTransfer.getStates() != TransferStatesType.OUT_PENDING.getValue()) { + return ResponseValue.error("鐘舵�侀敊璇紝涓嶈兘鎾ら攢"); + } int num = this.lWhFormTransferService.updateStatus(id); return num > 0 ? ResponseValue.success(1) : ResponseValue.error("淇敼澶辫触锛�"); @@ -251,8 +422,8 @@ @ApiOperation(value = "璋冩嫧鍏ュ簱", notes = "璋冩嫧鍏ュ簱") @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @PostMapping("/income") - public ResponseValue income(Long id) { - lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser()); + public ResponseValue income(Long id) throws Exception { + lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser(), null); return ResponseValue.success(); } @@ -264,48 +435,61 @@ @ApiOperation(value = "璋冩嫧鍑哄簱", notes = "璋冩嫧鍑哄簱") @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "璋冩嫧鍗昳d", required = true, dataType = "Long"),}) @PostMapping("/output") - public ResponseValue output(Long id) { - // 鍑哄簱鍓� 璁剧疆鍑哄簱浠撳簱 + public ResponseValue output(Long id) throws Exception { + + List<LWhProcureModel> modelByForm = lWhProcureModelService.getModelByForm(WhBusinessEnum.DIAOBO, id); + Set<Long> baseModelIds = + modelByForm.stream().map(LWhProcureModel::getBaseGoodsModelsId).collect(Collectors.toSet()); + FinSysTenantUser sysTenantUser = this.getSysInfo(); String agencyId = sysTenantUser.getTenantId(); List<BaseWarehouse> baseWarehouseList = - baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short)1, (short)1); - if (CollectionUtils.isEmpty(baseWarehouseList)) { - return ResponseValue.error("鏈烘瀯鏃犻粯璁や粨搴擄紒"); + baseWarehouseService.getBaseWareHouseList(Long.valueOf(agencyId), StatesType.NORMAL.getValue()); + Set<Long> wareHouseIds = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toSet()); + + // 閫氳繃璋冩嫧鍗曚腑鐨勫瀷鍙穒d鏌ヨ鍑鸿鍨嬪彿鐗╁搧鎵�鍦ㄧ殑浠撳簱浣嶇疆 + List<GoodsInfoDTO> goodsInfoDTOS = lWhGoodsService.queryGoodsInfo(baseModelIds, wareHouseIds, 1); + GoodsInfoDTO goodsInfoDTO = goodsInfoDTOS.stream().findFirst().orElse(null); + if (ObjectUtils.isEmpty(goodsInfoDTO)) { + return ResponseValue.error("璇ュ瀷鍙锋病鏈夊簱瀛樺彲浣跨敤"); } - BaseWarehouse baseWarehouse = baseWarehouseList.get(0); - Long wareHouseId = baseWarehouse.getId(); - String warehouseName = baseWarehouse.getWarehouseName(); + Long wareHouseId = goodsInfoDTO.getWarehouseId(); + String warehouseName = goodsInfoDTO.getWarehouseName(); LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id); lWhFormTransfer.setOutWarehouseId(wareHouseId); lWhFormTransfer.setOutWarehouseName(warehouseName); lWhFormTransferService.update(lWhFormTransfer); - lWhFormTransferCoreService.doTransferOutPut(id, getCurrentUser()); + // lWhFormTransferCoreService.doTransferOutPut(id, getCurrentUser()); + lWhFormTransferCoreService.doTransferOutPutNew(id, getCurrentUser(), WhBusinessEnum.DIAOBO); 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"),}) + @ApiImplicitParam(name = "type", value = "瀵煎嚭绫诲瀷 1 鍏ュ簱 2 鍑哄簱", required = true, dataType = "Integer"),}) @GetMapping("/list/export") - public void export(Long id, Integer type, HttpServletResponse response) throws Exception { + public ResponseValue<String> export(Long id, Integer type, HttpServletResponse response) throws Exception { TemplateExportParams params; String fileName; - if (type == 1) { + if (type == 0) { params = new TemplateExportParams("import/璋冩嫧鍏ュ簱鍗�.xls"); + fileName = "璋冩嫧鍏ュ簱鍗�"; + } else if (type == 1) { + params = new TemplateExportParams("import/璋冩嫧鍏ュ簱鍗�1.xls"); fileName = "璋冩嫧鍏ュ簱鍗�"; } else { params = new TemplateExportParams("import/璋冩嫧鍑哄簱鍗�.xls"); fileName = "璋冩嫧鍑哄簱鍗�"; } params.setHeadingStartRow(2); + params.setStyle(ExcelStyleUtil.class); List<TransferExcelTemplate> export = this.lWhFormTransferService.export(id, type); int countNum = - export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); + export.stream().filter(item -> item.getNum() != null).mapToInt(TransferExcelTemplate::getNum).sum(); double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null) - .mapToDouble(TransferExcelTemplate::getAmount).sum(); + .mapToDouble(TransferExcelTemplate::getAmount).sum(); Optional<TransferExcelTemplate> first = export.stream().findFirst(); TransferExcelTemplate entity = first.get(); String businessFormCode = entity.getBusinessFormCode(); @@ -322,7 +506,8 @@ map.put("totalAmount", totalAmount); Workbook workbook = ExcelExportUtil.exportExcel(params, TransferExcelTemplate.class, export, map); - downLoadExcel(fileName, response, workbook); + String filePath = downLoadExcel(fileName, workbook); + return ResponseValue.success("瀵煎嚭鎴愬姛", filePath); } @@ -341,12 +526,16 @@ CommonUtil.copyProperties(param, param2); param = param2; - S_user_core currentUser = this.getCurrentUser(); - if (currentUser == null) { + FinSysTenantUser sysInfo = this.getSysInfo(); + if (sysInfo == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } + String tenantId = sysInfo.getTenantId(); + if (param.getOutAgencyId() == null) { + param.setOutAgencyId(Long.valueOf(tenantId)); + } GenericPager<Map<String, Object>> transferInfoDetailsVoGenericPager = - this.lWhFormTransferService.queryTransferInfo(param); + this.lWhFormTransferService.queryTransferInfo(param); return ResponseValue.success(transferInfoDetailsVoGenericPager); } @@ -369,7 +558,7 @@ } Map<Long, List<ProcureModelInfoParam>> collect = param.getRecordInfoList().stream() - .collect(Collectors.groupingBy(ProcureModelInfoParam::getBaseGoodModelId)); + .collect(Collectors.groupingBy(ProcureModelInfoParam::getBaseGoodModelId)); for (Map.Entry<Long, List<ProcureModelInfoParam>> entry : collect.entrySet()) { Long baseGoodModelId = entry.getKey(); @@ -398,6 +587,12 @@ lWhProcureModelUser.setNowUserPhone(item.getPhone()); lWhProcureModelUser.setNowUserName(item.getUserName()); lWhProcureModelUser.setGoodsNum(item.getCount()); + + // 璁剧疆涓�涓嬪湪鐢ㄦ暟閲� + Long oldProcureModelId = item.getOldProcureModelId(); + LWhProcureModelUser oldInfo = + lWhProcureModelUserService.get(new LWhProcureModelUser(oldProcureModelId)); + lWhProcureModelUser.setUseCount(oldInfo.getUseCount()); procureModelUserList.add(lWhProcureModelUser); } @@ -420,62 +615,63 @@ @ApiImplicitParams({@ApiImplicitParam(name = "transferOrderId", value = "璋冩嫧鍗昳d", required = true)}) @GetMapping("/use/record") public ResponseValue useRecord(Long transferOrderId) { - S_user_core currentUser = this.getCurrentUser(); if (currentUser == null) { return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); } + List<UseRecordDTO> useRecordDTOList = lWhProcureModelUserService.selectUseRecord(transferOrderId); if (CollectionUtils.isEmpty(useRecordDTOList)) { return ResponseValue.error("鏈煡璇㈠埌浣跨敤璁板綍"); } - List<GoodsUseRecordVO> goodsUseRecordList = Lists.newArrayList(); - // 鍒嗙粍 - Map<Long, List<UseRecordDTO>> groupedRecords = - useRecordDTOList.stream().collect(Collectors.groupingBy(UseRecordDTO::getId)); - for (Entry<Long, List<UseRecordDTO>> entry : groupedRecords.entrySet()) { - Long id = entry.getKey(); - List<UseRecordDTO> useRecordList = entry.getValue(); - UseRecordDTO useRecordDto = useRecordList.get(0); - // 寮�濮嬪惊鐜痸alue - GoodsUseRecordVO goodsUseRecordVO = new GoodsUseRecordVO(); - goodsUseRecordVO.setId(id); - goodsUseRecordVO.setUpdateUserName(useRecordDto.getUpdateUserName()); - goodsUseRecordVO.setUpdateTime(useRecordDto.getUpdateTime()); - List<UseRecordSkuVO> useRecordSkuList = Lists.newArrayList(); - useRecordList.stream().collect(Collectors.groupingBy(UseRecordDTO::getProcureModelId)) - .forEach((key, recordList) -> { - UseRecordDTO useRecordDTO = recordList.get(0); - UseRecordSkuVO useRecordSkuVO = new UseRecordSkuVO(); - useRecordSkuVO.setBaseGoodModelId(useRecordDTO.getBaseGoodsModelsId()); - useRecordSkuVO.setBaseGoodModelName(useRecordDTO.getBaseGoodsModelsName()); - useRecordSkuVO.setUnit(useRecordDTO.getUnit()); - useRecordSkuVO.setProcureModelId(useRecordDTO.getProcureModelId()); - List<RecordUserInfoVO> recordUserInfoList = Lists.newArrayList(); - for (UseRecordDTO userInfo : recordList) { - RecordUserInfoVO recordUserInfoVO = new RecordUserInfoVO(); - recordUserInfoVO.setUseName(userInfo.getUseName()); - recordUserInfoVO.setPhone(userInfo.getPhone()); - recordUserInfoVO.setNum(userInfo.getNum()); - recordUserInfoList.add(recordUserInfoVO); - } - useRecordSkuVO.setRecordUserInfos(recordUserInfoList); - useRecordSkuList.add(useRecordSkuVO); - }); - goodsUseRecordVO.setRecordSkuDtoList(useRecordSkuList); - goodsUseRecordList.add(goodsUseRecordVO); - } - // 鍒嗙粍涔嬪悗閲嶆柊鎺掑簭 - List<GoodsUseRecordVO> result = goodsUseRecordList - .stream().sorted(Comparator - .comparing(GoodsUseRecordVO::getUpdateTime, Comparator.nullsFirst(Long::compareTo)).reversed()) - .collect(Collectors.toList()); - return ResponseValue.success(result); + + List<GoodsUseRecordVO> goodsUseRecordList = useRecordDTOList.stream() + .collect(Collectors.groupingBy(UseRecordDTO::getId)).entrySet().stream().map(entry -> { + Long id = entry.getKey(); + List<UseRecordDTO> useRecordList = entry.getValue(); + UseRecordDTO useRecordDto = useRecordList.get(0); + + GoodsUseRecordVO goodsUseRecordVO = new GoodsUseRecordVO(); + goodsUseRecordVO.setId(id); + goodsUseRecordVO.setUpdateUserName(useRecordDto.getUpdateUserName()); + goodsUseRecordVO.setUpdateTime(useRecordDto.getUpdateTime()); + + List<UseRecordSkuVO> useRecordSkuList = + useRecordList.stream().collect(Collectors.groupingBy(UseRecordDTO::getProcureModelId)).values() + .stream().map(recordList -> { + UseRecordDTO useRecordDTO = recordList.get(0); + UseRecordSkuVO useRecordSkuVO = new UseRecordSkuVO(); + useRecordSkuVO.setBaseGoodModelId(useRecordDTO.getBaseGoodsModelsId()); + useRecordSkuVO.setBaseGoodModelName(useRecordDTO.getBaseGoodsModelsName()); + useRecordSkuVO.setUnit(useRecordDTO.getUnit()); + useRecordSkuVO.setProcureModelId(useRecordDTO.getProcureModelId()); + + List<RecordUserInfoVO> recordUserInfoList = recordList.stream().map(userInfo -> { + RecordUserInfoVO recordUserInfoVO = new RecordUserInfoVO(); + recordUserInfoVO.setOldProcureModelId(userInfo.getOldProcureModelId()); + recordUserInfoVO.setUseName(userInfo.getUseName()); + recordUserInfoVO.setPhone(userInfo.getPhone()); + recordUserInfoVO.setNum(userInfo.getNum()); + return recordUserInfoVO; + }).collect(Collectors.toList()); + + useRecordSkuVO.setRecordUserInfos(recordUserInfoList); + return useRecordSkuVO; + }).collect(Collectors.toList()); + + goodsUseRecordVO.setRecordSkuDtoList(useRecordSkuList); + return goodsUseRecordVO; + + }).sorted(Comparator.comparing(GoodsUseRecordVO::getUpdateTime, Comparator.nullsFirst(Long::compareTo)) + .reversed()) + .collect(Collectors.toList()); + + return ResponseValue.success(goodsUseRecordList); } @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() { @@ -484,4 +680,330 @@ lWhFormTransferService.queryDepartmentTransferOrder(); return ResponseValue.success(transferInfoVO); } + + /** + * 鍒嗗彂鍗曞鍏� + * + * @param file + * @return + */ + @ApiOperation(value = "鍒嗗彂鍗曞鍏�", notes = "鍒嗗彂鍗曞鍏�") + @PostMapping("/import2") + public ResponseValue import2(MultipartFile file) { + String originalFilename = file.getOriginalFilename(); + // 鏂囦欢鏍煎紡鏍¢獙 +// if (!".xls".endsWith(originalFilename)) { +// return ResponseValue.error("鏂囦欢鏍煎紡鏈夎!"); +// } + FinSysTenantUser sysInfo = this.getSysInfo(); + if (sysInfo == null) { + return ResponseValue.error("褰撳墠鐧诲綍鐢ㄦ埛涓虹┖"); + } + try { + EasyExcelFactory.read(file.getInputStream(), LWhFormTransferTemplate.class, + new AnalysisEventListener<LWhFormTransferTemplate>() { + /** + * 鍒嗗彂鍗曚富鏁版嵁 + */ + final List<LWhFormTransferGoodsInfoParam> list = Lists.newArrayList(); + + /** + * 鍒嗗彂鍗曠殑澶栧眰鐨勪富鏁版嵁 + */ + final LWhFormTransferParam lWhFormTransferParam = new LWhFormTransferParam(); + + /** + * 琛岀储寮� + */ + Integer index = 0; + + /** + * 琛ㄥご淇℃伅 + * @param headMap + * @param context + */ + @Override + public void invokeHeadMap(Map headMap, AnalysisContext context) { + // 楠岃瘉琛ㄥご鏁伴噺 + logger.info("瑙f瀽鍒嗗彂鍗曠殑琛ㄥご闀垮害: {}", headMap.size()); + if (headMap.size() != 15) { + throw new ExcelAnalysisException("涓婁紶鐨勬枃浠朵笉绗�!"); + } + } + + /** + * 瀵煎叆涓�(鏂囦欢鏁版嵁澶勭悊) + * @param data + * @param analysisContext + */ + @Override + public void invoke(LWhFormTransferTemplate data, AnalysisContext analysisContext) { + index++; + String categoryOne = data.getCategoryOne(); + String categoryTwo = data.getCategoryTwo(); + String categoryThree = data.getCategoryThree(); + if (StrUtil.isEmpty(categoryThree)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝鍝佺被鍚嶇О涓嶈兘涓虹┖锛�" + categoryThree); + } + String goodsName = data.getGoodsName(); + if (StrUtil.isEmpty(goodsName)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝鍝佸悕涓嶈兘涓虹┖锛�" + goodsName); + } + String goodModelName = data.getGoodModelName(); + if (StrUtil.isEmpty(goodModelName)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝瑙勬牸鍨嬪彿涓嶈兘涓虹┖锛�" + goodModelName); + } + String unit = data.getUnit(); + String type = data.getType(); + if (StrUtil.isEmpty(type)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝绠$悊鍒嗙被涓嶈兘涓虹┖锛�" + type); + } + String agencyName = data.getAgencyName(); + if (StrUtil.isEmpty(agencyName)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝鍒涘缓鏈烘瀯涓嶈兘涓虹┖锛�" + agencyName); + } + //String warehouseName = data.getWarehouseName(); + String supplierName = data.getSupplierName(); + //String price = data.getPrice(); + String num = data.getNum(); + if (StrUtil.isEmpty(num)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝棰嗙敤鏁伴噺涓嶈兘涓虹┖锛�" + num); + } + // 鐗╁搧绫诲瀷(鑷噰闆嗛噰) + //String goodsType = data.getGoodsType(); + // 浣跨敤浜洪儴闂� + String userDepartment = data.getUserDepartment(); + if (StrUtil.isEmpty(userDepartment)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝浣跨敤浜洪儴闂ㄤ笉鑳戒负绌猴細" + userDepartment); + } + // 濉姤浜� + String reportedBy = data.getReportedBy(); + if (StrUtil.isEmpty(reportedBy)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝濉姤浜轰笉鑳戒负绌猴細" + reportedBy); + } + // 浣跨敤浜� + String user = data.getUser(); + if (StrUtil.isEmpty(user) && type.equals("A")) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝绠$悊鍒嗙被涓篈鐨勭墿鍝侊紝浣跨敤浜轰笉鑳戒负绌猴細" + user); + } + // 鑱旂郴鐢佃瘽 + String userContactPhone = data.getUserContactPhone(); + if (StrUtil.isEmpty(userContactPhone)) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹紝鑱旂郴鐢佃瘽涓嶈兘涓虹┖锛�" + userContactPhone); + } + // 绗竴娆¤繘鏉ユ妸澶栧眰鐨勫�艰缃竴涓� + if (StrUtil.isEmpty(lWhFormTransferParam.getDepartmentName())) { + // 鏈烘瀯id (鏍规嵁 鏈烘瀯鍚嶇О鍜岄儴闂ㄥ悕绉� 鏌ユ壘瀵瑰簲鐨刬d) + FinSysTenantDepartment finSysTenantDepartment = departmentService.queryIdByTenDepName(agencyName, userDepartment); + if (finSysTenantDepartment == null) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹� " + "鏈烘瀯-閮ㄩ棬鏈壘鍒帮細[" + agencyName + "-" + userDepartment + "]"); + } + lWhFormTransferParam.setTransferBusinessType(1); + lWhFormTransferParam.setDepartmentId(finSysTenantDepartment.getId()); + lWhFormTransferParam.setDepartmentName(userDepartment); + lWhFormTransferParam.setOperatorName(reportedBy); + lWhFormTransferParam.setTel(0L); + lWhFormTransferParam.setCreateTime(DateUtil.getNowDate()); + lWhFormTransferParam.setProcureDoc(""); + lWhFormTransferParam.setOutAgencyId(finSysTenantDepartment.getTenantId()); + } + // 鏌ヨ鍒嗙被id + BaseCategory baseCategory = baseCategoryService.getByCategoryByName(categoryThree); + if (baseCategory == null) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹�" + "姝ゅ垎绫绘湭鎵惧埌锛�" + categoryThree); + } + Long categoryId = baseCategory.getId(); + // 涓嶅悓閲囬泦绫诲瀷锛屼笉鍚岀瓫閫� + Optional<LWhFormTransferGoodsInfoParam> optional = null; + // 绛涢�夌被鍨� + optional = list.stream().filter(item -> item.getBaseCategoryId().equals(categoryId)).findFirst(); + // 绛涢�夌墿鍝佸悕 + Optional<LWhFormTransferGoodsInfoParam> optional2 = + list.stream().filter(item -> item.getGoodsTemplateName().equals(goodsName)).findFirst(); + // 鏁版嵁绗簩灞�-鐗╁搧鐨刬d + BaseGoodsTemplate goodsTemplate = baseGoodsTemplateService.getByGoodsNameAndCategoryId(goodsName, categoryId); + if (goodsTemplate == null) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹�" + "姝ょ墿鍝佹湭鎵惧埌锛�" + goodsName); + } + if (optional.isPresent() && optional2.isPresent()) { + // 鍐呭眰list(棰嗙敤浜�) + List<LWhTransferModelParam> models3 = optional.get().getModels(); + // 鎵惧瀷鍙峰悕瀛椾竴鏍风殑 + Optional<LWhTransferModelParam> optional3 = + models3.stream().filter(item -> item.getBaseGoodsModelsName().equals(goodModelName)).findFirst(); + int counts = 0; + for (LWhTransferModelParam m : models3) { + int addNum = 0; + if (m.getNum() != null) { + addNum = m.getCounts(); + } + counts += addNum; + } + // 鍚屼竴涓瀷鍙风殑 + if (optional3.isPresent()) { + if ("A".equals(type)) { + LWhProcureModelUserParam lWhProcureModelUserParam = new LWhProcureModelUserParam(); + lWhProcureModelUserParam.setGoodsNum(Integer.valueOf(num)); + lWhProcureModelUserParam.setNowUserName(user); + lWhProcureModelUserParam.setNowUserPhone(new Long(userContactPhone)); + Integer counts1 = optional3.get().getCounts(); + Integer num1 = optional3.get().getNum(); + optional3.get().setCounts(Integer.valueOf(num) + counts1); + optional3.get().setNum(Integer.valueOf(num) + num1); + optional3.get().getProcureModelUserList().add(lWhProcureModelUserParam); + } else { + Integer counts1 = optional3.get().getCounts(); + Integer num1 = optional3.get().getNum(); + optional3.get().setCounts(Integer.valueOf(num) + counts1); + optional3.get().setNum(Integer.valueOf(num) + num1); + } + } else { + // 姝ょ墿鍝佸彟澶栫殑瑙勬牸鍨嬪彿 + LWhTransferModelParam lWhTransferModelParam = new LWhTransferModelParam(); + // 妯℃澘鐨刬d + BaseGoodsModels selBaseGoodsModels = new BaseGoodsModels(); + selBaseGoodsModels.setModelName(goodModelName); + selBaseGoodsModels.setGoodsTemplatesId(goodsTemplate.getId()); + BaseGoodsModels selByModelNameAndGoodsTemplatesId = baseGoodsModelsService.getByModelNameAndGoodsTemplatesId(selBaseGoodsModels); + if (selByModelNameAndGoodsTemplatesId == null) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹�" + "鍝佸悕锛�" + goodsName + "锛岃鏍煎瀷鍙凤細" + goodModelName + "鏈壘鍒�"); + } + lWhTransferModelParam.setBaseGoodsModelsId(selByModelNameAndGoodsTemplatesId.getId()); + // 鍐呭眰list鐨勬暟閲忎箣鍜� + lWhTransferModelParam.setCounts(Integer.valueOf(num)); + // 妯℃澘鍚嶇О + lWhTransferModelParam.setBaseGoodsModelsName(goodModelName); + List<LWhProcureModelUserParam> addLWhProcureModelUserParam = new ArrayList<>(); + LWhProcureModelUserParam lWhProcureModelUserParam = new LWhProcureModelUserParam(); + lWhProcureModelUserParam.setGoodsNum(Integer.valueOf(num)); + + // 鏌ヨ搴撳瓨鏁伴噺 + Integer nowNum = selectAllNumber(lWhFormTransferParam.getOutAgencyId(), selByModelNameAndGoodsTemplatesId.getId()); + if(nowNum<new Integer(num)){ + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹�" + "鍝佸悕锛歔" + goodsName + "] 瑙勬牸鍨嬪彿锛歔" + goodModelName + "] 搴撳瓨鏁伴噺涓嶈冻锛歔"+nowNum+"]"); + } + lWhProcureModelUserParam.setNowUserName(user); + lWhProcureModelUserParam.setNowUserPhone(new Long(userContactPhone)); + addLWhProcureModelUserParam.add(lWhProcureModelUserParam); + lWhTransferModelParam.setProcureModelUserList(addLWhProcureModelUserParam); + optional.get().getModels().add(lWhTransferModelParam); + } + } else { + LWhFormTransferGoodsInfoParam lWhFormTransferGoodsInfoParam = new LWhFormTransferGoodsInfoParam(); + // 鍒嗙被id + lWhFormTransferGoodsInfoParam.setBaseCategoryId(categoryId); + // 鏁版嵁绗簩灞�-鐗╁搧鐨刬d + //BaseGoodsTemplate goodsTemplate = baseGoodsTemplateService.getByGoodsNameAndCategoryId(goodsName, categoryId); + BaseGoodsModels selBaseGoodsModels = new BaseGoodsModels(); + selBaseGoodsModels.setModelName(goodModelName); + selBaseGoodsModels.setGoodsTemplatesId(goodsTemplate.getId()); + BaseGoodsModels selByModelNameAndGoodsTemplatesId = baseGoodsModelsService.getByModelNameAndGoodsTemplatesId(selBaseGoodsModels); + if (selByModelNameAndGoodsTemplatesId == null) { + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹� " + "鍝佸悕锛�" + goodsName + "锛岃鏍煎瀷鍙凤細" + goodModelName + "鏈壘鍒�"); + } + // 鐗╁搧鐨刬d 锛氱埍鐜涚數鍔ㄨ溅 + lWhFormTransferGoodsInfoParam.setBaseGoodsTemplateId(goodsTemplate.getId()); + lWhFormTransferGoodsInfoParam.setGoodsTemplateName(goodsName); + // 鍐呭眰 + LWhTransferModelParam lWhTransferModelParam = new LWhTransferModelParam(); + // 瑙勬牸id + lWhTransferModelParam.setBaseGoodsModelsId(selByModelNameAndGoodsTemplatesId.getId()); + // 鏂板鐨勬椂鍊欓粯璁や竴鏉� + lWhTransferModelParam.setCounts(new Integer(num)); + lWhTransferModelParam.setNum(new Integer(num)); + List<LWhProcureModelUserParam> lWhFormProcureGoodsInfoParam = new ArrayList<>(); + LWhProcureModelUserParam lWhProcureModelUserParam = new LWhProcureModelUserParam(); + lWhProcureModelUserParam.setGoodsNum(Integer.valueOf(num)); + + // 鏌ヨ搴撳瓨鏁伴噺 + Integer nowNum = selectAllNumber(lWhFormTransferParam.getOutAgencyId(), selByModelNameAndGoodsTemplatesId.getId()); + if(nowNum<new Integer(num)){ + throw new ExcelAnalysisException("绗�" + index + "鏉℃暟鎹� " + "鍝佸悕锛歔" + goodsName + "] 瑙勬牸鍨嬪彿锛歔" + goodModelName + "] 搴撳瓨鏁伴噺涓嶈冻锛歔"+nowNum+"]"); + } + + lWhProcureModelUserParam.setNowUserName(user); + lWhProcureModelUserParam.setNowUserPhone(new Long(userContactPhone)); + lWhFormProcureGoodsInfoParam.add(lWhProcureModelUserParam); + lWhTransferModelParam.setProcureModelUserList(lWhFormProcureGoodsInfoParam); + lWhTransferModelParam.setBaseGoodsModelsName(goodModelName); + List<LWhTransferModelParam> lWhTransferModelParams = new ArrayList<>(); + lWhTransferModelParams.add(lWhTransferModelParam); + lWhFormTransferGoodsInfoParam.setModels(lWhTransferModelParams); + lWhFormTransferGoodsInfoParam.setType(type); + list.add(lWhFormTransferGoodsInfoParam); + } + } + + /** + * 鍒嗗彂鍗曞鍏ヤ富鏂规硶 + * @param analysisContext + */ + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + lWhFormTransferParam.setTransferGoods(list); + long id = IdUtil.generateId(); + //lWhFormTransferParam.setProcureDoc("[{\"fileType\":\"png\",\"id\":\"883654049218335\",\"name\":\"寰俊鎴浘_20240426143552.png\",\"url\":\"http://172.16.60.172:8083/lowConsum/file/2024/5/883654049218335.png\",\"path\":\"2024/5/883654049218335.png\",\"attSize\":6772}]"); + lWhFormTransferParam.setProcureDoc("-"); + lWhFormTransferParam.setId(id); + String jsonString = JSONObject.toJSONString(lWhFormTransferParam); + logger.info("瀵煎叆鍒嗗彂鍗昷son鏁版嵁 --------------------"); + logger.info(jsonString); + // 鍒嗗彂鍗曟嵁 + try { + ResponseValue responseValue = add2(lWhFormTransferParam); + logger.info(responseValue.toString()); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + @Override + public void onException(Exception exception, AnalysisContext analysisContext) throws Exception { + if (exception instanceof ExcelDataConvertException) { + ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception; + Integer row = excelDataConvertException.getRowIndex() + 1; + Integer column = excelDataConvertException.getColumnIndex() + 1; + throw new ExcelAnalysisException("绗�" + row + "琛岋紝绗�" + column + "鍒楄В鏋愬紓甯革紝璇锋纭~鍐�"); + } else { + throw new ExcelAnalysisException(exception.getMessage()); + } + } + }).sheet(0).doRead(); + } catch (ExcelAnalysisException e) { + return ResponseValue.error(e.getMessage()); + } catch (RuntimeException e) { + e.printStackTrace(); + return ResponseValue.error("绯荤粺閿欒"); + } catch (Exception e) { + e.printStackTrace(); + return ResponseValue.error("绯荤粺閿欒"); + } + return ResponseValue.success("瀵煎叆鎴愬姛!"); + } + + + /** + * 鏌ヨ搴撳瓨Id + * @param agencyId + * @param baseGoodsModelsId + * @return + */ + public Integer selectAllNumber(Long agencyId,Long baseGoodsModelsId) { + WarehouseQry warehouseQry = new WarehouseQry(); + warehouseQry.setAgencyId(agencyId); + warehouseQry.setBaseGoodsModelsId(baseGoodsModelsId); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getBaseWareHouseList(agencyId, StatesType.NORMAL.getValue()); + List<Long> warehouseIdList = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toList()); + Integer warehouseType = warehouseQry.getWarehouseType(); + Integer states = warehouseQry.getStates(); + Integer buyType = warehouseQry.getBuyType(); + // 璋冩嫧鏃跺彧鏌ユ満鏋勭被鍨嬬殑闆嗛噰浠撳簱搴撳瓨 + // 閮ㄩ棬鍒嗗彂鏃朵笉鍒嗘満鏋勫拰閮ㄩ棬锛屽洜涓鸿皟鎷ㄨ繘鏉ョ殑鐗╁搧涔熺畻鍦ㄥ簱瀛橀噷鍙槸绫诲瀷涓洪儴闂紝鍚屾牱妫�瑙嗘墍鏈変粨搴撹鍨嬪彿鐨勬暟閲� + int num = lWhGoodsService.queryGoodsModelInWareHouseNum(warehouseType, warehouseIdList, baseGoodsModelsId, + states, buyType); + return num; + } + } -- Gitblit v1.9.1