Переглянути джерело

CID信息采集绑定套餐包--可绑定多个套餐包

wjj 2 днів тому
батько
коміт
b6a58426d7

+ 3 - 0
fs-service/src/main/java/com/fs/his/domain/FsPackage.java

@@ -111,4 +111,7 @@ public class FsPackage extends BaseEntity
 
     //erp类型 1-聚水潭 2-兔零
     private Integer erpType;
+
+    //是否合并套餐包 0否 1是
+    private Integer isMerge;
 }

+ 3 - 1
fs-service/src/main/java/com/fs/his/mapper/FsPackageMapper.java

@@ -80,7 +80,7 @@ public interface FsPackageMapper
 
     @Select({"<script> " +
             "select * from fs_package "+
-            "where 1=1 "+
+            "where is_merge != 1 "+
             "            <if test=\"maps.packageName != null  and maps.packageName != ''\"> and package_name like concat('%', #{maps.packageName}, '%')</if>\n" +
 //            "            <if test=\"maps.sort != null \"> and sort = #{maps.sort}</if>\n" +
             "            <if test=\"maps.secondName != null  and maps.secondName != ''\"> and second_name like concat('%', #{maps.secondName}, '%')</if>\n" +
@@ -169,4 +169,6 @@ public interface FsPackageMapper
 
     List<FsPackage> selectFsPackageListByIds(Long[] packageIds);
 
+    List<FsPackage> selectFsPackageListByPackageIds(@Param("packageIds")List<Long> packageIds);
+
 }

+ 7 - 0
fs-service/src/main/java/com/fs/his/service/IFsPackageService.java

@@ -98,4 +98,11 @@ public interface IFsPackageService
 
     List<OptionsVO> selectPackageList();
     List<OptionsVO> selectPrizePackageList();
+
+    /**
+     * 合并套餐包 生成新的套餐包
+     * @param packageIds 多个套餐包id
+     * @return 合并的套餐包id
+     */
+    Long mergePackage(List<Long> packageIds);
 }

+ 2 - 2
fs-service/src/main/java/com/fs/his/service/impl/FsPackageOrderServiceImpl.java

@@ -577,7 +577,7 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
                 }
             }
         }
-        if(fsPackage.getStatus().equals(0)){
+        if(fsPackage.getStatus().equals(0) && fsPackage.getIsMerge() != 1){
             return R.error("套餐名已下架");
         }
         //私域下套餐包(可覆盖医生信息 使用销售绑定的医生信息)
@@ -767,7 +767,7 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
                 }
             }
         }
-        if(fsPackage.getStatus().equals(0)){
+        if(fsPackage.getStatus().equals(0) && fsPackage.getIsMerge() != 1){
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             return R.error("套餐名已下架");
         }

+ 85 - 4
fs-service/src/main/java/com/fs/his/service/impl/FsPackageServiceImpl.java

@@ -5,15 +5,14 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.function.Function;
 
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.core.domain.CustomMultipartFile;
+import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
@@ -25,6 +24,7 @@ import com.fs.system.domain.SysConfig;
 import com.fs.system.oss.CloudStorageService;
 import com.fs.system.oss.OSSFactory;
 import com.fs.system.service.ISysConfigService;
+import com.google.common.collect.Lists;
 import net.coobird.thumbnailator.Thumbnails;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
@@ -34,6 +34,7 @@ import com.fs.his.mapper.FsPackageMapper;
 import com.fs.his.domain.FsPackage;
 import com.fs.his.service.IFsPackageService;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import javax.imageio.ImageIO;
 
@@ -359,5 +360,85 @@ public class FsPackageServiceImpl implements IFsPackageService {
     public List<OptionsVO> selectPrizePackageList() {
         return fsPackageMapper.selectPrizePackageList();
     }
+
+    @Override
+    public Long mergePackage(List<Long> packageIds) {
+        List<FsPackage> fsPackages = fsPackageMapper.selectFsPackageListByPackageIds(packageIds);
+        if (!CollectionUtils.isEmpty(fsPackages)) {
+            //是否存在套餐包错误数据
+            if (fsPackages.size() != packageIds.size()) {
+                return -1L;
+            }
+            //判断ERP类型是否相同
+            boolean areAllSame = areAllSame(fsPackages, FsPackage::getErpType);
+            if (!areAllSame) {
+                return -2L;
+            }
+            //所有套餐包的商品信息
+            List<FsPackagePruductDTO> allProducts = Lists.newArrayList();
+            StringBuilder packageName = new StringBuilder();
+            Integer erpType = null;
+            BigDecimal totalPrice = BigDecimal.ZERO;
+            for (FsPackage fsPackage : fsPackages) {
+                if (erpType == null) {
+                    erpType = fsPackage.getErpType();
+                }
+                totalPrice = totalPrice.add(fsPackage.getTotalPrice());
+                packageName.append(fsPackage.getPackageName()).append("+");
+                if(StringUtils.isNotEmpty(fsPackage.getProductJson())) {
+                    JSONArray objects = JSONUtil.parseArray(fsPackage.getProductJson());
+                    List<FsPackagePruductDTO> products = JSONUtil.toList(objects, FsPackagePruductDTO.class);
+                    allProducts.addAll(products);
+                }
+            }
+            //组装合并套餐包数据
+            FsPackage mergePackage = new FsPackage();
+            mergePackage.setPackageName(StringUtils.removeEnd(packageName.toString(), "+"));
+            mergePackage.setErpType(erpType);
+            mergePackage.setStatus(0);//停用状态
+            mergePackage.setIsMerge(1);//合并套餐包标识
+            mergePackage.setCreateTime(new Date());
+            mergePackage.setUpdateTime(new Date());
+            mergePackage.setPackageType(1);
+            mergePackage.setPackageSubType(2);
+            mergePackage.setPayType("1,2,3");//全部支付类型
+            mergePackage.setProductType(1);//默认中药类型
+            mergePackage.setIsShow(0);
+            mergePackage.setProductJson(JSONUtil.toJsonStr(allProducts));
+            mergePackage.setDiseaseType(-1);
+            mergePackage.setSecondName("合并套餐包");
+            mergePackage.setFollowTempId(10L);
+            mergePackage.setPrivateType(1);
+            mergePackage.setStoreId(48L);
+            mergePackage.setNum(0);
+            mergePackage.setCycle(0);
+            mergePackage.setTotalPrice(totalPrice);//合并套餐包价格
+//            BigDecimal toal = new BigDecimal(0);
+//            for (FsPackagePruductDTO product : allProducts) {
+//                toal = toal.add(product.getCostPrice().multiply(new BigDecimal(product.getCount())));
+//            }
+//            mergePackage.setProductCostPrice(toal);
+//            SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("his.store");
+//            Map<String, Object> config = (Map<String, Object>) JSON.parse(sysConfig.getConfigValue());
+//            Integer followRate = (Integer) config.get("followRate");
+//            BigDecimal in = new BigDecimal((mergePackage.getCycle() / followRate) * 300);
+//            mergePackage.setInquiryCostPrice(in);
+//            mergePackage.setTotalCostPrice(toal.add(in));
+            mergePackage.setTotalCostPrice(totalPrice);
+
+            fsPackageMapper.insertFsPackage(mergePackage);
+            return mergePackage.getPackageId();
+        }
+        return 0L;
+    }
+
+
+
+    // 1. 判断所有对象字段是否相同
+    private  <T> boolean areAllSame(List<T> list, Function<T, ?> getter) {
+        if (list == null || list.isEmpty()) return true;
+        Object first = getter.apply(list.get(0));
+        return list.stream().allMatch(item -> Objects.equals(getter.apply(item), first));
+    }
 }
 

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsUserInformationCollection.java

@@ -132,4 +132,6 @@ public class FsUserInformationCollection extends BaseEntity{
      * 处方id
      * */
     private Long prescribeId;
+
+    private String packageIds;
 }

+ 4 - 0
fs-service/src/main/java/com/fs/hisStore/param/bindCollectionPackageParam.java

@@ -3,6 +3,7 @@ package com.fs.hisStore.param;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Data
 public class bindCollectionPackageParam {
@@ -18,4 +19,7 @@ public class bindCollectionPackageParam {
 
     //代收金额
     private BigDecimal amount;
+
+    //合并套餐包id
+    private List<Long> packageIds;
 }

+ 21 - 4
fs-service/src/main/java/com/fs/hisStore/service/impl/FsUserInformationCollectionServiceImpl.java

@@ -210,7 +210,6 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
     @Autowired
     private FsUserInformationCollectionPersonalLogMapper infoCollectionPersonalLogMapper;
 
-
     //"默认就诊人"常量字符串
     private static final String DEFAULT_PATIENT_NAME = "默认就诊人";
 
@@ -1749,6 +1748,7 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
     }
 
     @Override
+    @Transactional
     public Long bindCollectionPackage(bindCollectionPackageParam param) {
         //校验参数
         FsUserInformationCollection informationCollection = fsUserInformationCollectionMapper.selectFsUserInformationCollectionById(param.getId());
@@ -1776,9 +1776,24 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
         if (companyUser == null) {
             throw new CustomException("未查询到绑定销售人员");
         }
-        FsPackage fsPackage = packageMapper.selectFsPackageByPackageId(param.getPackageId());
+        Long packageId = null;
+        if (param.getPackageIds().size() > 1) {
+            Long mergePackageId = packageService.mergePackage(param.getPackageIds());
+            if (mergePackageId > 0L ) {
+                packageId = mergePackageId;
+            } else {
+                if (mergePackageId == -1L) {
+                    throw new CustomException("套餐包数据错误");
+                } else if (mergePackageId == -2L){
+                    throw new CustomException("ERP类型不相同");
+                }
+            }
+        } else {
+            packageId = param.getPackageIds().get(0);
+        }
+        FsPackage fsPackage = packageMapper.selectFsPackageByPackageId(packageId);
         if (fsPackage == null){
-            throw new CustomException("套餐包不存在或已下架");
+            throw new CustomException("套餐包不存在");
         }
         infoCollectionPersonalLog.setPackageId(fsPackage.getPackageId());
         infoCollectionPersonalLog.setPackageName(fsPackage.getPackageName());//套餐包名称
@@ -1786,10 +1801,12 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
         //套餐包必须是OTC、中药、处方药类型
         if (fsPackage.getProductType() == 1 || fsPackage.getProductType() == 2 || fsPackage.getProductType() == 3) {
             informationCollection.setIsPackage(1);//套餐包标识
-            informationCollection.setPackageId(param.getPackageId());
+            informationCollection.setPackageId(packageId);
             informationCollection.setPayType(param.getPayType());
             informationCollection.setAmount(param.getAmount());
             informationCollection.setPersonalCollectStatus(PostPayPrescStatusEnum.PENDING_SHARE.getCode());
+            String ids = param.getPackageIds().stream().map(String::valueOf).collect(Collectors.joining(","));
+            informationCollection.setPackageIds(ids);
             int result = fsUserInformationCollectionMapper.updateFsUserInformationCollection(informationCollection);
             if (result > 0){
                 return informationCollection.getId();

+ 15 - 1
fs-service/src/main/resources/mapper/his/FsPackageMapper.xml

@@ -51,10 +51,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="appIds"    column="app_ids"    />
         <result property="questionId"    column="question_id"    />
         <result property="erpType"    column="erp_type"    />
+        <result property="isMerge"    column="is_merge"    />
     </resultMap>
 
     <sql id="selectFsPackageVo">
-        select package_id,description,usage_per_use_count,icd_code,images,doctor_remark,second_name,follow_temp_id,product_cost_price,inquiry_cost_price,total_cost_price,follow_num,`explain`,indication,store_id,private_type,recipe_type,counts,usage_frequency_unit, package_name,img_url,is_show,total_price,cycle,duration,`desc`,product_type,price,tags,sales,disease_type,num,package_sub_type,describe_json,pay_type,package_type, sort, product_json, status, create_time, update_time, is_del,solar_term,app_ids,question_id,erp_type from fs_package
+        select package_id,description,usage_per_use_count,icd_code,images,doctor_remark,second_name,follow_temp_id,product_cost_price,inquiry_cost_price,total_cost_price,follow_num,`explain`,indication,store_id,private_type,recipe_type,counts,usage_frequency_unit, package_name,img_url,is_show,total_price,cycle,duration,`desc`,product_type,price,tags,sales,disease_type,num,package_sub_type,describe_json,pay_type,package_type, sort, product_json, status, create_time
+             , update_time, is_del,solar_term,app_ids,question_id,erp_type,is_merge from fs_package
     </sql>
 
     <select id="selectFsPackageList" parameterType="FsPackage" resultMap="FsPackageResult">
@@ -136,6 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="appIds != null">app_ids,</if>
             <if test="questionId != null">question_id,</if>
             <if test="erpType != null">erp_type,</if>
+            <if test="isMerge != null">is_merge,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="packageName != null">#{packageName},</if>
@@ -183,6 +186,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="appIds != null">#{appIds},</if>
             <if test="questionId != null">#{questionId},</if>
             <if test="erpType != null">#{erpType},</if>
+            <if test="isMerge != null">#{isMerge},</if>
         </trim>
     </insert>
 
@@ -234,6 +238,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="appIds != null ">app_ids = #{appIds},</if>
             <if test="questionId != null ">question_id = #{questionId},</if>
             <if test="erpType != null">erp_type = #{erpType},</if>
+            <if test="isMerge != null">is_merge = #{isMerge},</if>
         </trim>
         where package_id = #{packageId}
     </update>
@@ -248,4 +253,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{packageId}
         </foreach>
     </delete>
+
+
+    <select id="selectFsPackageListByPackageIds" resultType="com.fs.his.domain.FsPackage">
+        <include refid="selectFsPackageVo"/>
+        where package_id in
+        <foreach collection="packageIds" index="index" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
 </mapper>

+ 6 - 1
fs-service/src/main/resources/mapper/hisStore/FsUserInformationCollectionMapper.xml

@@ -62,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="packageName" column="package_name"/>
         <result property="packageOrderCode" column="package_order_code"/>
         <result property="prescribeId" column="prescribe_id"/>
+        <result property="packageIds" column="package_ids"/>
     </resultMap>
 
     <sql id="selectFsUserInformationCollectionVo">
@@ -69,7 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              , doctor_confirm, create_time, update_time,doctor_id,company_user_id
              ,package_id,pay_type,amount,is_package,user_confirm2,package_order_code
              ,status,user_advice,doctor_advice,doctor_confirm_time,sex,user_name,user_phone_four
-             ,allergy,remark,age,info_source,third_party_user_id,fill_flag,complete_status,qw_tag,personal_collect_status,prescribe_id  from fs_user_information_collection
+             ,allergy,remark,age,info_source,third_party_user_id,fill_flag,complete_status,qw_tag
+             ,personal_collect_status,prescribe_id, package_ids from fs_user_information_collection
     </sql>
 
     <select id="selectFsUserInformationCollectionList" parameterType="FsUserInformationCollection" resultMap="FsUserInformationCollectionResult">
@@ -298,6 +300,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwTag != null">qw_tag,</if>
             <if test="personalCollectStatus != null">personal_collect_status,</if>
             <if test="prescribeId != null">prescribe_id,</if>
+            <if test="packageIds != null">package_ids,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="questionId != null">#{questionId},</if>
@@ -332,6 +335,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwTag != null">#{qwTag},</if>
             <if test="personalCollectStatus != null">#{personalCollectStatus},</if>
             <if test="prescribeId != null">#{prescribeId},</if>
+            <if test="packageIds != null">#{packageIds},</if>
         </trim>
     </insert>
 
@@ -370,6 +374,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qwTag != null">qw_tag = #{qwTag},</if>
             <if test="personalCollectStatus != null">personal_collect_status = #{personalCollectStatus},</if>
             <if test="prescribeId != null">prescribe_id = #{prescribeId},</if>
+            <if test="packageIds != null">package_ids = #{packageIds},</if>
         </trim>
         where id = #{id}
     </update>