From 3be9cfcb6b59366b936821966d20a998a6895f9f Mon Sep 17 00:00:00 2001 From: 黎星凯 <13949086503@163.com> Date: 星期二, 30 四月 2024 14:38:13 +0800 Subject: [PATCH] bug41、42修改 --- consum-base/src/main/java/com/consum/base/controller/BaseGoodsTemplateController.java | 118 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 67 insertions(+), 51 deletions(-) diff --git a/consum-base/src/main/java/com/consum/base/controller/BaseGoodsTemplateController.java b/consum-base/src/main/java/com/consum/base/controller/BaseGoodsTemplateController.java index da2fb8c..fe31dc4 100644 --- a/consum-base/src/main/java/com/consum/base/controller/BaseGoodsTemplateController.java +++ b/consum-base/src/main/java/com/consum/base/controller/BaseGoodsTemplateController.java @@ -1,9 +1,12 @@ package com.consum.base.controller; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; @@ -15,21 +18,24 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.EasyExcelFactory; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.exception.ExcelDataConvertException; import com.consum.base.BaseController; +import com.consum.base.core.type.StatesType; import com.consum.base.core.utils.CommonUtil; import com.consum.base.core.utils.MapUtils; import com.consum.base.core.utils.MapperUtil; import com.consum.base.pojo.BaseGoodsTemplateParam; import com.consum.base.pojo.excel.ImportGoodsInfoTemplate; import com.consum.base.pojo.response.GoodsTemplateVO; +import com.consum.base.service.BaseCategoryService; import com.consum.base.service.BaseGoodsTemplateService; import com.consum.base.service.BaseWarehouseService; import com.consum.base.service.FinSysTenantService; import com.consum.base.service.LWhGoodsService; +import com.consum.model.po.BaseCategory; import com.consum.model.po.BaseGoodsModels; import com.consum.model.po.BaseGoodsTemplate; import com.consum.model.po.BaseWarehouse; @@ -38,10 +44,10 @@ import com.consum.model.po.SDictData; import com.consum.model.vo.BaseGoodsTemplateVo; import com.walker.db.page.GenericPager; -import com.walker.infrastructure.utils.DateUtils; import com.walker.infrastructure.utils.StringUtils; import com.walker.web.ResponseValue; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @@ -51,6 +57,7 @@ * @Author 鍗㈠簡闃� * @Date 2023/10/24 */ +@Api(value = "鐗╁搧妯℃澘", tags = "鐗╁搧妯℃澘") @RestController @RequestMapping("/pc/base/goods/template") public class BaseGoodsTemplateController extends BaseController { @@ -66,6 +73,9 @@ @Autowired private FinSysTenantService finSysTenantService; + + @Autowired + private BaseCategoryService baseCategoryService; /** * @Description 鏂板鐗╁搧妯℃澘 @@ -171,8 +181,10 @@ * * @author 鍗㈠簡闃� * @date 2023/10/25 + * <p> + * 鐗╁搧鐨勭鐢ㄦ垨鍒犻櫎锛屼笉褰卞搷宸茬粡閲囪喘鍏ヨ繃搴撶殑鐗╁搧淇℃伅銆� + * <p> */ - // TODO 鐗╁搧鐨勭鐢ㄦ垨鍒犻櫎锛屼笉褰卞搷宸茬粡閲囪喘鍏ヨ繃搴撶殑鐗╁搧淇℃伅銆� @PostMapping("/updStatus") public ResponseValue updateStatus() { BaseGoodsTemplate goodsTemplate = CommonUtil.getObjFromReqBody(BaseGoodsTemplate.class); @@ -180,7 +192,7 @@ CommonUtil.copyProperties(goodsTemplate, param2); goodsTemplate = param2; - if (goodsTemplate == null || goodsTemplate.getId() == null || goodsTemplate.getStates() == null) { + if (goodsTemplate.getId() == null || goodsTemplate.getStates() == null) { return ResponseValue.error("鍙傛暟閿欒"); } @@ -192,8 +204,10 @@ * @Description 鏍规嵁鐗╁搧id鍒犻櫎鐗╁搧 * @Author 鍗㈠簡闃� * @Date 2023/10/25 + * <p> + * 鐗╁搧鐨勭鐢ㄦ垨鍒犻櫎锛屼笉褰卞搷宸茬粡閲囪喘鍏ヨ繃搴撶殑鐗╁搧淇℃伅銆� + * <p/> */ - // TODO 鐗╁搧鐨勭鐢ㄦ垨鍒犻櫎锛屼笉褰卞搷宸茬粡閲囪喘鍏ヨ繃搴撶殑鐗╁搧淇℃伅銆� @DeleteMapping("/del") public ResponseValue updateById() { BaseGoodsTemplate goodsTemplate = CommonUtil.getObjFromReqBody(BaseGoodsTemplate.class); @@ -233,16 +247,16 @@ @GetMapping("/query/goodsTemplate") public ResponseValue queryGoodsTemplateByCategoryId(Long agencyId, Long categoryId) { - // TODO 涓嶉檺鍒舵満鏋� - List<BaseGoodsTemplate> list = - this.baseGoodsTemplateService.queryGoodsTemplateByCategoryId(null, categoryId, null, null); + // 涓嶉檺鍒舵満鏋� + List<BaseGoodsTemplate> list = baseGoodsTemplateService.queryGoodsTemplateByCategoryId(null, categoryId, + StatesType.NORMAL.getValue(), null); if (list == null) { return ResponseValue.error("鏌ヨ澶辫触锛�"); } return ResponseValue.success("鏌ヨ鎴愬姛!", list); } - @ApiOperation(value = "鏌ヨ鏈烘瀯涓嬮粯璁や粨搴撲笅鐨勫垎绫绘ā鏉夸俊鎭�", notes = "鏌ヨ鏈烘瀯涓嬮粯璁や粨搴撲笅鐨勫垎绫绘ā鏉夸俊鎭�") + @ApiOperation(value = "璋冩嫧鏌ヨ鏈烘瀯涓嬫墍鏈変粨搴撲笅鐨勫垎绫绘ā鏉夸俊鎭�", notes = "璋冩嫧鏌ヨ鏈烘瀯涓嬫墍鏈変粨搴撲笅鐨勫垎绫绘ā鏉夸俊鎭�") @ApiImplicitParams({ @ApiImplicitParam(name = "agencyId", value = "鐖剁骇鏈烘瀯id", required = true, dataType = "java.lang.Long", paramType = "query"), @@ -251,22 +265,23 @@ @GetMapping("/query/warehouse/goods") public ResponseValue queryWarehouseGoods(Long agencyId, Long categoryId) { - // TODO 璋冩嫧鏌ヨ浠撳簱鐗╁搧 + // 璋冩嫧鏌ヨ鎵�鏈変粨搴撶墿鍝佹ā鏉夸俊鎭� Map<String, Object> map = new HashMap<>(); map.put("categoryId", categoryId); - List<BaseWarehouse> baseWarehouseList = baseWarehouseService.getByAgencyId(agencyId, (short)1, (short)1); + List<BaseWarehouse> baseWarehouseList = + baseWarehouseService.getBaseWareHouseList(agencyId, StatesType.NORMAL.getValue()); if (CollectionUtils.isEmpty(baseWarehouseList)) { - return ResponseValue.error("鏈烘瀯鏃犻粯璁や粨搴擄紒"); + return ResponseValue.error("鏈烘瀯鏃犱粨搴擄紒"); } - map.put("warehouseId", baseWarehouseList.get(0).getId()); + List<Long> warehouseIdList = baseWarehouseList.stream().map(BaseWarehouse::getId).collect(Collectors.toList()); + map.put("warehouseIdList", warehouseIdList); String sql = "SELECT DISTINCT bgt.id,bgt.GOODS_NAME, CLASSIFICATION type FROM l_wh_goods g LEFT JOIN base_goods_template bgt ON g.BASE_GOODS_TEMPLATE_ID = bgt.id " - + "WHERE WAREHOUSE_TYPE = 0 " + "AND WAREHOUSE_ID = :warehouseId " - // TODO 涓存椂瑙e喅 - /*+ "AND CATEGORY_ID = :categoryId "*/ + + "WHERE WAREHOUSE_TYPE = 0 " + "AND WAREHOUSE_ID in (:warehouseIdList) " + + "AND CATEGORY_ID = :categoryId " // 1:闆嗛噰,2:鑷噰 + "AND BUY_TYPE =1"; @@ -282,14 +297,14 @@ @PostMapping("/import") public ResponseValue upload(MultipartFile file) throws IOException { String originalFilename = file.getOriginalFilename(); - if (!originalFilename.endsWith(".xls")) { + if (!".xls".endsWith(originalFilename)) { return ResponseValue.error("鏂囦欢鏍煎紡鏈夎!"); } FinSysTenantUser sysInfo = this.getSysInfo(); if (sysInfo == null) { return ResponseValue.error("褰撳墠鐧诲綍鐢ㄦ埛涓虹┖"); } - EasyExcel.read(file.getInputStream(), ImportGoodsInfoTemplate.class, + EasyExcelFactory.read(file.getInputStream(), ImportGoodsInfoTemplate.class, new AnalysisEventListener<ImportGoodsInfoTemplate>() { List<BaseGoodsTemplateParam> list = Lists.newArrayList(); @@ -298,48 +313,47 @@ String categoryOne = data.getCategoryOne(); String categoryTwo = data.getCategoryTwo(); String categoryThree = data.getCategoryThree(); - String goodName = data.getGoodName(); - String goodModel = data.getGoodModel(); + String goodsName = data.getGoodsName(); + String goodModelName = data.getGoodModelName(); String unit = data.getUnit(); String type = data.getType(); String agencyName = data.getAgencyName(); - list.stream().forEach(item -> { - if (!item.getCategoryId().equals(categoryThree)) { - BaseGoodsTemplateParam baseGoodsTemplate = new BaseGoodsTemplateParam(); - baseGoodsTemplate.setCategoryId(Long.valueOf(categoryThree)); - baseGoodsTemplate.setGoodsName(goodName); - baseGoodsTemplate.setStates(1); - FinSysTenant finSysTenant = finSysTenantService.selectByName(agencyName); - baseGoodsTemplate.setAgencyId(finSysTenant.getId()); + BaseCategory baseCategory = baseCategoryService.getByCategoryByName(categoryThree); + Long categoryId = baseCategory.getId(); - List<BaseGoodsModels> models = Lists.newArrayList(); - BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); - baseGoodsModels.setModelName(goodModel); - baseGoodsModels.setStates(1); - baseGoodsModels.setGoodsTemplatesId(item.getId()); - baseGoodsModels.setUnit(unit); - baseGoodsModels.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); - models.add(baseGoodsModels); - baseGoodsTemplate.setModels(models); - } else { - List<BaseGoodsModels> models = item.getModels(); - BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); - baseGoodsModels.setModelName(goodModel); - baseGoodsModels.setStates(1); - baseGoodsModels.setGoodsTemplatesId(item.getId()); - baseGoodsModels.setUnit(unit); - baseGoodsModels.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); - models.add(baseGoodsModels); - } - }); + Optional<BaseGoodsTemplateParam> optional = + list.stream().filter(item -> item.getCategoryId().equals(categoryId)).findFirst(); + if (optional.isPresent()) { + BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); + baseGoodsModels.setModelName(goodModelName); + baseGoodsModels.setUnit(unit); + optional.get().getModels().add(baseGoodsModels); + } else { + BaseGoodsTemplateParam baseGoodsTemplate = new BaseGoodsTemplateParam(); + baseGoodsTemplate.setCategoryId(categoryId); + baseGoodsTemplate.setGoodsName(goodsName); + baseGoodsTemplate.setStates(1); + FinSysTenant finSysTenant = finSysTenantService.selectByName(agencyName); + baseGoodsTemplate.setAgencyId(finSysTenant.getId()); + baseGoodsTemplate.setAgencyName(agencyName); + + List<BaseGoodsModels> models = new ArrayList<>(); + BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); + baseGoodsModels.setModelName(goodModelName); + baseGoodsModels.setUnit(unit); + models.add(baseGoodsModels); + baseGoodsTemplate.setModels(models); + + list.add(baseGoodsTemplate); + } } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { - for (BaseGoodsTemplateParam a : list) { - baseGoodsTemplateService.add(a, sysInfo); + for (BaseGoodsTemplateParam baseGoodsTemplate : list) { + baseGoodsTemplateService.add(baseGoodsTemplate, null); } } @@ -350,10 +364,12 @@ Integer row = excelDataConvertException.getRowIndex() + 1; Integer column = excelDataConvertException.getColumnIndex() + 1; throw new RuntimeException("绗�" + row + "琛岋紝绗�" + column + "鍒楄В鏋愬紓甯革紝璇锋纭~鍐�"); + } else { + throw new RuntimeException(exception.getMessage()); } } }).sheet(0).doRead(); - return ResponseValue.success("瀵煎叆鎴愬姛!", 1); + return ResponseValue.success("瀵煎叆鎴愬姛!"); } } -- Gitblit v1.9.1