/** * */ package com.zteits.pay.dao.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.zteits.clouds.api.dto.pay.RateDataDTO; import com.zteits.clouds.api.dto.pay.StatisticsDataDTO; import com.zteits.clouds.api.dto.pay.param.InvoiceStatisticsRequest; 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.util.StringUtils; import com.alibaba.fastjson.JSONObject; import com.clouds.common.utils.ListCopyUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xiaoleilu.hutool.util.CollectionUtil; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.dto.pay.TdCCustInvoiceHisDTO; import com.zteits.clouds.api.dto.pay.TdCCustInvoiceHisItemDTO; import com.zteits.clouds.api.dto.pay.param.TdCCustInvoiceHisQueryRequest; import com.zteits.clouds.api.dto.pay.param.TdCCustInvoiceHisRequest; import com.zteits.pay.dao.TdCCustInvoiceHisDao; import com.zteits.pay.domain.TdCCustInvoiceHis; import com.zteits.pay.domain.TdCCustInvoiceHisExample; import com.zteits.pay.domain.TdCCustInvoiceHisExample.Criteria; import com.zteits.pay.domain.TdCCustInvoiceHisItem; import com.zteits.pay.domain.TdCCustInvoiceHisItemExample; import com.zteits.pay.mapper.TdCCustInvoiceHisItemMapper; import com.zteits.pay.mapper.TdCCustInvoiceHisMapper; import com.zteits.pay.mapper.smapper.TdCCustInvoiceHisSMapper; /** * @author hxz * */ @Component public class TdCCustInvoiceHisDaoImpl implements TdCCustInvoiceHisDao { private static final Logger logger = LoggerFactory.getLogger(TdCCustInvoiceHisDaoImpl.class); @Autowired private TdCCustInvoiceHisMapper tdCCustInvoiceHisMapper; @Autowired private TdCCustInvoiceHisItemMapper tdCCustInvoiceHisItemMapper; @Autowired private TdCCustInvoiceHisSMapper tdCCustInvoiceHisSMapper; @Override public Long insertCustInvoiceHistoryInfo(TdCCustInvoiceHis record) { return new Long((long) tdCCustInvoiceHisMapper.insertSelective(record)); } @Override public Boolean insertCustInvoiceHistorItems(List records) { for (TdCCustInvoiceHisItem tdCCustInvoiceHisItem : records) { tdCCustInvoiceHisItemMapper.insertSelective(tdCCustInvoiceHisItem); } return true; } @Override public List queryRateData(InvoiceStatisticsRequest request) { return tdCCustInvoiceHisSMapper.selectRateData(request); } @Override public List queryStatisticsData(InvoiceStatisticsRequest request) { return tdCCustInvoiceHisSMapper.selectStatisticsData(request); } @Override public TdCCustInvoiceHis queryCustInvoiceHistoryInfo(Long id) { return tdCCustInvoiceHisMapper.selectByPrimaryKey(id); } @Override public List queryCustInvoiceHistoryList(TdCCustInvoiceHisExample example) { return tdCCustInvoiceHisMapper.selectByExample(example); } @Override public PageInfo queryListByVO(TdCCustInvoiceHisRequest request) { PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize()); logger.info("tdCCustInvoiceHisSMapper.selectListByVO入参={}",JSONObject.toJSONString(request)); List hisList = tdCCustInvoiceHisSMapper.selectListByVO (request); logger.info("tdCCustInvoiceHisSMapper.selectListByVO返回结果={}", JSONObject.toJSON(hisList)); return new PageInfo(hisList); } @Override public int updateInvioceById(TdCCustInvoiceHis record) { return tdCCustInvoiceHisMapper.updateByPrimaryKeySelective(record); } @Override public int updateInvioceByInvoiceId(TdCCustInvoiceHis record) { TdCCustInvoiceHisExample example = new TdCCustInvoiceHisExample(); example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()) .andInvoiceIdEqualTo(record.getInvoiceId()); record.setModfiyDate(new Date()); return tdCCustInvoiceHisMapper.updateByExampleSelective(record, example ); } @Override public PageInfo queryCustInvoiceHisForPage(TdCCustInvoiceHisQueryRequest request) { PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize()); TdCCustInvoiceHisExample example = new TdCCustInvoiceHisExample(); Criteria sql = example.createCriteria(); if(request.getId() != null){ sql.andIdEqualTo(request.getId()); } if(request.getOrgId() != null){ sql.andOrgIdEqualTo(request.getOrgId()); } if(request.getInvoiceObject() != null){ sql.andInvoiceObjectEqualTo(request.getInvoiceObject());// 新增查询条件,发票对象,1 车主个人,2 商户 } if(request.getBeginTime() != null){ sql.andCreateDateGreaterThanOrEqualTo(request.getBeginTime()); } if(request.getEndTime() != null){ sql.andCreateDateLessThanOrEqualTo(request.getEndTime()); } if(request.getInvoiceBeginTime() != null){ sql.andInvoiceDateGreaterThanOrEqualTo(request.getInvoiceBeginTime()); } if(request.getInvoiceEndTime() != null){ sql.andInvoiceDateLessThanOrEqualTo(request.getInvoiceEndTime()); } if(!StringUtils.isEmpty(request.getCustName())){ sql.andCustNameLike("%"+request.getCustName()+"%"); } if(!StringUtils.isEmpty(request.getInvoiceId())){ sql.andInvoiceIdLike("%"+request.getInvoiceId()+"%"); } if(!StringUtils.isEmpty(request.getSaleName())){ sql.andSaleNameLike("%"+request.getSaleName()+"%"); } if(!StringUtils.isEmpty(request.getSaleTaxid())){ sql.andSaleTaxidLike("%"+request.getSaleTaxid()+"%"); } if(!StringUtils.isEmpty(request.getInvoiceCode())){ sql.andInvoiceCodeLike("%"+request.getInvoiceCode()+"%"); } if(!StringUtils.isEmpty(request.getInvoiceNumber())){ sql.andInvoiceNumberLike("%"+request.getInvoiceNumber()+"%"); } if(CollectionUtil.isNotEmpty(request.getInvoiceBigTypes())){ sql.andInvoiceBigTypeIn(request.getInvoiceBigTypes()); } if(CollectionUtil.isNotEmpty(request.getInvoiceStates())){ sql.andInvoiceStateIn(request.getInvoiceStates()); } if(CollectionUtil.isNotEmpty(request.getInvoiceIds())){ sql.andInvoiceIdIn(request.getInvoiceIds()); } if(CollectionUtil.isNotEmpty(request.getSaleTaxids())){ sql.andSaleTaxidIn(request.getSaleTaxids()); } sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); example.setOrderByClause("id desc"); List list = tdCCustInvoiceHisMapper.selectByExample(example ); return new PageInfo(list); } @Override public TdCCustInvoiceHisDTO queryCustInvoiceHisById(TdCCustInvoiceHisQueryRequest request) { TdCCustInvoiceHisDTO dto = new TdCCustInvoiceHisDTO(); List itemDtos = new ArrayList(); TdCCustInvoiceHis tdCCustInvoiceHis = tdCCustInvoiceHisMapper.selectByPrimaryKey(request.getId()); if(tdCCustInvoiceHis == null){ return null; } TdCCustInvoiceHisItemExample example = new TdCCustInvoiceHisItemExample(); example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()) .andInvoiceIdEqualTo(tdCCustInvoiceHis.getInvoiceId()); List items = tdCCustInvoiceHisItemMapper.selectByExample(example); ListCopyUtil.listCopyProperties(items, itemDtos, TdCCustInvoiceHisItemDTO.class); BeanUtils.copyProperties(tdCCustInvoiceHis, dto); dto.setCustInvoiceHisItemDTOs(itemDtos); return dto; } /** * 查询商户电子发票详情 * @param request * @return */ @Override public TdCCustInvoiceHisDTO queryCustBusinessInvoiceHisById(TdCCustInvoiceHisQueryRequest request) { TdCCustInvoiceHisDTO dto = new TdCCustInvoiceHisDTO(); List itemDtos = new ArrayList(); TdCCustInvoiceHis tdCCustInvoiceHis = tdCCustInvoiceHisMapper.selectByPrimaryKey(request.getId()); if(tdCCustInvoiceHis == null){ return null; } TdCCustInvoiceHisItemExample example = new TdCCustInvoiceHisItemExample(); example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()) .andInvoiceIdEqualTo(tdCCustInvoiceHis.getInvoiceId()); List items = tdCCustInvoiceHisItemMapper.selectByExample(example); ListCopyUtil.listCopyProperties(items, itemDtos, TdCCustInvoiceHisItemDTO.class); BeanUtils.copyProperties(tdCCustInvoiceHis, dto); dto.setCustInvoiceHisItemDTOs(itemDtos); return dto; } @Override public TdCCustInvoiceHisDTO queryCustInvoiceHisByInvoiceId(String invoiceId) { TdCCustInvoiceHisDTO dto = new TdCCustInvoiceHisDTO(); TdCCustInvoiceHisExample example = new TdCCustInvoiceHisExample(); example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()) .andInvoiceIdEqualTo(invoiceId); List list = tdCCustInvoiceHisMapper.selectByExample(example); BeanUtils.copyProperties(list.get(0), dto); return dto; } @Override public List selectNuonuoPendingInvoiceList() { return tdCCustInvoiceHisSMapper.selectNuonuoPendingInvoiceList(); } @Override public List selectListByOrderId(TdCCustInvoiceHisRequest record) { return tdCCustInvoiceHisSMapper.selectListByOrderId(record); } }