TdCCouponRuleServiceImpl.java 22.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
package com.zteits.pay.biz;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.alibaba.fastjson.JSON;
import com.clouds.common.utils.ListCopyUtil;
import com.clouds.common.utils.SequenceUtil;
import com.github.pagehelper.PageInfo;
import com.zteits.clouds.api.apibase.bean.PageBean;
import com.zteits.clouds.api.apibase.constants.CardTypeEnum;
import com.zteits.clouds.api.apibase.constants.SequenceTypeEnum;
import com.zteits.clouds.api.dto.pay.BindingPersonCouponRequest;
import com.zteits.clouds.api.dto.pay.IsUsedByCardNoRequest;
import com.zteits.clouds.api.dto.pay.param.*;
import com.zteits.pay.pagepager.PageBeanUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.clouds.common.cache.park.ParkingLotCacheUtil;
import com.clouds.common.constants.YearAndShareCardNoConstant;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.dto.park.param.QueryParkLotInfoByPkNoRequest;
import com.zteits.clouds.api.dto.pay.HotAndColdCouponRuleDTO;
import com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO;
import com.zteits.clouds.api.service.park.ParkingLotQueryService;
import com.zteits.clouds.api.service.pay.TdCCouponRuleService;
import com.zteits.pay.dao.TdCCouponPersonDao;
import com.zteits.pay.dao.TdCCouponRuleDao;
import com.zteits.pay.domain.TdCCouponPerson;
import com.zteits.pay.domain.TdCCouponPersonDO;
import com.zteits.pay.domain.TdCCouponRule;

/**
 * Copyright: Copyright (c) 2017  zteits
 *
 * @Description:
 * @version: v1.0.0
 * @author: langlw
 * @date: 2017/12/27 15
 * Modification History:
 * Date             Author          Version            Description
 * ---------------------------------------------------------*
 * 2017/12/27      langlw         v1.0.0               创建
 */
@Service("com.zteits.pay.biz.TdCCouponRuleServiceImpl")
public class TdCCouponRuleServiceImpl implements TdCCouponRuleService {

    private static final Logger logger = LoggerFactory.getLogger(TdCCouponRuleServiceImpl.class);

    @Autowired
    private TdCCouponRuleDao tdCCouponRuleDao;

    @Autowired
    private TdCCouponPersonDao tdCCouponPersonDao;

    @Autowired
    private ParkingLotQueryService parkingLotQueryService;



    @Override
    public BizResult<List<TdCCouponRuleDTO>> queryCouponRuleList(TdCCouponRuleRequest request) {
        logger.info("查询优惠券规则表请求入参:request={}"+ JSONObject.toJSONString(request));
        request.setQueryDate(new Date());
        List<TdCCouponRuleDTO> list = tdCCouponRuleDao.queryCouponRuleList(request);
        logger.info("查询优惠券规则表响应结果:response={}"+ JSONObject.toJSONString(list));
        return new BizResult<>(list);
    }


    @Override
    public BizResult<List<TdCCouponRuleDTO>> queryAllSellingCoupons(TdCCouponRuleRequest request) {
        logger.info("领券中心-获取所有上架卡劵请求入参:request={}"+ JSONObject.toJSONString(request));
        //查询个人卡劵
        if(StringUtils.isEmpty(request.getCustId())){
            throw new BizException(ErrorType.PARAMM_NULL,"客户id为空!");
        }
        TdCCouponPersonRequest personRequest = new TdCCouponPersonRequest();
        BeanUtils.copyProperties(request, personRequest);
        personRequest.setQueryDate(new Date());
        personRequest.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
        List<TdCCouponPersonDO> tdCCouponPersonDOs = tdCCouponPersonDao.getCouponPersonState(personRequest);
        List<TdCCouponRuleDTO> tdCCouponRuleDTOs = new ArrayList<>();
        QueryParkLotInfoByPkNoRequest parkRequest = new QueryParkLotInfoByPkNoRequest();
        BeanUtils.copyProperties(request, parkRequest);
        TdCCouponPersonRequest tdCCouponPersonRequest = new TdCCouponPersonRequest();
        BeanUtils.copyProperties(request, tdCCouponPersonRequest);
        tdCCouponRuleDTOs = tdCCouponRuleDao.queryAllSellingCoupons(tdCCouponPersonRequest);
        //放入停车场名称和用户领取状态
        for (TdCCouponRuleDTO tdCCouponRuleDTO : tdCCouponRuleDTOs) {
            tdCCouponRuleDTO.setReceiveState(0);//初始化为未领取
            List<String> plNames = new ArrayList<>();
            if(StringUtils.isNotEmpty(tdCCouponRuleDTO.getPlNos())){
                String []plNos = (tdCCouponRuleDTO.getPlNos()).split(",");
                for (String plNo : plNos) {
                    parkRequest.setPklNo(plNo);
                    BizResult<ParkingLotDTO> parkingLot =  parkingLotQueryService.QueryParkingLotByPkNo(parkRequest);
                    plNames.add(parkingLot.getData().getPlName());
                }
            }
            tdCCouponRuleDTO.setPlNames(plNames);
            //判断当前卡劵是否已领取
            if(CollectionUtils.isNotEmpty(tdCCouponPersonDOs)){
                for (TdCCouponPersonDO tdCCouponPersonDO : tdCCouponPersonDOs) {
                    if((tdCCouponPersonDO.getCardNo().equals(tdCCouponRuleDTO.getCardNo()))){
                        tdCCouponRuleDTO.setReceiveState(1);//领取状态改为已领取
                    }
                }
            }

        }
        logger.info("领券中心-获取所有上架卡劵响应:request={}"+ JSONObject.toJSONString(tdCCouponRuleDTOs));
        return new BizResult<List<TdCCouponRuleDTO>>(tdCCouponRuleDTOs);
    }

    @Override
    public BizResult<List<TdCCouponRuleDTO>> querySellingAllCoupons(TdCCouponPersonRequest request) {
        List<TdCCouponRuleDTO> tdCCouponRuleDTOs = new ArrayList<>();
        request.setQueryDate(new Date());
        tdCCouponRuleDTOs = tdCCouponRuleDao.queryAllSellingCoupons(request);
        return new BizResult<>(tdCCouponRuleDTOs);
    }

    @Transactional
    @Override
    public BizResult<Boolean> custReceiveCoupon(TdCCouponRuleRequest request) {
        TdCCouponRule couponRule = new TdCCouponRule();
        logger.info("领券中心-客户根据卡劵编码领取相应的卡劵请求入参:request={}"+ JSONObject.toJSONString(request));
        if(StringUtils.isEmpty(request.getCustId())){
            throw new BizException(ErrorType.PARAMM_NULL,"客户id为空!");
        }
        if(StringUtils.isEmpty(request.getCardNo())){
            throw new BizException(ErrorType.PARAMM_NULL,"卡劵编码为空!");
        }
        //先判断当前卡劵是否还有剩余
        couponRule = tdCCouponRuleDao.queryCouponRuleByCardNo(request.getCardNo());
        if(couponRule == null){
            throw new BizException(ErrorType.NOTFOUND_COUPON,request.getCardNo());
        }
        if(null == couponRule.getCardRestNum() || couponRule.getCardRestNum() < 1){
            throw new BizException(ErrorType.COUPON_NOTREST,request.getCardNo());
        }
        //修改卡劵表数量
        couponRule.setCardRestNum(couponRule.getCardRestNum() -1);
        couponRule.setModfiyDate(new Date());
        Boolean up = tdCCouponRuleDao.updateCouponRuleByCardNo(couponRule);
        if(!up){
            throw new BizException(ErrorType.UPDATE_COUPON_FAIL,request.getCardNo());
        }
        //新增个人卡劵表
        TdCCouponPerson tdCCouponPerson = new TdCCouponPerson();
        tdCCouponPerson.setCardNo(request.getCardNo());
        tdCCouponPerson.setCreateDate(new Date());
        tdCCouponPerson.setCustId(request.getCustId());
        tdCCouponPerson.setCreateEmpid(request.getCustId());
        tdCCouponPerson.setOrgId(couponRule.getOrgId());
        tdCCouponPerson.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
        Integer ins = tdCCouponPersonDao.insertCouponPerson(tdCCouponPerson);
        if(ins < 0){
            throw new BizException(ErrorType.SAVE_COUPON_PERSON,ErrorType.SAVE_COUPON_PERSON.getMsg());
        }
        return new BizResult<Boolean>(true);
    }

    @Override
    public BizResult<HotAndColdCouponRuleDTO> queryHotAndColdCouponRule(QueryHotCouponRequest request) {
        List<TdCCouponRuleDTO> tdCCouponRuleDTOs = new ArrayList<>();
        TdCCouponPersonRequest tdCCouponPersonRequest = new TdCCouponPersonRequest();
        BeanUtils.copyProperties(request, tdCCouponPersonRequest);
        tdCCouponRuleDTOs = tdCCouponRuleDao.queryAllSellingCoupons(tdCCouponPersonRequest);
        /** 卡劵编码list*/
        List<String> cardNos = new ArrayList<>();
        HotAndColdCouponRuleDTO hotAndColdCouponRuleDTO =new HotAndColdCouponRuleDTO();
        if(CollectionUtils.isNotEmpty(tdCCouponRuleDTOs)){
            for(TdCCouponRuleDTO dto:tdCCouponRuleDTOs){
                cardNos.add(dto.getCardNo());
            }
            request.setCardNos(cardNos);
            /**1、查询热门优惠券*/
            List<TdCCouponRuleDTO> hotList = tdCCouponRuleDao.queryHotCouponRuleForList(request);
            /**2、查询冷门优惠券**/
            List<TdCCouponRuleDTO> coldList = tdCCouponRuleDao.queryColdCouponRuleForList(request);
            hotAndColdCouponRuleDTO.setColdCouponList(coldList);
            hotAndColdCouponRuleDTO.setHotCouponList(hotList);
        }
        return new BizResult<>(hotAndColdCouponRuleDTO);
    }


    @Override
    public BizResult<TdCCouponRuleDTO> queryCouponRuleParkMsg(TdCCouponRuleRequest request) {
        logger.info("查询优惠券规则表请求入参:request={}"+ JSONObject.toJSONString(request));
        List<TdCCouponRuleDTO> list = tdCCouponRuleDao.queryCouponRuleParkMsg(request);
        TdCCouponRuleDTO tdCCouponRuleDTO = new TdCCouponRuleDTO();
        /**if(CollectionUtil.isNotEmpty(list)){
            tdCCouponRuleDTO = list.get(0);
            List<String> plNames = new ArrayList<>();
            for (TdCCouponRuleDTO dto: list) {
                if(dto==null){
                    continue;
                }
                QueryParkLotInfoByPkNoRequest parkRequest=new QueryParkLotInfoByPkNoRequest();
                parkRequest.setSysCode(request.getSysCode());
                parkRequest.setPklNo(StringUtil.isEmpty(dto.getPlNo())?"":dto.getPlNo());
                BizResult<ParkingLotDTO> park = parkingLotQueryService.QueryParkingLotByPkNo(parkRequest);
                if(park==null || park.getData()==null){
                    continue;
                }
                plNames.add(park.getData().getPlName());
            }
            tdCCouponRuleDTO.setPlNames(plNames);
        }*/
        List<String> plNos = new ArrayList<>();
        if(CollectionUtil.isNotEmpty(list)){
            tdCCouponRuleDTO = list.get(0);
            List<String> plNames = new ArrayList<>();
            for (TdCCouponRuleDTO dto: list) {
                if(dto==null || StringUtils.isEmpty(dto.getPlNo())){
                    continue;
                }
                plNos.add(dto.getPlNo());
            }
            List<ParkingLotDTO> parkList = ParkingLotCacheUtil.getParkLotByPlNos(plNos);
            if(CollectionUtils.isNotEmpty(parkList)){
            	for(ParkingLotDTO parkingLotDTO:parkList){
            		if(parkingLotDTO == null){
            			continue;
            		}
            		plNames.add(parkingLotDTO.getPlName());
            	}
            }
            tdCCouponRuleDTO.setPlNames(plNames);
        }

        return new BizResult<TdCCouponRuleDTO>(tdCCouponRuleDTO) ;
    }


    @Override
    public TdCCouponRuleDTO selectByCardNo(TdCCouponRuleRequest request) {
        return tdCCouponRuleDao.selectByCardNo(request);
    }



    /**
     * 保存优惠券卡规则.<br/>
     * @param request
     * @return
     */
    @Transactional
    @Override
    public BizResult<Boolean> saveCouponRule(TdCCouponRuleSaveReq request) {
        logger.info("begin保存优惠券卡规则信息,入参={}",JSONObject.toJSON(request));
        Integer flg;
        if(Objects.equals(request.getCardType(), CardTypeEnum.CARD_TYPE_2.value())) {
            flg = this.saveCouponRuleList(request);
        }else{
            flg = tdCCouponRuleDao.saveCouponRule(request);
        }
        logger.info("end保存优惠券卡规则信息");
        return  new BizResult<>(flg >0 );
    }

    /**
     * 批量保存停车券
     * @param
     * @return
     * @Author: xiejianpeng
     * @Date: 2019/3/21 15:20
     *
     */
    public Integer saveCouponRuleList(TdCCouponRuleSaveReq request){
        List<String> cardNos = new ArrayList<>();
        List<String> cardNosQuery = new ArrayList<>();
        cardNos = this.getCardNoList(cardNos,cardNosQuery,request.getCardNum());
        List<TdCCouponRule> tdCCouponRuleList = new ArrayList<>();
        String batchNo = SequenceUtil.getNextId(SequenceTypeEnum.COUPON_RULE_PCH);
        /**对象中放入数据*/
        for(String cardNo :cardNos) {
            TdCCouponRule tdCCouponRule = new TdCCouponRule();
            BeanUtils.copyProperties(request,tdCCouponRule);
            tdCCouponRule.setBatchNo(batchNo);
            tdCCouponRule.setIsUesed(0);
            tdCCouponRule.setCardNo(cardNo);
            tdCCouponRule.setCardNum(1);
            tdCCouponRule.setReceiveNum(1);
            tdCCouponRule.setCardRestNum(1);
            tdCCouponRuleList.add(tdCCouponRule);
        }
        logger.info("begin保存优惠券卡规则信息,入参={}",JSONObject.toJSON(tdCCouponRuleList));
        Integer flg = tdCCouponRuleDao.saveCouponRuleList(tdCCouponRuleList);
        logger.info("end保存优惠券卡规则信息,出参={}",JSONObject.toJSON(flg));
        return flg;
    }
    /**
     * 生成停车卡的卡编码的数据
     * @param
     * @return
     * @Author: xiejianpeng
     * @Date: 2019/3/21 14:39
     *
     */
    private List<String> getCardNoList(List<String> cardNos,List<String> cardNosQuery,Integer cardNum){
        logger.info("生成批量卡编码:{}",JSONObject.toJSON(cardNos));
        if(cardNum > 0) {
            for (int i = 1; i <= cardNum; i++) {
                String cardNo = createBigStrOrNumberRadom(10);
                cardNos.add(cardNo);
                cardNosQuery.add(cardNo);
            }
            logger.info("查询是否存在重复的卡券编码入参:{}", JSONObject.toJSON(cardNosQuery));
            if(CollectionUtil.isNotEmpty(cardNosQuery)) {
                cardNosQuery = tdCCouponRuleDao.queryCouponRuleByCardNoList(cardNosQuery);
            }
            logger.info("查询是否存在重复的卡券编码结果:{}", JSONObject.toJSON(cardNosQuery));
            if(CollectionUtil.isNotEmpty(cardNosQuery)){
                cardNos.removeAll(cardNosQuery);
                cardNum = cardNosQuery.size();
                return getCardNoList(cardNos,cardNosQuery,cardNum);
            }
        }
        return cardNos;
    }
    /**
     * @param num
     * @return
     * @function 生成num位的随机字符串(小写字母与数字混排)
     */
    public static String createBigStrOrNumberRadom(int num) {
        String str = "";
        for (int i = 0; i < num; i++) {
            int intVal = (int) (Math.random() * 26 + 65);
//            if (intVal % 2 == 0) {
//                str += (char) intVal;
//            } else {
                str += (int) (Math.random() * 10);
//            }
        }
        return str;
    }

    /**
     * 更新优惠券卡规则.<br/>
     * @param request
     * @return
     */
    @Override
    public BizResult<Boolean> updateCouponRule(TdCCouponRuleSaveReq request) {
        logger.info("begin更新优惠券卡规则信息,入参={}",JSONObject.toJSON(request));
        Integer integer = tdCCouponRuleDao.updateCouponRule(request);
        logger.info("end更新优惠券卡规则信息");
        return  new BizResult<Boolean>(integer >0 );
    }

    /**
     * 删除优惠券卡规则.<br/>
     * @param request
     * @return
     */
    @Override
    public BizResult<Boolean> deleteCouponRule(TdCCouponRuleSaveReq request) {
        logger.info("begin删除优惠券卡规则信息,入参={}",JSONObject.toJSON(request));
        Integer integer = tdCCouponRuleDao.deleteCouponRule(request);
        logger.info("end删除优惠券卡规则信息");
        return  new BizResult<Boolean>(integer >0 );
    }
    /**
     * 分页查询优惠券规则
     * @Auther: wangfs
     * @param
     * @return
     */
    @Override
    public BizResult<PageBean<TdCCouponRuleDTO>> queryCouponRuleForPage(QueryCouponRuleReq request) {
        logger.info("begin分页查询优惠券规则,入参={}",JSONObject.toJSON(request));
        BizResult<PageBean<TdCCouponRuleDTO>> result = new BizResult<PageBean<TdCCouponRuleDTO>>();
        PageBean<TdCCouponRuleDTO>  pageBean = new PageBean<TdCCouponRuleDTO>();
        PageInfo<TdCCouponRule> pageInfo = tdCCouponRuleDao.queryCouponRuleForPage(request);

        PageBeanUtil.copyProperties(pageInfo,pageBean,TdCCouponRuleDTO.class);
        logger.info("end分页查询优惠券规则");
        return new BizResult<PageBean<TdCCouponRuleDTO>>(pageBean);
    }

    /**
     * 过滤年终活动卡劵和好友分享卡劵
     * @param tdCCouponRuleDTOs
     * @return
     * 2018年1月26日 wangfei
     */
    private List<TdCCouponRuleDTO> filterYearOrShareCard(List<TdCCouponRuleDTO> tdCCouponRuleDTOs){
        List<TdCCouponRuleDTO> result = new ArrayList<>();
        List<TdCCouponRuleDTO> removeList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(tdCCouponRuleDTOs)){
            for (TdCCouponRuleDTO dto : tdCCouponRuleDTOs) {
                if(YearAndShareCardNoConstant.yearCardNos.contains(dto.getCardNo())
                    || YearAndShareCardNoConstant.shareCardNos.contains(dto.getCardNo())){
                    removeList.add(dto);
                }
            }
        }
        tdCCouponRuleDTOs.removeAll(removeList);
        result = tdCCouponRuleDTOs;
        return result;
    }
    @Override
    @Transactional
    public BizResult<Boolean> bindingPersonCoupon(BindingPersonCouponRequest request) {
        logger.info("绑定个人优惠券入参:"+ JSON.toJSONString(request));
        //判断该优惠券是否已经被使用
        final TdCCouponRule usedByCardNo = _isUsedByCardNo(request.getCardNo());
        //修改为已绑定
        TdCCouponRuleSaveReq updateCouponRule = new TdCCouponRuleSaveReq();
        updateCouponRule.setIsUesed(1);
        updateCouponRule.setId(usedByCardNo.getId());
        updateCouponRule.setModfiyDate(new Date());
        tdCCouponRuleDao.updateCouponRule(updateCouponRule);
        //新增个人卡劵表
        TdCCouponPerson tdCCouponPerson = new TdCCouponPerson();
        tdCCouponPerson.setCardNo(request.getCardNo());
        tdCCouponPerson.setCreateDate(new Date());
        tdCCouponPerson.setCustId(request.getCustId());
        tdCCouponPerson.setCreateEmpid(request.getCustId());
        tdCCouponPerson.setOrgId(usedByCardNo.getOrgId());
        tdCCouponPerson.setBeginTime(usedByCardNo.getBeginTime());
        tdCCouponPerson.setEndTime(usedByCardNo.getEndTime());
        tdCCouponPerson.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
        tdCCouponPersonDao.insertCouponPerson(tdCCouponPerson);
        return new BizResult<>(true);
    }

    /**
     * 判断该优惠券是否已经被使用
     * @param request
     */
    @Override
    public BizResult<TdCCouponRuleDTO> isUsedByCardNo(IsUsedByCardNoRequest request) {
        final TdCCouponRule tdCCouponRule = _isUsedByCardNo(request.getCardNo());
        TdCCouponRuleDTO tdCCouponRuleDTO = new TdCCouponRuleDTO();
        BeanUtils.copyProperties(tdCCouponRule,tdCCouponRuleDTO);
        return new BizResult<>(tdCCouponRuleDTO);
    }

    @Override
    public BizResult<Boolean> updateCouponRuleByCardNo(TdCCouponRuleSaveReq req) {
        TdCCouponRule couponrule = new TdCCouponRule();
        BeanUtils.copyProperties(req,couponrule);
        couponrule.setCardNo(req.getCardNo());
        tdCCouponRuleDao.updateCouponRuleByCardNo(couponrule);
        return new BizResult<>(true);
    }

    @Override
    public BizResult<Boolean> deleteBatchCouponRule(TdCCouponRuleDeleteReq request) {
        logger.info("begin批量删除优惠券卡规则信息,入参={}",JSONObject.toJSON(request));
        Integer integer = tdCCouponRuleDao.deleteBatchCouponRule(request);
        logger.info("end批量删除优惠券卡规则信息");
        return  new BizResult<Boolean>(integer >0 );
    }

    private TdCCouponRule _isUsedByCardNo(String cardNo) {
        //查询该优惠券是否已经被使用
        final TdCCouponRule tdCCouponRule = tdCCouponRuleDao.queryCouponRuleByCardNo(cardNo);
        if(tdCCouponRule == null){
            throw new BizException(ErrorType.PARAM_NOT_VALID,"该优惠码无效",false,false);
        }
        //判断该优惠码是否是停车券(线下兑换使用),其他码不允许绑定
        if(tdCCouponRule.getCardType() != CardTypeEnum.CARD_TYPE_2.value()){
            throw new BizException(ErrorType.PARAM_NOT_VALID,"该优惠码不正确",false,false);
        }
        //获取是否已使用 1:已使用/绑定 0:未使用
        if(tdCCouponRule.getIsUesed()!=null && tdCCouponRule.getIsUesed()!=0){
            throw new BizException(ErrorType.PARAM_NOT_VALID,"该优惠码已经被使用或绑定",false,false);
        }
        return tdCCouponRule;
    }

    /**
     * 根据优惠券规则CardNo修改优惠券规则为无效
     *
     * @param request
     * @return
     */
    @Override
    public BizResult<Boolean> updateCouponRuleNoValidByCardNo(TdCCouponRuleSaveReq request) {
        logger.info("begin更新优惠券卡规则信息无效,入参={}", JSONObject.toJSON(request));
        Integer integer = tdCCouponRuleDao.updateCouponRuleNoValidByCardNo(request);
        logger.info("end更新优惠券卡规则信息无效");
        return new BizResult<>(integer > 0);
    }

    /**
     * 查询所有有效的优惠规则
     * @param request
     * @return
     */
    @Override
    public BizResult<List<TdCCouponRuleDTO>> getCouponRuleList(TdCCouponRuleRequest request) {
        List<TdCCouponRule> sourceList = tdCCouponRuleDao.getCouponRuleList(request);
        List<TdCCouponRuleDTO> targetList = new ArrayList<>();
        ListCopyUtil.listCopyProperties(sourceList, targetList, TdCCouponRuleDTO.class);
        return new BizResult<>(targetList);
    }

}