|
@@ -43,6 +43,87 @@ public class DcProductServiceImpl implements IDcProductService {
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新产品及其关联信息
|
|
|
+ * @param params 包含产品信息和规格信息的参数
|
|
|
+ * @return 更新成功返回1,失败返回0
|
|
|
+ */
|
|
|
+ public int update(Map<String, Object> params) {
|
|
|
+ try {
|
|
|
+ // 1. 更新产品基本信息
|
|
|
+ Map<String, Object> content = (Map<String, Object>) params.get("content");
|
|
|
+ DcProduct product = new DcProduct();
|
|
|
+ BeanUtils.mapToBean(content, product);
|
|
|
+ dcProductMapper.updateDcProduct(product);
|
|
|
+
|
|
|
+ // 获取关键ID
|
|
|
+ int dcpId = product.getDcp_id();
|
|
|
+ int sysNo = Integer.parseInt(content.get("sys_no").toString());
|
|
|
+ int wrId = Integer.parseInt(content.get("wr_id").toString());
|
|
|
+
|
|
|
+ // 2. 更新工程系统表
|
|
|
+ DcWorkSystem workSystem = new DcWorkSystem();
|
|
|
+ workSystem.setWr_id(wrId);
|
|
|
+ workSystem.setSys_id(sysNo);
|
|
|
+ // 先删除旧关联
|
|
|
+ dcWorkSystemMapper.deleteByWrIdAndSysId(wrId, sysNo);
|
|
|
+ // 插入新关联
|
|
|
+ dcWorkSystemMapper.insertDcWorkSystem(workSystem);
|
|
|
+
|
|
|
+ // 3. 更新系统产品表
|
|
|
+ DcSystemProduct systemProduct = new DcSystemProduct();
|
|
|
+ systemProduct.setSys_no(sysNo);
|
|
|
+ systemProduct.setDcp_id(dcpId);
|
|
|
+ // 先删除旧关联
|
|
|
+ dcSystemProductMapper.deleteBySysNoAndDcpId(sysNo, dcpId);
|
|
|
+ // 插入新关联
|
|
|
+ dcSystemProductMapper.insertDcSystemProduct(systemProduct);
|
|
|
+
|
|
|
+ // 4. 更新规格管理
|
|
|
+ List<Map> specs = (List<Map>) params.get("specs");
|
|
|
+ if (specs != null && !specs.isEmpty()) {
|
|
|
+ // 先删除原有规格
|
|
|
+ dcSpecMapper.deleteByProductId(dcpId);
|
|
|
+
|
|
|
+ // 插入新的规格信息
|
|
|
+ for (Map maps : specs) {
|
|
|
+ // 保存规格信息表
|
|
|
+ DcSpec dcSpec = new DcSpec();
|
|
|
+ dcSpec.setPs_p_id(dcpId);
|
|
|
+ BeanUtils.mapToBean(maps, dcSpec);
|
|
|
+ String psNo = maps.get("ps_no").toString();
|
|
|
+ dcSpec.setPs_no(psNo);
|
|
|
+ dcSpec.setPs_name(maps.get("ps_name").toString());
|
|
|
+ dcSpecMapper.insertDcSpec(dcSpec);
|
|
|
+
|
|
|
+ // 更新规格参数
|
|
|
+ DcPsParam dcPsParamQuery = new DcPsParam();
|
|
|
+ dcPsParamQuery.setPsp_mode(psNo);
|
|
|
+ List<DcPsParam> listDcPsParam = dcPsParamMapper.selectDcPsParamList(dcPsParamQuery);
|
|
|
+ if (CollectionUtils.isEmpty(listDcPsParam)) {
|
|
|
+ // 如果不存在则新增规格参数
|
|
|
+ DcPsParam dcPsParam = new DcPsParam();
|
|
|
+ BeanUtils.mapToBean(maps, dcPsParam);
|
|
|
+ dcPsParam.setPsp_mode(psNo);
|
|
|
+ dcPsParamMapper.insertDcPsParam(dcPsParam);
|
|
|
+ } else {
|
|
|
+ // 如果存在则更新规格参数
|
|
|
+ DcPsParam dcPsParam = listDcPsParam.get(0);
|
|
|
+ BeanUtils.mapToBean(maps, dcPsParam);
|
|
|
+ dcPsParamMapper.updateDcPsParam(dcPsParam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|