ExpenseAccountServiceImpl.java 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. package com.goafanti.expenseAccount.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.goafanti.admin.bo.AdminListBo;
  4. import com.goafanti.admin.service.DepartmentService;
  5. import com.goafanti.common.bo.AdminNoticeBo;
  6. import com.goafanti.common.bo.EmailBo;
  7. import com.goafanti.common.constant.AFTConstants;
  8. import com.goafanti.common.dao.*;
  9. import com.goafanti.common.enums.NoticeStatus;
  10. import com.goafanti.common.enums.NoticeTypes;
  11. import com.goafanti.common.error.BusinessException;
  12. import com.goafanti.common.model.*;
  13. import com.goafanti.common.utils.*;
  14. import com.goafanti.core.mybatis.BaseMybatisDao;
  15. import com.goafanti.core.mybatis.JDBCIdGenerator;
  16. import com.goafanti.core.mybatis.page.Pagination;
  17. import com.goafanti.core.shiro.token.TokenManager;
  18. import com.goafanti.expenseAccount.Enums.EAProcessStatus;
  19. import com.goafanti.expenseAccount.Enums.EATypes;
  20. import com.goafanti.expenseAccount.Enums.EAsecondaryTypes;
  21. import com.goafanti.expenseAccount.bo.*;
  22. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  23. import com.goafanti.organization.bo.OrganizationListOut;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.cache.annotation.CacheEvict;
  26. import org.springframework.cache.annotation.Cacheable;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. @Service
  33. public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
  34. @Autowired
  35. private AdminMapper adminMapper;
  36. @Autowired
  37. private ExpenseAccountMapper expenseAccountMapper;
  38. @Autowired
  39. private PublicReleaseMapper publicReleaseMapper;
  40. @Autowired
  41. private ExpenseAccountLogMapper expenseAccountLogMapper;
  42. @Autowired
  43. private AsyncUtils asyncUtils;
  44. @Autowired
  45. private WeChatUtils weChatUtils;
  46. @Autowired
  47. private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
  48. @Autowired
  49. private ExpenseAccountPrivateMapper expenseAccountPrivateMapper;
  50. @Autowired
  51. private ExpenseAccountExamineMapper expenseAccountExamineMapper;
  52. @Autowired
  53. private JDBCIdGenerator idGenerator;
  54. @Autowired
  55. private FinanceCountMapper financeCountMapper;
  56. @Autowired
  57. private ExpenseRelationshipMapper expenseRelationshipMapper;
  58. @Autowired
  59. private DepartmentService departmentService;
  60. @Autowired
  61. private DepartmentMapper departmentMapper;
  62. @Override
  63. public Integer add(InputExpenseAccount in) {
  64. //如果关联公出,获取公出信息
  65. if (in.getPrid()!=null){
  66. PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid());
  67. in.setReleaseStart(pr.getReleaseStart());
  68. in.setReleaseEnd(pr.getReleaseEnd());
  69. in.setDistrictName(pr.getDistrictName());
  70. in.setUserNames(pr.getUserNames());
  71. in.setDuration(pr.getDuration());
  72. }
  73. //判断报销类型,0=固定费用,1=报销到订单
  74. if (in.getOrderNo()==null){
  75. in.setTargetType(0);
  76. }else {
  77. in.setTargetType(1);
  78. }
  79. if (in.getAid()==null)in.setAid(TokenManager.getAdminId());
  80. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  81. in.setAname(admin.getName());
  82. in.setApplyDep(admin.getDepartmentId());
  83. in.setPayDep(admin.getDepartmentId());
  84. expenseAccountMapper.insertSelective(in);
  85. return in.getId();
  86. }
  87. /**
  88. * 新增报销审核流程
  89. */
  90. private void addExpenseAccountExamine(Integer id,ExpenseAccount ea) {
  91. List<ExpenseAccountExamine> list=new ArrayList<>();
  92. String aid = TokenManager.getAdminId();
  93. OrganizationListOut dep = departmentMapper.selectAllById(ea.getApplyDep());
  94. AdminNoticeBo a = adminMapper.selectMyAndSuperBySuperId(aid);
  95. //暂时只发起到财务
  96. for (int i=1;i<4;i++){
  97. ExpenseAccountExamine eae=new ExpenseAccountExamine(id,i);
  98. if (i==1){
  99. //新增一级
  100. String examineId=null;
  101. String examineName=null;
  102. //正常用上级,没有的情况下就是自己
  103. if (a.getSuperId()!=null){
  104. examineId=a.getSuperId();
  105. examineName=a.getSuperName();
  106. }else {
  107. examineId=a.getId();
  108. examineName=a.getName();
  109. }
  110. eae.setAuditor(examineId);
  111. eae.setAuditorname(examineName);
  112. ea.setExamineName(examineName);
  113. }else if (i==2){
  114. if (dep.getManagerId()==null|| StringUtils.isBlank(dep.getManagerId())){
  115. throw new BusinessException("报销申请部门管理员不存在。");
  116. }
  117. eae.setAuditor(dep.getManagerId());
  118. eae.setAuditorname(dep.getManagerName());
  119. }else if (i==3){
  120. if (dep.getExpenseFinanceName()==null)throw new BusinessException("报销部门财务审核人不存在。");
  121. eae.setAuditor(dep.getExpenseFinanceId());
  122. eae.setAuditorname(dep.getExpenseFinanceName());
  123. }else if (i==4){
  124. eae.setAuditor(dep.getExpenseRetrialFinanceId());
  125. eae.setAuditorname(dep.getExpenseRetrialFinanceName());
  126. }
  127. if (eae.getAuditor().equals(aid))eae.setStatus(1);
  128. else eae.setStatus(0);
  129. list.add(eae);
  130. }
  131. expenseAccountExamineMapper.insertBatch(list);
  132. }
  133. /**
  134. * 新增报销日志
  135. * @param eaid 报销编号
  136. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  137. * @param str 备注
  138. */
  139. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str) {
  140. addExpenseAccountLog(eaid,status,processStatus,aid,str,null);
  141. }
  142. /**
  143. * 新增报销日志
  144. * @param eaid 报销编号
  145. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  146. * @param str 备注
  147. */
  148. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str,Date date) {
  149. if (aid==null)aid=TokenManager.getAdminId();
  150. ExpenseAccountLog eaLog=new ExpenseAccountLog();
  151. eaLog.setEaid(eaid);
  152. eaLog.setStatus(status);
  153. eaLog.setRemarks(str);
  154. eaLog.setProcessStatus(processStatus);
  155. eaLog.setAuditor(aid);
  156. if (date !=null)eaLog.setCreateTime(date);
  157. expenseAccountLogMapper.insertSelective(eaLog);
  158. }
  159. /**
  160. * 发起、驳回发起流程切换和日志站内信发送
  161. */
  162. private void addExpenseAccountLogAndNoticEmail(ExpenseAccount in, Integer status, String str) {
  163. String aid=TokenManager.getAdminId();
  164. addExpenseAccountLog(in.getId(),status,in.getProcessStatus(),aid,str);
  165. if (status==0)in.setProcessStatus(1);
  166. Admin admin = adminMapper.selectByPrimaryKey(aid);
  167. if (admin.getSuperiorId()==null||admin.getId().equals(admin.getSuperiorId())){
  168. String str2=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(in.getProcessStatus()));
  169. Date date=new Date();
  170. date.setTime(date.getTime()+1000L);
  171. addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date);
  172. in.setProcessStatus(in.getProcessStatus()+1);
  173. }
  174. createExamineByProcess(in);
  175. }
  176. /**
  177. * 判断审核流程与发送日志与邮件
  178. */
  179. private void createExamineByProcess(ExpenseAccount in) {
  180. //审核流程推送到最新
  181. AdminListBo admin = adminMapper.getDeptNameByAid(in.getAid());
  182. List<ExpenseAccountExamine> list=examineByprocess(in,admin);
  183. List<Admin> aids=new ArrayList<>();
  184. StringBuffer aname =new StringBuffer();
  185. for (ExpenseAccountExamine e : list) {
  186. if (e.getProcessStatus()==in.getProcessStatus()&&e.getStatus()==0){
  187. Admin ad = adminMapper.selectByPrimaryKey(e.getAuditor());
  188. aids.add(ad);
  189. aname=aname.append(ad.getName()).append(",");
  190. }
  191. }
  192. in.setExamineName(aname.substring(0,aname.length()-1));
  193. StringBuffer str=new StringBuffer().append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  194. addNoticeAndEmail(in, EAProcessStatus.SJSH.getCode(),str.toString(), admin.getName(),aids);
  195. }
  196. @Override
  197. @Transactional
  198. public int update(InputExpenseAccount in) {
  199. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  200. if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
  201. throw new BusinessException("不能操作审核中与完成的订单");
  202. }
  203. if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
  204. in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  205. in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  206. }
  207. //计算总金额
  208. if (in.getTotalAmount()==null){
  209. in.setTotalAmount(expenseAccountDetailsMapper.selectAmountCountByEAid(in.getId()));
  210. in.setRealAmount(in.getTotalAmount());
  211. }
  212. in.setProcessStatus(0);
  213. if (in.getOrderNo()==null){
  214. in.setTargetType(0);
  215. }else {
  216. in.setTargetType(1);
  217. }
  218. //计算本单已扣金额 如果有选择借支单,则需要修改借支状态
  219. if (in.getDebitId()!=null){
  220. //如果以前没有选择借支,修改报销和借支数据
  221. if (useEA.getDebitId()==null){
  222. pushExpenseAccountDebit(in);
  223. }else if (useEA.getDebitId()!=in.getDebitId()) {
  224. //如果是修改编号
  225. pushExpenseAccountDebit(in);
  226. //并且要处理原编号的问题
  227. pushResettingDebit(in,useEA.getDebitId());
  228. }
  229. }
  230. if (in.getSettlementAmount()==null)in.setSettlementAmount(useEA.getSettlementAmount());
  231. in.setAmount(in.getTotalAmount().subtract(in.getSettlementAmount()));
  232. in.setRealAmount(in.getAmount());
  233. in.setStatus(0);
  234. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  235. }
  236. @Override
  237. public Object updateDebitId(InputExpenseAccount in) {
  238. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  239. if (useEA.getDebitId()!=null)pushResettingDebit(in,useEA.getDebitId());
  240. expenseAccountMapper.updateDeleteDebitId(in.getId());
  241. return 1;
  242. }
  243. private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
  244. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);
  245. List<ExpenseAccount> list = expenseAccountMapper.selectByDebitId(debitId);
  246. ExpenseAccount newDebit=new ExpenseAccount();
  247. newDebit.setId(debitId);
  248. //计算除开当前单,已选择抵扣金额
  249. BigDecimal count=new BigDecimal(0);
  250. for (ExpenseAccount e : list) {
  251. if (!in.getId().equals(e.getId())){
  252. count=count.add(e.getSettlementAmount());
  253. }
  254. }
  255. newDebit.setSettlementAmount(count);
  256. if (count.compareTo(new BigDecimal(0))==0){
  257. newDebit.setLiquidationStatus(0);
  258. }else if (count.compareTo(debit.getRealAmount())<0){
  259. newDebit.setLiquidationStatus(1);
  260. }else if (count.compareTo(debit.getRealAmount())==0){
  261. newDebit.setLiquidationStatus(2);
  262. }
  263. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  264. }
  265. private void pushExpenseAccountDebit(InputExpenseAccount in) {
  266. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(in.getDebitId());
  267. ExpenseAccount newDebit=new ExpenseAccount();
  268. newDebit.setId(debit.getId());
  269. //计算剩余需要支付金额
  270. BigDecimal decbitAmount=debit.getRealAmount().subtract(debit.getSettlementAmount());
  271. //本次金额大于等于需要抵扣金额,则变成完全抵扣,抵扣金额变成本次已付金额
  272. if (in.getRealAmount().compareTo(decbitAmount)>=0){
  273. in.setSettlementAmount(decbitAmount);
  274. newDebit.setSettlementAmount(debit.getRealAmount());
  275. newDebit.setLiquidationStatus(2);
  276. }else {
  277. // 本次金额小于需要抵扣,则本次变更全抵扣,借支已付加上本次金额
  278. in.setSettlementAmount(in.getRealAmount());
  279. BigDecimal setAmount=new BigDecimal(0).add(debit.getSettlementAmount()).add(in.getRealAmount());
  280. newDebit.setSettlementAmount(setAmount);
  281. newDebit.setLiquidationStatus(1);
  282. }
  283. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  284. }
  285. @Override
  286. public int addDetails(InputExpenseAccountDetails in) {
  287. if (in.getAgreeTimes()!=null){
  288. in.setAgreeTime(DateUtils.StringToDate(in.getAgreeTimes(),AFTConstants.YYYYMMDD));
  289. }
  290. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(in.getEaid());
  291. if (expenseAccount.getType()==2){
  292. in.setType(expenseAccount.getSecondaryType());
  293. if (in.getType()==0){
  294. in.setTypeOther(expenseAccount.getSecondaryTypeOther());
  295. }
  296. }
  297. in.setRealAmount(in.getAmount());
  298. expenseAccountDetailsMapper.insertSelective(in);
  299. return 1;
  300. }
  301. @Override
  302. public int deleteDetails(Integer id) {
  303. return expenseAccountDetailsMapper.deleteByPrimaryKey(id);
  304. }
  305. @Override
  306. public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
  307. return expenseAccountDetailsMapper.selectByEAid(eaid);
  308. }
  309. @Override
  310. public Object logList(Integer eaid) {
  311. List<OutExpenseAccountLog> list = expenseAccountLogMapper.selectByEaid(eaid);
  312. if (!list.isEmpty()){
  313. OutExpenseAccountLog lastout=list.get(list.size()-1);
  314. if (lastout.getStatus()!=3){
  315. List<OutExpenseAccountLog> eaelist = expenseAccountExamineMapper.selectNotExamineByEaidAndProcessStatus(eaid, lastout.getProcessStatus());
  316. list.addAll(eaelist);
  317. }
  318. }
  319. return list;
  320. }
  321. @Override
  322. public int updateExamine(InputExpenseAccount in) {
  323. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  324. ExpenseAccount newEa=new ExpenseAccount();
  325. newEa.setId(useEa.getId());
  326. in.setCheckNo(useEa.getCheckNo());
  327. in.setProcessStatus(useEa.getProcessStatus());
  328. //审核通知 获取发送人
  329. AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
  330. addExamineExpenseAccountLog(admin,in, useEa, newEa);
  331. //完成申请
  332. if (newEa.getStatus()==2){
  333. //如果是借支则订单新增
  334. List<ExpenseAccount> expenseAccounts1 = expenseAccountMapper.selectListByMainId(in.getId());
  335. for (ExpenseAccount e : expenseAccounts1) {
  336. if (e.getType()!=4){
  337. //不然就看是否挂载借支订单进行抵扣
  338. if (e.getDebitId()!=null){
  339. ExpenseAccount useDebit=expenseAccountMapper.selectByPrimaryKey(e.getDebitId());
  340. if (useDebit.getLiquidationStatus()==2){
  341. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByDebitId(e.getDebitId());
  342. boolean flag=true;
  343. for (ExpenseAccount expenseAccount : expenseAccounts) {
  344. if(!expenseAccount.getId().equals(in.getId())&&expenseAccount.getStatus()!=2){
  345. flag=false;
  346. break;
  347. }
  348. }
  349. if (flag){
  350. ExpenseAccount debit=new ExpenseAccount();
  351. debit.setId(e.getDebitId());
  352. debit.setLiquidationStatus(3);
  353. expenseAccountMapper.updateByPrimaryKeySelective(debit);
  354. }
  355. }
  356. }
  357. }
  358. ExpenseAccount updateSon=new ExpenseAccount();
  359. updateSon.setId(e.getId());
  360. updateSon.setStatus(2);
  361. expenseAccountMapper.updateByPrimaryKeySelective(updateSon);
  362. }
  363. }else if (newEa.getStatus()==1){
  364. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  365. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),0);
  366. //处理金额修改
  367. if(in.getRealList()!=null){
  368. List<Map> maps = JSONObject.parseArray(in.getRealList(), Map.class);
  369. for (Map map: maps) {
  370. Integer type= (Integer) map.get("type");
  371. Integer id= (Integer) map.get("id");
  372. BigDecimal amount= new BigDecimal(map.get("amount").toString());
  373. //type=1总计,type=2报销金额
  374. if(type==1){
  375. ExpenseAccount ea =new ExpenseAccount();
  376. ea.setId(id);
  377. ea.setRealAmount(amount);
  378. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  379. }else if (type==2){
  380. ExpenseAccountDetails ead=new ExpenseAccountDetails();
  381. ead.setId(id);
  382. ead.setRealAmount(amount);
  383. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ead);
  384. }
  385. }
  386. }
  387. }else if (newEa.getProcessStatus()==EAProcessStatus.CWSH.getCode()){
  388. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),1);
  389. }
  390. }else if (newEa.getStatus()==3){
  391. if (useEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  392. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),2);
  393. }else if (newEa.getProcessStatus()>EAProcessStatus.CWSH.getCode()){
  394. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),3);
  395. }
  396. }
  397. //审核处理审核表
  398. pushExpenseAccountExamine(in);
  399. expenseAccountMapper.updateByPrimaryKeySelective(newEa);
  400. expenseAccountMapper.updateSonByMainId(newEa.getId());
  401. return 1;
  402. }
  403. private void addFinanceCount(String aid,Date startTime ) {
  404. String forDate=DateUtils.formatDate(startTime,AFTConstants.YYYYMMDD);
  405. addFinanceCount(aid,forDate);
  406. }
  407. private void addFinanceCount(String aid,String startTime ) {
  408. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  409. if (financeCount ==null){
  410. financeCount =FinanceCount.initialization(aid, startTime);
  411. financeCount.setExpenseCount(1);
  412. financeCount.setExpenseUnauditedCount(1);
  413. financeCountMapper.insertSelective(financeCount);
  414. }else {
  415. FinanceCount newFinanceCount =new FinanceCount();
  416. newFinanceCount.setId(financeCount.getId());
  417. newFinanceCount.setExpenseCount(financeCount.getExpenseCount()+1);
  418. newFinanceCount.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  419. financeCountMapper.updateByPrimaryKeySelective(newFinanceCount);
  420. }
  421. }
  422. private void pushExpenseAccountExamine(InputExpenseAccount in) {
  423. if (in.getStatus()==1){
  424. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1);
  425. }else if (in.getStatus()==3){
  426. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),null,0);
  427. }
  428. }
  429. private void addExamineExpenseAccountLog(AdminListBo admin,InputExpenseAccount in, ExpenseAccount useEa, ExpenseAccount newEa) {
  430. List<Admin> aids=new ArrayList<>();
  431. StringBuffer str=new StringBuffer();
  432. Integer status=in.getStatus();
  433. if (status==1){
  434. str=str.append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  435. //新的流程是当前流程+1
  436. newEa.setProcessStatus(useEa.getProcessStatus()+1);
  437. newEa.setAid(useEa.getAid());
  438. newEa.setCreateTime(useEa.getCreateTime());
  439. List<ExpenseAccountExamine> list=examineByprocess(newEa,admin);
  440. if(newEa.getProcessStatus()==4){
  441. //完成后的流程
  442. status =2;
  443. // Admin finaceAdmin = adminMapper.selectByPrimaryKey(admin.getDepFinance());
  444. // //同事添加通知财务管理员与公司副总
  445. // List<Admin> admins = adminMapper.selectAdminByRoleType(AFTConstants.FINANCE_ADMIN);
  446. // aids.addAll(admins);
  447. // List<Admin> viceCEO = adminMapper.selectAdminByRoleType(AFTConstants.VICE_CEO);
  448. // aids.addAll(viceCEO);
  449. // aids.add(finaceAdmin);
  450. // str.setLength(0);
  451. // str=str.append("报销编号[").append(in.getCheckNo()).append("]审核已通过,请注意查看。");
  452. // addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
  453. // aids.clear();
  454. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  455. newEa.setStatus(status);
  456. newEa.setExamineName("");
  457. }else {
  458. StringBuffer aname =new StringBuffer();
  459. for (ExpenseAccountExamine e : list) {
  460. if (e.getProcessStatus()==newEa.getProcessStatus()&&e.getStatus()==0){
  461. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  462. aids.add(ad);
  463. aname=aname.append(ad.getName()).append(",");
  464. }
  465. }
  466. newEa.setExamineName(aname.substring(0,aname.length()-1));
  467. }
  468. }else {
  469. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  470. newEa.setStatus(3);
  471. newEa.setProcessStatus(0);
  472. str.setLength(0);
  473. str=str.append("您的报销审核已驳回,报销编号[").append(in.getCheckNo()).append("],请注意查看。");
  474. }
  475. if (newEa.getStatus()==null)newEa.setStatus(1);
  476. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  477. addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
  478. }
  479. /**
  480. *
  481. * @param aid
  482. * @param createTime
  483. * @param type 0 双新增 1 未审核减一 2双减 3总数减一
  484. */
  485. private void pushFinanceCount(String aid, Date createTime, Integer type) {
  486. String startTime= DateUtils.formatDate(createTime,AFTConstants.YYYYMMDD);
  487. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  488. FinanceCount newFinance=new FinanceCount();
  489. if (financeCount==null){
  490. newFinance=FinanceCount.initialization(aid,createTime);
  491. newFinance.setExpenseCount(1);
  492. newFinance.setExpenseUnauditedCount(1);
  493. financeCountMapper.insertSelective(newFinance);
  494. }else {
  495. newFinance.setId(financeCount.getId());
  496. if(type==0){
  497. newFinance.setExpenseCount(financeCount.getExpenseCount()+1);
  498. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  499. }else if(type==1){
  500. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  501. }else if(type==2){
  502. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  503. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  504. }else if(type==3){
  505. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  506. }
  507. financeCountMapper.updateByPrimaryKeySelective(newFinance);
  508. }
  509. }
  510. /**
  511. * 审核流程推送,只要不是完成状态就继续判断是否跳过
  512. * @param newEa
  513. */
  514. private List<ExpenseAccountExamine> examineByprocess( ExpenseAccount newEa,AdminListBo admin) {
  515. //获取当前流程审核人,如果有已审核则跳过当前审核
  516. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  517. boolean flag=false;
  518. String aid="";
  519. for (ExpenseAccountExamine e : list) {
  520. if (e.getStatus()==1){
  521. flag=true;
  522. aid=e.getAuditor();
  523. break;
  524. }
  525. if(e.getAuditor().equals(newEa.getAid())){
  526. flag=true;
  527. break;
  528. }
  529. }
  530. if (flag){
  531. String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
  532. Date date=new Date();
  533. date.setTime(date.getTime()+1000l);
  534. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date);
  535. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  536. addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
  537. }
  538. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  539. if (newEa.getProcessStatus()<EAProcessStatus.CWSH.getCode())examineByprocess(newEa,admin);
  540. list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  541. }
  542. return list;
  543. }
  544. private String getAdmins(List<Admin> list) {
  545. StringBuffer str =new StringBuffer();
  546. for (Admin admin : list) {
  547. str=str.append(admin.getName()).append(",");
  548. }
  549. return str.substring(0,str.length()-1);
  550. }
  551. private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
  552. Date date= new Date();
  553. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  554. if (status==2){
  555. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  556. }
  557. List<Notice> list=new ArrayList<>();
  558. if (aids!=null){
  559. for (Admin a : aids) {
  560. Notice notice=new Notice();
  561. notice.setId(UUID.randomUUID().toString());
  562. notice.setNoticeType(noticeStatus);
  563. notice.setType(NoticeTypes.getType(noticeStatus));
  564. notice.setAid(a.getId());
  565. notice.setCreateTime(date);
  566. notice.setContent(str);
  567. notice.setReaded(0);
  568. list.add(notice);
  569. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  570. asyncUtils.send(emailBo);
  571. weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
  572. }
  573. asyncUtils.addNoticeBatch(list);
  574. }
  575. }
  576. @Override
  577. public Object pageList(InputPageListBo in) {
  578. Map<String ,Object> param=new HashMap<>();
  579. addParam(in, param);
  580. Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
  581. "selectExpenseAccountCount",
  582. "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
  583. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
  584. for (OutExpenseAccountBo e : list) {
  585. e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
  586. }
  587. return pagePlus;
  588. }
  589. @Override
  590. public Object selectByPrid(InputExpenseAccount in) {
  591. in.setAid(TokenManager.getAdminId());
  592. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  593. return useEa;
  594. }
  595. @Override
  596. public Object selectById(Integer id) {
  597. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  598. //判断当前角色是否审核
  599. pushExpenseAccountGetExamine(useEa);
  600. if (useEa.getDebitId()!=null){
  601. pushExpenseAccountGetDebitAmount(useEa);
  602. }
  603. return useEa;
  604. }
  605. @Override
  606. public Object selectByCheckNo(String checkNo) {
  607. checkNo=checkNo.trim();
  608. OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
  609. if (useEa==null){
  610. throw new BusinessException("报销编号不存在,请客对后再查询。");
  611. }
  612. if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
  613. throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
  614. }
  615. return useEa;
  616. }
  617. @Override
  618. public Object pushMerge(List<ExpenseAccount> list) {
  619. //设置付款部门和支付部门
  620. InputExpenseAccount in =new InputExpenseAccount();
  621. in.setCheckNo(idGenerator.getNOgenerateId());
  622. if (in.getAid()==null){
  623. in.setAid(TokenManager.getAdminId());
  624. }
  625. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  626. in.setAname(admin.getName());
  627. in.setApplyDep(admin.getDepartmentId());
  628. in.setPayDep(admin.getDepartmentId());
  629. Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
  630. in.setEaaid(eaaid);
  631. BigDecimal count = new BigDecimal(0);
  632. BigDecimal amount = new BigDecimal(0);
  633. List<String> typeList = new ArrayList<String>();
  634. for (ExpenseAccount e : list) {
  635. count=count.add(e.getTotalAmount());
  636. amount=amount.add(e.getAmount());
  637. StringBuffer types=new StringBuffer();
  638. if (e.getType()!=0){
  639. types=types.append(EATypes.getDescByCode(e.getType()));
  640. }else {
  641. types=types.append(e.getTypeOther());
  642. }
  643. if (e.getType()==2){
  644. if (e.getSecondaryType()==0){
  645. types=types.append("-").append(e.getSecondaryTypeOther());
  646. }else{
  647. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  648. types=types.append("-").append(descByCode);
  649. }
  650. }
  651. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  652. }
  653. in.setTotalAmount(count);
  654. in.setAmount(amount);
  655. in.setRealAmount(amount);
  656. in.setExpenseMain(1);
  657. in.setTypeOther(String.join(",",typeList));
  658. expenseAccountMapper.insertSelective(in);
  659. list.stream().forEach(e -> {
  660. ExpenseRelationship er=new ExpenseRelationship();
  661. er.setId(in.getId());
  662. er.setEaId(e.getId());
  663. expenseRelationshipMapper.insertSelective(er);
  664. });
  665. expenseAccountMapper.updateByIds(list,1);
  666. return in.getId();
  667. }
  668. @Override
  669. public MainExpenseAccount mainExpense(Integer id) {
  670. MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
  671. res.setExamine(0);
  672. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, res.getProcessStatus());
  673. for (ExpenseAccountExamine e : expenseAccountExamines) {
  674. if (e.getAuditor().equals(TokenManager.getAdminId())){
  675. res.setExamine(1);
  676. break;
  677. }
  678. }
  679. if (res.getAid().equals(TokenManager.getAdminId())){
  680. res.setExamine(2);
  681. }
  682. return res;
  683. }
  684. @Override
  685. public Object updateMain(MainExpenseAccount in) {
  686. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  687. if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
  688. throw new BusinessException("主项目已发起,不可修改!");
  689. }
  690. ExpenseAccount update =new ExpenseAccount();
  691. if (in.getStatus()==null)in.setStatus(1);
  692. if (in.getStatus()==1){
  693. if (in.getOrderNo()!=null){
  694. update.setOrderNo(in.getOrderNo());
  695. update.setTargetType(1);
  696. }
  697. if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
  698. if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
  699. if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
  700. if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
  701. addExpenseAccountExamine(in.getId(),update);
  702. if (outExpenseAccount.getStatus()==0){
  703. addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
  704. }else if (outExpenseAccount.getStatus()==3){
  705. addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
  706. }
  707. }else if (in.getStatus()==4){
  708. expenseAccountMapper.updateByMainId(in.getId(),0);
  709. addExpenseAccountLog(in.getId(),4,0,in.getAid(),"撤销报销审核");
  710. }
  711. update.setStatus(in.getStatus());
  712. update.setProcessStatus(outExpenseAccount.getProcessStatus());
  713. update.setId(in.getId());
  714. update.setExamineName(outExpenseAccount.getExamineName());
  715. return expenseAccountMapper.updateByPrimaryKeySelective(update);
  716. }
  717. @Override
  718. public Object mainList(ExpenseMainListInput in) {
  719. Map<String,Object> params = new HashMap<>();
  720. if (in.getStatus()!=null) params.put("status",in.getStatus());
  721. if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
  722. if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
  723. if (in.getUsername() != null)params.put("username",in.getUsername());
  724. if (in.getStartTime()!=null && in.getEndTime() !=null) {
  725. params.put("startTime",in.getStartTime());
  726. params.put("endTime",in.getEndTime()+" 23:59:59");
  727. }
  728. //1-3s是不同人的审核
  729. if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
  730. if (TokenManager.hasRole(AFTConstants.FINANCE)){
  731. in.setProcessStatus(3);
  732. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  733. in.setProcessStatus(1);
  734. }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
  735. in.setProcessStatus(4);
  736. }else if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  737. //财务经理查看权限
  738. in.setProcessStatus(6);
  739. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  740. //财务管理员和超级管理员查看全部
  741. in.setProcessStatus(5);
  742. }
  743. }else {
  744. in.setProcessStatus(0);
  745. }
  746. if (in.getProcessStatus()!=null){
  747. params.put("aid",TokenManager.getAdminId());
  748. params.put("roleType",in.getProcessStatus());
  749. if (in.getProcessStatus()==3){
  750. params.put("deps",departmentService.selectMyDeps());
  751. }
  752. }
  753. Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
  754. List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
  755. if (!list.isEmpty()){
  756. List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
  757. List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
  758. for (MainExpenseAccount e : list) {
  759. for (MainExpenseAccount me : mainExpenseAccounts) {
  760. if (e.getId().equals(me.getId())){
  761. e.setSonList(me.getSonList());
  762. }
  763. }
  764. }
  765. }
  766. return page;
  767. }
  768. @Override
  769. public Object detailsList(InputDetailsListBo in) {
  770. Map<String,Object> params = new HashMap<>();
  771. if(in.getStatus()!=null)params.put("status",in.getStatus());
  772. if(in.getType()!=null)params.put("type",in.getType());
  773. if (in.getDepId()!=null)params.put("depId",in.getDepId());
  774. if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
  775. if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
  776. if (in.getAname()!=null)params.put("aname",in.getAname());
  777. if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
  778. if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
  779. if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
  780. if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
  781. if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
  782. //0=自己 1=财务 2=财务经理 3=超管
  783. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  784. params.put("roleType",3);
  785. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  786. params.put("roleType",2);
  787. params.put("aid",TokenManager.getAdminId());
  788. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  789. params.put("roleType",1);
  790. params.put("aid",TokenManager.getAdminId());
  791. }else{
  792. params.put("roleType",0);
  793. }
  794. return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
  795. }
  796. @Override
  797. public List<ExpenseAccount> selectByIds(List<String> list) {
  798. return expenseAccountMapper.selectByIds(list);
  799. }
  800. @Override
  801. public int selectCountByIdsAndType(List<String> list, Integer i) {
  802. return expenseAccountMapper.selectCountByIdsAndType(list,i);
  803. }
  804. @Override
  805. public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
  806. ExpenseAccountDetails ea= new ExpenseAccountDetails();
  807. ea.setId(id);
  808. ea.setRealAmount(amount);
  809. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
  810. expenseAccountMapper.updateSonByDetId(id);
  811. expenseAccountMapper.updateMainByDetId(id);
  812. return 1;
  813. }
  814. /**
  815. * 计算当前报销显示抵扣金额
  816. * @param useEa
  817. */
  818. private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
  819. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
  820. List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
  821. BigDecimal count =debit.getRealAmount();
  822. for (ExpenseAccount e : list1) {
  823. if (!e.getId().equals(useEa.getId())){
  824. count=count.subtract(e.getSettlementAmount());
  825. }
  826. }
  827. if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
  828. useEa.setDebitTotalAmount(count);
  829. }
  830. /**
  831. * 判断角色是否已经审核
  832. * @param useEa
  833. */
  834. private void pushExpenseAccountGetExamine(OutExpenseAccount useEa) {
  835. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(useEa.getId(), useEa.getProcessStatus());
  836. boolean flag=false;
  837. for (ExpenseAccountExamine e : list) {
  838. if (e.getAuditor().equals(TokenManager.getAdminId())){
  839. if (e.getStatus()==0){
  840. flag=true;
  841. break;
  842. }
  843. }
  844. }
  845. if (flag){
  846. useEa.setExamine(1);
  847. }else {
  848. useEa.setExamine(0);
  849. }
  850. }
  851. /**
  852. * 判断角色是否已经审核
  853. * @param
  854. */
  855. private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
  856. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
  857. boolean flag=false;
  858. for (ExpenseAccountExamine e : list) {
  859. if (e.getAuditor().equals(TokenManager.getAdminId())){
  860. if (e.getStatus()==0){
  861. flag=true;
  862. break;
  863. }
  864. }
  865. }
  866. if (flag){
  867. return 1;
  868. }else {
  869. return 0;
  870. }
  871. }
  872. @Override
  873. public Object updateType(InputExpenseAccount in) {
  874. expenseAccountDetailsMapper.deleteByeaid(in.getId());
  875. if (in.getType()!=2)in.setSecondaryType(0);
  876. in.setSettlementAmount(new BigDecimal(0));
  877. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  878. }
  879. @Override
  880. public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
  881. String aid= TokenManager.getAdminId();
  882. List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
  883. return list;
  884. }
  885. private void addParam(InputPageListBo in, Map<String, Object> param) {
  886. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  887. param.put("startTime",in.getStartTime());
  888. param.put("endTime",in.getEndTime()+" 23:59:59");
  889. }
  890. if (in.getStatus()!=null)param.put("status",in.getStatus());
  891. //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
  892. if (in.getProcessStatus()==null) in.setProcessStatus(0);
  893. if(in.getProcessStatus()==2){
  894. if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  895. //财务经理查看权限
  896. in.setProcessStatus(5);
  897. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  898. TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  899. //财务管理员和超级管理员查看全部
  900. in.setProcessStatus(6);
  901. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  902. //0 设置为财务查看
  903. param.put("roleType",0);
  904. }
  905. if (in.getAid()!=null){
  906. param.put("aid",in.getAid());
  907. }
  908. param.put("auditor",TokenManager.getAdminId());
  909. }else if(in.getProcessStatus()==1) {
  910. param.put("auditor",TokenManager.getAdminId());
  911. if (in.getAid()!=null){
  912. param.put("aid",in.getAid());
  913. }
  914. }else {
  915. param.put("aid",TokenManager.getAdminId());
  916. }
  917. param.put("processStatus",in.getProcessStatus());
  918. if (in.getExamineStatus()!=null){
  919. param.put("examineStatus",in.getExamineStatus());
  920. }else {
  921. param.put("examineStatus",0);
  922. }
  923. if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
  924. if (in.getDepId()!=null)param.put("depId",in.getDepId());
  925. if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
  926. if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
  927. if (in.getType()!=null)param.put("type",in.getType());
  928. if (in.getUsername()!=null)param.put("username",in.getUsername());
  929. if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
  930. if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
  931. //固定传0查看子列表
  932. if (in.getExpenseMain()==null)in.setExpenseMain(0);
  933. if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
  934. }
  935. /**
  936. * 检查权限判断是否是总裁、董事长或超级管理员权限
  937. * @return
  938. */
  939. private boolean checkShiroCED() {
  940. if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
  941. TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
  942. ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  943. return true;
  944. }
  945. return false;
  946. }
  947. @Override
  948. @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
  949. public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
  950. if (endTime != null) endTime = endTime + " 23:59:59";
  951. List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
  952. List<OutExpenseAccountStatistics> results = new ArrayList<>();
  953. Map<String, Object> map = new HashMap<>();
  954. for (OutMyEAStatistics e : list) {
  955. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
  956. out.setAname(e.getAname());
  957. if (e.getStatus() == 2) {
  958. if (e.getType() < 4) {
  959. out.setBx(1);
  960. out.setBxAmount(e.getTotalAmount());
  961. if (!e.getDebitId().equals(0)) {
  962. out.setDk(1);
  963. out.setDkAmount(e.getBxdkAmount());
  964. }
  965. } else if (e.getType() == 4) {
  966. out.setJz(1);
  967. out.setJzAmount(e.getTotalAmount());
  968. } else if (e.getType() == 5) {
  969. out.setDk(1);
  970. out.setDkAmount(e.getTotalAmount());
  971. }
  972. if (e.getTargetType() == 0) {
  973. out.setGdfyAmount(e.getTotalAmount());
  974. } else if (e.getTargetType() == 1) {
  975. out.setBxddAmount(e.getTotalAmount());
  976. }
  977. } else if (e.getStatus() == 1) {
  978. out.setWshs(1);
  979. } else if (e.getStatus() == 3) {
  980. out.setBhs(1);
  981. }
  982. //如果不存在就新增
  983. if (!map.keySet().contains(out.getAid())) {
  984. List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
  985. list2.add(out);
  986. map.put(out.getAid(), list2);
  987. } else {
  988. List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
  989. list2.add(out);
  990. }
  991. }
  992. for (String s : map.keySet()) {
  993. List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
  994. if (!list3.isEmpty()) {
  995. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
  996. for (OutExpenseAccountStatistics e : list3) {
  997. if (out.getAname() == null) out.setAname(e.getAname());
  998. if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
  999. if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
  1000. if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
  1001. if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
  1002. if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
  1003. if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
  1004. if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
  1005. if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
  1006. if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
  1007. if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
  1008. }
  1009. BigDecimal totalAmount = new BigDecimal(0);
  1010. totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
  1011. out.setTotalAmount(totalAmount);
  1012. results.add(out);
  1013. }
  1014. }
  1015. return results;
  1016. }
  1017. @Override
  1018. @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
  1019. public void statisticsEvict(String name, String depId, String startTime, String endTime) {
  1020. LoggerUtils.debug(getClass(), "报销统计缓存清除。");
  1021. }
  1022. @Override
  1023. public Object pushSupplementCheckNo() {
  1024. List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
  1025. if (!list.isEmpty()){
  1026. list.forEach(e ->{
  1027. ExpenseAccount ea=new ExpenseAccount();
  1028. ea.setId(e.getId());
  1029. ea.setCheckNo(idGenerator.getNOgenerateId());
  1030. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  1031. });
  1032. return 1;
  1033. }
  1034. return 0;
  1035. }
  1036. @Override
  1037. public void pushAll() {
  1038. List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
  1039. for (ExpenseAccount ea : list) {
  1040. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
  1041. List<String> typeList=new ArrayList<>();
  1042. for (ExpenseAccount e : expenseAccounts) {
  1043. StringBuffer types=new StringBuffer();
  1044. if (e.getType()!=0){
  1045. types=types.append(EATypes.getDescByCode(e.getType()));
  1046. }else {
  1047. types=types.append(e.getTypeOther());
  1048. }
  1049. if (e.getType()==2){
  1050. if (e.getSecondaryType()==0){
  1051. types=types.append("-").append(e.getSecondaryTypeOther());
  1052. }else{
  1053. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1054. types=types.append("-").append(descByCode);
  1055. }
  1056. }
  1057. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1058. }
  1059. String typeStr = String.join(",", typeList);
  1060. ExpenseAccount update=new ExpenseAccount();
  1061. update.setId(ea.getId());
  1062. update.setTypeOther(typeStr);
  1063. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1064. }
  1065. }
  1066. }