| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164 |
- package com.goafanti.expenseAccount.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.goafanti.admin.bo.AdminListBo;
- import com.goafanti.admin.service.DepartmentService;
- import com.goafanti.common.bo.AdminNoticeBo;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.*;
- import com.goafanti.common.enums.NoticeStatus;
- import com.goafanti.common.enums.NoticeTypes;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.*;
- import com.goafanti.common.utils.*;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.JDBCIdGenerator;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.expenseAccount.Enums.EAProcessStatus;
- import com.goafanti.expenseAccount.Enums.EATypes;
- import com.goafanti.expenseAccount.Enums.EAsecondaryTypes;
- import com.goafanti.expenseAccount.bo.*;
- import com.goafanti.expenseAccount.service.ExpenseAccountService;
- import com.goafanti.organization.bo.OrganizationListOut;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
- @Autowired
- private AdminMapper adminMapper;
- @Autowired
- private ExpenseAccountMapper expenseAccountMapper;
- @Autowired
- private PublicReleaseMapper publicReleaseMapper;
- @Autowired
- private ExpenseAccountLogMapper expenseAccountLogMapper;
- @Autowired
- private AsyncUtils asyncUtils;
- @Autowired
- private WeChatUtils weChatUtils;
- @Autowired
- private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
- @Autowired
- private ExpenseAccountPrivateMapper expenseAccountPrivateMapper;
- @Autowired
- private ExpenseAccountExamineMapper expenseAccountExamineMapper;
- @Autowired
- private JDBCIdGenerator idGenerator;
- @Autowired
- private FinanceCountMapper financeCountMapper;
- @Autowired
- private ExpenseRelationshipMapper expenseRelationshipMapper;
- @Autowired
- private DepartmentService departmentService;
- @Autowired
- private DepartmentMapper departmentMapper;
- @Override
- public Integer add(InputExpenseAccount in) {
- //如果关联公出,获取公出信息
- if (in.getPrid()!=null){
- PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid());
- in.setReleaseStart(pr.getReleaseStart());
- in.setReleaseEnd(pr.getReleaseEnd());
- in.setDistrictName(pr.getDistrictName());
- in.setUserNames(pr.getUserNames());
- in.setDuration(pr.getDuration());
- }
- //判断报销类型,0=固定费用,1=报销到订单
- if (in.getOrderNo()==null){
- in.setTargetType(0);
- }else {
- in.setTargetType(1);
- }
- if (in.getAid()==null)in.setAid(TokenManager.getAdminId());
- Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
- in.setAname(admin.getName());
- in.setApplyDep(admin.getDepartmentId());
- in.setPayDep(admin.getDepartmentId());
- expenseAccountMapper.insertSelective(in);
- return in.getId();
- }
- /**
- * 新增报销审核流程
- */
- private void addExpenseAccountExamine(Integer id,ExpenseAccount ea) {
- List<ExpenseAccountExamine> list=new ArrayList<>();
- String aid = TokenManager.getAdminId();
- OrganizationListOut dep = departmentMapper.selectAllById(ea.getApplyDep());
- AdminNoticeBo a = adminMapper.selectMyAndSuperBySuperId(aid);
- //暂时只发起到财务
- for (int i=1;i<4;i++){
- ExpenseAccountExamine eae=new ExpenseAccountExamine(id,i);
- if (i==1){
- //新增一级
- String examineId=null;
- String examineName=null;
- //正常用上级,没有的情况下就是自己
- if (a.getSuperId()!=null){
- examineId=a.getSuperId();
- examineName=a.getSuperName();
- }else {
- examineId=a.getId();
- examineName=a.getName();
- }
- eae.setAuditor(examineId);
- eae.setAuditorname(examineName);
- ea.setExamineName(examineName);
- }else if (i==2){
- if (dep.getManagerId()==null|| StringUtils.isBlank(dep.getManagerId())){
- throw new BusinessException("报销申请部门管理员不存在。");
- }
- eae.setAuditor(dep.getManagerId());
- eae.setAuditorname(dep.getManagerName());
- }else if (i==3){
- if (dep.getExpenseFinanceName()==null)throw new BusinessException("报销部门财务审核人不存在。");
- eae.setAuditor(dep.getExpenseFinanceId());
- eae.setAuditorname(dep.getExpenseFinanceName());
- }else if (i==4){
- eae.setAuditor(dep.getExpenseRetrialFinanceId());
- eae.setAuditorname(dep.getExpenseRetrialFinanceName());
- }
- if (eae.getAuditor().equals(aid))eae.setStatus(1);
- else eae.setStatus(0);
- list.add(eae);
- }
- expenseAccountExamineMapper.insertBatch(list);
- }
- /**
- * 新增报销日志
- * @param eaid 报销编号
- * @param status 状态 0发起 1通过 2完成 3驳回 4修改
- * @param str 备注
- */
- private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str) {
- addExpenseAccountLog(eaid,status,processStatus,aid,str,null);
- }
- /**
- * 新增报销日志
- * @param eaid 报销编号
- * @param status 状态 0发起 1通过 2完成 3驳回 4修改
- * @param str 备注
- */
- private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str,Date date) {
- if (aid==null)aid=TokenManager.getAdminId();
- ExpenseAccountLog eaLog=new ExpenseAccountLog();
- eaLog.setEaid(eaid);
- eaLog.setStatus(status);
- eaLog.setRemarks(str);
- eaLog.setProcessStatus(processStatus);
- eaLog.setAuditor(aid);
- if (date !=null)eaLog.setCreateTime(date);
- expenseAccountLogMapper.insertSelective(eaLog);
- }
- /**
- * 发起、驳回发起流程切换和日志站内信发送
- */
- private void addExpenseAccountLogAndNoticEmail(ExpenseAccount in, Integer status, String str) {
- String aid=TokenManager.getAdminId();
- addExpenseAccountLog(in.getId(),status,in.getProcessStatus(),aid,str);
- if (status==0)in.setProcessStatus(1);
- Admin admin = adminMapper.selectByPrimaryKey(aid);
- if (admin.getSuperiorId()==null||admin.getId().equals(admin.getSuperiorId())){
- String str2=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(in.getProcessStatus()));
- Date date=new Date();
- date.setTime(date.getTime()+1000L);
- addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date);
- in.setProcessStatus(in.getProcessStatus()+1);
- }
- createExamineByProcess(in);
- }
- /**
- * 判断审核流程与发送日志与邮件
- */
- private void createExamineByProcess(ExpenseAccount in) {
- //审核流程推送到最新
- AdminListBo admin = adminMapper.getDeptNameByAid(in.getAid());
- List<ExpenseAccountExamine> list=examineByprocess(in,admin);
- List<Admin> aids=new ArrayList<>();
- StringBuffer aname =new StringBuffer();
- for (ExpenseAccountExamine e : list) {
- if (e.getProcessStatus()==in.getProcessStatus()&&e.getStatus()==0){
- Admin ad = adminMapper.selectByPrimaryKey(e.getAuditor());
- aids.add(ad);
- aname=aname.append(ad.getName()).append(",");
- }
- }
- in.setExamineName(aname.substring(0,aname.length()-1));
- StringBuffer str=new StringBuffer().append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
- addNoticeAndEmail(in, EAProcessStatus.SJSH.getCode(),str.toString(), admin.getName(),aids);
- }
- @Override
- @Transactional
- public int update(InputExpenseAccount in) {
- OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
- if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
- throw new BusinessException("不能操作审核中与完成的订单");
- }
- if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
- in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
- in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
- }
- //计算总金额
- if (in.getTotalAmount()==null){
- in.setTotalAmount(expenseAccountDetailsMapper.selectAmountCountByEAid(in.getId()));
- in.setRealAmount(in.getTotalAmount());
- }
- in.setProcessStatus(0);
- if (in.getOrderNo()==null){
- in.setTargetType(0);
- }else {
- in.setTargetType(1);
- }
- //计算本单已扣金额 如果有选择借支单,则需要修改借支状态
- if (in.getDebitId()!=null){
- //如果以前没有选择借支,修改报销和借支数据
- if (useEA.getDebitId()==null){
- pushExpenseAccountDebit(in);
- }else if (useEA.getDebitId()!=in.getDebitId()) {
- //如果是修改编号
- pushExpenseAccountDebit(in);
- //并且要处理原编号的问题
- pushResettingDebit(in,useEA.getDebitId());
- }
- }
- if (in.getSettlementAmount()==null)in.setSettlementAmount(useEA.getSettlementAmount());
- in.setAmount(in.getTotalAmount().subtract(in.getSettlementAmount()));
- in.setRealAmount(in.getAmount());
- in.setStatus(0);
- return expenseAccountMapper.updateByPrimaryKeySelective(in);
- }
- @Override
- public Object updateDebitId(InputExpenseAccount in) {
- OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
- if (useEA.getDebitId()!=null)pushResettingDebit(in,useEA.getDebitId());
- expenseAccountMapper.updateDeleteDebitId(in.getId());
- return 1;
- }
- private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
- ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);
- List<ExpenseAccount> list = expenseAccountMapper.selectByDebitId(debitId);
- ExpenseAccount newDebit=new ExpenseAccount();
- newDebit.setId(debitId);
- //计算除开当前单,已选择抵扣金额
- BigDecimal count=new BigDecimal(0);
- for (ExpenseAccount e : list) {
- if (!in.getId().equals(e.getId())){
- count=count.add(e.getSettlementAmount());
- }
- }
- newDebit.setSettlementAmount(count);
- if (count.compareTo(new BigDecimal(0))==0){
- newDebit.setLiquidationStatus(0);
- }else if (count.compareTo(debit.getRealAmount())<0){
- newDebit.setLiquidationStatus(1);
- }else if (count.compareTo(debit.getRealAmount())==0){
- newDebit.setLiquidationStatus(2);
- }
- expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
- }
- private void pushExpenseAccountDebit(InputExpenseAccount in) {
- ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(in.getDebitId());
- ExpenseAccount newDebit=new ExpenseAccount();
- newDebit.setId(debit.getId());
- //计算剩余需要支付金额
- BigDecimal decbitAmount=debit.getRealAmount().subtract(debit.getSettlementAmount());
- //本次金额大于等于需要抵扣金额,则变成完全抵扣,抵扣金额变成本次已付金额
- if (in.getRealAmount().compareTo(decbitAmount)>=0){
- in.setSettlementAmount(decbitAmount);
- newDebit.setSettlementAmount(debit.getRealAmount());
- newDebit.setLiquidationStatus(2);
- }else {
- // 本次金额小于需要抵扣,则本次变更全抵扣,借支已付加上本次金额
- in.setSettlementAmount(in.getRealAmount());
- BigDecimal setAmount=new BigDecimal(0).add(debit.getSettlementAmount()).add(in.getRealAmount());
- newDebit.setSettlementAmount(setAmount);
- newDebit.setLiquidationStatus(1);
- }
- expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
- }
- @Override
- public int addDetails(InputExpenseAccountDetails in) {
- if (in.getAgreeTimes()!=null){
- in.setAgreeTime(DateUtils.StringToDate(in.getAgreeTimes(),AFTConstants.YYYYMMDD));
- }
- ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(in.getEaid());
- if (expenseAccount.getType()==2){
- in.setType(expenseAccount.getSecondaryType());
- if (in.getType()==0){
- in.setTypeOther(expenseAccount.getSecondaryTypeOther());
- }
- }
- in.setRealAmount(in.getAmount());
- expenseAccountDetailsMapper.insertSelective(in);
- return 1;
- }
- @Override
- public int deleteDetails(Integer id) {
- return expenseAccountDetailsMapper.deleteByPrimaryKey(id);
- }
- @Override
- public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
- return expenseAccountDetailsMapper.selectByEAid(eaid);
- }
- @Override
- public Object logList(Integer eaid) {
- List<OutExpenseAccountLog> list = expenseAccountLogMapper.selectByEaid(eaid);
- if (!list.isEmpty()){
- OutExpenseAccountLog lastout=list.get(list.size()-1);
- if (lastout.getStatus()!=3){
- List<OutExpenseAccountLog> eaelist = expenseAccountExamineMapper.selectNotExamineByEaidAndProcessStatus(eaid, lastout.getProcessStatus());
- list.addAll(eaelist);
- }
- }
- return list;
- }
- @Override
- public int updateExamine(InputExpenseAccount in) {
- ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
- ExpenseAccount newEa=new ExpenseAccount();
- newEa.setId(useEa.getId());
- in.setCheckNo(useEa.getCheckNo());
- in.setProcessStatus(useEa.getProcessStatus());
- //审核通知 获取发送人
- AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
- addExamineExpenseAccountLog(admin,in, useEa, newEa);
- //完成申请
- if (newEa.getStatus()==2){
- //如果是借支则订单新增
- List<ExpenseAccount> expenseAccounts1 = expenseAccountMapper.selectListByMainId(in.getId());
- for (ExpenseAccount e : expenseAccounts1) {
- if (e.getType()!=4){
- //不然就看是否挂载借支订单进行抵扣
- if (e.getDebitId()!=null){
- ExpenseAccount useDebit=expenseAccountMapper.selectByPrimaryKey(e.getDebitId());
- if (useDebit.getLiquidationStatus()==2){
- List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByDebitId(e.getDebitId());
- boolean flag=true;
- for (ExpenseAccount expenseAccount : expenseAccounts) {
- if(!expenseAccount.getId().equals(in.getId())&&expenseAccount.getStatus()!=2){
- flag=false;
- break;
- }
- }
- if (flag){
- ExpenseAccount debit=new ExpenseAccount();
- debit.setId(e.getDebitId());
- debit.setLiquidationStatus(3);
- expenseAccountMapper.updateByPrimaryKeySelective(debit);
- }
- }
- }
- }
- ExpenseAccount updateSon=new ExpenseAccount();
- updateSon.setId(e.getId());
- updateSon.setStatus(2);
- expenseAccountMapper.updateByPrimaryKeySelective(updateSon);
- }
- }else if (newEa.getStatus()==1){
- if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
- pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),0);
- //处理金额修改
- if(in.getRealList()!=null){
- List<Map> maps = JSONObject.parseArray(in.getRealList(), Map.class);
- for (Map map: maps) {
- Integer type= (Integer) map.get("type");
- Integer id= (Integer) map.get("id");
- BigDecimal amount= new BigDecimal(map.get("amount").toString());
- //type=1总计,type=2报销金额
- if(type==1){
- ExpenseAccount ea =new ExpenseAccount();
- ea.setId(id);
- ea.setRealAmount(amount);
- expenseAccountMapper.updateByPrimaryKeySelective(ea);
- }else if (type==2){
- ExpenseAccountDetails ead=new ExpenseAccountDetails();
- ead.setId(id);
- ead.setRealAmount(amount);
- expenseAccountDetailsMapper.updateByPrimaryKeySelective(ead);
- }
- }
- }
- }else if (newEa.getProcessStatus()==EAProcessStatus.CWSH.getCode()){
- pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),1);
- }
- }else if (newEa.getStatus()==3){
- if (useEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
- pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),2);
- }else if (newEa.getProcessStatus()>EAProcessStatus.CWSH.getCode()){
- pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),3);
- }
- }
- //审核处理审核表
- pushExpenseAccountExamine(in);
- expenseAccountMapper.updateByPrimaryKeySelective(newEa);
- expenseAccountMapper.updateSonByMainId(newEa.getId());
- return 1;
- }
- private void addFinanceCount(String aid,Date startTime ) {
- String forDate=DateUtils.formatDate(startTime,AFTConstants.YYYYMMDD);
- addFinanceCount(aid,forDate);
- }
- private void addFinanceCount(String aid,String startTime ) {
- FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
- if (financeCount ==null){
- financeCount =FinanceCount.initialization(aid, startTime);
- financeCount.setExpenseCount(1);
- financeCount.setExpenseUnauditedCount(1);
- financeCountMapper.insertSelective(financeCount);
- }else {
- FinanceCount newFinanceCount =new FinanceCount();
- newFinanceCount.setId(financeCount.getId());
- newFinanceCount.setExpenseCount(financeCount.getExpenseCount()+1);
- newFinanceCount.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
- financeCountMapper.updateByPrimaryKeySelective(newFinanceCount);
- }
- }
- private void pushExpenseAccountExamine(InputExpenseAccount in) {
- if (in.getStatus()==1){
- expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1);
- }else if (in.getStatus()==3){
- expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),null,0);
- }
- }
- private void addExamineExpenseAccountLog(AdminListBo admin,InputExpenseAccount in, ExpenseAccount useEa, ExpenseAccount newEa) {
- List<Admin> aids=new ArrayList<>();
- StringBuffer str=new StringBuffer();
- Integer status=in.getStatus();
- if (status==1){
- str=str.append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
- //新的流程是当前流程+1
- newEa.setProcessStatus(useEa.getProcessStatus()+1);
- newEa.setAid(useEa.getAid());
- newEa.setCreateTime(useEa.getCreateTime());
- List<ExpenseAccountExamine> list=examineByprocess(newEa,admin);
- if(newEa.getProcessStatus()==4){
- //完成后的流程
- status =2;
- // Admin finaceAdmin = adminMapper.selectByPrimaryKey(admin.getDepFinance());
- // //同事添加通知财务管理员与公司副总
- // List<Admin> admins = adminMapper.selectAdminByRoleType(AFTConstants.FINANCE_ADMIN);
- // aids.addAll(admins);
- // List<Admin> viceCEO = adminMapper.selectAdminByRoleType(AFTConstants.VICE_CEO);
- // aids.addAll(viceCEO);
- // aids.add(finaceAdmin);
- // str.setLength(0);
- // str=str.append("报销编号[").append(in.getCheckNo()).append("]审核已通过,请注意查看。");
- // addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
- // aids.clear();
- aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
- newEa.setStatus(status);
- newEa.setExamineName("");
- }else {
- StringBuffer aname =new StringBuffer();
- for (ExpenseAccountExamine e : list) {
- if (e.getProcessStatus()==newEa.getProcessStatus()&&e.getStatus()==0){
- Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
- aids.add(ad);
- aname=aname.append(ad.getName()).append(",");
- }
- }
- newEa.setExamineName(aname.substring(0,aname.length()-1));
- }
- }else {
- aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
- newEa.setStatus(3);
- newEa.setProcessStatus(0);
- str.setLength(0);
- str=str.append("您的报销审核已驳回,报销编号[").append(in.getCheckNo()).append("],请注意查看。");
- }
- if (newEa.getStatus()==null)newEa.setStatus(1);
- addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
- addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
- }
- /**
- *
- * @param aid
- * @param createTime
- * @param type 0 双新增 1 未审核减一 2双减 3总数减一
- */
- private void pushFinanceCount(String aid, Date createTime, Integer type) {
- String startTime= DateUtils.formatDate(createTime,AFTConstants.YYYYMMDD);
- FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
- FinanceCount newFinance=new FinanceCount();
- if (financeCount==null){
- newFinance=FinanceCount.initialization(aid,createTime);
- newFinance.setExpenseCount(1);
- newFinance.setExpenseUnauditedCount(1);
- financeCountMapper.insertSelective(newFinance);
- }else {
- newFinance.setId(financeCount.getId());
- if(type==0){
- newFinance.setExpenseCount(financeCount.getExpenseCount()+1);
- newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
- }else if(type==1){
- newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
- }else if(type==2){
- newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
- newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
- }else if(type==3){
- newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
- }
- financeCountMapper.updateByPrimaryKeySelective(newFinance);
- }
- }
- /**
- * 审核流程推送,只要不是完成状态就继续判断是否跳过
- * @param newEa
- */
- private List<ExpenseAccountExamine> examineByprocess( ExpenseAccount newEa,AdminListBo admin) {
- //获取当前流程审核人,如果有已审核则跳过当前审核
- List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
- boolean flag=false;
- String aid="";
- for (ExpenseAccountExamine e : list) {
- if (e.getStatus()==1){
- flag=true;
- aid=e.getAuditor();
- break;
- }
- if(e.getAuditor().equals(newEa.getAid())){
- flag=true;
- break;
- }
- }
- if (flag){
- String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
- Date date=new Date();
- date.setTime(date.getTime()+1000l);
- addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date);
- if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
- addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
- }
- newEa.setProcessStatus(newEa.getProcessStatus()+1);
- if (newEa.getProcessStatus()<EAProcessStatus.CWSH.getCode())examineByprocess(newEa,admin);
- list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
- }
- return list;
- }
- private String getAdmins(List<Admin> list) {
- StringBuffer str =new StringBuffer();
- for (Admin admin : list) {
- str=str.append(admin.getName()).append(",");
- }
- return str.substring(0,str.length()-1);
- }
- private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
- Date date= new Date();
- Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
- if (status==2){
- noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
- }
- List<Notice> list=new ArrayList<>();
- if (aids!=null){
- for (Admin a : aids) {
- Notice notice=new Notice();
- notice.setId(UUID.randomUUID().toString());
- notice.setNoticeType(noticeStatus);
- notice.setType(NoticeTypes.getType(noticeStatus));
- notice.setAid(a.getId());
- notice.setCreateTime(date);
- notice.setContent(str);
- notice.setReaded(0);
- list.add(notice);
- EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
- asyncUtils.send(emailBo);
- weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
- }
- asyncUtils.addNoticeBatch(list);
- }
- }
- @Override
- public Object pageList(InputPageListBo in) {
- Map<String ,Object> param=new HashMap<>();
- addParam(in, param);
- Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
- "selectExpenseAccountCount",
- "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
- List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
- for (OutExpenseAccountBo e : list) {
- e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
- }
- return pagePlus;
- }
- @Override
- public Object selectByPrid(InputExpenseAccount in) {
- in.setAid(TokenManager.getAdminId());
- OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
- return useEa;
- }
- @Override
- public Object selectById(Integer id) {
- OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
- //判断当前角色是否审核
- pushExpenseAccountGetExamine(useEa);
- if (useEa.getDebitId()!=null){
- pushExpenseAccountGetDebitAmount(useEa);
- }
- return useEa;
- }
- @Override
- public Object selectByCheckNo(String checkNo) {
- checkNo=checkNo.trim();
- OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
- if (useEa==null){
- throw new BusinessException("报销编号不存在,请客对后再查询。");
- }
- if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
- throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
- }
- return useEa;
- }
- @Override
- public Object pushMerge(List<ExpenseAccount> list) {
- //设置付款部门和支付部门
- InputExpenseAccount in =new InputExpenseAccount();
- in.setCheckNo(idGenerator.getNOgenerateId());
- if (in.getAid()==null){
- in.setAid(TokenManager.getAdminId());
- }
- Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
- in.setAname(admin.getName());
- in.setApplyDep(admin.getDepartmentId());
- in.setPayDep(admin.getDepartmentId());
- Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
- in.setEaaid(eaaid);
- BigDecimal count = new BigDecimal(0);
- BigDecimal amount = new BigDecimal(0);
- List<String> typeList = new ArrayList<String>();
- for (ExpenseAccount e : list) {
- count=count.add(e.getTotalAmount());
- amount=amount.add(e.getAmount());
- StringBuffer types=new StringBuffer();
- if (e.getType()!=0){
- types=types.append(EATypes.getDescByCode(e.getType()));
- }else {
- types=types.append(e.getTypeOther());
- }
- if (e.getType()==2){
- if (e.getSecondaryType()==0){
- types=types.append("-").append(e.getSecondaryTypeOther());
- }else{
- String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
- types=types.append("-").append(descByCode);
- }
- }
- if (!typeList.contains(types.toString()))typeList.add(types.toString());
- }
- in.setTotalAmount(count);
- in.setAmount(amount);
- in.setRealAmount(amount);
- in.setExpenseMain(1);
- in.setTypeOther(String.join(",",typeList));
- expenseAccountMapper.insertSelective(in);
- list.stream().forEach(e -> {
- ExpenseRelationship er=new ExpenseRelationship();
- er.setId(in.getId());
- er.setEaId(e.getId());
- expenseRelationshipMapper.insertSelective(er);
- });
- expenseAccountMapper.updateByIds(list,1);
- return in.getId();
- }
- @Override
- public MainExpenseAccount mainExpense(Integer id) {
- MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
- res.setExamine(0);
- List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, res.getProcessStatus());
- for (ExpenseAccountExamine e : expenseAccountExamines) {
- if (e.getAuditor().equals(TokenManager.getAdminId())){
- res.setExamine(1);
- break;
- }
- }
- if (res.getAid().equals(TokenManager.getAdminId())){
- res.setExamine(2);
- }
- return res;
- }
- @Override
- public Object updateMain(MainExpenseAccount in) {
- OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
- if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
- throw new BusinessException("主项目已发起,不可修改!");
- }
- ExpenseAccount update =new ExpenseAccount();
- if (in.getStatus()==null)in.setStatus(1);
- if (in.getStatus()==1){
- if (in.getOrderNo()!=null){
- update.setOrderNo(in.getOrderNo());
- update.setTargetType(1);
- }
- if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
- if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
- if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
- if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
- addExpenseAccountExamine(in.getId(),update);
- if (outExpenseAccount.getStatus()==0){
- addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
- }else if (outExpenseAccount.getStatus()==3){
- addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
- }
- }else if (in.getStatus()==4){
- expenseAccountMapper.updateByMainId(in.getId(),0);
- addExpenseAccountLog(in.getId(),4,0,in.getAid(),"撤销报销审核");
- }
- update.setStatus(in.getStatus());
- update.setProcessStatus(outExpenseAccount.getProcessStatus());
- update.setId(in.getId());
- update.setExamineName(outExpenseAccount.getExamineName());
- return expenseAccountMapper.updateByPrimaryKeySelective(update);
- }
- @Override
- public Object mainList(ExpenseMainListInput in) {
- Map<String,Object> params = new HashMap<>();
- if (in.getStatus()!=null) params.put("status",in.getStatus());
- if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
- if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
- if (in.getUsername() != null)params.put("username",in.getUsername());
- if (in.getStartTime()!=null && in.getEndTime() !=null) {
- params.put("startTime",in.getStartTime());
- params.put("endTime",in.getEndTime()+" 23:59:59");
- }
- //1-3s是不同人的审核
- if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
- if (TokenManager.hasRole(AFTConstants.FINANCE)){
- in.setProcessStatus(3);
- }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
- in.setProcessStatus(1);
- }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
- in.setProcessStatus(4);
- }else if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
- //财务经理查看权限
- in.setProcessStatus(6);
- }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- //财务管理员和超级管理员查看全部
- in.setProcessStatus(5);
- }
- }else {
- in.setProcessStatus(0);
- }
- if (in.getProcessStatus()!=null){
- params.put("aid",TokenManager.getAdminId());
- params.put("roleType",in.getProcessStatus());
- if (in.getProcessStatus()==3){
- params.put("deps",departmentService.selectMyDeps());
- }
- }
- Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
- List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
- if (!list.isEmpty()){
- List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
- List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
- for (MainExpenseAccount e : list) {
- for (MainExpenseAccount me : mainExpenseAccounts) {
- if (e.getId().equals(me.getId())){
- e.setSonList(me.getSonList());
- }
- }
- }
- }
- return page;
- }
- @Override
- public Object detailsList(InputDetailsListBo in) {
- Map<String,Object> params = new HashMap<>();
- if(in.getStatus()!=null)params.put("status",in.getStatus());
- if(in.getType()!=null)params.put("type",in.getType());
- if (in.getDepId()!=null)params.put("depId",in.getDepId());
- if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
- if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
- if (in.getAname()!=null)params.put("aname",in.getAname());
- if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
- if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
- if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
- if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
- if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
- //0=自己 1=财务 2=财务经理 3=超管
- if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- params.put("roleType",3);
- }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
- params.put("roleType",2);
- params.put("aid",TokenManager.getAdminId());
- }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
- params.put("roleType",1);
- params.put("aid",TokenManager.getAdminId());
- }else{
- params.put("roleType",0);
- }
- return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
- }
- @Override
- public List<ExpenseAccount> selectByIds(List<String> list) {
- return expenseAccountMapper.selectByIds(list);
- }
- @Override
- public int selectCountByIdsAndType(List<String> list, Integer i) {
- return expenseAccountMapper.selectCountByIdsAndType(list,i);
- }
- @Override
- public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
- ExpenseAccountDetails ea= new ExpenseAccountDetails();
- ea.setId(id);
- ea.setRealAmount(amount);
- expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
- expenseAccountMapper.updateSonByDetId(id);
- expenseAccountMapper.updateMainByDetId(id);
- return 1;
- }
- /**
- * 计算当前报销显示抵扣金额
- * @param useEa
- */
- private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
- ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
- List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
- BigDecimal count =debit.getRealAmount();
- for (ExpenseAccount e : list1) {
- if (!e.getId().equals(useEa.getId())){
- count=count.subtract(e.getSettlementAmount());
- }
- }
- if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
- useEa.setDebitTotalAmount(count);
- }
- /**
- * 判断角色是否已经审核
- * @param useEa
- */
- private void pushExpenseAccountGetExamine(OutExpenseAccount useEa) {
- List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(useEa.getId(), useEa.getProcessStatus());
- boolean flag=false;
- for (ExpenseAccountExamine e : list) {
- if (e.getAuditor().equals(TokenManager.getAdminId())){
- if (e.getStatus()==0){
- flag=true;
- break;
- }
- }
- }
- if (flag){
- useEa.setExamine(1);
- }else {
- useEa.setExamine(0);
- }
- }
- /**
- * 判断角色是否已经审核
- * @param
- */
- private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
- List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
- boolean flag=false;
- for (ExpenseAccountExamine e : list) {
- if (e.getAuditor().equals(TokenManager.getAdminId())){
- if (e.getStatus()==0){
- flag=true;
- break;
- }
- }
- }
- if (flag){
- return 1;
- }else {
- return 0;
- }
- }
- @Override
- public Object updateType(InputExpenseAccount in) {
- expenseAccountDetailsMapper.deleteByeaid(in.getId());
- if (in.getType()!=2)in.setSecondaryType(0);
- in.setSettlementAmount(new BigDecimal(0));
- return expenseAccountMapper.updateByPrimaryKeySelective(in);
- }
- @Override
- public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
- String aid= TokenManager.getAdminId();
- List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
- return list;
- }
- private void addParam(InputPageListBo in, Map<String, Object> param) {
- if (in.getStartTime()!=null&&in.getEndTime()!=null){
- param.put("startTime",in.getStartTime());
- param.put("endTime",in.getEndTime()+" 23:59:59");
- }
- if (in.getStatus()!=null)param.put("status",in.getStatus());
- //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
- if (in.getProcessStatus()==null) in.setProcessStatus(0);
- if(in.getProcessStatus()==2){
- if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
- //财务经理查看权限
- in.setProcessStatus(5);
- }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
- TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
- //财务管理员和超级管理员查看全部
- in.setProcessStatus(6);
- }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
- //0 设置为财务查看
- param.put("roleType",0);
- }
- if (in.getAid()!=null){
- param.put("aid",in.getAid());
- }
- param.put("auditor",TokenManager.getAdminId());
- }else if(in.getProcessStatus()==1) {
- param.put("auditor",TokenManager.getAdminId());
- if (in.getAid()!=null){
- param.put("aid",in.getAid());
- }
- }else {
- param.put("aid",TokenManager.getAdminId());
- }
- param.put("processStatus",in.getProcessStatus());
- if (in.getExamineStatus()!=null){
- param.put("examineStatus",in.getExamineStatus());
- }else {
- param.put("examineStatus",0);
- }
- if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
- if (in.getDepId()!=null)param.put("depId",in.getDepId());
- if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
- if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
- if (in.getType()!=null)param.put("type",in.getType());
- if (in.getUsername()!=null)param.put("username",in.getUsername());
- if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
- if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
- //固定传0查看子列表
- if (in.getExpenseMain()==null)in.setExpenseMain(0);
- if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
- }
- /**
- * 检查权限判断是否是总裁、董事长或超级管理员权限
- * @return
- */
- private boolean checkShiroCED() {
- if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
- TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
- ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
- return true;
- }
- return false;
- }
- @Override
- @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
- public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
- if (endTime != null) endTime = endTime + " 23:59:59";
- List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
- List<OutExpenseAccountStatistics> results = new ArrayList<>();
- Map<String, Object> map = new HashMap<>();
- for (OutMyEAStatistics e : list) {
- OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
- out.setAname(e.getAname());
- if (e.getStatus() == 2) {
- if (e.getType() < 4) {
- out.setBx(1);
- out.setBxAmount(e.getTotalAmount());
- if (!e.getDebitId().equals(0)) {
- out.setDk(1);
- out.setDkAmount(e.getBxdkAmount());
- }
- } else if (e.getType() == 4) {
- out.setJz(1);
- out.setJzAmount(e.getTotalAmount());
- } else if (e.getType() == 5) {
- out.setDk(1);
- out.setDkAmount(e.getTotalAmount());
- }
- if (e.getTargetType() == 0) {
- out.setGdfyAmount(e.getTotalAmount());
- } else if (e.getTargetType() == 1) {
- out.setBxddAmount(e.getTotalAmount());
- }
- } else if (e.getStatus() == 1) {
- out.setWshs(1);
- } else if (e.getStatus() == 3) {
- out.setBhs(1);
- }
- //如果不存在就新增
- if (!map.keySet().contains(out.getAid())) {
- List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
- list2.add(out);
- map.put(out.getAid(), list2);
- } else {
- List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
- list2.add(out);
- }
- }
- for (String s : map.keySet()) {
- List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
- if (!list3.isEmpty()) {
- OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
- for (OutExpenseAccountStatistics e : list3) {
- if (out.getAname() == null) out.setAname(e.getAname());
- if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
- if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
- if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
- if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
- if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
- if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
- if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
- if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
- if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
- if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
- }
- BigDecimal totalAmount = new BigDecimal(0);
- totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
- out.setTotalAmount(totalAmount);
- results.add(out);
- }
- }
- return results;
- }
- @Override
- @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
- public void statisticsEvict(String name, String depId, String startTime, String endTime) {
- LoggerUtils.debug(getClass(), "报销统计缓存清除。");
- }
- @Override
- public Object pushSupplementCheckNo() {
- List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
- if (!list.isEmpty()){
- list.forEach(e ->{
- ExpenseAccount ea=new ExpenseAccount();
- ea.setId(e.getId());
- ea.setCheckNo(idGenerator.getNOgenerateId());
- expenseAccountMapper.updateByPrimaryKeySelective(ea);
- });
- return 1;
- }
- return 0;
- }
- @Override
- public void pushAll() {
- List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
- for (ExpenseAccount ea : list) {
- List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
- List<String> typeList=new ArrayList<>();
- for (ExpenseAccount e : expenseAccounts) {
- StringBuffer types=new StringBuffer();
- if (e.getType()!=0){
- types=types.append(EATypes.getDescByCode(e.getType()));
- }else {
- types=types.append(e.getTypeOther());
- }
- if (e.getType()==2){
- if (e.getSecondaryType()==0){
- types=types.append("-").append(e.getSecondaryTypeOther());
- }else{
- String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
- types=types.append("-").append(descByCode);
- }
- }
- if (!typeList.contains(types.toString()))typeList.add(types.toString());
- }
- String typeStr = String.join(",", typeList);
- ExpenseAccount update=new ExpenseAccount();
- update.setId(ea.getId());
- update.setTypeOther(typeStr);
- expenseAccountMapper.updateByPrimaryKeySelective(update);
- }
- }
- }
|