|
@@ -5,17 +5,16 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.gqy.common.utils.CustomJsonParser;
|
|
|
import com.gqy.common.utils.bean.BeanUtils;
|
|
|
import com.gqy.document.domain.*;
|
|
|
-import com.gqy.document.mapper.DcProductMapper;
|
|
|
-import com.gqy.document.mapper.DcSpecMapper;
|
|
|
-import com.gqy.document.mapper.DcSystemProductMapper;
|
|
|
-import com.gqy.document.mapper.DcWorkSystemMapper;
|
|
|
+import com.gqy.document.mapper.*;
|
|
|
import com.gqy.document.service.IDcProductService;
|
|
|
import com.gqy.system.mapper.DcPsParamMapper;
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -44,6 +43,13 @@ public class DcProductServiceImpl implements IDcProductService {
|
|
|
private DcPsParamMapper dcPsParamMapper;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DcSystemMapper dcSystemMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkMapper workMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取
|
|
@@ -251,81 +257,25 @@ public class DcProductServiceImpl implements IDcProductService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param params
|
|
|
- * @return
|
|
|
- */
|
|
|
- public int addJson(Map<String,Object> params){
|
|
|
- //产品code
|
|
|
- String productCode = (String) params.get("productCode");
|
|
|
- return 0;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param params
|
|
|
- * @return
|
|
|
+ * 新增产品信息
|
|
|
+ * @param params 包含产品内容和规格的参数Map
|
|
|
+ * @return 成功返回1,失败返回0
|
|
|
*/
|
|
|
public int add(Map<String, Object> params) {
|
|
|
|
|
|
try {
|
|
|
+ // 获取产品基本信息
|
|
|
Map<String, Object> content = (Map<String, Object>) params.get("content");
|
|
|
|
|
|
- DcProduct product = new DcProduct();
|
|
|
- // 拷贝参数
|
|
|
- BeanUtils.mapToBean(content,product );
|
|
|
- // 保存
|
|
|
- dcProductMapper.insertDcProduct(product);
|
|
|
- // 产品id
|
|
|
- int dcpId = product.getDcp_id();
|
|
|
- //系统类别id
|
|
|
- int sys_no = Integer.parseInt(content.get("sys_no").toString());
|
|
|
- //工程id
|
|
|
- int wr_id = Integer.parseInt(content.get("wr_id").toString());
|
|
|
-
|
|
|
-
|
|
|
- // 工程系统表 保存信息 dc_work_system
|
|
|
- DcWorkSystem workSystem = new DcWorkSystem();
|
|
|
- workSystem.setWr_id(wr_id);
|
|
|
- workSystem.setSys_id(sys_no);
|
|
|
-
|
|
|
- dcWorkSystemMapper.insertDcWorkSystem(workSystem);
|
|
|
-
|
|
|
- // 系统产品表 保存信息 dc_system_product
|
|
|
- DcSystemProduct systemProduct = new DcSystemProduct();
|
|
|
- systemProduct.setSys_no(sys_no);
|
|
|
- systemProduct.setDcp_id(dcpId);
|
|
|
- dcSystemProductMapper.insertDcSystemProduct(systemProduct);
|
|
|
+ // 保存产品基本信息并获取产品ID
|
|
|
+ int dcpId = getDcpIdAdd(content);
|
|
|
|
|
|
- // 规格管理
|
|
|
+ // 获取规格信息并保存
|
|
|
List<Map> specs = (List<Map>) params.get("specs");
|
|
|
- for (Map maps : specs) {
|
|
|
-
|
|
|
- //保存规格信息表
|
|
|
- DcSpec dcSpec = new DcSpec();
|
|
|
- BeanUtils.mapToBean(maps,dcSpec);
|
|
|
-
|
|
|
- String ps_no = maps.get("ps_no").toString();
|
|
|
- dcSpec.setPs_no(ps_no);
|
|
|
- dcSpec.setPs_name(maps.get("ps_name").toString());
|
|
|
- dcSpec.setPs_p_id(dcpId);
|
|
|
- //dcSpec.setPs_category(maps.get("ps_category").toString());
|
|
|
-
|
|
|
- dcSpecMapper.insertDcSpec(dcSpec);
|
|
|
-
|
|
|
- //查询 规格参数
|
|
|
- DcPsParam dcPsParamQuery = new DcPsParam();
|
|
|
- dcPsParamQuery.setPsp_mode(ps_no);
|
|
|
- List<DcPsParam> listDcPsParam = dcPsParamMapper.selectDcPsParamList(dcPsParamQuery);
|
|
|
- if(CollectionUtils.isEmpty(listDcPsParam)){
|
|
|
- //规格参数
|
|
|
- DcPsParam dcPsParam = new DcPsParam();
|
|
|
- BeanUtils.mapToBean(maps,dcPsParam );
|
|
|
- dcPsParam.setPsp_mode(ps_no);
|
|
|
- dcPsParamMapper.insertDcPsParam(dcPsParam);
|
|
|
- }
|
|
|
- }
|
|
|
+ extractedAdd(specs, dcpId);
|
|
|
+
|
|
|
return 1;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
@@ -333,26 +283,233 @@ public class DcProductServiceImpl implements IDcProductService {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存产品规格信息
|
|
|
+ * @param specs 规格信息列表
|
|
|
+ * @param dcpId 产品ID
|
|
|
+ */
|
|
|
+ private void extractedAdd(List<Map> specs, int dcpId) {
|
|
|
+ for (Map maps : specs) {
|
|
|
+
|
|
|
+ //保存规格信息表
|
|
|
+ DcSpec dcSpec = new DcSpec();
|
|
|
+ BeanUtils.mapToBean(maps,dcSpec);
|
|
|
+
|
|
|
+ String ps_no = maps.get("ps_no").toString();
|
|
|
+ dcSpec.setPs_no(ps_no);
|
|
|
+ dcSpec.setPs_name(maps.get("ps_name").toString());
|
|
|
+ dcSpec.setPs_p_id(dcpId);
|
|
|
+ //dcSpec.setPs_category(maps.get("ps_category").toString());
|
|
|
+
|
|
|
+ dcSpecMapper.insertDcSpec(dcSpec);
|
|
|
+
|
|
|
+ //查询规格参数是否已存在
|
|
|
+ DcPsParam dcPsParamQuery = new DcPsParam();
|
|
|
+ dcPsParamQuery.setPsp_mode(ps_no);
|
|
|
+ List<DcPsParam> listDcPsParam = dcPsParamMapper.selectDcPsParamList(dcPsParamQuery);
|
|
|
+ if(CollectionUtils.isEmpty(listDcPsParam)){
|
|
|
+ //规格参数不存在则新增
|
|
|
+ DcPsParam dcPsParam = new DcPsParam();
|
|
|
+ BeanUtils.mapToBean(maps,dcPsParam );
|
|
|
+ dcPsParam.setPsp_mode(ps_no);
|
|
|
+ dcPsParamMapper.insertDcPsParam(dcPsParam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * 导入JSON
|
|
|
- * @param context
|
|
|
- * @return
|
|
|
+ * 保存产品基本信息并关联工程和系统
|
|
|
+ * @param content 产品基本信息
|
|
|
+ * @return 新增产品的ID
|
|
|
*/
|
|
|
- public int exportJSON(String context){
|
|
|
- try{
|
|
|
+ private int getDcpIdAdd(Map<String, Object> content) {
|
|
|
+ // 保存产品基本信息
|
|
|
+ DcProduct product = new DcProduct();
|
|
|
+ BeanUtils.mapToBean(content,product );
|
|
|
+ dcProductMapper.insertDcProduct(product);
|
|
|
+
|
|
|
+ // 获取相关ID
|
|
|
+ int dcpId = product.getDcp_id();
|
|
|
+ int sys_no = Integer.parseInt(content.get("sys_no").toString());
|
|
|
+ int wr_id = Integer.parseInt(content.get("wr_id").toString());
|
|
|
+
|
|
|
+ // 保存工程系统关联信息
|
|
|
+ DcWorkSystem workSystem = new DcWorkSystem();
|
|
|
+ workSystem.setWr_id(wr_id);
|
|
|
+ workSystem.setSys_id(sys_no);
|
|
|
+ dcWorkSystemMapper.insertDcWorkSystem(workSystem);
|
|
|
+
|
|
|
+ // 保存系统产品关联信息
|
|
|
+ DcSystemProduct systemProduct = new DcSystemProduct();
|
|
|
+ systemProduct.setSys_no(sys_no);
|
|
|
+ systemProduct.setDcp_id(dcpId);
|
|
|
+ dcSystemProductMapper.insertDcSystemProduct(systemProduct);
|
|
|
+
|
|
|
+ return dcpId;
|
|
|
+ }
|
|
|
|
|
|
- String dcp_name = CustomJsonParser.getParamValue(context,"OA编码");
|
|
|
- String dcp_oa_code = CustomJsonParser.getParamValue(context,"产品名称");
|
|
|
+ /**
|
|
|
+ * 导入JSON格式的产品信息
|
|
|
+ * @param context JSON格式字符串
|
|
|
+ * @return 成功返回1,失败返回对应错误码
|
|
|
+ * -1: 基本格式不正确
|
|
|
+ * -2: 缺少必要分隔符
|
|
|
+ * -3: 括号不匹配
|
|
|
+ * -4: 错误的分隔符模式
|
|
|
+ * -5: 缺少必要字段
|
|
|
+ * -99: 其他异常
|
|
|
+ */
|
|
|
+ public int exportJSON(String context) {
|
|
|
+ try {
|
|
|
+ // 1. 验证JSON格式
|
|
|
+ if (!validateJsonFormat(context)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 验证必要分隔符
|
|
|
+ if (!validateSeparators(context)) {
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
|
|
|
+ // 3. 验证括号匹配
|
|
|
+ if (!validateBraces(context)) {
|
|
|
+ return -3;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 验证分隔符模式
|
|
|
+ if (!validateSeparatorPattern(context)) {
|
|
|
+ return -4;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 验证必要字段
|
|
|
+ if (!validateRequiredFields(context)) {
|
|
|
+ return -5;
|
|
|
+ }
|
|
|
|
|
|
+ // 格式验证通过,解析并保存产品信息
|
|
|
+ return processAndSaveProduct(context);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return -99;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }catch(Exception e){
|
|
|
+ private boolean validateJsonFormat(String context) {
|
|
|
+ return context.startsWith("DDW{") && context.endsWith("},}");
|
|
|
+ }
|
|
|
|
|
|
+ private boolean validateSeparators(String context) {
|
|
|
+ String[] sections = {"箱体{", "屏幕{", "},投影机{"};
|
|
|
+ for (String section : sections) {
|
|
|
+ if (!context.contains(section)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- return 0;
|
|
|
+ private boolean validateBraces(String context) {
|
|
|
+ int leftBraces = context.length() - context.replace("{", "").length();
|
|
|
+ int rightBraces = context.length() - context.replace("}", "").length();
|
|
|
+ return leftBraces == rightBraces;
|
|
|
}
|
|
|
+
|
|
|
+ private boolean validateSeparatorPattern(String context) {
|
|
|
+ String[] errorPatterns = {"}箱体", "}屏幕", "}投影机"};
|
|
|
+ for (String pattern : errorPatterns) {
|
|
|
+ if (context.contains(pattern)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequiredFields(String context) {
|
|
|
+ String[] requiredFields = {
|
|
|
+ "OA编码:", "产品名称:", "工程:", "系统类别:",
|
|
|
+ "类型:", "材质:", "宽:", "高:", "厚:",
|
|
|
+ "型号:", "屏幕比例:", "屏幕尺寸:",
|
|
|
+ "光源:", "分辨率", "亮度:", "控制盒:"
|
|
|
+ };
|
|
|
+ for (String field : requiredFields) {
|
|
|
+ if (!context.contains(field)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int processAndSaveProduct(String context) {
|
|
|
+ // 解析JSON
|
|
|
+ Map mapResult = CustomJsonParser.getParam(context);
|
|
|
+
|
|
|
+ // 获取系统信息
|
|
|
+ String sys_name = mapResult.get("sys_name").toString();
|
|
|
+ DcSystem dcSystem = dcSystemMapper.selectDcSystemByName(sys_name);
|
|
|
+ mapResult.put("sys_no", dcSystem.getSysId());
|
|
|
+ String wk_name = mapResult.get("wk_name").toString();
|
|
|
+ DcWork dcWork = workMapper.selectWorkByName(wk_name);
|
|
|
+ mapResult.put("wr_id", dcWork.getWkId());
|
|
|
+
|
|
|
+// workMapper.selectWorkByName()
|
|
|
+
|
|
|
+// DcWorkSystem dcWorkSystemQuery = new DcWorkSystem();
|
|
|
+// dcWorkSystemQuery.setSys_id(dcSystem.getSysId().intValue());
|
|
|
+// List<DcWorkSystem> dcWorkSystemList = dcWorkSystemMapper.selectDcWorkSystemList(dcWorkSystemQuery);
|
|
|
+// if(!CollectionUtils.isEmpty(dcWorkSystemList)){
|
|
|
+// DcWorkSystem dcWorkSystem = dcWorkSystemList.get(0);
|
|
|
+// mapResult.put("wr_id", dcWorkSystem.getWr_id());
|
|
|
+//
|
|
|
+// }
|
|
|
+ // 查询规格参数
|
|
|
+ DcPsParam queryDcPsParam = new DcPsParam();
|
|
|
+ List<DcPsParam> listDcPsParam = dcPsParamMapper.selectDcPsParamList(queryDcPsParam);
|
|
|
+
|
|
|
+ // 保存产品基本信息
|
|
|
+ int dcpId = getDcpIdAdd(mapResult);
|
|
|
+
|
|
|
+ // 处理规格信息
|
|
|
+ List<Map> specs = new ArrayList<>();
|
|
|
+ for (DcPsParam dcPsParam : listDcPsParam) {
|
|
|
+ if (ObjectUtils.isNotEmpty(mapResult.get(dcPsParam.getPsp_mode()))) {
|
|
|
+ Map maps = new HashMap();
|
|
|
+ maps.put("ps_no", dcPsParam.getPsp_mode());
|
|
|
+ maps.put("psp_name", dcPsParam.getPsp_name());
|
|
|
+ maps.put("ps_name", mapResult.get(dcPsParam.getPsp_mode()));
|
|
|
+ maps.put("psp_type",dcPsParam.getPsp_type());
|
|
|
+ specs.add(maps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapResult.put("specs", specs);
|
|
|
+
|
|
|
+ // 保存产品信息
|
|
|
+ extractedAdd(specs, dcpId);
|
|
|
+
|
|
|
+
|
|
|
+ // 创建新的规格列表用于JSON序列化
|
|
|
+ List<Map<String, String>> newSpecs = new ArrayList<>();
|
|
|
+
|
|
|
+ // 遍历specs并构建新的JSON格式
|
|
|
+ for (Map spec : specs) {
|
|
|
+ Map<String, String> newSpec = new HashMap<>();
|
|
|
+ newSpec.put("ps_no", String.valueOf(spec.get("ps_no")));
|
|
|
+ newSpec.put("psp_name", String.valueOf(spec.get("psp_name")));
|
|
|
+ newSpec.put("psp_type", String.valueOf(spec.get("psp_type")));
|
|
|
+ newSpec.put("ps_name", String.valueOf(spec.get("ps_name")));
|
|
|
+ newSpecs.add(newSpec);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将新的规格列表转换为JSON字符串
|
|
|
+ String specsJson = JSON.toJSONString(newSpecs);
|
|
|
+
|
|
|
+ // 更新产品基本信息
|
|
|
+ DcProduct dcProduct = dcProductMapper.selectDcProductById(new Long(dcpId));
|
|
|
+ dcProduct.setDcp_p_no(specsJson);
|
|
|
+ dcProductMapper.updateDcProduct(dcProduct);
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|