|
|
@@ -1,6 +1,7 @@
|
|
|
package com.jzg.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jzg.commons.core.page.HttpResult;
|
|
|
import com.jzg.commons.entity.dto.JyxConfigAdd;
|
|
|
@@ -10,6 +11,9 @@ import com.jzg.commons.entity.po.JyxBlame;
|
|
|
import com.jzg.commons.entity.po.JyxConfig;
|
|
|
import com.jzg.commons.entity.po.jyxSetting;
|
|
|
import com.jzg.commons.entity.vo.JyxConfigVo;
|
|
|
+import com.jzg.commons.util.ConvertUtils;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
+import com.jzg.constants.ConstantsParent;
|
|
|
import com.jzg.mapper.JyxConfigMapper;
|
|
|
import com.jzg.service.JyxBlameService;
|
|
|
import com.jzg.service.JyxConfigService;
|
|
|
@@ -18,8 +22,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static java.util.stream.Collectors.collectingAndThen;
|
|
|
+import static java.util.stream.Collectors.toCollection;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -35,20 +45,18 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
private JyxBlameService blameService;
|
|
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult saveAll(JyxConfigAdd configAdd) {
|
|
|
try {
|
|
|
- List<JyxBlame> blameList = configAdd.getBlameList();
|
|
|
- if (CollectionUtils.isEmpty(blameList)){
|
|
|
- return HttpResult.error("请添加保险责任");
|
|
|
- }
|
|
|
- List<jyxSetting> settingList = configAdd.getSettingList();
|
|
|
- if (CollectionUtils.isEmpty(settingList)){
|
|
|
- return HttpResult.error("请添加保费设置");
|
|
|
+ if (StringUtils.isEmpty(configAdd.getParentId())){
|
|
|
+ configAdd.setParentId("0");
|
|
|
}
|
|
|
JyxConfig jyxConfig = BeanUtil.copyProperties(configAdd, JyxConfig.class);
|
|
|
int insert = jyxConfigMapper.insert(jyxConfig);
|
|
|
+ List<JyxBlame> blameList = configAdd.getBlameList();
|
|
|
+ List<jyxSetting> settingList = configAdd.getSettingList();
|
|
|
blameList.stream().forEach(blame -> {
|
|
|
blame.setJyxConfigId(jyxConfig.getId());
|
|
|
});
|
|
|
@@ -64,7 +72,7 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpResult selectById(Long id) {
|
|
|
+ public HttpResult selectById(String id) {
|
|
|
JyxConfig config = jyxConfigMapper.selectById(id);
|
|
|
if (config == null){
|
|
|
return HttpResult.error("查询失败");
|
|
|
@@ -93,13 +101,45 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
}
|
|
|
return HttpResult.error("修改失败");
|
|
|
}catch (Exception e){
|
|
|
- return HttpResult.error("修改失败" + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ return HttpResult.error("修改失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<JyxConfigVo> jyxList(JyxConfigParam configParam) {
|
|
|
- return jyxConfigMapper.jyxList(configParam);
|
|
|
+ try {
|
|
|
+ List<JyxConfigVo> jyxConfigVos = Optional.ofNullable(jyxConfigMapper.jyxList(configParam)).orElse(Collections.emptyList());
|
|
|
+ if (StringUtils.isNotEmpty(configParam.getSeats()) || StringUtils.isNotEmpty(configParam.getParams())) {
|
|
|
+ configParam.setParentId(ConstantsParent.PARENT_ID_ROOT);
|
|
|
+ List<JyxConfigVo> additionalConfigs = Optional.ofNullable(jyxConfigMapper.jyxList(configParam)).orElse(Collections.emptyList());
|
|
|
+ if (!additionalConfigs.isEmpty()) {
|
|
|
+ Set<String> ids = additionalConfigs.stream().map(JyxConfigVo::getId).collect(Collectors.toSet());
|
|
|
+ List<JyxConfigVo> parentConfigs = jyxConfigMapper.selectParentIds(new ArrayList<>(ids));
|
|
|
+ jyxConfigVos.addAll(parentConfigs);
|
|
|
+ jyxConfigVos = jyxConfigVos.stream().collect(collectingAndThen(
|
|
|
+ toCollection(() -> new TreeSet<>(Comparator.comparing(JyxConfigVo::getId))), ArrayList::new
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (jyxConfigVos.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Set<String> parentIds = jyxConfigVos.stream().map(JyxConfigVo::getParentId).collect(Collectors.toSet());
|
|
|
+ List<JyxConfigVo> jyxConfigs = Optional.ofNullable(jyxConfigMapper.selectIds(new ArrayList<>(parentIds))).orElse(Collections.emptyList());
|
|
|
+ Map<String, List<JyxConfigVo>> childrenMap = jyxConfigVos.stream()
|
|
|
+ .filter(vo -> !ConstantsParent.PARENT_ID_ROOT.equals(vo.getParentId()))
|
|
|
+ .collect(Collectors.groupingBy(vo -> String.valueOf(vo.getParentId()), Collectors.mapping(Function.identity(), Collectors.toList())));
|
|
|
+ List<JyxConfigVo> parentConfigs = BeanUtil.copyToList(jyxConfigs, JyxConfigVo.class);
|
|
|
+ parentConfigs.forEach(parentConfig -> {
|
|
|
+ parentConfig.setChildren(childrenMap.getOrDefault(String.valueOf(parentConfig.getId()), Collections.emptyList()));
|
|
|
+ });
|
|
|
+ return parentConfigs;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录日志或进行其他异常处理
|
|
|
+ e.printStackTrace();
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -107,28 +147,49 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
public HttpResult deleteById(String id) {
|
|
|
try {
|
|
|
JyxConfig config = jyxConfigMapper.selectById(id);
|
|
|
- if (config == null){
|
|
|
+ if (config == null) {
|
|
|
return HttpResult.error("该驾意险配置不存在");
|
|
|
}
|
|
|
- config.setIsDelete(1);
|
|
|
- int i = jyxConfigMapper.updateById(config);
|
|
|
- if (i > 0){
|
|
|
- blameService.lambdaUpdate().eq(JyxBlame::getJyxConfigId, id).set(JyxBlame::getIsDelete, 1).update();
|
|
|
- settingService.lambdaUpdate().eq(jyxSetting::getJyxConfigId, id).set(jyxSetting::getIsDelete, 1).update();
|
|
|
- return HttpResult.ok("删除成功");
|
|
|
+ int deletedRows = jyxConfigMapper.deleteById(config);
|
|
|
+ if (deletedRows <= 0) {
|
|
|
+ return HttpResult.error("删除失败");
|
|
|
}
|
|
|
- return HttpResult.error("删除失败");
|
|
|
- }catch (Exception e){
|
|
|
- return HttpResult.error("删除失败" + e.getMessage());
|
|
|
+ if (ConstantsParent.PARENT_ID_ROOT.equals(config.getParentId())) {
|
|
|
+ LambdaQueryWrapper<JyxConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(JyxConfig::getParentId, config.getId());
|
|
|
+ // 批量删除子配置
|
|
|
+ List<String> childIds = jyxConfigMapper.selectList(lambdaQueryWrapper).stream()
|
|
|
+ .map(JyxConfig::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!childIds.isEmpty()) {
|
|
|
+ jyxConfigMapper.deleteBatchIds(childIds);
|
|
|
+ blameService.lambdaUpdate().in(JyxBlame::getJyxConfigId, childIds).remove();
|
|
|
+ settingService.lambdaUpdate().in(jyxSetting::getJyxConfigId, childIds).remove();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ blameService.lambdaUpdate().eq(JyxBlame::getJyxConfigId, config.getId()).remove();
|
|
|
+ settingService.lambdaUpdate().eq(jyxSetting::getJyxConfigId, config.getId()).remove();
|
|
|
+ }
|
|
|
+ return HttpResult.ok("删除成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常信息到日志
|
|
|
+ return HttpResult.error("删除失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<JyxConfigVo> selectMainInsurance(String company) {
|
|
|
+ List<JyxConfigVo> jyxConfigVos = jyxConfigMapper.selectMainInsurance(company);
|
|
|
+ return jyxConfigVos;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- public List<JyxBlame> selectBlameList(Long id){
|
|
|
+ public List<JyxBlame> selectBlameList(String id){
|
|
|
return blameService.lambdaQuery().eq(JyxBlame::getJyxConfigId, id).list();
|
|
|
}
|
|
|
|
|
|
- public List<jyxSetting> selectSettingList(Long id){
|
|
|
+ public List<jyxSetting> selectSettingList(String id){
|
|
|
return settingService.lambdaQuery().eq(jyxSetting::getJyxConfigId, id).list();
|
|
|
}
|
|
|
|