|
|
@@ -5,11 +5,10 @@ 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.stream.Collectors;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -17,6 +16,8 @@ import com.fs.common.core.domain.CustomMultipartFile;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.course.domain.FsUserCourse;
|
|
|
+import com.fs.course.mapper.FsUserCourseMapper;
|
|
|
import com.fs.his.dto.FsPackagePruductDTO;
|
|
|
import com.fs.his.param.FsPackageListUParam;
|
|
|
import com.fs.his.param.FsPackageParam;
|
|
|
@@ -50,6 +51,9 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
@Autowired
|
|
|
private ISysConfigService sysConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseMapper fsUserCourseMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询套餐包
|
|
|
*
|
|
|
@@ -79,27 +83,31 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- @CacheEvict(value = "getPackageList",allEntries = true)
|
|
|
+ @CacheEvict(value = "getPackageList", allEntries = true)
|
|
|
public int insertFsPackage(FsPackage fsPackage) {
|
|
|
|
|
|
fsPackage.setCreateTime(DateUtils.getNowDate());
|
|
|
// if (fsPackage.getPackageSubType() != 1) {
|
|
|
- if (fsPackage.getProductJson() != null) {
|
|
|
- JSONArray objects = JSONUtil.parseArray(fsPackage.getProductJson());
|
|
|
- List<FsPackagePruductDTO> products = JSONUtil.toList(objects, FsPackagePruductDTO.class);
|
|
|
- BigDecimal toal = new BigDecimal(0);
|
|
|
- for (FsPackagePruductDTO product : products) {
|
|
|
- toal = toal.add(product.getCostPrice().multiply(new BigDecimal(product.getCount())));
|
|
|
- }
|
|
|
- fsPackage.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((fsPackage.getCycle() / followRate) * 300);
|
|
|
- fsPackage.setInquiryCostPrice(in);
|
|
|
- fsPackage.setTotalCostPrice(toal.add(in));
|
|
|
+ if (fsPackage.getProductJson() != null) {
|
|
|
+ JSONArray objects = JSONUtil.parseArray(fsPackage.getProductJson());
|
|
|
+ List<FsPackagePruductDTO> products = JSONUtil.toList(objects, FsPackagePruductDTO.class);
|
|
|
+ BigDecimal toal = new BigDecimal(0);
|
|
|
+ for (FsPackagePruductDTO product : products) {
|
|
|
+ toal = toal.add(product.getCostPrice().multiply(new BigDecimal(product.getCount())));
|
|
|
}
|
|
|
+ fsPackage.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((fsPackage.getCycle() / followRate) * 300);
|
|
|
+ fsPackage.setInquiryCostPrice(in);
|
|
|
+ fsPackage.setTotalCostPrice(toal.add(in));
|
|
|
+ }
|
|
|
// }
|
|
|
+ //检查课程是否已被绑定
|
|
|
+ if (fsPackageMapper.existsByCourseId(fsPackage.getCourseId())) {
|
|
|
+ throw new ServiceException("该课程已被绑定到其他套餐包");
|
|
|
+ }
|
|
|
return fsPackageMapper.insertFsPackage(fsPackage);
|
|
|
}
|
|
|
|
|
|
@@ -111,22 +119,22 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- @CacheEvict(value = "getPackageList",allEntries = true)
|
|
|
+ @CacheEvict(value = "getPackageList", allEntries = true)
|
|
|
public int updateFsPackage(FsPackage fsPackage) {
|
|
|
fsPackage.setUpdateTime(DateUtils.getNowDate());
|
|
|
// if (fsPackage.getPackageSubType() != null && fsPackage.getPackageSubType() != 1) {
|
|
|
- if (fsPackage.getProductJson() != null) {
|
|
|
- JSONArray objects = JSONUtil.parseArray(fsPackage.getProductJson());
|
|
|
- List<FsPackagePruductDTO> products = JSONUtil.toList(objects, FsPackagePruductDTO.class);
|
|
|
- BigDecimal toal = new BigDecimal(0);
|
|
|
- for (FsPackagePruductDTO product : products) {
|
|
|
- toal = toal.add(product.getCostPrice().multiply(new BigDecimal(product.getCount())));
|
|
|
- }
|
|
|
- fsPackage.setProductCostPrice(toal);
|
|
|
- BigDecimal in = new BigDecimal((fsPackage.getCycle() / 6) * 300);
|
|
|
- fsPackage.setInquiryCostPrice(in);
|
|
|
- fsPackage.setTotalCostPrice(toal.add(in));
|
|
|
+ if (fsPackage.getProductJson() != null) {
|
|
|
+ JSONArray objects = JSONUtil.parseArray(fsPackage.getProductJson());
|
|
|
+ List<FsPackagePruductDTO> products = JSONUtil.toList(objects, FsPackagePruductDTO.class);
|
|
|
+ BigDecimal toal = new BigDecimal(0);
|
|
|
+ for (FsPackagePruductDTO product : products) {
|
|
|
+ toal = toal.add(product.getCostPrice().multiply(new BigDecimal(product.getCount())));
|
|
|
}
|
|
|
+ fsPackage.setProductCostPrice(toal);
|
|
|
+ BigDecimal in = new BigDecimal((fsPackage.getCycle() / 6) * 300);
|
|
|
+ fsPackage.setInquiryCostPrice(in);
|
|
|
+ fsPackage.setTotalCostPrice(toal.add(in));
|
|
|
+ }
|
|
|
// }
|
|
|
//如果公域改私域 需要去掉disease_type值
|
|
|
Integer isShow = fsPackage.getIsShow();
|
|
|
@@ -148,7 +156,7 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- @CacheEvict(value = "getPackageList",allEntries = true)
|
|
|
+ @CacheEvict(value = "getPackageList", allEntries = true)
|
|
|
public int deleteFsPackageByPackageIds(Long[] packageIds) {
|
|
|
|
|
|
return fsPackageMapper.deleteFsPackageByPackageIds(packageIds);
|
|
|
@@ -176,7 +184,22 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
if (privateType != null) {
|
|
|
fsPackage.setIsShow(0);
|
|
|
}
|
|
|
- return fsPackageMapper.selectFsPackageListVO(fsPackage);
|
|
|
+ //课程信息
|
|
|
+ List<FsUserCourse> fsUserCourses = fsUserCourseMapper.selectAllCourse();
|
|
|
+ Map<Long, FsUserCourse> map = CollectionUtil.isEmpty(fsUserCourses)
|
|
|
+ ? Collections.emptyMap() // 返回不可变的空Map,更高效
|
|
|
+ : fsUserCourses.stream()
|
|
|
+ .collect(Collectors.toMap(FsUserCourse::getCourseId, a -> a));
|
|
|
+ List<FsPackageListVO> fsPackageListVOS = fsPackageMapper.selectFsPackageListVO(fsPackage);
|
|
|
+ if (!CollectionUtil.isEmpty(fsPackageListVOS)) {
|
|
|
+ for (FsPackageListVO fsPackageListVO : fsPackageListVOS) {
|
|
|
+ FsUserCourse fsUserCourse = map.getOrDefault(fsPackageListVO.getCourseId(), null);
|
|
|
+ if (fsUserCourse != null) {
|
|
|
+ fsPackageListVO.setCourseName(fsUserCourse.getCourseName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fsPackageListVOS;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -261,13 +284,13 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @CacheEvict(value = "getPackageList",allEntries = true)
|
|
|
+ @CacheEvict(value = "getPackageList", allEntries = true)
|
|
|
public int updatePackagesStatus(Long[] packageIds, Long status) {
|
|
|
return fsPackageMapper.updatePackagesStatus(packageIds, status);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String convertImageToJpg(String imgUrl,Long packageId) {
|
|
|
+ public String convertImageToJpg(String imgUrl, Long packageId) {
|
|
|
if (StringUtils.isBlank(imgUrl)) {
|
|
|
throw new IllegalArgumentException("图片 URL 不能为空");
|
|
|
}
|
|
|
@@ -308,7 +331,7 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- if (!imgUrl.equals(url) && packageId !=null) {
|
|
|
+ if (!imgUrl.equals(url) && packageId != null) {
|
|
|
//更新数据库
|
|
|
FsPackage temp = new FsPackage();
|
|
|
temp.setPackageId(packageId);
|
|
|
@@ -333,7 +356,7 @@ public class FsPackageServiceImpl implements IFsPackageService {
|
|
|
@Transactional
|
|
|
public int bulkCopyFsPackageByPackage(Long[] packageIds) {
|
|
|
List<FsPackage> list = fsPackageMapper.selectFsPackageListByIds(packageIds);
|
|
|
- if(list != null && !list.isEmpty()){
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
try {
|
|
|
for (FsPackage fsPackage : list) {
|
|
|
fsPackageMapper.insertFsPackage(fsPackage);
|