ExpenseAccountServiceImpl.java 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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. private void pushExamineProcess( ExpenseAccount newEa,AdminListBo admin) {
  511. //如果到了董事长审核,无需判断了
  512. if (newEa.getProcessStatus()<EAProcessStatus.CWSH.getCode()){
  513. //判断没一个流程是否可以跳过
  514. examineByprocess(newEa,admin);
  515. }
  516. }
  517. /**
  518. * 审核流程推送,只要不是完成状态就继续判断是否跳过
  519. * @param newEa
  520. */
  521. private List<ExpenseAccountExamine> examineByprocess( ExpenseAccount newEa,AdminListBo admin) {
  522. //获取当前流程审核人,如果有已审核则跳过当前审核
  523. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  524. boolean flag=false;
  525. String aid="";
  526. for (ExpenseAccountExamine e : list) {
  527. if (e.getStatus()==1){
  528. flag=true;
  529. aid=e.getAuditor();
  530. break;
  531. }
  532. if(e.getAuditor().equals(newEa.getAid())){
  533. flag=true;
  534. break;
  535. }
  536. }
  537. if (flag){
  538. String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
  539. Date date=new Date();
  540. date.setTime(date.getTime()+1000l);
  541. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date);
  542. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  543. addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
  544. }
  545. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  546. if (newEa.getProcessStatus()<EAProcessStatus.CWSH.getCode())examineByprocess(newEa,admin);
  547. }
  548. return list;
  549. }
  550. private String getAdmins(List<Admin> list) {
  551. StringBuffer str =new StringBuffer();
  552. for (Admin admin : list) {
  553. str=str.append(admin.getName()).append(",");
  554. }
  555. return str.substring(0,str.length()-1);
  556. }
  557. private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
  558. Date date= new Date();
  559. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  560. if (status==2){
  561. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  562. }
  563. List<Notice> list=new ArrayList<>();
  564. if (aids!=null){
  565. for (Admin a : aids) {
  566. Notice notice=new Notice();
  567. notice.setId(UUID.randomUUID().toString());
  568. notice.setNoticeType(noticeStatus);
  569. notice.setType(NoticeTypes.getType(noticeStatus));
  570. notice.setAid(a.getId());
  571. notice.setCreateTime(date);
  572. notice.setContent(str);
  573. notice.setReaded(0);
  574. list.add(notice);
  575. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  576. asyncUtils.send(emailBo);
  577. weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
  578. }
  579. asyncUtils.addNoticeBatch(list);
  580. }
  581. }
  582. @Override
  583. public Object pageList(InputPageListBo in) {
  584. Map<String ,Object> param=new HashMap<>();
  585. addParam(in, param);
  586. Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
  587. "selectExpenseAccountCount",
  588. "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
  589. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
  590. for (OutExpenseAccountBo e : list) {
  591. e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
  592. }
  593. return pagePlus;
  594. }
  595. @Override
  596. public Object selectByPrid(InputExpenseAccount in) {
  597. in.setAid(TokenManager.getAdminId());
  598. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  599. return useEa;
  600. }
  601. @Override
  602. public Object selectById(Integer id) {
  603. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  604. //判断当前角色是否审核
  605. pushExpenseAccountGetExamine(useEa);
  606. if (useEa.getDebitId()!=null){
  607. pushExpenseAccountGetDebitAmount(useEa);
  608. }
  609. return useEa;
  610. }
  611. @Override
  612. public Object selectByCheckNo(String checkNo) {
  613. checkNo=checkNo.trim();
  614. OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
  615. if (useEa==null){
  616. throw new BusinessException("报销编号不存在,请客对后再查询。");
  617. }
  618. if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
  619. throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
  620. }
  621. return useEa;
  622. }
  623. @Override
  624. public Object pushMerge(List<ExpenseAccount> list) {
  625. //设置付款部门和支付部门
  626. InputExpenseAccount in =new InputExpenseAccount();
  627. in.setCheckNo(idGenerator.getNOgenerateId());
  628. if (in.getAid()==null){
  629. in.setAid(TokenManager.getAdminId());
  630. }
  631. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  632. in.setAname(admin.getName());
  633. in.setApplyDep(admin.getDepartmentId());
  634. in.setPayDep(admin.getDepartmentId());
  635. Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
  636. in.setEaaid(eaaid);
  637. BigDecimal count = new BigDecimal(0);
  638. BigDecimal amount = new BigDecimal(0);
  639. List<String> typeList = new ArrayList<String>();
  640. for (ExpenseAccount e : list) {
  641. count=count.add(e.getTotalAmount());
  642. amount=amount.add(e.getAmount());
  643. StringBuffer types=new StringBuffer();
  644. if (e.getType()!=0){
  645. types=types.append(EATypes.getDescByCode(e.getType()));
  646. }else {
  647. types=types.append(e.getTypeOther());
  648. }
  649. if (e.getType()==2){
  650. if (e.getSecondaryType()==0){
  651. types=types.append("-").append(e.getSecondaryTypeOther());
  652. }else{
  653. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  654. types=types.append("-").append(descByCode);
  655. }
  656. }
  657. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  658. }
  659. in.setTotalAmount(count);
  660. in.setAmount(amount);
  661. in.setRealAmount(amount);
  662. in.setExpenseMain(1);
  663. in.setTypeOther(String.join(",",typeList));
  664. expenseAccountMapper.insertSelective(in);
  665. list.stream().forEach(e -> {
  666. ExpenseRelationship er=new ExpenseRelationship();
  667. er.setId(in.getId());
  668. er.setEaId(e.getId());
  669. expenseRelationshipMapper.insertSelective(er);
  670. });
  671. expenseAccountMapper.updateByIds(list,1);
  672. return in.getId();
  673. }
  674. @Override
  675. public MainExpenseAccount mainExpense(Integer id) {
  676. MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
  677. res.setExamine(0);
  678. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, res.getProcessStatus());
  679. for (ExpenseAccountExamine e : expenseAccountExamines) {
  680. if (e.getAuditor().equals(TokenManager.getAdminId())){
  681. res.setExamine(1);
  682. break;
  683. }
  684. }
  685. if (res.getAid().equals(TokenManager.getAdminId())){
  686. res.setExamine(2);
  687. }
  688. return res;
  689. }
  690. @Override
  691. public Object updateMain(MainExpenseAccount in) {
  692. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  693. if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
  694. throw new BusinessException("主项目已发起,不可修改!");
  695. }
  696. ExpenseAccount update =new ExpenseAccount();
  697. if (in.getStatus()==null)in.setStatus(1);
  698. if (in.getStatus()==1){
  699. if (in.getOrderNo()!=null){
  700. update.setOrderNo(in.getOrderNo());
  701. update.setTargetType(1);
  702. }
  703. if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
  704. if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
  705. if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
  706. if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
  707. addExpenseAccountExamine(in.getId(),update);
  708. if (outExpenseAccount.getStatus()==0){
  709. addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
  710. }else if (outExpenseAccount.getStatus()==3){
  711. addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
  712. }
  713. }else if (in.getStatus()==4){
  714. expenseAccountMapper.updateByMainId(in.getId(),0);
  715. addExpenseAccountLog(in.getId(),4,0,in.getAid(),"撤销报销审核");
  716. }
  717. update.setStatus(in.getStatus());
  718. update.setProcessStatus(outExpenseAccount.getProcessStatus());
  719. update.setId(in.getId());
  720. update.setExamineName(outExpenseAccount.getExamineName());
  721. return expenseAccountMapper.updateByPrimaryKeySelective(update);
  722. }
  723. @Override
  724. public Object mainList(ExpenseMainListInput in) {
  725. Map<String,Object> params = new HashMap<>();
  726. if (in.getStatus()!=null) params.put("status",in.getStatus());
  727. if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
  728. if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
  729. if (in.getUsername() != null)params.put("username",in.getUsername());
  730. if (in.getStartTime()!=null && in.getEndTime() !=null) {
  731. params.put("startTime",in.getStartTime());
  732. params.put("endTime",in.getEndTime()+" 23:59:59");
  733. }
  734. //1-3s是不同人的审核
  735. if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
  736. if (TokenManager.hasRole(AFTConstants.FINANCE)){
  737. in.setProcessStatus(3);
  738. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  739. in.setProcessStatus(1);
  740. }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
  741. in.setProcessStatus(4);
  742. }else if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  743. //财务经理查看权限
  744. in.setProcessStatus(6);
  745. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  746. //财务管理员和超级管理员查看全部
  747. in.setProcessStatus(5);
  748. }
  749. }else {
  750. in.setProcessStatus(0);
  751. }
  752. if (in.getProcessStatus()!=null){
  753. params.put("aid",TokenManager.getAdminId());
  754. params.put("roleType",in.getProcessStatus());
  755. if (in.getProcessStatus()==3){
  756. params.put("deps",departmentService.selectMyDeps());
  757. }
  758. }
  759. Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
  760. List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
  761. if (!list.isEmpty()){
  762. List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
  763. List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
  764. for (MainExpenseAccount e : list) {
  765. for (MainExpenseAccount me : mainExpenseAccounts) {
  766. if (e.getId().equals(me.getId())){
  767. e.setSonList(me.getSonList());
  768. }
  769. }
  770. }
  771. }
  772. return page;
  773. }
  774. @Override
  775. public Object detailsList(InputDetailsListBo in) {
  776. Map<String,Object> params = new HashMap<>();
  777. if(in.getStatus()!=null)params.put("status",in.getStatus());
  778. if(in.getType()!=null)params.put("type",in.getType());
  779. if (in.getDepId()!=null)params.put("depId",in.getDepId());
  780. if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
  781. if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
  782. if (in.getAname()!=null)params.put("aname",in.getAname());
  783. if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
  784. if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
  785. if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
  786. if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
  787. if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
  788. //0=自己 1=财务 2=财务经理 3=超管
  789. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  790. params.put("roleType",3);
  791. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  792. params.put("roleType",2);
  793. params.put("aid",TokenManager.getAdminId());
  794. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  795. params.put("roleType",1);
  796. params.put("aid",TokenManager.getAdminId());
  797. }else{
  798. params.put("roleType",0);
  799. }
  800. return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
  801. }
  802. @Override
  803. public List<ExpenseAccount> selectByIds(List<String> list) {
  804. return expenseAccountMapper.selectByIds(list);
  805. }
  806. @Override
  807. public int selectCountByIdsAndType(List<String> list, Integer i) {
  808. return expenseAccountMapper.selectCountByIdsAndType(list,i);
  809. }
  810. @Override
  811. public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
  812. ExpenseAccountDetails ea= new ExpenseAccountDetails();
  813. ea.setId(id);
  814. ea.setRealAmount(amount);
  815. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
  816. expenseAccountMapper.updateSonByDetId(id);
  817. expenseAccountMapper.updateMainByDetId(id);
  818. return 1;
  819. }
  820. /**
  821. * 计算当前报销显示抵扣金额
  822. * @param useEa
  823. */
  824. private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
  825. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
  826. List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
  827. BigDecimal count =debit.getRealAmount();
  828. for (ExpenseAccount e : list1) {
  829. if (!e.getId().equals(useEa.getId())){
  830. count=count.subtract(e.getSettlementAmount());
  831. }
  832. }
  833. if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
  834. useEa.setDebitTotalAmount(count);
  835. }
  836. /**
  837. * 判断角色是否已经审核
  838. * @param useEa
  839. */
  840. private void pushExpenseAccountGetExamine(OutExpenseAccount useEa) {
  841. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(useEa.getId(), useEa.getProcessStatus());
  842. boolean flag=false;
  843. for (ExpenseAccountExamine e : list) {
  844. if (e.getAuditor().equals(TokenManager.getAdminId())){
  845. if (e.getStatus()==0){
  846. flag=true;
  847. break;
  848. }
  849. }
  850. }
  851. if (flag){
  852. useEa.setExamine(1);
  853. }else {
  854. useEa.setExamine(0);
  855. }
  856. }
  857. /**
  858. * 判断角色是否已经审核
  859. * @param
  860. */
  861. private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
  862. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
  863. boolean flag=false;
  864. for (ExpenseAccountExamine e : list) {
  865. if (e.getAuditor().equals(TokenManager.getAdminId())){
  866. if (e.getStatus()==0){
  867. flag=true;
  868. break;
  869. }
  870. }
  871. }
  872. if (flag){
  873. return 1;
  874. }else {
  875. return 0;
  876. }
  877. }
  878. @Override
  879. public Object updateType(InputExpenseAccount in) {
  880. expenseAccountDetailsMapper.deleteByeaid(in.getId());
  881. if (in.getType()!=2)in.setSecondaryType(0);
  882. in.setSettlementAmount(new BigDecimal(0));
  883. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  884. }
  885. @Override
  886. public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
  887. String aid= TokenManager.getAdminId();
  888. List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
  889. return list;
  890. }
  891. private void addParam(InputPageListBo in, Map<String, Object> param) {
  892. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  893. param.put("startTime",in.getStartTime());
  894. param.put("endTime",in.getEndTime()+" 23:59:59");
  895. }
  896. if (in.getStatus()!=null)param.put("status",in.getStatus());
  897. //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
  898. if (in.getProcessStatus()==null) in.setProcessStatus(0);
  899. if(in.getProcessStatus()==2){
  900. if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  901. //财务经理查看权限
  902. in.setProcessStatus(5);
  903. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  904. TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  905. //财务管理员和超级管理员查看全部
  906. in.setProcessStatus(6);
  907. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  908. //0 设置为财务查看
  909. param.put("roleType",0);
  910. }
  911. if (in.getAid()!=null){
  912. param.put("aid",in.getAid());
  913. }
  914. param.put("auditor",TokenManager.getAdminId());
  915. }else if(in.getProcessStatus()==1) {
  916. param.put("auditor",TokenManager.getAdminId());
  917. if (in.getAid()!=null){
  918. param.put("aid",in.getAid());
  919. }
  920. }else {
  921. param.put("aid",TokenManager.getAdminId());
  922. }
  923. param.put("processStatus",in.getProcessStatus());
  924. if (in.getExamineStatus()!=null){
  925. param.put("examineStatus",in.getExamineStatus());
  926. }else {
  927. param.put("examineStatus",0);
  928. }
  929. if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
  930. if (in.getDepId()!=null)param.put("depId",in.getDepId());
  931. if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
  932. if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
  933. if (in.getType()!=null)param.put("type",in.getType());
  934. if (in.getUsername()!=null)param.put("username",in.getUsername());
  935. if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
  936. if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
  937. //固定传0查看子列表
  938. if (in.getExpenseMain()==null)in.setExpenseMain(0);
  939. if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
  940. }
  941. /**
  942. * 检查权限判断是否是总裁、董事长或超级管理员权限
  943. * @return
  944. */
  945. private boolean checkShiroCED() {
  946. if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
  947. TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
  948. ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  949. return true;
  950. }
  951. return false;
  952. }
  953. @Override
  954. @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
  955. public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
  956. if (endTime != null) endTime = endTime + " 23:59:59";
  957. List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
  958. List<OutExpenseAccountStatistics> results = new ArrayList<>();
  959. Map<String, Object> map = new HashMap<>();
  960. for (OutMyEAStatistics e : list) {
  961. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
  962. out.setAname(e.getAname());
  963. if (e.getStatus() == 2) {
  964. if (e.getType() < 4) {
  965. out.setBx(1);
  966. out.setBxAmount(e.getTotalAmount());
  967. if (!e.getDebitId().equals(0)) {
  968. out.setDk(1);
  969. out.setDkAmount(e.getBxdkAmount());
  970. }
  971. } else if (e.getType() == 4) {
  972. out.setJz(1);
  973. out.setJzAmount(e.getTotalAmount());
  974. } else if (e.getType() == 5) {
  975. out.setDk(1);
  976. out.setDkAmount(e.getTotalAmount());
  977. }
  978. if (e.getTargetType() == 0) {
  979. out.setGdfyAmount(e.getTotalAmount());
  980. } else if (e.getTargetType() == 1) {
  981. out.setBxddAmount(e.getTotalAmount());
  982. }
  983. } else if (e.getStatus() == 1) {
  984. out.setWshs(1);
  985. } else if (e.getStatus() == 3) {
  986. out.setBhs(1);
  987. }
  988. //如果不存在就新增
  989. if (!map.keySet().contains(out.getAid())) {
  990. List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
  991. list2.add(out);
  992. map.put(out.getAid(), list2);
  993. } else {
  994. List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
  995. list2.add(out);
  996. }
  997. }
  998. for (String s : map.keySet()) {
  999. List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
  1000. if (!list3.isEmpty()) {
  1001. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
  1002. for (OutExpenseAccountStatistics e : list3) {
  1003. if (out.getAname() == null) out.setAname(e.getAname());
  1004. if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
  1005. if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
  1006. if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
  1007. if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
  1008. if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
  1009. if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
  1010. if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
  1011. if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
  1012. if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
  1013. if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
  1014. }
  1015. BigDecimal totalAmount = new BigDecimal(0);
  1016. totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
  1017. out.setTotalAmount(totalAmount);
  1018. results.add(out);
  1019. }
  1020. }
  1021. return results;
  1022. }
  1023. @Override
  1024. @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
  1025. public void statisticsEvict(String name, String depId, String startTime, String endTime) {
  1026. LoggerUtils.debug(getClass(), "报销统计缓存清除。");
  1027. }
  1028. @Override
  1029. public Object pushSupplementCheckNo() {
  1030. List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
  1031. if (!list.isEmpty()){
  1032. list.forEach(e ->{
  1033. ExpenseAccount ea=new ExpenseAccount();
  1034. ea.setId(e.getId());
  1035. ea.setCheckNo(idGenerator.getNOgenerateId());
  1036. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  1037. });
  1038. return 1;
  1039. }
  1040. return 0;
  1041. }
  1042. @Override
  1043. public void pushAll() {
  1044. List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
  1045. for (ExpenseAccount ea : list) {
  1046. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
  1047. List<String> typeList=new ArrayList<>();
  1048. for (ExpenseAccount e : expenseAccounts) {
  1049. StringBuffer types=new StringBuffer();
  1050. if (e.getType()!=0){
  1051. types=types.append(EATypes.getDescByCode(e.getType()));
  1052. }else {
  1053. types=types.append(e.getTypeOther());
  1054. }
  1055. if (e.getType()==2){
  1056. if (e.getSecondaryType()==0){
  1057. types=types.append("-").append(e.getSecondaryTypeOther());
  1058. }else{
  1059. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1060. types=types.append("-").append(descByCode);
  1061. }
  1062. }
  1063. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1064. }
  1065. String typeStr = String.join(",", typeList);
  1066. ExpenseAccount update=new ExpenseAccount();
  1067. update.setId(ea.getId());
  1068. update.setTypeOther(typeStr);
  1069. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1070. }
  1071. }
  1072. }