package com.doumee.service.business.impl;
|
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.business.TaxDetialMapper;
|
import com.doumee.dao.business.TaxesMapper;
|
import com.doumee.dao.business.join.TaxDetailJoinMapper;
|
import com.doumee.dao.business.join.TaxesJoinMapper;
|
import com.doumee.dao.business.model.*;
|
import com.doumee.dao.system.model.SystemUser;
|
import com.doumee.service.business.TaxesService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 发票信息表Service实现
|
* @author 江蹄蹄
|
* @date 2024/01/16 10:03
|
*/
|
@Service
|
public class TaxesServiceImpl implements TaxesService {
|
|
@Autowired
|
private TaxesMapper taxesMapper;
|
@Autowired
|
private TaxDetialMapper taxDetialMapper;
|
@Autowired
|
private TaxesJoinMapper taxesJoinMapper;
|
@Autowired
|
private TaxDetailJoinMapper taxDetailJoinMapper;
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Override
|
public Integer create(Taxes taxes) {
|
taxesMapper.insert(taxes);
|
return taxes.getId();
|
}
|
|
/**
|
* 退回申请
|
* @param taxes
|
*/
|
@Override
|
@Transactional
|
public void backApply(Taxes taxes) {
|
if(taxes.getId() == null ){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
Taxes model = taxesMapper.selectById(taxes.getId());
|
if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
if(!Constants.equalsInteger(taxes.getStatus(), Constants.ZERO)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前发票状态不支持撤回申请!");
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
Taxes update = new Taxes();
|
update.setId(taxes.getId());
|
update.setImgurl(taxes.getImgurl());
|
update.setEditDate(new Date());
|
update.setStatus(Constants.TWO);
|
update.setEditor(user.getId());
|
update.setCancelUserId(user.getId());
|
update.setCancelDate(update.getEditDate());
|
update.setCancelInfo(taxes.getCancelInfo());
|
taxesMapper.updateById(update);
|
|
List<TaxDetial> detialList = getDetailListById(taxes.getId());
|
if(detialList!=null && detialList.size()>0){
|
for(TaxDetial detial :detialList){
|
//类型 0保单申请 1加减保申请 2冲红单
|
if(Constants.equalsInteger(detial.getType(),Constants.TWO)){
|
//如果是冲红单,还原该申请为已开票
|
Taxes tu = new Taxes();
|
tu.setId(detial.getDelTaxId());
|
tu.setEditDate(new Date());
|
tu.setStatus(Constants.ONE);
|
tu.setEditor(user.getId());
|
taxesMapper.updateById(tu);
|
}
|
}
|
}
|
}
|
|
private List<TaxDetial> getDetailListById(Integer id) {
|
List<TaxDetial> detialList = taxDetialMapper.selectList(new QueryWrapper<TaxDetial>().lambda().eq(TaxDetial::getTaxId,id).eq(TaxDetial::getIsdeleted,Constants.ZERO));
|
return detialList;
|
}
|
private List<TaxDetial> getJoinDetailListById(Integer id) {
|
MPJLambdaWrapper<TaxDetial> queryWrapper = new MPJLambdaWrapper<>();
|
queryWrapper.selectAll(TaxDetial.class);
|
queryWrapper.selectAs(Taxes::getDoneCode,TaxDetial::getTaxDoneCode);
|
queryWrapper.selectAs(Taxes::getCreateDate,TaxDetial::getTaxCreateDate);
|
queryWrapper.selectAs(InsuranceApply::getCode,TaxDetial::getApplyCode);
|
queryWrapper.selectAs(ApplyChange::getCode,TaxDetial::getChangApplyCode);
|
queryWrapper.select("(CASE t.type\n" +
|
"WHEN 0 THEN (select count(1) from apply_detail c where c.APPLY_ID=t.INSURANCE_APPLY_ID) \n" +
|
"ELSE 0 \n" +
|
"END) as applyNum,\n" +
|
"(CASE t.type \n" +
|
"WHEN 1 THEN (select count(1) from apply_chagne_detail c where c.APPLY_CHANGE_ID=t.INSURANCE_APPLY_ID) \n" +
|
"ELSE 0 \n" +
|
"END) as applyChangeAddNum,\n" +
|
"(CASE t.type \n" +
|
"WHEN 1 THEN (select count(1) from apply_chagne_detail c where c.APPLY_CHANGE_ID=t.APPLY_CHANGE_ID) \n" +
|
"ELSE 0 \n" +
|
"END) as applyChangeAddNum");
|
queryWrapper.leftJoin(InsuranceApply.class,InsuranceApply::getId,TaxDetial::getInsuranceApplyId);
|
queryWrapper.leftJoin(ApplyChange.class,ApplyChange::getId,TaxDetial::getApplyChangeId);
|
queryWrapper.leftJoin(Taxes.class,Taxes::getId,TaxDetial::getDelTaxId);
|
List<TaxDetial> detialList = taxDetailJoinMapper.selectJoinList(TaxDetial.class,queryWrapper.orderByAsc(TaxDetial::getType));
|
return detialList;
|
}
|
|
|
/**
|
* 上传发票凭证
|
* @param taxes
|
*/
|
@Override
|
public void doneApply(Taxes taxes) {
|
if(taxes.getId() == null
|
||StringUtils.isBlank(taxes.getImgurl())
|
||StringUtils.isBlank(taxes.getDoneCode())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
Taxes model = taxesMapper.selectById(taxes.getId());
|
if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
if(!Constants.equalsInteger(taxes.getStatus(), Constants.ZERO)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前发票状态不支持上传发票信息!");
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
Taxes update = new Taxes();
|
update.setId(taxes.getId());
|
update.setImgurl(taxes.getImgurl());
|
update.setEditDate(new Date());
|
update.setStatus(Constants.ONE);
|
update.setEditor(user.getId());
|
update.setDoneCode(taxes.getDoneCode());
|
update.setDoneUserId(user.getId());
|
update.setDoneDate(update.getEditDate());
|
update.setImgurl(taxes.getImgurl());
|
taxesMapper.updateById(update);
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
taxesMapper.deleteById(id);
|
}
|
|
@Override
|
public void delete(Taxes taxes) {
|
UpdateWrapper<Taxes> deleteWrapper = new UpdateWrapper<>(taxes);
|
taxesMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
taxesMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(Taxes taxes) {
|
taxesMapper.updateById(taxes);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<Taxes> taxess) {
|
if (CollectionUtils.isEmpty(taxess)) {
|
return;
|
}
|
for (Taxes taxes: taxess) {
|
this.updateById(taxes);
|
}
|
}
|
|
@Override
|
public Taxes findById(Integer id) {
|
MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>();
|
queryWrapper.selectAll(Taxes.class);
|
queryWrapper.selectAs(Solutions::getName,Taxes::getSolutionName);
|
queryWrapper.leftJoin(Solutions.class,Solutions::getId,Taxes::getSolutionId);
|
Taxes model =taxesJoinMapper.selectById(id);
|
if(model==null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
if(Constants.equalsInteger(model.getType(),Constants.ZERO)){
|
List<TaxDetial> detialList = getDetailsApplysListById(id);
|
model.setApplyList(detialList);
|
}else{
|
//查询明细列表
|
List<TaxDetial> detialList = getJoinDetailListById(id);
|
List<TaxDetial> applyList = new ArrayList<>();//投保和加减保
|
List<TaxDetial> delList = new ArrayList<>();//冲红单
|
if(detialList!=null){
|
for(TaxDetial d :delList){
|
d.setSolutionName(model.getSolutionName());
|
d.setFee(Constants.formatBigdecimal(d.getFee()));
|
d.setTotalFee(Constants.formatBigdecimal(d.getTotalFee()));
|
if(Constants.equalsInteger(d.getType(),Constants.ZERO) || Constants.equalsInteger(d.getType(),Constants.ONE)){
|
applyList.add(d);
|
}else if(Constants.equalsInteger(d.getType(),Constants.TWO)){
|
delList.add(d);
|
}
|
}
|
}
|
model.setApplyList(applyList);
|
model.setDelTaxList(delList);
|
}
|
return model;
|
}
|
|
private List<TaxDetial> getDetailsApplysListById(Integer id) {
|
MPJLambdaWrapper<TaxDetial> queryWrapper = new MPJLambdaWrapper<>();
|
queryWrapper.selectAll(TaxDetial.class);
|
queryWrapper.selectAs(InsuranceApply::getCode,TaxDetial::getApplyCode);
|
queryWrapper.selectAs(Solutions::getName,TaxDetial::getSolutionName);
|
queryWrapper.leftJoin(InsuranceApply.class,InsuranceApply::getId,TaxDetial::getInsuranceApplyId);
|
queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId);
|
List<TaxDetial> detialList = taxDetailJoinMapper.selectJoinList(TaxDetial.class,queryWrapper.orderByAsc(TaxDetial::getType));
|
return detialList;
|
}
|
|
@Override
|
public Taxes findOne(Taxes taxes) {
|
QueryWrapper<Taxes> wrapper = new QueryWrapper<>(taxes);
|
return taxesMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<Taxes> findList(Taxes taxes) {
|
QueryWrapper<Taxes> wrapper = new QueryWrapper<>(taxes);
|
return taxesMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<Taxes> findPage(PageWrap<Taxes> pageWrap) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
IPage<Taxes> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
MPJLambdaWrapper<Taxes> queryWrapper = new MPJLambdaWrapper<>();
|
queryWrapper.selectAll(Taxes.class);
|
queryWrapper.selectAs(SystemUser::getRealname,Taxes::getCreatorName);
|
queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Taxes::getCreator);
|
Utils.MP.blankToNull(pageWrap.getModel());
|
queryWrapper.eq(Taxes::getIsdeleted, Constants.ZERO);
|
if(user.getCompanyIdList() == null || user.getCompanyIdList().size() == 0){
|
queryWrapper.eq(Taxes::getCompanyId,-1);//设置无效访问
|
}else{
|
queryWrapper.in(Taxes::getCompanyId,user.getCompanyIdList());
|
queryWrapper.ge(pageWrap.getModel().getStartDate() != null,Taxes::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getStartDate()));
|
queryWrapper.le(SignRecord::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate()));
|
queryWrapper.eq(pageWrap.getModel().getTaxBank() != null,Taxes::getTaxBank, pageWrap.getModel().getTaxBank());
|
queryWrapper.eq(pageWrap.getModel().getTaxBank() != null,Taxes::getTaxBank, pageWrap.getModel().getTaxBank());
|
queryWrapper.eq(pageWrap.getModel().getRemark() != null,Taxes::getRemark, pageWrap.getModel().getRemark());
|
queryWrapper.eq(pageWrap.getModel().getStatus() != null,Taxes::getStatus, pageWrap.getModel().getStatus());
|
queryWrapper.eq(pageWrap.getModel().getCompanyId() != null,Taxes::getCompanyId, pageWrap.getModel().getCompanyId());
|
queryWrapper.eq(pageWrap.getModel().getType() != null,Taxes::getType, pageWrap.getModel().getType());
|
queryWrapper.eq(pageWrap.getModel().getTaxCode() != null,Taxes::getTaxCode, pageWrap.getModel().getTaxCode());
|
queryWrapper.eq(pageWrap.getModel().getTaxAccount() != null,Taxes::getTaxAccount, pageWrap.getModel().getTaxAccount());
|
queryWrapper.eq(pageWrap.getModel().getTaxAddr() != null,Taxes::getTaxAddr, pageWrap.getModel().getTaxAddr());
|
queryWrapper.eq(pageWrap.getModel().getAddr() !=null,Taxes::getAddr, pageWrap.getModel().getAddr());
|
queryWrapper.like(pageWrap.getModel().getCompanyName() != null,Taxes::getCompanyName, pageWrap.getModel().getCompanyName());
|
queryWrapper.eq(pageWrap.getModel().getApplyType() != null,Taxes::getApplyType, pageWrap.getModel().getApplyType());
|
queryWrapper.orderByDesc(Taxes::getCreateDate);
|
}
|
PageData<Taxes> result =PageData.from(taxesJoinMapper.selectJoinPage(page,Taxes.class, queryWrapper));
|
if(result!=null && result.getRecords()!=null){
|
String path =systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.TAXES_FILE).getCode();
|
for(Taxes t : result.getRecords()){
|
if(StringUtils.isNotBlank(t.getImgurl())){
|
t.setImgurlFull(path + t.getImgurl());
|
}
|
}
|
}
|
return result;
|
}
|
|
@Override
|
public long count(Taxes taxes) {
|
QueryWrapper<Taxes> wrapper = new QueryWrapper<>(taxes);
|
return taxesMapper.selectCount(wrapper);
|
}
|
}
|