|
|
@@ -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));
|
|
|
+ }
|
|
|
}
|
|
|
|