zishan-an vor 11 Monaten
Ursprung
Commit
c2946c8b34

+ 28 - 21
src/main/java/com/kexun/controller/CooperatorProductController.java

@@ -7,6 +7,8 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.*;
+import com.kexun.mapper.CooperatorProductFieldMapper;
+import com.kexun.mapper.FieldDefineMapper;
 import com.kexun.service.CooperatorProductFieldService;
 import com.kexun.service.CooperatorProductService;
 import com.kexun.service.FieldDefineService;
@@ -31,6 +33,11 @@ public class CooperatorProductController {
     @Autowired
     private CooperatorProductService CooperatorProductService;
 
+    @Autowired
+    CooperatorProductFieldMapper cooperatorProductFieldMapper;
+
+    @Autowired
+    FieldDefineMapper fieldDefineMapper;
     @Autowired
     private com.kexun.service.CooperatorProductFieldService CooperatorProductFieldService;
 
@@ -160,22 +167,22 @@ public class CooperatorProductController {
         //合作方产品字段关系表
         String fieldSelected = req.getString("fieldSelected");
         List<String> fieldSelectedList= JSONArray.parseArray(fieldSelected,String.class);
+
         List<CooperatorProductField> cooperatorProductFieldList = new ArrayList<>();
+        List<FieldDefineEntity> productFieldList = fieldDefineMapper.selectBatchIds(fieldSelectedList);
 
         for (int i=0;i<fieldSelectedList.size();i++){
-            Long fid = Long.parseLong(fieldSelectedList.get(i));
-            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
             CooperatorProductField cooperatorProductField = new CooperatorProductField();
             cooperatorProductField.setIsDeleted(false);
-            cooperatorProductField.setFieldId(fieldDefine.getId());
-            cooperatorProductField.setFieldNo(fieldDefine.getFieldNo());
-            cooperatorProductField.setName(fieldDefine.getName());
+            cooperatorProductField.setFieldId(productFieldList.get(i).getId());
+            cooperatorProductField.setFieldNo(productFieldList.get(i).getFieldNo());
+            cooperatorProductField.setName(productFieldList.get(i).getName());
             cooperatorProductField.setProductId(id.toString());
             cooperatorProductField.setProductNum(req.getString("product_num"));
             cooperatorProductField.setProductName(req.getString("product_name"));
-            CooperatorProductFieldService.save(cooperatorProductField);
+            cooperatorProductFieldList.add(cooperatorProductField);
         }
-
+        CooperatorProductFieldService.saveBatch(cooperatorProductFieldList);
         return Result.success();
     }
 
@@ -186,31 +193,31 @@ public class CooperatorProductController {
         JSONObject req = JSON.parseObject(json);
         //原有合作方产品字段关系表
         String fieldSelectedOld = req.getString("fieldSelectedOld");
-        List<String> fieldSelectedOldList= JSONArray.parseArray(fieldSelectedOld,String.class);
-        for (int i=0;i<fieldSelectedOldList.size();i++){
-            Long foid = Long.parseLong(fieldSelectedOldList.get(i));
-            System.out.println("this id ");
-            System.out.println(foid);
-            CooperatorProductFieldService.removeById(foid);
-        }
+        List<Long> fieldSelectedOldList= JSONArray.parseArray(fieldSelectedOld,Long.class);
+        CooperatorProductFieldService.removeByIds(fieldSelectedOldList);
+
 
         //合作方产品字段关系表
         String fieldSelected = req.getString("fieldSelected");
-        List<String> fieldSelectedList= JSONArray.parseArray(fieldSelected,String.class);
+        List<Long> fieldSelectedList= JSONArray.parseArray(fieldSelected,Long.class);
+
+        List<CooperatorProductField> cooperatorProductFieldList = new ArrayList<>();
+        List<FieldDefineEntity> productFieldList = fieldDefineMapper.selectBatchIds(fieldSelectedList);
+
 
         for (int i=0;i<fieldSelectedList.size();i++){
-            Long fid = Long.parseLong(fieldSelectedList.get(i));
-            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
+
             CooperatorProductField cooperatorProductField = new CooperatorProductField();
             cooperatorProductField.setIsDeleted(false);
-            cooperatorProductField.setFieldId(fieldDefine.getId());
-            cooperatorProductField.setFieldNo(fieldDefine.getFieldNo());
-            cooperatorProductField.setName(fieldDefine.getName());
+            cooperatorProductField.setFieldId(productFieldList.get(i).getId());
+            cooperatorProductField.setFieldNo(productFieldList.get(i).getFieldNo());
+            cooperatorProductField.setName(productFieldList.get(i).getName());
             cooperatorProductField.setProductId(req.getString("productId"));
             cooperatorProductField.setProductNum(req.getString("productNum"));
             cooperatorProductField.setProductName(req.getString("productName"));
-            CooperatorProductFieldService.save(cooperatorProductField);
+            cooperatorProductFieldList.add(cooperatorProductField);
         }
+        CooperatorProductFieldService.saveBatch(cooperatorProductFieldList);
 
         return Result.success();
     }

+ 23 - 25
src/main/java/com/kexun/service/impl/FieldTemplateServiceImpl.java

@@ -112,7 +112,7 @@ public class FieldTemplateServiceImpl extends ServiceImpl<FieldTemplateMapper, F
             List<FieldDefineEntity> fieldDeriveDefineList = fieldDefineMapper.selectBatchIds(fieldSelected2);
 
             for (int i=0;i<fieldSelected.size();i++){
-                Long fid = Long.parseLong(fieldSelected.get(i));
+//                Long fid = Long.parseLong(fieldSelected.get(i));
 //                FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
                 FieldTemplateRefEntity fieldTemplateRefEntity = new FieldTemplateRefEntity();
                 fieldTemplateRefEntity.setIsDeleted(false);
@@ -159,46 +159,44 @@ public class FieldTemplateServiceImpl extends ServiceImpl<FieldTemplateMapper, F
         BeanUtils.copyProperties(filedTemplateUpdateRO,fieldTemplateEntity);
         updateById(fieldTemplateEntity);
 
-        List <String> fieldBaseSelectedOld = filedTemplateUpdateRO.getFieldBaseSelectedOld();
-        for (int i=0;i<fieldBaseSelectedOld.size();i++){
-            Long foid = Long.parseLong(fieldBaseSelectedOld.get(i));
+        //删除改为批处理
+        List <Long> fieldBaseSelectedOld = filedTemplateUpdateRO.getFieldBaseSelectedOld();
+        fieldTemplateRefService.removeByIds(fieldBaseSelectedOld);
 
-            fieldTemplateRefService.removeById(foid);
-        }
-        List <String> fieldDeriveSelectedOld = filedTemplateUpdateRO.getFieldDeriveSelectedOld();
-        for (int i=0;i<fieldDeriveSelectedOld.size();i++){
-            Long foid = Long.parseLong(fieldDeriveSelectedOld.get(i));
+        List <Long> fieldDeriveSelectedOld = filedTemplateUpdateRO.getFieldDeriveSelectedOld();
+        fieldTemplateRefService.removeByIds(fieldDeriveSelectedOld);
 
-            fieldTemplateRefService.removeById(foid);
-        }
-        List <String> fieldBaseSelected = filedTemplateUpdateRO.getFieldBaseSelected();
         List<FieldTemplateRefEntity> fieldTemplateRefList = new ArrayList<>();
+        List <String> fieldBaseSelected = filedTemplateUpdateRO.getFieldBaseSelected();
+        List <String> fieldDeriveSelected = filedTemplateUpdateRO.getFieldDeriveSelected();
+        List<FieldDefineEntity> fieldBaseDefineList = fieldDefineMapper.selectBatchIds(fieldBaseSelected);
+        List<FieldDefineEntity> fieldDeriveDefineList = fieldDefineMapper.selectBatchIds(fieldDeriveSelected);
+
 
         for (int i=0;i<fieldBaseSelected.size();i++){
-            Long fid = Long.parseLong(fieldBaseSelected.get(i));
-            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
+//            Long fid = Long.parseLong(fieldBaseSelected.get(i));
+//            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
             FieldTemplateRefEntity fieldTemplateRefEntity = new FieldTemplateRefEntity();
             fieldTemplateRefEntity.setIsDeleted(false);
-            fieldTemplateRefEntity.setFieldDefineId(fieldDefine.getId());
-            fieldTemplateRefEntity.setFieldNo(fieldDefine.getFieldNo());
-            fieldTemplateRefEntity.setName(fieldDefine.getName());
-            fieldTemplateRefEntity.setType(fieldDefine.getCategory());
+            fieldTemplateRefEntity.setFieldDefineId(fieldBaseDefineList.get(i).getId());
+            fieldTemplateRefEntity.setFieldNo(fieldBaseDefineList.get(i).getFieldNo());
+            fieldTemplateRefEntity.setName(fieldBaseDefineList.get(i).getName());
+            fieldTemplateRefEntity.setType(fieldBaseDefineList.get(i).getCategory());
             fieldTemplateRefEntity.setFieldTemplateId(id);
             fieldTemplateRefEntity.setTemplateNo(fieldTemplateEntity.getTemplateNo());
             fieldTemplateRefList.add(fieldTemplateRefEntity);
         }
 
-        List <String> fieldDeriveSelected = filedTemplateUpdateRO.getFieldDeriveSelected();
 
         for (int i=0;i<fieldDeriveSelected.size();i++){
-            Long fid = Long.parseLong(fieldDeriveSelected.get(i));
-            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
+//            Long fid = Long.parseLong(fieldDeriveSelected.get(i));
+//            FieldDefineEntity fieldDefine = fieldDefineService.findByID(fid);
             FieldTemplateRefEntity fieldTemplateRefEntity = new FieldTemplateRefEntity();
             fieldTemplateRefEntity.setIsDeleted(false);
-            fieldTemplateRefEntity.setFieldDefineId(fieldDefine.getId());
-            fieldTemplateRefEntity.setFieldNo(fieldDefine.getFieldNo());
-            fieldTemplateRefEntity.setName(fieldDefine.getName());
-            fieldTemplateRefEntity.setType(fieldDefine.getCategory());
+            fieldTemplateRefEntity.setFieldDefineId(fieldDeriveDefineList.get(i).getId());
+            fieldTemplateRefEntity.setFieldNo(fieldDeriveDefineList.get(i).getFieldNo());
+            fieldTemplateRefEntity.setName(fieldDeriveDefineList.get(i).getName());
+            fieldTemplateRefEntity.setType(fieldDeriveDefineList.get(i).getCategory());
             fieldTemplateRefEntity.setFieldTemplateId(id);
             fieldTemplateRefEntity.setTemplateNo(fieldTemplateEntity.getTemplateNo());
             fieldTemplateRefList.add(fieldTemplateRefEntity);

+ 1 - 1
src/main/resources/mapper/CooperatorProductFieldMapper.xml

@@ -4,7 +4,7 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.kexun.mapper.CooperatorProductFieldMapper">
 
-    <resultMap id="BaseResultMap" type="com.kexun.entity.CooperatorInfo">
+    <resultMap id="BaseResultMap" type="com.kexun.entity.CooperatorProductField">
         <result property="partnerName" column="partner_name" jdbcType="VARCHAR"/>
         <result property="contactName" column="contact_name" jdbcType="VARCHAR"/>
         <result property="mobileNo" column="mobile_no" jdbcType="VARCHAR"/>