|
@@ -3,6 +3,9 @@ package com.fjhx.item.service.product.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.fastjson2.JSONWriter;
|
|
@@ -29,13 +32,15 @@ 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.DictTenantDataDto;
|
|
|
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;
|
|
|
+import com.fjhx.tenant.utils.DictUtils;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
@@ -48,6 +53,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -183,7 +190,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;
|
|
@@ -241,7 +248,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
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));
|
|
|
+ record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
|
|
|
}
|
|
|
}
|
|
|
//赋值创建人名称
|
|
@@ -262,27 +269,28 @@ 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());
|
|
|
+ item.put("spec", productInfo1.getSpec());
|
|
|
}
|
|
|
jsonArray.add(item);
|
|
|
}
|
|
|
- json.put("productCombinationList",jsonArray);
|
|
|
+ json.put("productCombinationList", jsonArray);
|
|
|
result.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
}
|
|
|
}
|
|
@@ -295,14 +303,14 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
// 赋值产品编号
|
|
|
productInfoDto.setCode(CodeEnum.PRODUCT.getCode());
|
|
|
// 排除名称重复
|
|
|
- this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), "产品名称重复");
|
|
|
+ this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), "产品名称重复:" + productInfoDto.getName());
|
|
|
// 排除不为空的自定义编码重复
|
|
|
- long count = this.count(q -> q.eq(ProductInfo::getCustomCode, productInfoDto.getCustomCode()).ne(ProductInfo::getCustomCode,""));
|
|
|
+ long count = this.count(q -> q.eq(ProductInfo::getCustomCode, productInfoDto.getCustomCode()).ne(ProductInfo::getCustomCode, ""));
|
|
|
if (count != 0) {
|
|
|
- throw new ServiceException("产品自定义编码重复");
|
|
|
+ throw new ServiceException("产品自定义编码重复:" + productInfoDto.getCustomCode());
|
|
|
}
|
|
|
// 排除不为空的条码编号重复
|
|
|
- long count1 = this.count(q -> q.eq(ProductInfo::getBarCode, productInfoDto.getBarCode()).ne(ProductInfo::getBarCode,""));
|
|
|
+ long count1 = this.count(q -> q.eq(ProductInfo::getBarCode, productInfoDto.getBarCode()).ne(ProductInfo::getBarCode, ""));
|
|
|
if (count1 != 0) {
|
|
|
throw new ServiceException("产品条码编码重复");
|
|
|
}
|
|
@@ -321,7 +329,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());
|
|
@@ -346,7 +354,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
productInfoEhsdJson.setCostPrice(newProductInfoEhsdJson.getCostPrice());//成本价
|
|
|
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());
|
|
@@ -364,7 +372,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));
|
|
|
}
|
|
|
}
|
|
|
//赋值创建人名称
|
|
@@ -435,7 +443,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);
|
|
@@ -449,7 +457,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);
|
|
|
}
|
|
@@ -498,13 +506,222 @@ 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
|
|
|
+ @DSTransactional
|
|
|
public void excelImport(MultipartFile file) {
|
|
|
-// List<Object> read = ExcelUtil.read(file, Object.class);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd");
|
|
|
+ //获取所有产品分类
|
|
|
+ List<ProductClassify> productClassifyList = productClassifyService.list();
|
|
|
+ //获取字典数据
|
|
|
+ List<DictTenantDataVo> productTypeDictList = DictUtils.getDictList("product_type");//产品类型
|
|
|
+ List<DictTenantDataVo> unitDictList = DictUtils.getDictList("unit");//产品单位
|
|
|
+ List<DictTenantDataVo> salesStatusDictList = DictUtils.getDictList("sales_status");//销售状态
|
|
|
+ //获取部门列表
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ List<SysDept> deptList = sysDeptService.list();
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ Map<String, Long> deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptName, SysDept::getDeptId));
|
|
|
+
|
|
|
+ //读取Excel
|
|
|
+ List<Map<Integer, String>> excelList = new ArrayList<>();
|
|
|
+ EasyExcel.read(ExcelUtil.getInputStream(file)).sheet(0).registerReadListener(new AnalysisEventListener<Map<Integer, String>>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
|
|
|
+ excelList.add(integerStringMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ //数据读取完毕
|
|
|
+ }
|
|
|
+ }).headRowNumber(2).doRead();
|
|
|
+ for (Map<Integer, String> integerStringMap : excelList) {
|
|
|
+ String productClassifyNames = integerStringMap.get(0);
|
|
|
+ String productType = integerStringMap.get(1);
|
|
|
+ String productCode = integerStringMap.get(4);
|
|
|
+ String productUnit = integerStringMap.get(5);
|
|
|
+ String salesStatus = integerStringMap.get(12);
|
|
|
+
|
|
|
+ //数据预处理
|
|
|
+ Long productClassifyId = -1L;//产品分类id
|
|
|
+ if (ObjectUtil.isNotEmpty(productClassifyNames)) {
|
|
|
+ String[] split = productClassifyNames.split(">");
|
|
|
+ ProductClassify productClassify = null;
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ int finalI = i;
|
|
|
+ ProductClassify finalTempProductClassify = productClassify;
|
|
|
+ List<ProductClassify> collect = productClassifyList.stream().filter(item -> {
|
|
|
+ boolean re = Objects.equals(item.getName(), split[finalI]);
|
|
|
+ //如果为空说明是顶级分类
|
|
|
+ if (ObjectUtil.isEmpty(finalTempProductClassify)) {
|
|
|
+ //过滤父级id为0或空
|
|
|
+ re = re && (item.getParentId() == 0 || ObjectUtil.isEmpty(item.getParentId()));
|
|
|
+ } else {
|
|
|
+ //过滤父级id为上一级的id
|
|
|
+ re = re && ObjectUtil.equal(item.getParentId(), finalTempProductClassify.getId());
|
|
|
+ }
|
|
|
+ return re;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (collect.size() > 1) {
|
|
|
+ throw new ServiceException("同级存在多个相同名称的分类:" + split[i]);
|
|
|
+ }
|
|
|
+ if (collect.size() == 0) {
|
|
|
+ throw new ServiceException("分类不存在:" + split[i]);
|
|
|
+ }
|
|
|
+ productClassify = collect.get(0);
|
|
|
+ }
|
|
|
+ productClassifyId = productClassify.getId();//产品分类id
|
|
|
+ }
|
|
|
+ //产品类型处理
|
|
|
+ if (ObjectUtil.isNotEmpty(productType)) {
|
|
|
+ String finalProductType = productType;
|
|
|
+ List<DictTenantDataVo> collect = productTypeDictList.stream().filter(item -> Objects.equals(item.getDictValue(), finalProductType)).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isEmpty(collect)) {
|
|
|
+ throw new ServiceException(String.format("产品 %s 的 产品类型 %s 不存在", productCode, productType));
|
|
|
+ }
|
|
|
+ productType = collect.get(0).getDictKey();
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(String.format("产品 %s 的 产品类型 不能为空", productCode));
|
|
|
+ }
|
|
|
+ //单位处理
|
|
|
+ if (ObjectUtil.isNotEmpty(productUnit)) {
|
|
|
+ String finalProductUnit = productUnit;
|
|
|
+ List<DictTenantDataVo> collect = unitDictList.stream().filter(item -> Objects.equals(item.getDictValue(), finalProductUnit)).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isEmpty(collect)) {
|
|
|
+ //创建字典
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ DictTenantDataDto dictTenantData = new DictTenantDataDto();
|
|
|
+ dictTenantData.setDictCode("unit");
|
|
|
+ dictTenantData.setDictKey(productUnit);
|
|
|
+ dictTenantData.setDictValue(productUnit);
|
|
|
+ dictTenantDataService.add(dictTenantData);
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ unitDictList.add(BeanUtil.copyProperties(dictTenantData, DictTenantDataVo.class));
|
|
|
+ } else {
|
|
|
+ productUnit = collect.get(0).getDictKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //销售状态处理
|
|
|
+ if (ObjectUtil.isNotEmpty(salesStatus)) {
|
|
|
+ String finalSalesStatus = salesStatus;
|
|
|
+ List<DictTenantDataVo> collect = salesStatusDictList.stream().filter(item -> Objects.equals(item.getDictValue(), finalSalesStatus)).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isEmpty(collect)) {
|
|
|
+ //创建字典
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ DictTenantDataDto dictTenantData = new DictTenantDataDto();
|
|
|
+ dictTenantData.setDictCode("sales_status");
|
|
|
+ dictTenantData.setDictKey(salesStatus);
|
|
|
+ dictTenantData.setDictValue(salesStatus);
|
|
|
+ dictTenantDataService.add(dictTenantData);
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ salesStatusDictList.add(BeanUtil.copyProperties(dictTenantData, DictTenantDataVo.class));
|
|
|
+ } else {
|
|
|
+ salesStatus = collect.get(0).getDictKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建实体
|
|
|
+ JSONObject victoriatouristJson = new JSONObject();
|
|
|
+
|
|
|
+ ProductInfoDto productInfoDto = new ProductInfoDto();
|
|
|
+ productInfoDto.setDefinition(1);//产品
|
|
|
+
|
|
|
+ productInfoDto.setProductClassifyId(productClassifyId);
|
|
|
+ productInfoDto.setType(productType);
|
|
|
+ productInfoDto.setName(integerStringMap.get(2));
|
|
|
+ productInfoDto.setSpec(integerStringMap.get(3));
|
|
|
+
|
|
|
+ //检查产品Code是否存在
|
|
|
+ long count = count(q -> q.eq(ProductInfo::getCustomCode, productCode)
|
|
|
+ .ne(ProductInfo::getCustomCode, "")
|
|
|
+ );
|
|
|
+ if (count > 0) {
|
|
|
+ throw new ServiceException("产品已存在:" + productCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ productInfoDto.setCustomCode(productCode);
|
|
|
+ productInfoDto.setUnit(productUnit);
|
|
|
+ productInfoDto.setRemark(integerStringMap.get(6));
|
|
|
+ victoriatouristJson.put("jdPurchasePrice", integerStringMap.get(7));
|
|
|
+ victoriatouristJson.put("sellingPrice", integerStringMap.get(8));
|
|
|
+ victoriatouristJson.put("weight", integerStringMap.get(9));
|
|
|
+ victoriatouristJson.put("materialQuality", integerStringMap.get(10));
|
|
|
+ victoriatouristJson.put("applicableTemp", integerStringMap.get(11));
|
|
|
+ victoriatouristJson.put("salesStatus", salesStatus);
|
|
|
+ String clearancePeriod = integerStringMap.get(13);
|
|
|
+ if (ObjectUtil.isNotEmpty(clearancePeriod)) {
|
|
|
+ try {
|
|
|
+ Date parse = sdf.parse(clearancePeriod);
|
|
|
+ clearancePeriod = sdf1.format(parse);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new ServiceException(String.format("产品 %s 的库存清空期限时间格式化失败请检查"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ victoriatouristJson.put("clearancePeriod", clearancePeriod);
|
|
|
+ //新品期
|
|
|
+ String[] newProductsDays = integerStringMap.get(14).split("-");
|
|
|
+ Integer newProductsDay1 = Integer.parseInt(newProductsDays[0]);
|
|
|
+ Integer newProductsDay = Integer.parseInt(newProductsDays[1]);
|
|
|
+ victoriatouristJson.put("newProductsDay", newProductsDay);
|
|
|
+ victoriatouristJson.put("newProductsDay1", newProductsDay1);
|
|
|
+ //成长期
|
|
|
+ String[] growUpDays = integerStringMap.get(16).split("-");
|
|
|
+ Integer growUpDay1 = Integer.parseInt(growUpDays[0]);
|
|
|
+ Integer growUpDay = Integer.parseInt(growUpDays[1]);
|
|
|
+ if (growUpDay1 <= newProductsDay) {
|
|
|
+ throw new ServiceException(String.format("产品%s成长期的开始时间要大于新品器的结束时间", productInfoDto.getCustomCode()));
|
|
|
+ }
|
|
|
+ victoriatouristJson.put("growUpDay1", growUpDay1);
|
|
|
+ victoriatouristJson.put("growUpDay", growUpDay);
|
|
|
+ //销量
|
|
|
+ victoriatouristJson.put("newProductsExpectedSales", integerStringMap.get(15));
|
|
|
+ victoriatouristJson.put("growUpExpectedSales", integerStringMap.get(17));
|
|
|
+ victoriatouristJson.put("matureExpectedSales", integerStringMap.get(18));
|
|
|
+ //部门
|
|
|
+ String deptName = integerStringMap.getOrDefault(19, "");
|
|
|
+ if (ObjectUtil.isNotEmpty(deptName)) {
|
|
|
+ Long deptId = deptMap.get(deptName);
|
|
|
+ if (ObjectUtil.isEmpty(deptId)) {
|
|
|
+ throw new ServiceException(String.format("产品 %s 的部门 %s 不存在", productCode, deptName));
|
|
|
+ }
|
|
|
+ victoriatouristJson.put("deptId", deptId);
|
|
|
+ }
|
|
|
+ //是否组合
|
|
|
+ Integer combination = "是".equals(integerStringMap.getOrDefault(20, "")) ? 1 : 0;
|
|
|
+ victoriatouristJson.put("combination", combination);
|
|
|
+ //如果是组合
|
|
|
+ if (combination == 1) {
|
|
|
+ JSONArray productCombinationList = new JSONArray();
|
|
|
+ for (int i = 21; i < integerStringMap.size(); i += 2) {
|
|
|
+ String linkProductCode = integerStringMap.get(i);
|
|
|
+ String linkQuantity = integerStringMap.get(i + 1);
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(linkProductCode)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ProductInfo linkProduct = getOne(q -> q.eq(ProductInfo::getCustomCode, linkProductCode));
|
|
|
+ if (ObjectUtil.isEmpty(linkProduct)) {
|
|
|
+ throw new ServiceException("关联产品不存在:" + linkProductCode);
|
|
|
+ }
|
|
|
+ JSONObject linkProductJson = new JSONObject();
|
|
|
+ linkProductJson.put("linkProductId", linkProduct.getId());
|
|
|
+ linkProductJson.put("linkQuantity", linkQuantity);
|
|
|
+ productCombinationList.add(linkProductJson);
|
|
|
+ }
|
|
|
+ victoriatouristJson.put("productCombinationList", productCombinationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ productInfoDto.setVictoriatouristJson(victoriatouristJson.toJSONString());
|
|
|
+ //添加产品
|
|
|
+ add(productInfoDto);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -513,7 +730,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);
|
|
|
}
|
|
|
|
|
@@ -716,6 +933,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
/**
|
|
|
* 产品统计
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
@@ -727,9 +945,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<>();
|
|
@@ -742,30 +960,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;
|
|
|
}
|
|
|
|