浏览代码

公司产品库报错问题处理

yzc 1 年之前
父节点
当前提交
41a507564b
共有 1 个文件被更改,包括 36 次插入31 次删除
  1. 36 31
      hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

+ 36 - 31
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -181,7 +181,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             //将部门id转为字符串(帮助解决前端问题)
             json.put("deptId", json.getString("deptId"));
 
-            record.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            record.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
 
         return page;
@@ -231,7 +231,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         List<Long> customerIds = new ArrayList<>();
         for (ProductInfoVo record : records) {
             ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
-            if(ObjectUtil.isNotEmpty(productInfoEhsdJson.getCustomerId())) {
+            if (ObjectUtil.isNotEmpty(productInfoEhsdJson.getCustomerId())) {
                 customerIds.add(Long.parseLong(productInfoEhsdJson.getCustomerId()));
             }
         }
@@ -239,9 +239,13 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             Map<Long, String> customerMap = customerService.mapKV(Customer::getId, Customer::getName, q -> q.in(Customer::getId, customerIds));
             for (ProductInfoVo record : records) {
                 ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
-                String customerName = customerMap.get(Long.parseLong(productInfoEhsdJson.getCustomerId()));
-                productInfoEhsdJson.setCustomerName(customerName);
-                record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+
+                String customerId = productInfoEhsdJson.getCustomerId();
+                if (ObjectUtil.isNotEmpty(customerId)) {
+                    String customerName = customerMap.get(Long.parseLong(customerId));
+                    productInfoEhsdJson.setCustomerName(customerName);
+                }
+                record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             }
         }
         //赋值创建人名称
@@ -262,27 +266,27 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         //赋值维多利亚组合产品信息
         JSONObject json = JSONObject.parseObject(result.getVictoriatouristJson());
         List<Long> ids = new ArrayList<>();
-        if(ObjectUtil.isNotEmpty(json) && ObjectUtil.isNotEmpty(json.getJSONArray("productCombinationList"))){
+        if (ObjectUtil.isNotEmpty(json) && ObjectUtil.isNotEmpty(json.getJSONArray("productCombinationList"))) {
             JSONArray productCombinationList = json.getJSONArray("productCombinationList");
-            for (int i=0;i<productCombinationList.size();i++) {
+            for (int i = 0; i < productCombinationList.size(); i++) {
                 JSONObject item = productCombinationList.getJSONObject(i);
                 ids.add(item.getLong("linkProductId"));
             }
-            if(ObjectUtil.isNotEmpty(ids)){
+            if (ObjectUtil.isNotEmpty(ids)) {
                 List<ProductInfo> productInfoList = this.listByIds(ids);
                 Map<Long, ProductInfo> productInfoMap = productInfoList.stream().collect(Collectors.toMap(ProductInfo::getId, Function.identity()));
                 JSONArray jsonArray = new JSONArray();
-                for (int i=0;i<productCombinationList.size();i++) {
+                for (int i = 0; i < productCombinationList.size(); i++) {
                     JSONObject item = productCombinationList.getJSONObject(i);
                     ProductInfo productInfo1 = productInfoMap.get(item.getLong("linkProductId"));
-                    if(ObjectUtil.isNotEmpty(productInfo1)) {
-                        item.put("code",productInfo1.getCode());
-                        item.put("customCode",productInfo1.getCustomCode());
-                        item.put("name",productInfo1.getName());
+                    if (ObjectUtil.isNotEmpty(productInfo1)) {
+                        item.put("code", productInfo1.getCode());
+                        item.put("customCode", productInfo1.getCustomCode());
+                        item.put("name", productInfo1.getName());
                     }
                     jsonArray.add(item);
                 }
-                json.put("productCombinationList",jsonArray);
+                json.put("productCombinationList", jsonArray);
                 result.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             }
         }
@@ -328,7 +332,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             productInfoEhsdJson.setCustomerId("0");
             productInfoEhsdJson.setType("1");//默认公司产品
         }
-        productInfoDto.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+        productInfoDto.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
 
         // 赋值产品编号
         productInfoDto.setCode(CodeEnum.PRODUCT.getCode());
@@ -357,7 +361,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         productInfoEhsdJson.setNetWeight(newProductInfoEhsdJson.getNetWeight());//净重
 
         productInfo.setRemark(productInfoDto.getRemark());//备注
-        productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+        productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
         this.updateById(productInfo);
         //修改图片
         ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
@@ -375,7 +379,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             Customer customer = customerService.getById(productInfoEhsdJson.getCustomerId());
             if (ObjectUtil.isNotEmpty(customer)) {
                 productInfoEhsdJson.setCustomerName(customer.getName());
-                result.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+                result.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             }
         }
         //赋值创建人名称
@@ -446,7 +450,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                 }
                 productInfoEhsdJson.setOuterPackMethod(String.join(",", split));
             }
-            productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+            productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             productInfoList.add(productInfo);
         }
         saveBatch(productInfoList);
@@ -460,7 +464,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
             JSONObject json = JSONObject.parseObject(victoriatouristJson);
             json.put("deptId", SecurityUtils.getDeptId());
-            productInfoDto.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            productInfoDto.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
         add(productInfoDto);
     }
@@ -516,8 +520,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * @return
      */
     @Override
-    public List<ProductInfoVo> getListByProductType(Integer productType, Integer definition,String productName,String productCode) {
-        return baseMapper.getListByProductType(productType, definition,productName,productCode);
+    public List<ProductInfoVo> getListByProductType(Integer productType, Integer definition, String productName, String productCode) {
+        return baseMapper.getListByProductType(productType, definition, productName, productCode);
     }
 
     @Override
@@ -531,7 +535,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         String victoriatouristJson = productInfo.getVictoriatouristJson();
         JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
         json.put("deptId", productInfoDto.getDeptId());
-        productInfo.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+        productInfo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         updateById(productInfo);
     }
 
@@ -734,6 +738,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
     /**
      * 产品统计
+     *
      * @return
      */
     @Override
@@ -745,9 +750,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * 产品库统计(根据产品库类型进行分类统计)
      */
     @Override
-    public  Map<String,Object> productInfoStatistics(ProductInfoSelectDto dto) {
+    public Map<String, Object> productInfoStatistics(ProductInfoSelectDto dto) {
         //存放产品库统计数据
-        Map<String,Object> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
 
         //存放产品分类统计数据
         List<Map<String, Object>> list = new ArrayList<>();
@@ -760,30 +765,30 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         //计算统计合计
         Integer amount = productInfos.stream().map(productInfo -> productInfo.getCount()).reduce(Integer::sum).orElse(0);
 
-        map.put("amount",amount);
+        map.put("amount", amount);
         //获取产品类型统计数据
         DynamicDataSourceContextHolder.push(SourceConstant.BASE);
         List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
         DynamicDataSourceContextHolder.poll();
-        if (dictTenantDataVoList.size()==0){
+        if (dictTenantDataVoList.size() == 0) {
             throw new ServiceException("数据异常:产品没有设置产品类型字典,请先添加");
         }
 
         for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
             Map typeMap = new HashMap();
             //设置初始值
-            typeMap.put("type",dictTenantDataVo.getDictValue());
-            typeMap.put("count",0);
+            typeMap.put("type", dictTenantDataVo.getDictValue());
+            typeMap.put("count", 0);
 
             //赋值
             List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
-            if (CollectionUtils.isNotEmpty(productInfoList)){
-                typeMap.put("count",productInfoList.get(0).getCount());
+            if (CollectionUtils.isNotEmpty(productInfoList)) {
+                typeMap.put("count", productInfoList.get(0).getCount());
             }
             list.add(typeMap);
 
         }
-        map.put("typeList",list);
+        map.put("typeList", list);
         return map;
     }