TVipAreaCardDaoImpl.java 6.31 KB
package com.zteits.bill.dao.impl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zteits.bill.dao.TVipAreaCardDao;
import com.zteits.bill.domain.TVipAreaCard;
import com.zteits.bill.domain.TVipAreaCardExample;
import com.zteits.bill.mapper.TVipAreaCardMapper;
import com.zteits.clouds.api.apibase.constants.AuditorStatusEnum;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.dto.bill.param.TVipAreaCardRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class TVipAreaCardDaoImpl implements  TVipAreaCardDao {
    @Autowired
    private TVipAreaCardMapper tVipAreaCardMapper;

    @Override
    public int saveTVipAreaCard(TVipAreaCard tVipAreaCard) {
        if(tVipAreaCard.getCreateDate()==null){
            tVipAreaCard.setCreateDate(new Date());
        }
        return tVipAreaCardMapper.insertSelective(tVipAreaCard);
    }

    @Override
    public int updateByExampleSelective(TVipAreaCard record, TVipAreaCardExample example) {
        return tVipAreaCardMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(TVipAreaCard record) {
        return tVipAreaCardMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<TVipAreaCard> selectByExample(TVipAreaCardExample example) {
        return tVipAreaCardMapper.selectByExample(example);
    }

    @Override
    public TVipAreaCard queryByPrimaryKey(Long id) {
        return tVipAreaCardMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TVipAreaCard> queryTVipAreaCard(TVipAreaCardRequest request) {
        TVipAreaCardExample example = new TVipAreaCardExample();
        TVipAreaCardExample.Criteria sql = example.createCriteria();
        sql.andAuditorStatusEqualTo(AuditorStatusEnum.AUDITOR_STATUS_AUDIT_PASS.value())
                .andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
        if(request.getOrgId() != null){
            sql.andOrgIdEqualTo(request.getOrgId());
        }
        if(request.getCardType() != null){
            sql.andCardTypeEqualTo(request.getCardType());
        }
        if(request.getCarType() != null ){
            sql.andCarTypeEqualTo(request.getCarType());
        }
        if(request.getAreaCardType() != null ){
            sql.andAreaCardTypeEqualTo(request.getAreaCardType());
        }
        if(request.getSaleChannel() != null ){
            sql.andSaleChannelEqualTo(request.getSaleChannel());
        }
        if(request.getType() != null ){
            sql.andTypeEqualTo(request.getType());
        }
        if(DataStatusEnum.DATA_STATUS_VALID.value().equals(request.getCardStatus())){//若只查询上架的
             sql.andCardStatusEqualTo(1)
                     .andEffDateLessThanOrEqualTo(new Date())  //EffDate<=new Date()
                    .andExpDateGreaterThanOrEqualTo(new Date()); //ExpDate>= new Date()
        }
        if(StringUtils.isNotEmpty(request.getCardNo())){
            sql.andCardNoEqualTo(request.getCardNo());
        }

        return  tVipAreaCardMapper.selectByExample(example);
    }

    @Override
    public int batchDeleteTVipAreaCardByPrimaryKey(List<Long> ids, String opId, String opName) {
        TVipAreaCard record = new TVipAreaCard();
        record.setModifyEmpid(opId);
        record.setModifyName(opName);
        record.setModifyDate(new Date());
        record.setCardStatus(2);
        record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
        TVipAreaCardExample example = new TVipAreaCardExample();
        example.createCriteria().andIdIn(ids);
        return tVipAreaCardMapper.updateByExampleSelective(record,example);
    }

    @Override
    public PageInfo<TVipAreaCard> queryTVipAreaCardForPage(TVipAreaCardRequest request) {
        //1.设置分页
        PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
        TVipAreaCardExample example = new TVipAreaCardExample();
        TVipAreaCardExample.Criteria sql = example.createCriteria();
        sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
        if(null != request.getCardType()){
            sql.andCardTypeEqualTo(request.getCardType());
        }
        if(null != request.getCarType()){
            sql.andCarTypeEqualTo(request.getCarType());
        }
        if(null != request.getType()){
            sql.andTypeEqualTo(request.getType());
        }
        if(null != request.getAreaCardType()){
            sql.andAreaCardTypeEqualTo(request.getAreaCardType());
        }
        if(null != request.getCardStatus()){
            sql.andCardStatusEqualTo(request.getCardStatus());
        }
        sql.andOrgIdEqualTo(request.getOrgId());

        example.setOrderByClause(" id desc");
        List<TVipAreaCard> tVipAreaCards = tVipAreaCardMapper.selectByExample(example);
        return new  PageInfo<TVipAreaCard>(tVipAreaCards);
    }

    /**
     * 通过卡编码查询卡规则信息
     * @Auther: wangfs
     * @param
     * @return
     */
    @Override
    public TVipAreaCard queryTVipAreaCardByCardNo(String cardNo) {
        TVipAreaCard tVipAreaCard = new TVipAreaCard();
        TVipAreaCardExample example = new TVipAreaCardExample();
        example.createCriteria().andCardNoEqualTo(cardNo)
                .andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
        List<TVipAreaCard> tVipAreaCardList = tVipAreaCardMapper.selectByExample(example);
        if(!CollectionUtils.isEmpty(tVipAreaCardList)){
            tVipAreaCard = tVipAreaCardList.get(0);
        }
        return tVipAreaCard;
    }

    /*@Override
    public PageInfo<TVipAreaCard> queryTVipAreaCardForPage(TVipAreaCardRequest request) {
        PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
        //TODO 编写smapper实现
        *//*List<TVipAreaCard> list = tVipAreaCardSMapper.queryTVipAreaCard(request);
        if (CollectionUtils.isNotEmpty(list)) {
            return new PageInfo<TVipAreaCard>(list);
        }*//*
        return new PageInfo<TVipAreaCard>(new ArrayList<TVipAreaCard>());
    }*/
}