package com.zteits.bill.biz.billrule; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import com.alibaba.fastjson.JSONObject; import com.clouds.common.cache.bill.BillingDescCacheUtil; import com.clouds.common.constants.BillingFreeTimeTypeEnum; import com.clouds.common.utils.SequenceUtil; import com.github.pagehelper.PageInfo; import com.xiaoleilu.hutool.date.DateUtil; import com.zteits.bill.biz.billrule.inner.BillingRuleInnerService; import com.zteits.bill.dao.billingdesc.TBillingDescriptionDao; import com.zteits.bill.dao.billingrulecollect.BillingRuleCollectiDao; import com.zteits.bill.dao.billparkrulerel.BillingParkRuleRelDao; import com.zteits.bill.dao.billrule.BillingRuleDao; import com.zteits.bill.dao.billrulecollect.BillingRuleCollectDao; import com.zteits.bill.dao.billruleconfig.BillingRuleConfigDao; import com.zteits.bill.domain.TBillingRule; import com.zteits.bill.domain.TBillingRuleCollect; import com.zteits.bill.domain.TBillingRuleConfig; import com.zteits.bill.pagepager.PageBeanUtil; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.bean.PageBean; import com.zteits.clouds.api.apibase.constants.BillRuleEnum; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.apibase.constants.ErrorType; import com.zteits.clouds.api.apibase.constants.SequenceTypeEnum; import com.zteits.clouds.api.apibase.exception.BizException; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingParkRuleRelDTO; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingRuleCollectDTO; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingRuleConfigDTO; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingRuleDTO; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingParkRuleRelQueryForPageReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingParkRuleRelSaveReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleByCollectNoReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleCollectsByOrgIdReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleConfigForRuleReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleDeleteReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleQueryByPlNoReq; import com.zteits.clouds.api.dto.bill.billingrule.param.BillingRuleQueryByRuleNoReq; import com.zteits.clouds.api.dto.bill.billingrule.param.SaveBillingRuleAndConfigAndCollectReq; import com.zteits.clouds.api.service.bill.billrule.BillingRuleService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; /** * Copyright: Copyright (c) 2017 zteits * * @ClassName: com.zteits.billing.biz.billrule * @Description: 计费规则服务实现类 * @version: v1.0.0 * @author: atao * @date: 2017/10/27 下午2:56 * Modification History: * Date Author Version Description * ---------------------------------------------------------* * 2017/10/27 atao v1.0.0 创建 */ @Component public class BillingRuleServiceImpl implements BillingRuleService { private static final Logger logger = LoggerFactory.getLogger(BillingRuleServiceImpl.class); @Autowired private BillingRuleInnerService billingRuleInnerService; @Autowired private BillingRuleDao billingRuleDao; @Autowired private BillingRuleCollectDao billingRuleCollectDao; @Autowired private BillingRuleConfigDao billingRuleConfigDao; @Autowired private BillingParkRuleRelDao billingParkRuleRelDao; @Autowired private BillingRuleCollectiDao billingRuleCollectiDao; @Autowired private TBillingDescriptionDao tBillingDescriptionDao; @Override public BizResult> queryBillingRuleByPlNo(BillingRuleQueryByPlNoReq req) { if (StringUtils.isEmpty(req.getPlNo())) { throw new BizException(ErrorType.PARAMM_NULL, "停车场编码"); } List ruleDTOS = billingRuleInnerService.queryBillingRuleDTOByPlNos(req.getPlNo()); for (BillingRuleDTO dto : ruleDTOS) { //根据规则编码查询规则明细 List ruleConfigDTOS = billingRuleInnerService.queryBillingRuleConfigByRuleNo( dto.getRuleNo()); dto.setBillingRuleConfigs(ruleConfigDTOS); } return new BizResult<>(ruleDTOS); } @Transactional(rollbackFor = Exception.class) @Override public BizResult saveBillingRuleAndConfigAndCollect(SaveBillingRuleAndConfigAndCollectReq request) { /**1、校验参数 */ this.validateRequest(request); /**雪花算法生成规则编码*/ String ruleNoForMinCar = SequenceUtil.getNextId(SequenceTypeEnum.BILL_RULE_NO); /**雪花算法生成规则配置编码*/ String ruleConfigNoForMinCar = SequenceUtil.getNextId(SequenceTypeEnum.BILL_RULE_CONFIG_NO); /**雪花算法生成规则编码*/ String ruleNoForMaxCar = SequenceUtil.getNextId(SequenceTypeEnum.BILL_RULE_NO); /**雪花算法生成规则配置编码*/ String ruleConfigNoForMaxCar = SequenceUtil.getNextId(SequenceTypeEnum.BILL_RULE_CONFIG_NO); /**雪花算法生成规则集合编码*/ String ruleCollectNo = SequenceUtil.getNextId(SequenceTypeEnum.BILL_RULE_COLLECT_NO); int saveBillRuleForMax = 0; /**1、保存大型车规则*/ saveBillRuleForMax = this.saveBillingRuleALL(request, ruleNoForMaxCar, ruleConfigNoForMaxCar, ruleCollectNo, BillRuleEnum.BILL_RULE_CAR_TYPE_MAX.value()); int saveBillRuleForMin = 0; if (saveBillRuleForMax > 0) { /**2、保存小型车规则*/ saveBillRuleForMin = this.saveBillingRuleALL(request, ruleNoForMinCar, ruleConfigNoForMinCar, ruleCollectNo, BillRuleEnum.BILL_RULE_CAR_TYPE_MIN.value()); } // ////保存计费规则描述 //TBillingDescription tBillingDescription = new TBillingDescription(); //tBillingDescription.setOrgId(request.getOrgId()); //tBillingDescription.setCreateTime(new Date()); //tBillingDescription.setCreateOp(request.getsOpId()); //tBillingDescription.setRuleCollectNo(ruleCollectNo); //tBillingDescription.setModifyTime(new Date()); //tBillingDescription.setModifyOp(request.getsOpId()); //tBillingDescription.setDescText(request.getBillDesc()); //tBillingDescription.setDataState(DataStatusEnum.DATA_STATUS_VALID.value()); // //Boolean flag = tBillingDescriptionDao.saveBillDescription(tBillingDescription); //if(flag){ // logger.info("保存计费规则描述成功!"); //}else{ // logger.info("保存计费规则描述失败!"); //} return new BizResult(saveBillRuleForMin > 0 ? true : false); } private void validateRequest(SaveBillingRuleAndConfigAndCollectReq request) { if (request == null || request.getCreateOp() == null) { throw new BizException(ErrorType.PARAMM_NULL, "入参不能为空"); } String start = "0"; if (!StringUtils.isEmpty(request.getStartTimeForDay())) { start = request.getStartTimeForDay().substring(0, 2); } String end = "12"; if (!StringUtils.isEmpty(request.getEndTimeForDay())) { end = request.getEndTimeForDay().substring(0, 2); } int max = (Integer.parseInt(end) - Integer.parseInt(start)) * 3600; int nightMax = 24 * 3600 - max; if (CollectionUtils.isEmpty(request.getRuleConfigListForMaxDay())) { throw new BizException(ErrorType.PARAMM_NULL, "大型车白天配置规则不能为空"); } else { int tmp = 0; for (int i = 0; i < request.getRuleConfigListForMaxDay().size(); i++) { Integer begin = request.getRuleConfigListForMaxDay().get(i).getStartBillingTime(); if (null != begin) { if (begin != tmp) { throw new BizException(ErrorType.PARAMM_NULL, "大型车白天上一个结束时间必须等于下一个开始时间"); } Integer endBilling = request.getRuleConfigListForMaxDay().get(i).getEndBillingTime(); // if (null != endBilling) { // if (endBilling >= max) { // throw new BizException(ErrorType.PARAMM_NULL, "大型车白天结束时间必须小于时间差的最大值"); // } // } tmp = endBilling; } } Integer lastEndBilling = request.getRuleConfigListForMaxDay().get( request.getRuleConfigListForMaxDay().size() - 1).getEndBillingTime(); if (null != lastEndBilling) { if (lastEndBilling < max) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜结束时间必须大于时间差的最大值"); } } } if (CollectionUtils.isEmpty(request.getRuleConfigListForMaxNight())) { throw new BizException(ErrorType.PARAMM_NULL, "大型车黑夜配置规则不能为空"); } else { int tmp = 0; for (int i = 0; i < request.getRuleConfigListForMaxNight().size(); i++) { Integer begin = request.getRuleConfigListForMaxNight().get(i).getStartBillingTime(); if (null != begin) { if (begin != tmp) { throw new BizException(ErrorType.PARAMM_NULL, "大型车黑夜上一个结束时间必须等于下一个开始时间"); } Integer endBilling = request.getRuleConfigListForMaxNight().get(i).getEndBillingTime(); // if (null != endBilling) { // if (endBilling >= max) { // throw new BizException(ErrorType.PARAMM_NULL, "大型车黑夜结束时间必须小于时间差的最大值"); // } // } tmp = endBilling; } } Integer lastEndBilling = request.getRuleConfigListForMaxNight().get( request.getRuleConfigListForMaxNight().size() - 1).getEndBillingTime(); if (null != lastEndBilling) { if (lastEndBilling < nightMax) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜结束时间必须大于时间差的最大值"); } } } if (CollectionUtils.isEmpty(request.getRuleConfigListForMinDay())) { throw new BizException(ErrorType.PARAMM_NULL, "小型车白天配置规则不能为空"); } else { int tmp = 0; for (int i = 0; i < request.getRuleConfigListForMinDay().size(); i++) { Integer begin = request.getRuleConfigListForMinDay().get(i).getStartBillingTime(); if (null != begin) { if (begin != tmp) { throw new BizException(ErrorType.PARAMM_NULL, "小型车白天上一个结束时间必须等于下一个开始时间"); } Integer endBilling = request.getRuleConfigListForMinDay().get(i).getEndBillingTime(); // if (null != endBilling) { // if (endBilling >= max) { // throw new BizException(ErrorType.PARAMM_NULL, "小型车白天结束时间必须小于时间差的最大值"); // } // } tmp = endBilling; } } Integer lastEndBilling = request.getRuleConfigListForMinDay().get( request.getRuleConfigListForMinDay().size() - 1).getEndBillingTime(); if (null != lastEndBilling) { if (lastEndBilling < max) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜结束时间必须大于时间差的最大值"); } } } if (CollectionUtils.isEmpty(request.getRuleConfigListForMinNight())) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜配置规则不能为空"); } else { int tmp = 0; for (int i = 0; i < request.getRuleConfigListForMinNight().size(); i++) { Integer begin = request.getRuleConfigListForMinNight().get(i).getStartBillingTime(); if (null != begin) { if (begin != tmp) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜上一个结束时间必须等于下一个开始时间"); } Integer endBilling = request.getRuleConfigListForMinNight().get(i).getEndBillingTime(); // if (null != endBilling) { // if (endBilling >= max) { // throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜结束时间必须小于时间差的最大值"); // } // } tmp = endBilling; } } Integer lastEndBilling = request.getRuleConfigListForMinNight().get( request.getRuleConfigListForMinNight().size() - 1).getEndBillingTime(); if (null != lastEndBilling) { if (lastEndBilling < nightMax) { throw new BizException(ErrorType.PARAMM_NULL, "小型车黑夜结束时间必须大于时间差的最大值"); } } } if (request.getOrgId() == null) { throw new BizException(ErrorType.PARAMM_NULL, "所属组织不能为空"); } //如果大型车单次封顶金额为空, 取值为单次封顶金额 if (null == request.getMaxChargeForBig()) { request.setMaxChargeForBig(request.getMaxCharge()); } //如果大型车单天封顶金额为空, 取值为单天封顶金额 if (null == request.getDayMaxChargeForBig()) { request.setDayMaxChargeForBig(request.getDayMaxCharge()); } } private int saveBillingRuleALL(SaveBillingRuleAndConfigAndCollectReq request, String ruleNo, String ruleConfigNo, String ruleCollectNo, int carType) { /**1、保存计费规则主表。*/ TBillingRule tBillRule = new TBillingRule(); BeanUtils.copyProperties(request, tBillRule); if (carType == BillRuleEnum.BILL_RULE_CAR_TYPE_MIN.value()) { tBillRule.setMaxCharge(request.getMaxCharge()); tBillRule.setDayMaxCharge(request.getDayMaxCharge()); } if (carType == BillRuleEnum.BILL_RULE_CAR_TYPE_MAX.value()) { tBillRule.setMaxCharge(request.getMaxChargeForBig()); tBillRule.setDayMaxCharge(request.getDayMaxChargeForBig()); } tBillRule.setCarType(carType); tBillRule.setCreateTime(new Date()); tBillRule.setRuleNo(ruleNo); tBillRule.setRuleType(BillRuleEnum.BILL_RULE_TYPE_CUSTOM.value()); tBillRule.setModifyOp(request.getCreateOp()); tBillRule.setDataState(DataStatusEnum.DATA_STATUS_VALID.value()); tBillRule.setCheckState(BillRuleEnum.BILL_CHECK_STATE_AUDIT_PASS.value()); int saveBillRuleCount = billingRuleDao.saveBillRule(tBillRule); /** 2、保存计费规则明细表。*/ int saveBillRuleConfigCount = 0; if (saveBillRuleCount > 0) { if (carType == BillRuleEnum.BILL_RULE_CAR_TYPE_MIN.value()) { /***白天小型车*/ saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMinDay(), request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_DAY.value(), request.getStartTimeForDay(), request.getStartTimeForNight(), request.getEndTimeForDay(), request.getEndTimeForNight(), ruleNo, ruleConfigNo); /***黑夜小型车 黑夜开始时间到23:59:59*/ saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMinNight(), request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value(), request.getStartTimeForDay(), request.getStartTimeForNight(), request.getEndTimeForDay(), request.getEndTimeForNight(), ruleNo, ruleConfigNo); ///***黑夜小型车 黑夜00:00:00到黑夜结束时间*/ //saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMinNight(), // request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value(), // request.getStartTimeForDay(), "00:00:00", // request.getEndTimeForDay(), request.getEndTimeForNight(), // ruleNo, ruleConfigNo); } else if (carType == BillRuleEnum.BILL_RULE_CAR_TYPE_MAX.value()) { /***白天大型车*/ saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMaxDay(), request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_DAY.value(), request.getStartTimeForDay(), request.getStartTimeForNight(), request.getEndTimeForDay(), request.getEndTimeForNight(), ruleNo, ruleConfigNo); /***黑夜大型车 黑夜开始时间到23:59:59*/ saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMaxNight(), request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value(), request.getStartTimeForDay(), request.getStartTimeForNight(), request.getEndTimeForDay(), request.getEndTimeForNight(), ruleNo, ruleConfigNo); ///***黑夜大型车 黑夜00:00:00到黑夜结束时间*/ //saveBillRuleConfigCount = this.saveBillRuleConfigCount(request.getRuleConfigListForMaxNight(), // request.getCreateOp(), request.getCreateOpName(), BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value(), // request.getStartTimeForDay(), "00:00:00", // request.getEndTimeForDay(), request.getEndTimeForNight(), // ruleNo, ruleConfigNo); } } /** 3、保存计费规则集合表*/ int saveBillRuleCollectCount = 0; if (saveBillRuleConfigCount > 0) { TBillingRuleCollect tBillingRuleCollect = new TBillingRuleCollect(); Integer freeTimeType = (null == request.getFreeTimeType()) ? BillingFreeTimeTypeEnum.BILLING_FREE_TIME_FREE_IN_TIME.getVal() : request.getFreeTimeType(); tBillingRuleCollect.setFreeTimeType(freeTimeType); tBillingRuleCollect.setDayStartTime(DateUtil.parse(request.getStartTimeForDay(), "HH:mm:ss")); tBillingRuleCollect.setDayEndTime(DateUtil.parse(request.getEndTimeForDay(), "HH:mm:ss")); tBillingRuleCollect.setRuleCollectNo(ruleCollectNo); tBillingRuleCollect.setRuleNo(ruleNo); tBillingRuleCollect.setRuleCollectName( StringUtils.isEmpty(request.getRuleCollectName()) ? "" : request.getRuleCollectName()); tBillingRuleCollect.setCreateTime(new Date()); tBillingRuleCollect.setModifyTime(new Date()); tBillingRuleCollect.setCreateOp(request.getCreateOp()); tBillingRuleCollect.setModifyOp(request.getCreateOp()); tBillingRuleCollect.setDataState(DataStatusEnum.DATA_STATUS_VALID.value()); tBillingRuleCollect.setOrgId(request.getOrgId()); saveBillRuleCollectCount = billingRuleCollectDao.saveBillingRuleCollect(tBillingRuleCollect); } return saveBillRuleCollectCount; } /** * @param ruleConfigList * @param createOp * @param createOpName * @param isDay * @param startTimeForDay * @param startTimeForNight * @param endTimeForDay * @param endTimeForNight * @param ruleNo * @param ruleConfigNo * @return 2017年11月20日 langlw */ private int saveBillRuleConfigCount( List ruleConfigList, Long createOp, String createOpName, int isDay, String startTimeForDay, String startTimeForNight, String endTimeForDay, String endTimeForNight, String ruleNo, String ruleConfigNo) { int saveBillRuleConfigCount = 0; if (StringUtils.isEmpty(startTimeForDay) || StringUtils.isEmpty(startTimeForNight) || StringUtils.isEmpty(endTimeForDay) || StringUtils.isEmpty(endTimeForNight) ) { throw new BizException(ErrorType.PARAMM_NULL, "白天和黑夜时间不能为空"); } if (CollectionUtils.isEmpty(ruleConfigList)) { throw new BizException(ErrorType.PARAMM_NULL, "规则配置不能为空"); } for (BillingRuleConfigForRuleReq rulereq : ruleConfigList) { Integer unit = rulereq.getUnit(); if (rulereq.getUnit() == null) { throw new BizException(ErrorType.PARAMM_NULL, "计时单位不能为空"); } TBillingRuleConfig tBillingRuleConfig = new TBillingRuleConfig(); tBillingRuleConfig.setRuleNo(ruleNo); tBillingRuleConfig.setRuleConfigNo(ruleConfigNo); if (BillRuleEnum.BILL_CONFIG_UNIT_NUM.value().equals(unit)) { tBillingRuleConfig.setBillingConfigType(BillRuleEnum.BILL_CONFIG_TYPE_NUM.value()); } else { tBillingRuleConfig.setBillingConfigType(BillRuleEnum.BILL_CONFIG_TYPE_TIME.value()); } if (isDay == BillRuleEnum.BILL_CONFIG_ISDAY_DAY.value()) { tBillingRuleConfig.setIsday(BillRuleEnum.BILL_CONFIG_ISDAY_DAY.value()); tBillingRuleConfig.setStartTime(DateUtil.parse(startTimeForDay, "HH:mm:ss")); tBillingRuleConfig.setEndTime(DateUtil.parse(endTimeForDay, "HH:mm:ss")); } else if (isDay == BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value()) { tBillingRuleConfig.setIsday(BillRuleEnum.BILL_CONFIG_ISDAY_NIGHT.value()); tBillingRuleConfig.setStartTime(DateUtil.parse(startTimeForNight, "HH:mm:ss")); tBillingRuleConfig.setEndTime(DateUtil.parse(endTimeForNight, "HH:mm:ss")); } tBillingRuleConfig.setUnit(rulereq.getUnit()); tBillingRuleConfig.setUnitRate(rulereq.getUnitRate()); tBillingRuleConfig.setStartBillingTime(rulereq.getStartBillingTime()); tBillingRuleConfig.setEndBillingTime(rulereq.getEndBillingTime()); tBillingRuleConfig.setSort(rulereq.getSort()); tBillingRuleConfig.setUnitFreeTime(BillRuleEnum.BILL_UNIT_FREE_TIME.value()); tBillingRuleConfig.setCreateOp(createOp); tBillingRuleConfig.setCreateOpName(createOpName); tBillingRuleConfig.setCreateTime(new Date()); tBillingRuleConfig.setModifyOp(createOp); saveBillRuleConfigCount = billingRuleConfigDao.saveBillingRuleConfig(tBillingRuleConfig); } return saveBillRuleConfigCount; } @Override public BizResult> queryBillingRuleByRuleNo(BillingRuleQueryByRuleNoReq req) { if (StringUtils.isEmpty(req.getRuleNos())) { throw new BizException(ErrorType.PARAMM_NULL, "计费规则编码"); } List ruleDTOS = billingRuleInnerService.queryBillingRuleByRuleNo(req.getRuleNos()); for (BillingRuleDTO dto : ruleDTOS) { //根据规则编码查询规则明细 List ruleConfigDTOS = billingRuleInnerService.queryBillingRuleConfigByRuleNo( dto.getRuleNo()); dto.setBillingRuleConfigs(ruleConfigDTOS); } return new BizResult<>(ruleDTOS); } @Override public BizResult> queryBillingRuleCollectsByOrgId(BillingRuleCollectsByOrgIdReq req) { List ruleCollects = billingRuleCollectiDao.queryBillingRuleCollectsByOrgId(req.getOrgId()); List resultList = new ArrayList<>(); if (CollectionUtils.isEmpty(ruleCollects)) { return new BizResult<>(resultList); } for (TBillingRuleCollect ruleCollect : ruleCollects) { BillingRuleCollectDTO dto = new BillingRuleCollectDTO(); BeanUtils.copyProperties(ruleCollect, dto); resultList.add(dto); } return new BizResult<>(resultList); } @Override public BizResult> queryBillingRuleByCollectNo(BillingRuleByCollectNoReq req) { if (StringUtils.isEmpty(req.getCollectNo())) { throw new BizException(ErrorType.PARAMM_NULL, "计费集合编码"); } List billingRules = billingRuleDao.queryBillingRuleByCollectNo(req.getCollectNo()); for (BillingRuleDTO dto : billingRules) { //根据规则编码查询规则明细 List ruleConfigDTOS = billingRuleInnerService.queryBillingRuleConfigByRuleNo( dto.getRuleNo()); dto.setBillingRuleConfigs(ruleConfigDTOS); } return new BizResult<>(billingRules); } /** * 分页查询计费规则与停车场管理关系 * langlw 2017-11-23 */ @Override public BizResult> queryBillingParkRuleRelForPage( BillingParkRuleRelQueryForPageReq req) { PageBean pageBean = new PageBean(); logger.info("---begin 分页查询计费规则与停车场管理关系,入参={}", JSONObject.toJSON(req)); if (req == null) { logger.info("入参为空"); throw new BizException(ErrorType.PARAMM_NULL, "入参为空!"); } if (CollectionUtils.isEmpty(req.getPlNos())) { throw new BizException(ErrorType.PARAMM_NULL, "停车场编号集合不能为空"); } PageInfo pageInfo = billingParkRuleRelDao.queryBillingParkRuleRelForPage(req); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, BillingParkRuleRelDTO.class); } logger.info("---end 分页查询计费规则与停车场管理关系..."); return new BizResult>(pageBean); } @Override @Transactional public BizResult saveBillingParkRuleRel(BillingParkRuleRelSaveReq req) { if (CollectionUtils.isEmpty(req.getPlNos())) { throw new BizException(ErrorType.PARAMM_NULL, "停车场编号"); } if (StringUtils.isEmpty(req.getRuleCollectNo())) { throw new BizException(ErrorType.PARAMM_NULL, "计费规则集合编号"); } if (StringUtils.isEmpty(req.getEffectTime())) { throw new BizException(ErrorType.PARAMM_NULL, "生效时间"); } Date inputTime = DateUtil.parse(req.getEffectTime(), "yyyy-MM-dd"); Date date = DateUtil.endOfDay(DateUtil.yesterday()); if (inputTime.getTime() < date.getTime()) { throw new BizException(ErrorType.BIZ_ERROR, "生效时间必须大于昨日"); } //生效时间 Date effectTime = inputTime; //失效时间 = 新的生效时间-1毫秒 Date expireTime = DateUtil.offsetMillisecond(inputTime, -1); //Date expireTime= inputTime; //1、将以前停车场与计费规则绑定关系的失效时间设置为生效时间 -1毫秒 billingParkRuleRelDao.updateBillingRuleCollectExpireTimeByPlNos(req.getPlNos(), effectTime, expireTime, req.getOpId(), req.getOpName()); //2、将新的停车场与计费规则绑定关系进行保存 billingParkRuleRelDao.batchSaveBillingRuleCollectParkRel(req.getPlNos(), req.getRuleCollectNo(), effectTime, req.getOpId(), req.getOpName()); try{ //在车场绑定新的计费规则的时候 删除缓存中的信息 req.getPlNos().parallelStream().forEach(plNo->{ BillingDescCacheUtil.deleteBillDescInfoByPlNo(plNo); }); }catch(Exception e){ logger.error("新增车场与计费规则绑定关系时,删除计费规则描述缓存信息失败!",e); } return new BizResult<>(true); } @Override @Transactional(rollbackFor = Exception.class) public BizResult deleteBillingRule(BillingRuleDeleteReq req) { if (StringUtils.isEmpty(req.getRuleCollectNo())) { throw new BizException(ErrorType.PARAMM_NULL, "计费规则集合编码不能为空!"); } /** * 1、查询计费集合 */ List ruleCollects = billingRuleCollectDao.queryBillingRuleCollectByCollectionNo( req.getRuleCollectNo()); if (CollectionUtils.isEmpty(ruleCollects)) { throw new BizException(ErrorType.BIZ_ERROR, "查不到对应的计费组规则"); } /** * 2、判断计费集合与车场的有效绑定数量 */ int num = billingRuleCollectDao.queryEffectRuleCollect(req.getRuleCollectNo(), new Date()); if (num > 0) { throw new BizException(ErrorType.BIZ_ERROR, "此规则还与" + num + "个车场存在生效(或未生效)绑定关系,请解绑后删除!"); } /** * 3、删除计费规则集合 */ int deleteNum = billingRuleCollectDao.deleteBillingRuleCollect(Arrays.asList(req.getRuleCollectNo())); /** * 4、删除计费规则 */ List ruleNos = ruleCollects.parallelStream().map(a -> a.getRuleNo()).collect(Collectors.toList()); deleteNum = billingRuleDao.deleteBillingRuleByRuleNos(ruleNos); /** * 5、删除计费规则组 与 车场绑定关系 */ deleteNum = billingParkRuleRelDao.deleteBillingRuleCollectParkRel(req.getRuleCollectNo()); return new BizResult<>(true); } }