Browse Source

Merge remote-tracking branch 'origin/dev' into dev

赵冬冬 4 years ago
parent
commit
39a73354dd

+ 24 - 27
carbon-back/carbon-back-service/src/main/java/com/hcloud/microserver/bank/service/impl/ProductInfoServiceImpl.java

@@ -11,6 +11,7 @@ import com.hcloud.microserver.commoncore.util.GeneratorIdUtils;
 import com.hcloud.microserver.commoncore.util.UUIDUtils;
 import com.hcloud.microserver.facade.carbon.entity.*;
 import com.hcloud.microserver.facade.carbon.forms.*;
+import com.hcloud.microserver.system.util.CurrUserUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -152,6 +153,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
             productInfo.setState(1);
             productInfo.setIsEnable(1);
             productInfo.setProductCode(getMaxProductCode());
+            productInfo.setCreateUser(CurrUserUtil.getUserId());
 
             // 批量添加产品归属信息
             List<ProductBelongForm> productBelongForms = productInfoForm.getProductBelongForms();
@@ -185,24 +187,21 @@ public class ProductInfoServiceImpl implements ProductInfoService {
                 String collectiveGuid = collectiveFarmerForm.getGuid();
                 if (StringUtils.isNotEmpty(collectiveGuid) && collectiveGuid.matches("^\\w{32}$")) {
                     CollectiveFarmer collectiveFarmer = this.collectiveFarmerMapper.selectByPrimaryKey(collectiveGuid);
-                    List<FarmerInfo> farmerInfos = this.farmerInfoMapper.selectByCollectiveId(collectiveGuid);
-                    if (Objects.nonNull(collectiveFarmer) && Objects.nonNull(farmerInfos)) {
-                        List<ProductBelong> productBelongs = new ArrayList<>();
-                        farmerInfos.forEach(farmerInfo -> {
+                    //集体主体与个人主体不强关联
+                    if (Objects.nonNull(collectiveFarmer)) {
+                            List<ProductBelong> productBelongs = new ArrayList<>();
                             ProductBelong productBelong = new ProductBelong();
                             productBelong.setGuid(UUIDUtils.randomUUID());
-                            productBelong.setBelongType(1);
+                            productBelong.setBelongType(2);
                             productBelong.setCreateTime(new Date());
                             productBelong.setFkProductGuid(guid);
-                            productBelong.setFarmerName(farmerInfo.getFarmerName());
-                            productBelong.setFarmerNum(farmerInfo.getFamilyNum());
+                            productBelong.setFarmerNum(collectiveFarmer.getCollectivePersonNum());
                             productBelong.setFarmerVillage(collectiveFarmer.getCollectiveName());
-                            productBelong.setFkFarmerGuid(farmerInfo.getGuid());
                             productBelong.setModifiedTime(new Date());
                             productBelong.setState(1);
+                            productBelong.setFkCollectiveGuid(collectiveGuid);
                             productBelongs.add(productBelong);
-                        });
-                        if (Objects.nonNull(productBelongs) && productBelongs.size() > 0) {
+
                             result = this.productBelongMapper.batchInsert(productBelongs);
                             if (result < 1) {
                                 throw new RuntimeException("新增产品信息 -- 批量新增产品归属失败");
@@ -210,7 +209,6 @@ public class ProductInfoServiceImpl implements ProductInfoService {
                         }
                     }
                 }
-            }
 
             // 添加产品信息
             result = this.productInfoMapper.insert(productInfo);
@@ -299,23 +297,18 @@ public class ProductInfoServiceImpl implements ProductInfoService {
                     String collectiveGuid = collectiveFarmerForm.getGuid();
                     if (StringUtils.isNotEmpty(collectiveGuid) && collectiveGuid.matches("^\\w{32}$")) {
                         CollectiveFarmer collectiveFarmer = this.collectiveFarmerMapper.selectByPrimaryKey(collectiveGuid);
-                        List<FarmerInfo> farmerInfos = this.farmerInfoMapper.selectByCollectiveId(collectiveGuid);
-                        if (Objects.nonNull(collectiveFarmer) && Objects.nonNull(farmerInfos)) {
+                        if (Objects.nonNull(collectiveFarmer)) {
                             List<ProductBelong> productBelongs = new ArrayList<>();
-                            farmerInfos.forEach(farmerInfo -> {
-                                ProductBelong productBelong = new ProductBelong();
-                                productBelong.setGuid(UUIDUtils.randomUUID());
-                                productBelong.setBelongType(1);
-                                productBelong.setCreateTime(new Date());
-                                productBelong.setFkProductGuid(guid);
-                                productBelong.setFarmerName(farmerInfo.getFarmerName());
-                                productBelong.setFarmerNum(farmerInfo.getFamilyNum());
-                                productBelong.setFarmerVillage(collectiveFarmer.getCollectiveName());
-                                productBelong.setFkFarmerGuid(farmerInfo.getGuid());
-                                productBelong.setModifiedTime(new Date());
-                                productBelong.setState(1);
-                                productBelongs.add(productBelong);
-                            });
+                            ProductBelong productBelong = new ProductBelong();
+                            productBelong.setGuid(UUIDUtils.randomUUID());
+                            productBelong.setBelongType(2);
+                            productBelong.setCreateTime(new Date());
+                            productBelong.setFkProductGuid(guid);
+                            productBelong.setFarmerNum(collectiveFarmer.getCollectivePersonNum());
+                            productBelong.setFarmerVillage(collectiveFarmer.getCollectiveName());
+                            productBelong.setModifiedTime(new Date());
+                            productBelong.setState(1);
+                            productBelongs.add(productBelong);
                             if (Objects.nonNull(productBelongs) && productBelongs.size() > 0) {
                                 result = this.productBelongMapper.batchInsert(productBelongs);
                                 if (result < 1) throw new RuntimeException("修改产品 -- 批量添加产品归属失败");
@@ -328,11 +321,15 @@ public class ProductInfoServiceImpl implements ProductInfoService {
                 if (Objects.nonNull(goodsInfos) && goodsInfos.size() > 0) {
                     for (GoodsInfo goodsInfo : goodsInfos) {
                         goodsInfo.setGoodsImages(productInfo.getProductImgs());
+                        goodsInfo.setModifiedTime(new Date());
+                        goodsInfo.setModifiedUser(CurrUserUtil.getUserId());
                     }
                     result = this.goodsInfoMapper.batchUpdate(goodsInfos);
                     if (result < 0) throw new RuntimeException("修改产品 -- 批量更新商品失败");
                 }
 
+                productInfo.setModifiedUser(CurrUserUtil.getUserId());
+                productInfo.setModifiedTime(new Date());
                 result = this.productInfoMapper.updateByPrimaryKeySelective(productInfo);
                 if (result < 1) throw new RuntimeException("修改产品信息失败");
             }

+ 5 - 2
carbon-back/carbon-back-service/src/main/resources/carbon/ProductBelongMapper.xml

@@ -200,8 +200,11 @@
     </delete>
 
     <select id="selectByProductGuid" parameterType="string" resultMap="BaseResultMap">
-        select <include refid="Base_Column_List"></include> from t_product_belong
-        where fk_product_guid = #{productInfoGuid,jdbcType=CHAR}
+         select guid, fk_product_guid, fk_farmer_guid, fk_collective_guid,
+            (CASE belong_type WHEN 1 THEN farmer_name ELSE farmer_village END ) AS farmer_name,
+            farmer_village, farmer_num, state, create_time, modified_time, belong_type
+          from t_product_belong
+          where fk_product_guid = #{productInfoGuid,jdbcType=CHAR}
     </select>
 
     <delete id="deleteByProductInfoGuids" parameterType="list">