|
@@ -3,6 +3,7 @@ package com.jzg.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.jzg.commons.constants.Constants;
|
|
|
import com.jzg.commons.core.page.HttpResult;
|
|
import com.jzg.commons.core.page.HttpResult;
|
|
|
import com.jzg.commons.entity.dto.JyxConfigAdd;
|
|
import com.jzg.commons.entity.dto.JyxConfigAdd;
|
|
|
import com.jzg.commons.entity.dto.JyxConfigEnd;
|
|
import com.jzg.commons.entity.dto.JyxConfigEnd;
|
|
@@ -11,6 +12,7 @@ import com.jzg.commons.entity.po.JyxBlame;
|
|
|
import com.jzg.commons.entity.po.JyxConfig;
|
|
import com.jzg.commons.entity.po.JyxConfig;
|
|
|
import com.jzg.commons.entity.po.jyxSetting;
|
|
import com.jzg.commons.entity.po.jyxSetting;
|
|
|
import com.jzg.commons.entity.vo.JyxConfigVo;
|
|
import com.jzg.commons.entity.vo.JyxConfigVo;
|
|
|
|
|
+import com.jzg.commons.util.AssertionUtils;
|
|
|
import com.jzg.commons.util.ConvertUtils;
|
|
import com.jzg.commons.util.ConvertUtils;
|
|
|
import com.jzg.commons.util.StringUtils;
|
|
import com.jzg.commons.util.StringUtils;
|
|
|
import com.jzg.constants.ConstantsParent;
|
|
import com.jzg.constants.ConstantsParent;
|
|
@@ -18,6 +20,7 @@ import com.jzg.mapper.JyxConfigMapper;
|
|
|
import com.jzg.service.JyxBlameService;
|
|
import com.jzg.service.JyxBlameService;
|
|
|
import com.jzg.service.JyxConfigService;
|
|
import com.jzg.service.JyxConfigService;
|
|
|
import com.jzg.service.jyxSettingService;
|
|
import com.jzg.service.jyxSettingService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -25,13 +28,14 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static java.util.stream.Collectors.collectingAndThen;
|
|
import static java.util.stream.Collectors.collectingAndThen;
|
|
|
import static java.util.stream.Collectors.toCollection;
|
|
import static java.util.stream.Collectors.toCollection;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig> implements JyxConfigService {
|
|
public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig> implements JyxConfigService {
|
|
|
|
|
|
|
@@ -50,22 +54,31 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult saveAll(JyxConfigAdd configAdd) {
|
|
public HttpResult saveAll(JyxConfigAdd configAdd) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ AssertionUtils.isFail(Optional.ofNullable(baseMapper.selectOne(new LambdaQueryWrapper<JyxConfig>().eq(JyxConfig::getProductCode, configAdd.getProductCode())
|
|
|
|
|
+ .eq(JyxConfig::getIsDelete, Constants.NOT_DELETED))).isEmpty(), "产品编码重复");
|
|
|
if (StringUtils.isEmpty(configAdd.getParentId())){
|
|
if (StringUtils.isEmpty(configAdd.getParentId())){
|
|
|
- configAdd.setParentId("0");
|
|
|
|
|
|
|
+ configAdd.setParentId(Constants.DEFAULT_PARENT_ID);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ AssertionUtils.isFail(Optional.ofNullable(baseMapper.selectOne(new LambdaQueryWrapper<JyxConfig>().eq(JyxConfig::getId, configAdd.getParentId())
|
|
|
|
|
+ .eq(JyxConfig::getIsDelete, Constants.NOT_DELETED))).isEmpty(), "上级产品不存在或已删除,请重新选择");
|
|
|
}
|
|
}
|
|
|
JyxConfig jyxConfig = BeanUtil.copyProperties(configAdd, JyxConfig.class);
|
|
JyxConfig jyxConfig = BeanUtil.copyProperties(configAdd, JyxConfig.class);
|
|
|
int insert = jyxConfigMapper.insert(jyxConfig);
|
|
int insert = jyxConfigMapper.insert(jyxConfig);
|
|
|
|
|
+ if (insert <= 0) {
|
|
|
|
|
+ return HttpResult.error("添加失败");
|
|
|
|
|
+ }
|
|
|
List<JyxBlame> blameList = configAdd.getBlameList();
|
|
List<JyxBlame> blameList = configAdd.getBlameList();
|
|
|
List<jyxSetting> settingList = configAdd.getSettingList();
|
|
List<jyxSetting> settingList = configAdd.getSettingList();
|
|
|
- blameList.stream().forEach(blame -> {
|
|
|
|
|
- blame.setJyxConfigId(jyxConfig.getId());
|
|
|
|
|
- });
|
|
|
|
|
- settingList.stream().forEach(setting -> {
|
|
|
|
|
- setting.setJyxConfigId(jyxConfig.getId());
|
|
|
|
|
- });
|
|
|
|
|
- blameService.saveBatch(blameList);
|
|
|
|
|
- settingService.saveBatch(settingList);
|
|
|
|
|
- return insert > 0 ? HttpResult.ok("添加成功") : HttpResult.error("添加失败");
|
|
|
|
|
|
|
+ // 确保列表不为空再进行操作
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(blameList)) {
|
|
|
|
|
+ blameList.forEach(blame -> blame.setJyxConfigId(jyxConfig.getId()));
|
|
|
|
|
+ blameService.saveBatch(blameList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(settingList)) {
|
|
|
|
|
+ settingList.forEach(setting -> setting.setJyxConfigId(jyxConfig.getId()));
|
|
|
|
|
+ settingService.saveBatch(settingList);
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.ok("添加成功");
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
return HttpResult.error("添加失败" + e.getMessage());
|
|
return HttpResult.error("添加失败" + e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -73,37 +86,66 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public HttpResult selectById(String id) {
|
|
public HttpResult selectById(String id) {
|
|
|
- JyxConfig config = jyxConfigMapper.selectById(id);
|
|
|
|
|
- if (config == null){
|
|
|
|
|
- return HttpResult.error("查询失败");
|
|
|
|
|
|
|
+ if (id == null || id.trim().isEmpty()) {
|
|
|
|
|
+ return HttpResult.error("ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ JyxConfig config = jyxConfigMapper.selectById(id);
|
|
|
|
|
+ if (config == null) {
|
|
|
|
|
+ return HttpResult.error("查询失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ JyxConfigVo jyxConfigVo = BeanUtil.copyProperties(config, JyxConfigVo.class);
|
|
|
|
|
+ CompletableFuture<Void> blameFuture = CompletableFuture.runAsync(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ jyxConfigVo.setBlameList(selectBlameList(id));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("加载 blameList 失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ CompletableFuture<Void> settingFuture = CompletableFuture.runAsync(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ jyxConfigVo.setSettingList(selectSettingList(id));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("加载 settingList 失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ CompletableFuture.allOf(blameFuture, settingFuture).join();
|
|
|
|
|
+
|
|
|
|
|
+ return HttpResult.ok(jyxConfigVo);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("查询配置失败", e);
|
|
|
|
|
+ return HttpResult.error("系统错误");
|
|
|
}
|
|
}
|
|
|
- JyxConfigVo jyxConfigVo = BeanUtil.copyProperties(config, JyxConfigVo.class);
|
|
|
|
|
- jyxConfigVo.setBlameList(selectBlameList(id));
|
|
|
|
|
- jyxConfigVo.setSettingList(selectSettingList(id));
|
|
|
|
|
- return HttpResult.ok(jyxConfigVo);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult updateById(JyxConfigEnd configEnd) {
|
|
public HttpResult updateById(JyxConfigEnd configEnd) {
|
|
|
- try {
|
|
|
|
|
- JyxConfig jyxConfig = BeanUtil.copyProperties(configEnd, JyxConfig.class);
|
|
|
|
|
- if (jyxConfigMapper.updateById(jyxConfig) > 0){
|
|
|
|
|
- configEnd.getBlameList().stream().forEach(blame -> {
|
|
|
|
|
- blame.setJyxConfigId(jyxConfig.getId());
|
|
|
|
|
- });
|
|
|
|
|
- configEnd.getSettingList().stream().forEach(setting -> {
|
|
|
|
|
- setting.setJyxConfigId(jyxConfig.getId());
|
|
|
|
|
- });
|
|
|
|
|
- blameService.saveOrUpdateBatch(configEnd.getBlameList());
|
|
|
|
|
- settingService.saveOrUpdateBatch(configEnd.getSettingList());
|
|
|
|
|
- return HttpResult.ok("修改成功");
|
|
|
|
|
- }
|
|
|
|
|
- return HttpResult.error("修改失败");
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- return HttpResult.error("修改失败");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ JyxConfig jyxConfig = BeanUtil.copyProperties(configEnd, JyxConfig.class);
|
|
|
|
|
+ if (jyxConfigMapper.updateById(jyxConfig) <= 0) {
|
|
|
|
|
+ return HttpResult.error("修改失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //同步删除或者新增驾意险配置
|
|
|
|
|
+ updateRelatedLists(configEnd, configEnd.getId());
|
|
|
|
|
+ return HttpResult.ok("修改成功");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("更新配置失败", e);
|
|
|
|
|
+ throw new RuntimeException("更新配置失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateRelatedLists(JyxConfigEnd configEnd, String jyxConfigId) {
|
|
|
|
|
+ blameService.deleteByJyxConfigId(jyxConfigId);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(configEnd.getBlameList())) {
|
|
|
|
|
+ configEnd.getBlameList().forEach(blame -> blame.setJyxConfigId(jyxConfigId));
|
|
|
|
|
+ blameService.saveBatch(configEnd.getBlameList());
|
|
|
|
|
+ }
|
|
|
|
|
+ settingService.deleteByJyxConfigId(jyxConfigId);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(configEnd.getSettingList())) {
|
|
|
|
|
+ configEnd.getSettingList().forEach(setting -> setting.setJyxConfigId(jyxConfigId));
|
|
|
|
|
+ settingService.saveBatch(configEnd.getSettingList());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|