|
@@ -42,6 +42,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
@@ -499,6 +500,74 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
? HttpResult.ok("批量修改成功,共修改 " + finalCostIds.size() + " 条记录")
|
|
? HttpResult.ok("批量修改成功,共修改 " + finalCostIds.size() + " 条记录")
|
|
|
: HttpResult.error("批量修改失败");
|
|
: HttpResult.error("批量修改失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public HttpResult<String> batchAdjustCostRatio(PtlAgreementCostBatchAdjustParam param) {
|
|
|
|
|
+ log.info("批量调整费用比例。param=[{}]", JSONUtil.toJsonStr(param));
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(param.getCostIds())) {
|
|
|
|
|
+ return HttpResult.error("费用ID列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询所有需要调整的费用类型记录
|
|
|
|
|
+ LambdaQueryWrapper<PtlAgreementCostType> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.in(PtlAgreementCostType::getPtlAgreementCostId, param.getCostIds());
|
|
|
|
|
+ List<PtlAgreementCostType> costTypeList = ptlAgreementCostTypeService.list(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(costTypeList)) {
|
|
|
|
|
+ return HttpResult.error("未找到需要调整的费用类型记录");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ boolean isAdd = "ADD".equalsIgnoreCase(param.getOperationType());
|
|
|
|
|
+
|
|
|
|
|
+ for (PtlAgreementCostType costType : costTypeList) {
|
|
|
|
|
+ String costTypeStr = costType.getCostType();
|
|
|
|
|
+
|
|
|
|
|
+ // 根据费用类型进行调整
|
|
|
|
|
+ if ("交强险".equals(costTypeStr)) {
|
|
|
|
|
+ adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
|
|
|
|
|
+ } else if ("商业险".equals(costTypeStr)) {
|
|
|
|
|
+ adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
|
|
|
|
|
+ } else if ("驾意险".equals(costTypeStr)) {
|
|
|
|
|
+ adjustCostType(costType, param.getInletRatio(), param.getInletKeepPointRatio(), isAdd);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 批量更新
|
|
|
|
|
+ ptlAgreementCostTypeService.updateBatchById(costTypeList);
|
|
|
|
|
+
|
|
|
|
|
+ return HttpResult.ok("批量调整成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 调整费用类型的各项比例
|
|
|
|
|
+ */
|
|
|
|
|
+ private void adjustCostType(PtlAgreementCostType costType, BigDecimal inlet,
|
|
|
|
|
+ BigDecimal keepPointRatio, boolean isAdd) {
|
|
|
|
|
+ // 入口比例
|
|
|
|
|
+ if (inlet != null) {
|
|
|
|
|
+ costType.setInlet(calculateNewValue(costType.getInlet(), inlet, isAdd));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 入口留点比例
|
|
|
|
|
+ if (keepPointRatio != null) {
|
|
|
|
|
+ costType.setKeepPointRatio(calculateNewValue(costType.getKeepPointRatio(), keepPointRatio, isAdd));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算新值
|
|
|
|
|
+ */
|
|
|
|
|
+ private BigDecimal calculateNewValue(BigDecimal currentValue, BigDecimal adjustValue, boolean isAdd) {
|
|
|
|
|
+ if (currentValue == null) {
|
|
|
|
|
+ currentValue = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isAdd) {
|
|
|
|
|
+ return currentValue.add(adjustValue);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BigDecimal result = currentValue.subtract(adjustValue);
|
|
|
|
|
+ // 确保结果不小于0
|
|
|
|
|
+ return result.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : result;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|