CustPersonCreditDaoImpl.java 4.42 KB
package com.zteits.pay.dao.impl;
import org.apache.commons.collections4.CollectionUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zteits.pay.domain.CustPersonCredit;
import com.zteits.pay.domain.CustPersonCreditExample;
import com.zteits.clouds.api.dto.pay.param.CustPersonCreditRequest;
import com.zteits.pay.dao.CustPersonCreditDao;
import com.zteits.pay.mapper.CustPersonCreditMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import org.springframework.util.StringUtils;

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

@Component
public class CustPersonCreditDaoImpl implements  CustPersonCreditDao {
    @Autowired
    private CustPersonCreditMapper custPersonCreditMapper;

    @Override
    public int saveCustPersonCredit(CustPersonCredit custPersonCredit) {
        if(custPersonCredit.getCreateDate()==null){
            custPersonCredit.setCreateDate(new Date());
        }
        return custPersonCreditMapper.insertSelective(custPersonCredit);
    }

    @Override
    public int updateByExampleSelective(CustPersonCredit record, CustPersonCreditExample example) {
        return custPersonCreditMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(CustPersonCredit record) {
        return custPersonCreditMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<CustPersonCredit> selectByExample(CustPersonCreditExample example) {
        return custPersonCreditMapper.selectByExample(example);
    }

    @Override
    public CustPersonCredit queryByPrimaryKey(Long id) {
        return custPersonCreditMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CustPersonCredit> queryCustPersonCredit(CustPersonCreditRequest request) {
        CustPersonCreditExample example = new CustPersonCreditExample();
        CustPersonCreditExample.Criteria sql = example.createCriteria();

        if (!StringUtils.isEmpty(request.getCustName())) {
            sql.andCustNameLike(request.getUserPhone() + "%");
        }
        if (!StringUtils.isEmpty(request.getUserPhone())) {
            sql.andUserPhoneLike(request.getUserPhone() + "%");
        }
        if (!StringUtils.isEmpty(request.getExamineState())) {
            sql.andExamineStateEqualTo(request.getExamineState());
        }
        if (!StringUtils.isEmpty(request.getCustId())) {
            sql.andCustIdEqualTo(request.getCustId());
        }
        if (!StringUtils.isEmpty(request.getDataState())) {
            sql.andDataStateEqualTo(request.getDataState());
        }
        List<CustPersonCredit> list = custPersonCreditMapper.selectByExample(example);
        return list;
    }

    @Override
    public int batchDeleteCustPersonCreditByPrimaryKey(List<Long> ids, String opId, String opName) {
        CustPersonCredit record = new CustPersonCredit();
//        record.setModifyEmpId(opId);
//        record.setModifyEmpName(opName);
//        record.setModifyTime(new Date());
        record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
        CustPersonCreditExample example = new CustPersonCreditExample();
        example.createCriteria().andIdIn(ids);
        return custPersonCreditMapper.updateByExampleSelective(record,example);
    }

    @Override
    public PageInfo<CustPersonCredit> queryCustPersonCreditForPage(CustPersonCreditRequest request) {
        PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
        CustPersonCreditExample example = new CustPersonCreditExample();
        CustPersonCreditExample.Criteria sql = example.createCriteria();

        if (!StringUtils.isEmpty(request.getCustName())) {
            sql.andCustNameLike(request.getUserPhone() + "%");
        }
        if (!StringUtils.isEmpty(request.getUserPhone())) {
            sql.andUserPhoneLike(request.getUserPhone() + "%");
        }
        if (!StringUtils.isEmpty(request.getExamineState())) {
            sql.andExamineStateEqualTo(request.getExamineState());
        }
        List<CustPersonCredit> list = custPersonCreditMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(list)) {
            return new PageInfo<CustPersonCredit>(list);
        }
        return new PageInfo<CustPersonCredit>(new ArrayList<CustPersonCredit>());
    }
}