|
|
@@ -8,21 +8,21 @@ import com.jzg.commons.constants.Constants;
|
|
|
import com.jzg.commons.constants.ReturnInformation;
|
|
|
import com.jzg.commons.core.base.StateResult;
|
|
|
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.po.PtlAgreementCostRule;
|
|
|
-import com.jzg.commons.entity.po.PtlAgreementCostType;
|
|
|
-import com.jzg.commons.entity.po.RuleConditionsVerify;
|
|
|
+import com.jzg.commons.entity.dto.*;
|
|
|
+import com.jzg.commons.entity.po.*;
|
|
|
+import com.jzg.commons.entity.vo.CostListVo;
|
|
|
import com.jzg.commons.entity.vo.PtlAgreementCostRuleVo;
|
|
|
+import com.jzg.commons.entity.vo.PtlAgreementCostTypeVo;
|
|
|
import com.jzg.commons.entity.vo.PtlAgreementCostVo;
|
|
|
+import com.jzg.commons.util.BuildDescUtils;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
import com.jzg.commons.util.ListUtils;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
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 com.jzg.organization.service.PtlAgreementUndwrtRulesAttrService;
|
|
|
import com.jzg.organization.state.CostState;
|
|
|
import com.jzg.organization.state.UserState;
|
|
|
import com.jzg.organization.state.listener.CostStateListener;
|
|
|
@@ -34,6 +34,8 @@ import org.springframework.statemachine.StateMachine;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -52,6 +54,10 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
@Resource
|
|
|
private PtlAgreementCostMapper ptlAgreementCostMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PtlAgreementUndwrtRulesAttrService agreementUndwrtRulesAttrService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
@@ -63,54 +69,60 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResult save(List<PtlAgreementCostAdd> costAddList) {
|
|
|
+ public HttpResult save(List<CostAdd> 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(BeanUtil.copyToList(ptlAgreementCostAdd.getPtlAgreementCostTypeList(), PtlAgreementCostType.class), ptlAgreementCost.getId());
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(ptlAgreementCostAdd.getRuleConditions())) {
|
|
|
- costRuleService.saveOrUpdateCostRule(BeanUtil.copyToList(ptlAgreementCostAdd.getRuleConditions(), PtlAgreementCostRule.class), ptlAgreementCost.getId());
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = agreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
|
|
|
+ for (CostAdd costAdd : costAddList) {
|
|
|
+ for (PtlAgreementCostAdd ptlAgreementCostAdd : costAdd.getPtlAgreementCostAddList()){
|
|
|
+ if (ListUtils.hasDuplicates(ptlAgreementCostAdd.getRuleConditions())){
|
|
|
+ return HttpResult.error("存在相同费用规则,请检查");
|
|
|
+ }
|
|
|
+ ptlAgreementCostAdd.setPtlAgreementId(costAdd.getPtlAgreementId());
|
|
|
+ ptlAgreementCostAdd.setProductId(costAdd.getProductId());
|
|
|
+ ptlAgreementCostAdd.setProductName(costAdd.getProductName());
|
|
|
+ ptlAgreementCostAdd.setCoverRuleId(costAdd.getCoverRuleId());
|
|
|
+ boolean verify = verify(ptlAgreementCostAdd);
|
|
|
+ if (verify){
|
|
|
+ return HttpResult.error("已存在相同且有效的费用规则,请检查");
|
|
|
+ }
|
|
|
+ PtlAgreementCost ptlAgreementCost = BeanUtil.copyProperties(ptlAgreementCostAdd, PtlAgreementCost.class);
|
|
|
+ ptlAgreementCost.setCostRules(BuildDescUtils.buildDesc(BeanUtil.copyToList(ptlAgreementCostAdd.getRuleConditions(), PtlAgreementUndwrtRulesAttr.class), undwrtRulesAttrList));
|
|
|
+ if (baseMapper.insert(ptlAgreementCost) <= 0) {
|
|
|
+ log.error("插入操作失败");
|
|
|
+ throw new RuntimeException(ReturnInformation.FAILURE_MESSAGE);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(ptlAgreementCostAdd.getPtlAgreementCostTypeList())) {
|
|
|
+ costTypeService.saveOrUpdateCostType(BeanUtil.copyToList(ptlAgreementCostAdd.getPtlAgreementCostTypeList(), PtlAgreementCostType.class), ptlAgreementCost.getId());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(ptlAgreementCostAdd.getRuleConditions())) {
|
|
|
+ costRuleService.saveOrUpdateCostRule(BeanUtil.copyToList(ptlAgreementCostAdd.getRuleConditions(), PtlAgreementCostRule.class), ptlAgreementCost.getId());
|
|
|
+ }
|
|
|
+ log.info("保存成功");
|
|
|
}
|
|
|
- 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());
|
|
|
- }
|
|
|
+ public HttpResult update(PtlAgreementCostEnd ptlAgreementCostEnd) {
|
|
|
+
|
|
|
+// 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);
|
|
|
}
|
|
|
|
|
|
@@ -123,7 +135,7 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
return false;
|
|
|
}
|
|
|
// 先比较规则是否相同
|
|
|
- Map<String, List<PtlAgreementCostVo>> listMap = voList.stream().filter(v -> v.isEnabled() && v.isValid()).collect(Collectors.groupingBy(PtlAgreementCostVo::getProductId));
|
|
|
+ Map<String, List<PtlAgreementCostVo>> listMap = voList.stream().filter(v -> Constants.ENABLE == v.getIsEnabled() && Constants.NOT_DELETED == v.getIsValid()).collect(Collectors.groupingBy(PtlAgreementCostVo::getProductId));
|
|
|
List<PtlAgreementCostVo> ptlAgreementCostVos = listMap.get(ptlAgreementCostAdd.getProductId());
|
|
|
if (CollectionUtils.isEmpty(ptlAgreementCostVos)){
|
|
|
return false;
|
|
|
@@ -144,23 +156,36 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
@Override
|
|
|
public HttpResult queryById(Long id) {
|
|
|
PtlAgreementCostVo ptlAgreementCostVo = ptlAgreementCostMapper.queryById(id);
|
|
|
- ptlAgreementCostVo.setRulesList(ptlAgreementCostVo.getRuleConditions().stream().map(PtlAgreementCostRuleVo::getAttrId).collect(Collectors.toList()));
|
|
|
+ if (ObjectUtil.isEmpty(ptlAgreementCostVo)){
|
|
|
+ return HttpResult.ok(ptlAgreementCostVo);
|
|
|
+ }
|
|
|
+ for (PtlAgreementCostRuleVo ruleCondition : ptlAgreementCostVo.getRuleConditions()) {
|
|
|
+ if (StringUtils.isNotEmpty(ruleCondition.getMin()) && ruleCondition.getMin().contains(",")){
|
|
|
+ ruleCondition.setMinArray(Arrays.asList(ruleCondition.getMin().split(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
return HttpResult.ok(ptlAgreementCostVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<PtlAgreementCostVo> queryByAgreementId(CostAgreementParam costAgreementParam) {
|
|
|
+ public List<CostListVo> queryByAgreementIdAndCoverRuleId(CostAgreementParam costAgreementParam) {
|
|
|
+ return ptlAgreementCostMapper.queryByAgreementIdAndCoverRuleId(costAgreementParam);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private 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);
|
|
|
+ ptlAgreementCost.setIsEnabled(isEnabled ? 0 : 1);
|
|
|
+ ptlAgreementCost.setIsValid(isEnabled ? 0 : 1);
|
|
|
return baseMapper.update(ptlAgreementCost,new LambdaQueryWrapper<>(PtlAgreementCost.class)
|
|
|
.in(PtlAgreementCost::getId,ids)) > 0 ?
|
|
|
HttpResult.ok(isEnabled ? "启用成功" : "禁用成功") : HttpResult.error(isEnabled ? "启用失败" : "禁用失败");
|
|
|
@@ -224,5 +249,10 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpResult pageList(PtlAgreementCostParam costParam) {
|
|
|
+ return HttpResult.ok(baseMapper.pageList(costParam.getPage(),costParam));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|