|
|
@@ -1,25 +1,30 @@
|
|
|
package com.jzg.organization.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.constants.Constants;
|
|
|
import com.jzg.commons.constants.ReturnInformation;
|
|
|
import com.jzg.commons.core.page.HttpResult;
|
|
|
import com.jzg.commons.entity.dto.CostAgreementParam;
|
|
|
import com.jzg.commons.entity.dto.PtlAgreementCostAdd;
|
|
|
+import com.jzg.commons.entity.dto.PtlAgreementCostEnd;
|
|
|
import com.jzg.commons.entity.po.PtlAgreementCost;
|
|
|
-import com.jzg.commons.entity.vo.PtlAgreementCostTypeVo;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementCostRule;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementCostType;
|
|
|
+import com.jzg.commons.entity.po.RuleConditionsVerify;
|
|
|
import com.jzg.commons.entity.vo.PtlAgreementCostVo;
|
|
|
-
|
|
|
+import com.jzg.commons.util.ListUtils;
|
|
|
import com.jzg.organization.mapper.PtlAgreementCostMapper;
|
|
|
import com.jzg.organization.service.PtlAgreementCostRuleService;
|
|
|
import com.jzg.organization.service.PtlAgreementCostService;
|
|
|
import com.jzg.organization.service.PtlAgreementCostTypeService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -29,62 +34,92 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMapper, PtlAgreementCost> implements PtlAgreementCostService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private PtlAgreementCostTypeService costTypeService;
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private PtlAgreementCostRuleService costRuleService;
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private PtlAgreementCostMapper ptlAgreementCostMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult save(List<PtlAgreementCostAdd> costAddList) {
|
|
|
+ if (costAddList.isEmpty()) {
|
|
|
+ return HttpResult.error("保存数据不能为空");
|
|
|
+ }
|
|
|
for (PtlAgreementCostAdd ptlAgreementCostAdd : costAddList){
|
|
|
+ if (ListUtils.hasDuplicates(ptlAgreementCostAdd.getRuleConditions())){
|
|
|
+ return HttpResult.error("存在相同费用规则,请检查");
|
|
|
+ }
|
|
|
+ boolean verify = verify(ptlAgreementCostAdd);
|
|
|
+ if (verify){
|
|
|
+ return HttpResult.error("已存在相同且有效的费用规则,请检查");
|
|
|
+ }
|
|
|
PtlAgreementCost ptlAgreementCost = BeanUtil.copyProperties(ptlAgreementCostAdd, PtlAgreementCost.class);
|
|
|
+ ptlAgreementCost.setIsEnabled(Constants.ENABLE);
|
|
|
+ ptlAgreementCost.setIsValid(Constants.ENABLE);
|
|
|
if (baseMapper.insert(ptlAgreementCost) <= 0) {
|
|
|
log.error("插入操作失败");
|
|
|
throw new RuntimeException(ReturnInformation.FAILURE_MESSAGE);
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(ptlAgreementCostAdd.getPtlAgreementCostTypeList())) {
|
|
|
- costTypeService.saveOrUpdateCostType(ptlAgreementCostAdd.getPtlAgreementCostTypeList(), ptlAgreementCost.getId());
|
|
|
+ costTypeService.saveOrUpdateCostType(BeanUtil.copyToList(ptlAgreementCostAdd.getPtlAgreementCostTypeList(), PtlAgreementCostType.class), ptlAgreementCost.getId());
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(ptlAgreementCostAdd.getRuleConditions())) {
|
|
|
- costRuleService.saveOrUpdateCostRule(ptlAgreementCostAdd.getRuleConditions(), ptlAgreementCost.getId());
|
|
|
+ costRuleService.saveOrUpdateCostRule(BeanUtil.copyToList(ptlAgreementCostAdd.getRuleConditions(), PtlAgreementCostRule.class), ptlAgreementCost.getId());
|
|
|
}
|
|
|
log.info("保存成功");
|
|
|
}
|
|
|
return HttpResult.ok(ReturnInformation.SUCCESS_MESSAGE);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResult update(List<PtlAgreementCostEnd> costEndList) {
|
|
|
+ for (PtlAgreementCostEnd ptlAgreementCostEnd : costEndList) {
|
|
|
+ if (ListUtils.hasDuplicates(ptlAgreementCostEnd.getRuleConditions())){
|
|
|
+ return HttpResult.error("已存在相同且有效的费用规则,请检查");
|
|
|
+ }
|
|
|
+ PtlAgreementCost ptlAgreementCost = BeanUtil.copyProperties(ptlAgreementCostEnd, PtlAgreementCost.class);
|
|
|
+ if (baseMapper.updateById(ptlAgreementCost) <= 0) {
|
|
|
+ throw new RuntimeException(ReturnInformation.UPDATE_FAILED);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(ptlAgreementCostEnd.getPtlAgreementCostTypeList())) {
|
|
|
+ costTypeService.saveOrUpdateCostType(BeanUtil.copyToList(ptlAgreementCostEnd.getPtlAgreementCostTypeList(), PtlAgreementCostType.class), ptlAgreementCost.getId());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(ptlAgreementCostEnd.getRuleConditions())) {
|
|
|
+ costRuleService.saveOrUpdateCostRule(BeanUtil.copyToList(ptlAgreementCostEnd.getRuleConditions(), PtlAgreementCostRule.class), ptlAgreementCost.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.ok(ReturnInformation.UPDATE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
public boolean verify(PtlAgreementCostAdd ptlAgreementCostAdd){
|
|
|
CostAgreementParam costAgreementParam = new CostAgreementParam();
|
|
|
costAgreementParam.setPtlAgreementId(ptlAgreementCostAdd.getPtlAgreementId());
|
|
|
costAgreementParam.setCoverRuleId(ptlAgreementCostAdd.getCoverRuleId());
|
|
|
- Map<String, List<PtlAgreementCostVo>> listMap = queryByAgreementId(costAgreementParam);
|
|
|
- if (CollectionUtils.isEmpty(listMap)){
|
|
|
- return true;
|
|
|
+ List<PtlAgreementCostVo> voList = queryByAgreementId(costAgreementParam);
|
|
|
+ if (CollectionUtils.isEmpty(voList)){
|
|
|
+ return false;
|
|
|
}
|
|
|
// 先比较规则是否相同
|
|
|
+ Map<String, List<PtlAgreementCostVo>> listMap = voList.stream().filter(v -> v.isEnabled() && v.isValid()).collect(Collectors.groupingBy(PtlAgreementCostVo::getProductId));
|
|
|
List<PtlAgreementCostVo> ptlAgreementCostVos = listMap.get(ptlAgreementCostAdd.getProductId());
|
|
|
+ if (CollectionUtils.isEmpty(ptlAgreementCostVos)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<RuleConditionsVerify> ruleConditionsVerifies = BeanUtil.copyToList(ptlAgreementCostAdd.getRuleConditions(), RuleConditionsVerify.class);
|
|
|
+ if (CollectionUtils.isEmpty(ruleConditionsVerifies)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
for (PtlAgreementCostVo ptlAgreementCostVo : ptlAgreementCostVos) {
|
|
|
- List<PtlAgreementCostTypeVo> ptlAgreementCostTypeList = ptlAgreementCostVo.getPtlAgreementCostTypeList();
|
|
|
- for (PtlAgreementCostAdd.PtlAgreementCostTypeDto dto : ptlAgreementCostAdd.getPtlAgreementCostTypeList()) {
|
|
|
- for (PtlAgreementCostTypeVo ptlAgreementCostTypeVo : ptlAgreementCostTypeList) {
|
|
|
- if (dto.getCostType() == ptlAgreementCostTypeVo.getCostType()){
|
|
|
- if (dto.getInlet().compareTo(ptlAgreementCostTypeVo.getInlet()) != 0){
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (dto.getExport().compareTo(ptlAgreementCostTypeVo.getExport()) != 0){ }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ List<RuleConditionsVerify> verifies = BeanUtil.copyToList(ptlAgreementCostVo.getRuleConditions(), RuleConditionsVerify.class);
|
|
|
+ if (ObjectUtil.equals(verifies,ruleConditionsVerifies)){
|
|
|
+ return true;
|
|
|
+ };
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -94,9 +129,28 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, List<PtlAgreementCostVo>> queryByAgreementId(CostAgreementParam costAgreementParam) {
|
|
|
- return ptlAgreementCostMapper.queryByAgreementId(costAgreementParam)
|
|
|
- .stream().collect(Collectors.groupingBy(PtlAgreementCostVo::getProductId));
|
|
|
+ public List<PtlAgreementCostVo> queryByAgreementId(CostAgreementParam costAgreementParam) {
|
|
|
+ return ptlAgreementCostMapper.queryByAgreementId(costAgreementParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult enableDisableByIds(List<String> ids,Boolean isEnabled) {
|
|
|
+ if (CollectionUtils.isEmpty(ids)){
|
|
|
+ return HttpResult.error("参数不能为空");
|
|
|
+ }
|
|
|
+ PtlAgreementCost ptlAgreementCost = new PtlAgreementCost();
|
|
|
+ ptlAgreementCost.setIsEnabled(isEnabled);
|
|
|
+ ptlAgreementCost.setIsValid(isEnabled);
|
|
|
+ return baseMapper.update(ptlAgreementCost,new LambdaQueryWrapper<>(PtlAgreementCost.class)
|
|
|
+ .in(PtlAgreementCost::getId,ids)) > 0 ?
|
|
|
+ HttpResult.ok(isEnabled ? "启用成功" : "禁用成功") : HttpResult.error(isEnabled ? "启用失败" : "禁用失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateAuditMethod(List<Long> ids) {
|
|
|
+ PtlAgreementCost ptlAgreementCost = new PtlAgreementCost();
|
|
|
+ ptlAgreementCost.setAuditMethod(0);
|
|
|
+ baseMapper.update(ptlAgreementCost,new LambdaQueryWrapper<>(PtlAgreementCost.class).in(PtlAgreementCost::getId,ids));
|
|
|
}
|
|
|
|
|
|
|