Parcourir la source

ehsd产品库excel导入

yzc il y a 2 ans
Parent
commit
2cff7f240e

+ 15 - 4
hx-item/src/main/java/com/fjhx/item/controller/product/ProductInfoController.java

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.item.entity.product.dto.ProductInfoDto;
 import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
-import com.fjhx.item.entity.product.po.ProductInfo;
 import com.fjhx.item.entity.product.vo.ProductInfoVo;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -88,6 +87,7 @@ public class ProductInfoController {
     public void editByEhsd(@RequestBody ProductInfoDto productInfoDto) {
         productInfoService.editByEhsd(productInfoDto);
     }
+
     /**
      * 产品库明细 尔泓扩展
      */
@@ -97,6 +97,14 @@ public class ProductInfoController {
     }
 
     /**
+     * 产品库Excel导入 尔泓扩展
+     */
+    @PostMapping("/excelImportByEhsd")
+    public void excelImportByEhsd(@RequestParam("file") MultipartFile file) {
+        productInfoService.excelImportByEhsd(file);
+    }
+
+    /**
      * 产品库明细
      */
     @PostMapping("/detail")
@@ -152,6 +160,7 @@ public class ProductInfoController {
 
     /**
      * 产品统计(数据看板-产品分析页面)
+     *
      * @param productInfoDto
      */
     @PostMapping("/productStatistics")
@@ -161,24 +170,27 @@ public class ProductInfoController {
 
     /**
      * 产品分布(数据看板-产品分析页面)
+     *
      * @param productInfoDto
      */
     @PostMapping("/productDistribution")
-    public List<Map<String,Object>> productDistribution(@RequestBody ProductInfoDto productInfoDto) {
+    public List<Map<String, Object>> productDistribution(@RequestBody ProductInfoDto productInfoDto) {
         return productInfoService.productDistribution(productInfoDto);
     }
 
     /**
      * 产品类型排行(数据看板-产品分析页面)
+     *
      * @param productInfoDto
      */
     @PostMapping("/productTypeRanking")
-    public List<Map<String,Object>> productTypeRanking(@RequestBody ProductInfoSelectDto productInfoDto) {
+    public List<Map<String, Object>> productTypeRanking(@RequestBody ProductInfoSelectDto productInfoDto) {
         return productInfoService.productTypeRanking(productInfoDto);
     }
 
     /**
      * 产品排行(数据看板-产品分析页面)
+     *
      * @param productInfoDto
      */
     @PostMapping("/productRanking")
@@ -187,5 +199,4 @@ public class ProductInfoController {
     }
 
 
-
 }

+ 46 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/po/ProductInfoEhsdExcel.java

@@ -0,0 +1,46 @@
+package com.fjhx.item.entity.product.po;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class ProductInfoEhsdExcel {
+    /**
+     * 产品分类id
+     */
+    private Long productClassifyId;
+    @ExcelProperty("产品分类名称")
+    private String productClassifyName;
+    @ExcelProperty("产品名称")
+    private String name;
+    @ExcelProperty("产品英文名")
+    private String nameEnglish;
+    @ExcelProperty("单位")
+    private String unit;
+    @ExcelProperty("销售指导价")
+    private BigDecimal price;
+    @ExcelProperty("成本价")
+    private BigDecimal costPrice;
+    @ExcelProperty("规格型号")
+    private String spec;
+    @ExcelProperty("产品尺寸长")
+    private String productLong;
+    @ExcelProperty("产品尺寸宽")
+    private String productWide;
+    @ExcelProperty("产品尺寸高")
+    private String productHigh;
+    @ExcelProperty("内包装方式-英文逗号分隔")
+    private String innerPackMethod;
+    @ExcelProperty("外包装方式-英文逗号分隔")
+    private String outerPackMethod;
+    @ExcelProperty("净重")
+    private Double netWeight;
+    @ExcelProperty("海关编码")
+    private String hsCode;
+    @ExcelProperty("备注")
+    private String remark;
+}

+ 5 - 0
hx-item/src/main/java/com/fjhx/item/service/product/ProductInfoService.java

@@ -73,6 +73,11 @@ public interface ProductInfoService extends BaseService<ProductInfo> {
     ProductInfoVo detailByEhsd(Long id);
 
     /**
+     * 产品库Excel导入 尔泓扩展
+     */
+    void excelImportByEhsd(MultipartFile file);
+
+    /**
      * 产品库新增 维多利亚
      */
     void addByWdly(ProductInfoDto productInfoDto);

+ 116 - 44
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -19,13 +19,16 @@ import com.fjhx.item.entity.product.dto.ProductInfoDto;
 import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
 import com.fjhx.item.entity.product.po.ProductClassify;
 import com.fjhx.item.entity.product.po.ProductInfo;
+import com.fjhx.item.entity.product.po.ProductInfoEhsdExcel;
 import com.fjhx.item.entity.product.po.ProductInfoEhsdJson;
 import com.fjhx.item.entity.product.vo.ProductInfoVo;
 import com.fjhx.item.mapper.product.ProductInfoMapper;
 import com.fjhx.item.service.product.ProductClassifyService;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.item.util.CodeEnum;
+import com.fjhx.item.util.excel.util.ExcelUtil;
 import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
+import com.fjhx.tenant.entity.dict.po.DictTenantData;
 import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
 import com.obs.services.internal.ServiceException;
@@ -302,6 +305,75 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
     @DSTransactional
     @Override
+    public void excelImportByEhsd(MultipartFile file) {
+        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+        Map<String, String> unitMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
+                DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "unit"));
+        Map<String, String> innerPackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
+                DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "inner_packaging_method_ehsd"));
+        Map<String, String> outsidePackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
+                DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "outside_packaging_method_ehsd"));
+        DynamicDataSourceContextHolder.poll();
+
+        List<ProductInfoEhsdExcel> read = ExcelUtil.read(file, ProductInfoEhsdExcel.class);
+        List<ProductInfo> productInfoList = new ArrayList<>();
+        for (ProductInfoEhsdExcel productInfoEhsdExcel : read) {
+            ProductInfo productInfo = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfo.class);
+            // 赋值产品编号
+            productInfo.setCode(CodeEnum.PRODUCT.getCode());
+            // 排除名称重复
+            this.nameDuplication(ProductInfo::getName, productInfo.getName(), "产品名称重复");
+
+            //产品分类名称转id
+            ProductClassify productClassify = productClassifyService.getOne(q -> q.eq(ProductClassify::getName, productInfoEhsdExcel.getProductClassifyName()));
+            if (ObjectUtil.isEmpty(productClassify)) {
+                throw new ServiceException("未知产品分类"+ productInfoEhsdExcel.getProductClassifyName());
+            }
+            productInfo.setProductClassifyId(productClassify.getId());
+            //单位名称转字典key
+            if (ObjectUtil.isNotEmpty(productInfo.getUnit())) {
+                String unit = unitMap.get(productInfo.getUnit());
+                if (ObjectUtil.isEmpty(unit)) {
+                    throw new ServiceException("未知单位" + productInfo.getUnit());
+                }
+                productInfo.setUnit(unit);
+            }
+            ProductInfoEhsdJson productInfoEhsdJson = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfoEhsdJson.class);
+            productInfoEhsdJson.setType("1");//公司产品
+            productInfoEhsdJson.setCustomerId(0l);//客户id为0 公司产品
+            //内外包装方式名称转字典key
+            String innerPackMethod = productInfoEhsdJson.getInnerPackMethod();
+            if (ObjectUtil.isNotEmpty(innerPackMethod)) {
+                String[] split = innerPackMethod.split(",");
+                for (int i = 0; i < split.length; i++) {
+                    String key = innerPackMethodMap.get(split[i]);
+                    if (ObjectUtil.isEmpty(key)) {
+                        throw new ServiceException("未知内包装方式" + split[i]);
+                    }
+                    split[i] = key;
+                }
+                productInfoEhsdJson.setInnerPackMethod(String.join(",", split));
+            }
+            String outerPackMethod = productInfoEhsdJson.getOuterPackMethod();
+            if (ObjectUtil.isNotEmpty(outerPackMethod)) {
+                String[] split = outerPackMethod.split(",");
+                for (int i = 0; i < split.length; i++) {
+                    String key = outsidePackMethodMap.get(split[i]);
+                    if (ObjectUtil.isEmpty(key)) {
+                        throw new ServiceException("未知外包装方式" + split[i]);
+                    }
+                    split[i] = key;
+                }
+                productInfoEhsdJson.setOuterPackMethod(String.join(",", split));
+            }
+            productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
+            productInfoList.add(productInfo);
+        }
+        saveBatch(productInfoList);
+    }
+
+    @DSTransactional
+    @Override
     public void addByWdly(ProductInfoDto productInfoDto) {
         //处理维多利亚扩展
         String victoriatouristJson = productInfoDto.getVictoriatouristJson();
@@ -444,13 +516,13 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * @param productInfoDto
      */
     @Override
-    public List<Map<String,Object>> productDistribution(ProductInfoDto productInfoDto) {
+    public List<Map<String, Object>> productDistribution(ProductInfoDto productInfoDto) {
         if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
-                && StringUtils.isNotEmpty(productInfoDto.getEndTime())){
-            throw  new ServiceException("参数缺失:开始时间,结束时间不能为null");
+                && StringUtils.isNotEmpty(productInfoDto.getEndTime())) {
+            throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
         }
         //存放产品分布列表
-        List<Map<String,Object>> list = new ArrayList<>();
+        List<Map<String, Object>> list = new ArrayList<>();
 
         QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
         query.select("count(*) count,ifnull(type,999) type");
@@ -459,30 +531,30 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         query.le("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
         //查询每个类型的总计
         List<ProductInfo> productInfos = baseMapper.selectList(query);
-        if (productInfos.size()==0){
+        if (productInfos.size() == 0) {
             new ArrayList<>();
         }
-        Map<String, List<ProductInfo>>  productInfoMap= productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
+        Map<String, List<ProductInfo>> productInfoMap = productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
         //获取产品类型的字典数据
         DynamicDataSourceContextHolder.push(SourceConstant.BASE);
         List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
         DynamicDataSourceContextHolder.poll();
 
-        if (dictTenantDataVoList.size()==0){
+        if (dictTenantDataVoList.size() == 0) {
             new ArrayList<>();
         }
 
         //赋值
         for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
-            Map<String,Object> map = new HashMap<>();
+            Map<String, Object> map = new HashMap<>();
             //初始化
-            map.put("type",dictTenantDataVo.getDictKey());
-            map.put("name",dictTenantDataVo.getDictValue());
-            map.put("count",0);
+            map.put("type", dictTenantDataVo.getDictKey());
+            map.put("name", dictTenantDataVo.getDictValue());
+            map.put("count", 0);
 
             List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
-            if (ObjectUtil.isNotEmpty(productInfoList)){
-                map.put("count",productInfoList.get(0).getCount());
+            if (ObjectUtil.isNotEmpty(productInfoList)) {
+                map.put("count", productInfoList.get(0).getCount());
             }
             list.add(map);
         }
@@ -495,21 +567,21 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * @param productInfoDto
      */
     @Override
-    public List<Map<String,Object>> productTypeRanking(ProductInfoSelectDto productInfoDto) {
+    public List<Map<String, Object>> productTypeRanking(ProductInfoSelectDto productInfoDto) {
         //存放产品类型排行数据
-        List<Map<String,Object>> list = new ArrayList<>();
+        List<Map<String, Object>> list = new ArrayList<>();
 
         QueryWrapper<Object> query = Wrappers.query();
         String beginTime = DateUtil.format(productInfoDto.getBeginTime(), "yyyy-MM-dd");
         String endTime = DateUtil.format(productInfoDto.getEndTime(), "yyyy-MM-dd");
-        query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",beginTime);
-        query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",endTime);
-        query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()),"bc.buy_country_id",productInfoDto.getCountryId());
+        query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", beginTime);
+        query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", endTime);
+        query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()), "bc.buy_country_id", productInfoDto.getCountryId());
 //        sort(query,productInfoDto);
         query.groupBy("pi.type");
         //查询产品类型排行数据
         List<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(query);
-        if (productInfoVos.size()==0){
+        if (productInfoVos.size() == 0) {
             return list;
         }
         Map<String, List<ProductInfoVo>> productInfoVoMap = productInfoVos.stream().collect(Collectors.groupingBy(ProductInfoVo::getType));
@@ -521,26 +593,26 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         //赋值
         for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
             //初始化
-            Map<String,Object> map = new HashMap<>();
-            map.put("type",dictTenantDataVo.getDictKey());
-            map.put("name",dictTenantDataVo.getDictValue());
-            map.put("contractAmount",new BigDecimal(0));
-            map.put("contractQuantity",new BigDecimal(0));
-            map.put("purchaseAmount",new BigDecimal(0));
-            map.put("purchaseQuantity",new BigDecimal(0));
+            Map<String, Object> map = new HashMap<>();
+            map.put("type", dictTenantDataVo.getDictKey());
+            map.put("name", dictTenantDataVo.getDictValue());
+            map.put("contractAmount", new BigDecimal(0));
+            map.put("contractQuantity", new BigDecimal(0));
+            map.put("purchaseAmount", new BigDecimal(0));
+            map.put("purchaseQuantity", new BigDecimal(0));
             //赋值
             List<ProductInfoVo> productInfoVos1 = productInfoVoMap.get(dictTenantDataVo.getDictKey());
-            if (ObjectUtil.isNotEmpty(productInfoVos1)){
-                map.put("contractAmount",productInfoVos1.get(0).getContractAmount());
-                map.put("contractQuantity",productInfoVos1.get(0).getContractQuantity());
-                map.put("purchaseAmount",productInfoVos1.get(0).getPurchaseAmount());
-                map.put("purchaseQuantity",productInfoVos1.get(0).getPurchaseQuantity());
+            if (ObjectUtil.isNotEmpty(productInfoVos1)) {
+                map.put("contractAmount", productInfoVos1.get(0).getContractAmount());
+                map.put("contractQuantity", productInfoVos1.get(0).getContractQuantity());
+                map.put("purchaseAmount", productInfoVos1.get(0).getPurchaseAmount());
+                map.put("purchaseQuantity", productInfoVos1.get(0).getPurchaseQuantity());
             }
             list.add(map);
         }
-        if (ObjectUtil.isNotEmpty(list)){
+        if (ObjectUtil.isNotEmpty(list)) {
             //排序
-            list= typeSort(list,productInfoDto);
+            list = typeSort(list, productInfoDto);
         }
         return list;
     }
@@ -590,49 +662,49 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
     }
 
     //产品类型排序
-    private List<Map<String,Object>> typeSort(List<Map<String,Object>> list,ProductInfoSelectDto productInfoSelectDto){
-        if (productInfoSelectDto.getOrderBy() ==10){
-            if (productInfoSelectDto.getSort() ==10){
+    private List<Map<String, Object>> typeSort(List<Map<String, Object>> list, ProductInfoSelectDto productInfoSelectDto) {
+        if (productInfoSelectDto.getOrderBy() == 10) {
+            if (productInfoSelectDto.getSort() == 10) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
                         .collect(Collectors.toList());
                 return list;
-            }else if (productInfoSelectDto.getSort() ==20){
+            } else if (productInfoSelectDto.getSort() == 20) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
                         .collect(Collectors.toList());
                 return list;
-            }else if (productInfoSelectDto.getSort() ==30){
+            } else if (productInfoSelectDto.getSort() == 30) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
                         .collect(Collectors.toList());
                 return list;
-            }else if (productInfoSelectDto.getSort() ==40){
+            } else if (productInfoSelectDto.getSort() == 40) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
                         .collect(Collectors.toList());
                 return list;
             }
-        }else {
-            if (productInfoSelectDto.getSort() ==10){
+        } else {
+            if (productInfoSelectDto.getSort() == 10) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
                         .collect(Collectors.toList());
                 Collections.reverse(list);
                 return list;
-            }else if (productInfoSelectDto.getSort() ==20){
+            } else if (productInfoSelectDto.getSort() == 20) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
                         .collect(Collectors.toList());
                 Collections.reverse(list);
                 return list;
-            }else if (productInfoSelectDto.getSort() ==30){
+            } else if (productInfoSelectDto.getSort() == 30) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
                         .collect(Collectors.toList());
                 Collections.reverse(list);
                 return list;
-            }else if (productInfoSelectDto.getSort() ==40){
+            } else if (productInfoSelectDto.getSort() == 40) {
                 list = list.stream()
                         .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
                         .collect(Collectors.toList());