|
|
@ -1,15 +1,26 @@ |
|
|
|
package com.ccsens.ptccsens.service; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import com.ccsens.common.persist.dao.ProMemberDao; |
|
|
|
import com.ccsens.ptccsens.bean.dto.FinanceDto; |
|
|
|
import com.ccsens.ptccsens.bean.po.*; |
|
|
|
import com.ccsens.ptccsens.bean.vo.FinanceVo; |
|
|
|
import com.ccsens.ptccsens.persist.dao.FinanceDao; |
|
|
|
import com.ccsens.ptccsens.persist.mapper.*; |
|
|
|
import com.ccsens.ptccsens.util.BasicsCodeError; |
|
|
|
import com.ccsens.ptccsens.util.BasicsConstant; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -21,8 +32,21 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class FinanceService implements IFinanceService { |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private FinanceDao financeDao; |
|
|
|
@Resource |
|
|
|
private PluFinanceApplyMapper pluFinanceApplyMapper; |
|
|
|
@Resource |
|
|
|
private ProMemberMapper proMemberMapper; |
|
|
|
@Resource |
|
|
|
private PluFinanceCheckMapper pluFinanceCheckMapper; |
|
|
|
@Resource |
|
|
|
private PluFinanceCheckLogMapper pluFinanceCheckLogMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public FinanceVo.FinanceItem getByTask(FinanceDto.TaskId param, Long userId) { |
|
|
@ -45,4 +69,124 @@ public class FinanceService implements IFinanceService { |
|
|
|
} |
|
|
|
return item; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<FinanceVo.Type> queryType(FinanceDto.Type param, Long userId) { |
|
|
|
List<FinanceVo.Type> types = financeDao.queryType(param.getType(), param.getParentId()); |
|
|
|
return types; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void apply(FinanceDto.Apply param, Long userId) { |
|
|
|
// 判断是否是项目成员
|
|
|
|
ProMemberExample memberExample = new ProMemberExample(); |
|
|
|
memberExample.createCriteria().andProjectIdEqualTo(param.getProjectId()) |
|
|
|
.andUserIdEqualTo(userId); |
|
|
|
memberExample.setOrderByClause("id desc limit 1"); |
|
|
|
List<ProMember> proMembers = proMemberMapper.selectByExample(memberExample); |
|
|
|
log.info("项目成员:{}", proMembers); |
|
|
|
if (CollectionUtil.isEmpty(proMembers)) { |
|
|
|
throw new BaseException(BasicsCodeError.NOT_MEMBER_SHEET); |
|
|
|
} |
|
|
|
// 计算总金额和发票金额是否一致
|
|
|
|
if (CollectionUtil.isNotEmpty(param.getInvoiceList())) { |
|
|
|
long invoiceTotal = 0L; |
|
|
|
for (FinanceDto.Invoice invoice : param.getInvoiceList()){ |
|
|
|
invoiceTotal += invoice.getMoney(); |
|
|
|
} |
|
|
|
if (param.getMoney() != invoiceTotal) { |
|
|
|
log.info("总金额:{},发票金额:{}不一致", param.getMoney(), invoiceTotal); |
|
|
|
throw new BaseException(BasicsCodeError.TOTAL_MONEY_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
PluFinanceApply apply = new PluFinanceApply(); |
|
|
|
BeanUtils.copyProperties(param, apply); |
|
|
|
apply.setId(snowflake.nextId()); |
|
|
|
apply.setMemberId(proMembers.get(0).getId()); |
|
|
|
pluFinanceApplyMapper.insertSelective(apply); |
|
|
|
if (CollectionUtil.isNotEmpty(param.getInvoiceList())) { |
|
|
|
List<PluFinanceInvoice> invoices = new ArrayList<>(); |
|
|
|
param.getInvoiceList().forEach(invoice -> { |
|
|
|
PluFinanceInvoice copy = new PluFinanceInvoice(); |
|
|
|
BeanUtils.copyProperties(invoice, copy); |
|
|
|
copy.setId(snowflake.nextId()); |
|
|
|
copy.setFinanceApplyId(apply.getId()); |
|
|
|
copy.setOperator(userId); |
|
|
|
invoices.add(copy); |
|
|
|
}); |
|
|
|
financeDao.batchSaveInvoice(invoices); |
|
|
|
} |
|
|
|
List<PluFinanceCheck> checks = new ArrayList<>(); |
|
|
|
param.getCheckerList().forEach(check -> { |
|
|
|
PluFinanceCheck copy = new PluFinanceCheck(); |
|
|
|
copy.setId(snowflake.nextId()); |
|
|
|
copy.setFinanceApplyId(apply.getId()); |
|
|
|
copy.setCheckerId(check); |
|
|
|
copy.setOperator(userId); |
|
|
|
checks.add(copy); |
|
|
|
}); |
|
|
|
financeDao.batchSaveCheck(checks); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public FinanceVo.ApplyDetail getApplyDetail(FinanceDto.ApplyId param, Long userId) { |
|
|
|
|
|
|
|
FinanceVo.ApplyDetail detail = financeDao.getApplyDetail(param.getApplyId()); |
|
|
|
if (detail == null) { |
|
|
|
log.info("未找到{}对应的申请", param.getApplyId()); |
|
|
|
throw new BaseException(BasicsCodeError.PARAM_ERROR); |
|
|
|
} |
|
|
|
List<FinanceVo.Invoice> invoices = financeDao.queryInvoices(param.getApplyId()); |
|
|
|
List<FinanceVo.Checker> checkers = financeDao.queryCheckers(param.getApplyId(), userId); |
|
|
|
detail.setCheckerList(checkers); |
|
|
|
detail.setInvoiceList(invoices); |
|
|
|
return detail; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void audit(FinanceDto.Audit param, Long userId) { |
|
|
|
// 判断是否审核人
|
|
|
|
PluFinanceCheck check = pluFinanceCheckMapper.selectByPrimaryKey(param.getFinanceCheckId()); |
|
|
|
log.info("{}审核信息:{}", param.getFinanceCheckId(), check); |
|
|
|
if (check == null) { |
|
|
|
throw new BaseException(BasicsCodeError.CHECK_NOT_FOUND); |
|
|
|
} |
|
|
|
// 判断是否已经审核过
|
|
|
|
PluFinanceCheckLogExample logExample = new PluFinanceCheckLogExample(); |
|
|
|
logExample.createCriteria().andCheckIdEqualTo(param.getFinanceCheckId()) |
|
|
|
.andCheckIdEqualTo(check.getCheckerId()); |
|
|
|
long l = pluFinanceCheckLogMapper.countByExample(logExample); |
|
|
|
log.info("{}关于{}的审核数:{}", check.getCheckerId(), check.getId(), l); |
|
|
|
if (l > 0) { |
|
|
|
throw new BaseException(BasicsCodeError.CHECK_EXISTED); |
|
|
|
} |
|
|
|
// 保存记录
|
|
|
|
PluFinanceCheckLog log = new PluFinanceCheckLog(); |
|
|
|
log.setId(snowflake.nextId()); |
|
|
|
log.setCheckId(param.getFinanceCheckId()); |
|
|
|
log.setCheckStatus(param.getCheckStatus()); |
|
|
|
log.setCheckTime(System.currentTimeMillis()); |
|
|
|
log.setRemark(param.getRemark()); |
|
|
|
pluFinanceCheckLogMapper.insertSelective(log); |
|
|
|
// 更新申请状态
|
|
|
|
if (param.getCheckStatus() == BasicsConstant.Finance.AUDIT_FAIL) { |
|
|
|
// 设置审核状态为失败
|
|
|
|
PluFinanceApply apply = new PluFinanceApply(); |
|
|
|
apply.setId(check.getFinanceApplyId()); |
|
|
|
apply.setApplyType(BasicsConstant.Finance.AUDIT_FAIL); |
|
|
|
pluFinanceApplyMapper.updateByPrimaryKeySelective(apply); |
|
|
|
} else { |
|
|
|
// 判断有无未审核或审核拒绝的,有,则不更新状态,无,则更新为审核通过
|
|
|
|
long noAuditNum = financeDao.countNoAuditPass(check.getFinanceApplyId()); |
|
|
|
if (noAuditNum <= 0) { |
|
|
|
PluFinanceApply apply = new PluFinanceApply(); |
|
|
|
apply.setId(check.getFinanceApplyId()); |
|
|
|
apply.setApplyType(BasicsConstant.Finance.AUDIT_PASS); |
|
|
|
pluFinanceApplyMapper.updateByPrimaryKeySelective(apply); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|