ExpenseAccountServiceImpl.java 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  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.common.utils.excel.NewExcelUtil;
  15. import com.goafanti.core.mybatis.BaseMybatisDao;
  16. import com.goafanti.core.mybatis.JDBCIdGenerator;
  17. import com.goafanti.core.mybatis.page.Pagination;
  18. import com.goafanti.core.shiro.token.TokenManager;
  19. import com.goafanti.expenseAccount.Enums.EAProcessStatus;
  20. import com.goafanti.expenseAccount.Enums.EATypes;
  21. import com.goafanti.expenseAccount.Enums.EAsecondaryTypes;
  22. import com.goafanti.expenseAccount.bo.*;
  23. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  24. import com.goafanti.organization.bo.OrganizationListOut;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.cache.annotation.CacheEvict;
  28. import org.springframework.cache.annotation.Cacheable;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import java.math.BigDecimal;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. @Service
  35. public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
  36. @Autowired
  37. private AdminMapper adminMapper;
  38. @Autowired
  39. private ExpenseAccountMapper expenseAccountMapper;
  40. @Autowired
  41. private PublicReleaseMapper publicReleaseMapper;
  42. @Autowired
  43. private ExpenseAccountLogMapper expenseAccountLogMapper;
  44. @Autowired
  45. private AsyncUtils asyncUtils;
  46. @Autowired
  47. private WeChatUtils weChatUtils;
  48. @Autowired
  49. private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
  50. @Autowired
  51. private ExpenseAccountPrivateMapper expenseAccountPrivateMapper;
  52. @Autowired
  53. private ExpenseAccountExamineMapper expenseAccountExamineMapper;
  54. @Autowired
  55. private JDBCIdGenerator idGenerator;
  56. @Autowired
  57. private FinanceCountMapper financeCountMapper;
  58. @Autowired
  59. private ExpenseRelationshipMapper expenseRelationshipMapper;
  60. @Autowired
  61. private DepartmentService departmentService;
  62. @Autowired
  63. private DepartmentMapper departmentMapper;
  64. @Autowired
  65. private ExpenseConfigDetailsMapper expenseConfigDetailsMapper;
  66. @Value(value = "${upload.path}")
  67. private final String uploadPath = null;
  68. @Override
  69. public Integer add(InputExpenseAccount in) {
  70. //如果关联公出,获取公出信息
  71. if (in.getPrid()!=null){
  72. PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid());
  73. in.setReleaseStart(pr.getReleaseStart());
  74. in.setReleaseEnd(pr.getReleaseEnd());
  75. in.setDistrictName(pr.getDistrictName());
  76. in.setUserNames(pr.getUserNames());
  77. in.setDuration(pr.getDuration());
  78. if (in.getOrderNo()==null)in.setOrderNo(pr.getOrderNo());
  79. }
  80. //判断报销类型,0=固定费用,1=报销到订单
  81. if (in.getOrderNo()==null){
  82. in.setTargetType(0);
  83. }else {
  84. in.setTargetType(1);
  85. }
  86. if (in.getAid()==null)in.setAid(TokenManager.getAdminId());
  87. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  88. in.setAname(admin.getName());
  89. in.setApplyDep(admin.getDepartmentId());
  90. in.setPayDep(admin.getDepartmentId());
  91. expenseAccountMapper.insertSelective(in);
  92. return in.getId();
  93. }
  94. /**
  95. * 新增报销审核流程
  96. */
  97. private void addExpenseAccountExamine(Integer id,ExpenseAccount ea) {
  98. List<ExpenseAccountExamine> list=new ArrayList<>();
  99. String aid = TokenManager.getAdminId();
  100. OrganizationListOut dep = departmentMapper.selectAllById(ea.getApplyDep());
  101. AdminNoticeBo a = adminMapper.selectMyAndSuperBySuperId(aid);
  102. //暂时只发起到财务
  103. for (int i=1;i<4;i++){
  104. ExpenseAccountExamine eae=new ExpenseAccountExamine(id,i);
  105. if (i==1){
  106. //新增一级
  107. String examineId=null;
  108. String examineName=null;
  109. //正常用上级,没有的情况下就是自己
  110. if (a.getSuperId()!=null){
  111. examineId=a.getSuperId();
  112. examineName=a.getSuperName();
  113. }else {
  114. examineId=a.getId();
  115. examineName=a.getName();
  116. }
  117. eae.setAuditor(examineId);
  118. eae.setAuditorname(examineName);
  119. ea.setExamineName(examineName);
  120. }else if (i==2){
  121. if (StringUtils.isBlank(dep.getManagerName())){
  122. throw new BusinessException("报销申请部门[管理员]不存在。");
  123. }
  124. eae.setAuditor(dep.getManagerId());
  125. eae.setAuditorname(dep.getManagerName());
  126. }else if (i==3){
  127. if (StringUtils.isBlank(dep.getExpenseFinanceName()))throw new BusinessException("报销部门财务审核人不存在。");
  128. eae.setAuditor(dep.getExpenseFinanceId());
  129. eae.setAuditorname(dep.getExpenseFinanceName());
  130. }
  131. if (StringUtils.isNotEmpty(eae.getAuditor())){
  132. if (eae.getAuditor().equals(aid))eae.setStatus(1);
  133. else eae.setStatus(0);
  134. list.add(eae);
  135. }
  136. }
  137. expenseAccountExamineMapper.insertBatch(list);
  138. }
  139. /**
  140. * 新增报销日志
  141. * @param eaid 报销编号
  142. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  143. * @param str 备注
  144. */
  145. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str) {
  146. addExpenseAccountLog(eaid,status,processStatus,aid,str,null);
  147. }
  148. /**
  149. * 新增报销日志
  150. * @param eaid 报销编号
  151. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  152. * @param str 备注
  153. */
  154. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str,Date date) {
  155. ExpenseAccountLog eaLog=new ExpenseAccountLog();
  156. eaLog.setEaid(eaid);
  157. eaLog.setStatus(status);
  158. eaLog.setRemarks(str);
  159. eaLog.setProcessStatus(processStatus);
  160. eaLog.setAuditor(aid);
  161. if (date !=null)eaLog.setCreateTime(date);
  162. expenseAccountLogMapper.insertSelective(eaLog);
  163. }
  164. /**
  165. * 发起、驳回发起流程切换和日志站内信发送
  166. */
  167. private void addExpenseAccountLogAndNoticEmail(ExpenseAccount in, Integer status, String str) {
  168. String aid=TokenManager.getAdminId();
  169. addExpenseAccountLog(in.getId(),status,in.getProcessStatus(),aid,str);
  170. if (status==0)in.setProcessStatus(1);
  171. Admin admin = adminMapper.selectByPrimaryKey(aid);
  172. if (admin.getExpenseSuperExamine()==0){
  173. String str2=String.format("未设置[%s]审核。",EAProcessStatus.getDesc(in.getProcessStatus()));
  174. Date date=new Date();
  175. date.setTime(date.getTime()+1000L);
  176. addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date);
  177. in.setProcessStatus(in.getProcessStatus()+1);
  178. }else {
  179. if (admin.getSuperiorId()==null||admin.getId().equals(admin.getSuperiorId())){
  180. String str2=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(in.getProcessStatus()));
  181. Date date=new Date();
  182. date.setTime(date.getTime()+1000L);
  183. addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date);
  184. in.setProcessStatus(in.getProcessStatus()+1);
  185. }
  186. }
  187. createExamineByProcess(in);
  188. }
  189. /**
  190. * 判断审核流程与发送日志与邮件
  191. */
  192. private void createExamineByProcess(ExpenseAccount in) {
  193. //审核流程推送到最新
  194. AdminListBo admin = adminMapper.getDeptNameByAid(in.getAid());
  195. OrganizationListOut dep = departmentMapper.selectAllById(in.getApplyDep());
  196. List<ExpenseConfigDetails> configDetailsList = expenseConfigDetailsMapper.selectByDepId(in.getApplyDep());
  197. if (in.getApproval()==null)in.setApproval(0);
  198. examineByprocess(in,admin,dep,configDetailsList);
  199. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(in.getId(), in.getProcessStatus());
  200. List<Admin> aids=new ArrayList<>();
  201. StringBuffer aname =new StringBuffer();
  202. for (ExpenseAccountExamine e : list) {
  203. if (e.getProcessStatus()==in.getProcessStatus()&&e.getStatus()==0){
  204. Admin ad = adminMapper.selectByPrimaryKey(e.getAuditor());
  205. aids.add(ad);
  206. aname=aname.append(ad.getName()).append(",");
  207. }
  208. }
  209. in.setExamineName(aname.substring(0,aname.length()-1));
  210. StringBuffer str=new StringBuffer().append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  211. addNoticeAndEmail(in, EAProcessStatus.SJSH.getCode(),str.toString(), admin.getName(),aids);
  212. }
  213. @Override
  214. @Transactional
  215. public int update(InputExpenseAccount in) {
  216. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  217. if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
  218. throw new BusinessException("不能操作审核中与完成的订单");
  219. }
  220. if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
  221. in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  222. in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  223. }
  224. //计算总金额
  225. if (in.getTotalAmount()==null){
  226. pushExpenseAccountAmount(in);
  227. }
  228. in.setProcessStatus(0);
  229. if (in.getOrderNo()==null){
  230. in.setTargetType(0);
  231. }else {
  232. in.setTargetType(1);
  233. }
  234. //计算本单已扣金额 如果有选择借支单,则需要修改借支状态
  235. if (in.getDebitId()!=null){
  236. //如果以前没有选择借支,修改报销和借支数据
  237. if (useEA.getDebitId()==null){
  238. pushExpenseAccountDebit(in);
  239. }else if (useEA.getDebitId()!=in.getDebitId()) {
  240. //如果是修改编号
  241. pushExpenseAccountDebit(in);
  242. //并且要处理原编号的问题
  243. pushResettingDebit(in,useEA.getDebitId());
  244. }
  245. }
  246. if (in.getSettlementAmount()==null)in.setSettlementAmount(useEA.getSettlementAmount());
  247. in.setAmount(in.getRealAmount().subtract(in.getSettlementAmount()));
  248. in.setRealAmount(in.getAmount());
  249. in.setStatus(0);
  250. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  251. }
  252. private void pushExpenseAccountAmount(ExpenseAccount in) {
  253. List<OutExpenseAccountDetails> list = expenseAccountDetailsMapper.selectByEAid(in.getId());
  254. BigDecimal totalAmount = BigDecimal.ZERO;
  255. BigDecimal realAmount = BigDecimal.ZERO;
  256. for (OutExpenseAccountDetails e : list) {
  257. totalAmount=totalAmount.add(e.getAmount());
  258. realAmount=realAmount.add(e.getRealAmount());
  259. }
  260. in.setTotalAmount(totalAmount);
  261. in.setRealAmount(realAmount);
  262. }
  263. @Override
  264. public Object updateDebitId(InputExpenseAccount in) {
  265. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  266. if (useEA.getDebitId()!=null)pushResettingDebit(in,useEA.getDebitId());
  267. expenseAccountMapper.updateDeleteDebitId(in.getId());
  268. return 1;
  269. }
  270. @Override
  271. public Object delete(String ids) {
  272. String[] split = ids.split(",");
  273. for (String s : split) {
  274. Integer id=Integer.valueOf(s);
  275. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(id);
  276. if (expenseAccount.getStatus()!=0&&expenseAccount.getStatus()!=3){
  277. throw new BusinessException("该费用单状态无法删除");
  278. }
  279. ExpenseAccount update =new ExpenseAccount();
  280. update.setId(id);
  281. update.setStatus(4);
  282. expenseAccountMapper.updateByPrimaryKeySelective(update);
  283. }
  284. return 1;
  285. }
  286. @Override
  287. public Object pageListExport(InputPageListBo in) {
  288. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pageList(in).getList();
  289. for (OutExpenseAccountBo e : list) {
  290. if (e.getTargetType()!=null){
  291. if (e.getTargetType()==0){
  292. e.setTargetName("固定费用");
  293. }else {
  294. e.setTargetName(e.getContractNo()+"-"+e.getBuyerName());
  295. }
  296. }
  297. if (e.getType()!=0){
  298. e.setTypeOther(EATypes.getDescByCode(e.getType()));
  299. }else{
  300. e.setTypeOther(String.format("其他(%s)",e.getTypeOther()));
  301. }
  302. }
  303. NewExcelUtil excelUtil=new NewExcelUtil(OutExpenseAccountBo.class);
  304. return excelUtil.exportExcel(list,"费用单列表",uploadPath);
  305. }
  306. @Override
  307. public Object detailsListExport(InputDetailsListBo in) {
  308. List<OutExpenseAccountDetailsList> list = (List<OutExpenseAccountDetailsList>) detailsList(in).getList();
  309. for (OutExpenseAccountDetailsList e : list) {
  310. if (e.getTargetType()!=null){
  311. if (e.getTargetType()==0){
  312. e.setTargetName("固定费用");
  313. }else {
  314. e.setTargetName(e.getContractNo()+"-"+e.getBuyerName());
  315. }
  316. }
  317. if (e.getType()!=0){
  318. e.setTypeOther(EAsecondaryTypes.getDescByCode(e.getType()));
  319. }else{
  320. //如果是其他,又说明显示说明,没有说明显示费用类型
  321. if (StringUtils.isBlank(e.getTypeOther())){
  322. if (e.getSonType()!=0){
  323. e.setTypeOther(EATypes.getDescByCode(e.getSonType()));
  324. }else{
  325. e.setTypeOther(String.format("其他(%s)",e.getSonTypeOther()));
  326. }
  327. }else {
  328. e.setTypeOther(String.format("其他(%s)",e.getTypeOther()));
  329. }
  330. }
  331. }
  332. NewExcelUtil excelUtil=new NewExcelUtil(OutExpenseAccountDetailsList.class);
  333. return excelUtil.exportExcel(list,"费用详细列表",uploadPath);
  334. }
  335. private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
  336. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);
  337. List<ExpenseAccount> list = expenseAccountMapper.selectByDebitId(debitId);
  338. ExpenseAccount newDebit=new ExpenseAccount();
  339. newDebit.setId(debitId);
  340. //计算除开当前单,已选择抵扣金额
  341. BigDecimal count=new BigDecimal(0);
  342. for (ExpenseAccount e : list) {
  343. if (!in.getId().equals(e.getId())){
  344. count=count.add(e.getSettlementAmount());
  345. }
  346. }
  347. newDebit.setSettlementAmount(count);
  348. if (count.compareTo(new BigDecimal(0))==0){
  349. newDebit.setLiquidationStatus(0);
  350. }else if (count.compareTo(debit.getRealAmount())<0){
  351. newDebit.setLiquidationStatus(1);
  352. }else if (count.compareTo(debit.getRealAmount())==0){
  353. newDebit.setLiquidationStatus(2);
  354. }
  355. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  356. }
  357. private void pushExpenseAccountDebit(InputExpenseAccount in) {
  358. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(in.getDebitId());
  359. ExpenseAccount newDebit=new ExpenseAccount();
  360. newDebit.setId(debit.getId());
  361. //计算剩余需要支付金额
  362. BigDecimal decbitAmount=debit.getRealAmount().subtract(debit.getSettlementAmount());
  363. //本次金额大于等于需要抵扣金额,则变成完全抵扣,抵扣金额变成本次已付金额
  364. if (in.getRealAmount().compareTo(decbitAmount)>=0){
  365. in.setSettlementAmount(decbitAmount);
  366. newDebit.setSettlementAmount(debit.getRealAmount());
  367. newDebit.setLiquidationStatus(2);
  368. }else {
  369. // 本次金额小于需要抵扣,则本次变更全抵扣,借支已付加上本次金额
  370. in.setSettlementAmount(in.getRealAmount());
  371. BigDecimal setAmount=new BigDecimal(0).add(debit.getSettlementAmount()).add(in.getRealAmount());
  372. newDebit.setSettlementAmount(setAmount);
  373. newDebit.setLiquidationStatus(1);
  374. }
  375. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  376. }
  377. @Override
  378. public int addDetails(InputExpenseAccountDetails in) {
  379. if (in.getAgreeTimes()!=null){
  380. in.setAgreeTime(DateUtils.StringToDate(in.getAgreeTimes(),AFTConstants.YYYYMMDD));
  381. }
  382. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(in.getEaid());
  383. if (expenseAccount.getType()==2){
  384. in.setType(expenseAccount.getSecondaryType());
  385. if (in.getType()==0){
  386. in.setTypeOther(expenseAccount.getSecondaryTypeOther());
  387. }
  388. }
  389. in.setRealAmount(in.getAmount());
  390. expenseAccountDetailsMapper.insertSelective(in);
  391. ExpenseAccount ea =new ExpenseAccount();
  392. ea.setId(in.getEaid());
  393. pushExpenseAccountAmount(ea);
  394. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  395. return 1;
  396. }
  397. @Override
  398. public int deleteDetails(Integer id) {
  399. expenseAccountDetailsMapper.deleteByPrimaryKey(id);
  400. ExpenseAccount ea =new ExpenseAccount();
  401. ea.setId(id);
  402. pushExpenseAccountAmount(ea);
  403. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  404. return 1;
  405. }
  406. @Override
  407. public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
  408. return expenseAccountDetailsMapper.selectByEAid(eaid);
  409. }
  410. @Override
  411. public Object logList(Integer eaid) {
  412. List<OutExpenseAccountLog> list = expenseAccountLogMapper.selectByEaid(eaid);
  413. if (!list.isEmpty()) {
  414. OutExpenseAccountLog lastout = list.get(list.size() - 1);
  415. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(eaid);
  416. Integer processStatus = lastout.getProcessStatus();
  417. if (lastout.getStatus() != 3) {
  418. if (processStatus <3){
  419. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountExamineMapper.selectNotExamineByEaidAndProcessStatus(eaid, processStatus);
  420. list.addAll(outExpenseAccountLogs);
  421. }
  422. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(eaid, processStatus);
  423. for (ExpenseAccountExamine e : expenseAccountExamines) {
  424. if (e.getStatus()==0){
  425. OutExpenseAccountLog out =new OutExpenseAccountLog();
  426. out.setEaid(eaid);
  427. out.setProcessStatus(e.getProcessStatus());
  428. out.setAuditorName(e.getAuditorname());
  429. list.add(out);
  430. }
  431. }
  432. if (processStatus<8)addDetailsLog(list, expenseAccount,processStatus);
  433. }
  434. }
  435. return list;
  436. }
  437. private void addDetailsLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount,Integer useStatus) {
  438. OrganizationListOut dep = departmentMapper.selectAllById(expenseAccount.getApplyDep());
  439. List<ExpenseConfigDetails> configDetails = expenseConfigDetailsMapper.selectByDepId(expenseAccount.getApplyDep());
  440. for (int processStatus = useStatus; processStatus < 8; processStatus++) {
  441. if (processStatus ==3){
  442. if (dep.getExpenseRetrialFinanceExamine()==1){
  443. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  444. for (ExpenseConfigDetails e : collect) {
  445. addDetailsTypeLog(list, expenseAccount, e);
  446. }
  447. }
  448. }else if (processStatus ==4){
  449. if (expenseAccount.getApproval()==1&&dep.getCeoExamine()==1){
  450. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 2).collect(Collectors.toList());
  451. for (ExpenseConfigDetails e : collect) {
  452. addDetailsTypeLog(list, expenseAccount, e);
  453. }
  454. }
  455. }else if (processStatus ==5){
  456. if (dep.getCfoExamine()==1){
  457. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 3).collect(Collectors.toList());
  458. for (ExpenseConfigDetails e : collect) {
  459. addDetailsTypeLog(list, expenseAccount, e);
  460. }
  461. }
  462. }else if (processStatus ==6){
  463. if (dep.getViceCeoExamine()==1){
  464. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  465. for (ExpenseConfigDetails e : collect) {
  466. addDetailsTypeLog(list, expenseAccount, e);
  467. }
  468. }
  469. }else if (processStatus ==7){
  470. if (dep.getCashierExamine()==1){
  471. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 5).collect(Collectors.toList());
  472. for (ExpenseConfigDetails e : collect) {
  473. addDetailsTypeLog(list, expenseAccount, e);
  474. }
  475. }
  476. }
  477. }
  478. }
  479. private static void addDetailsTypeLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount, ExpenseConfigDetails e) {
  480. OutExpenseAccountLog addLog=new OutExpenseAccountLog();
  481. addLog.setEaid(expenseAccount.getId());
  482. addLog.setAuditor(e.getAid());
  483. addLog.setAuditorName(e.getAdminName());
  484. list.add(addLog);
  485. }
  486. @Override
  487. public int updateExamine(InputExpenseAccount in) {
  488. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  489. ExpenseAccount newEa=new ExpenseAccount();
  490. newEa.setId(useEa.getId());
  491. newEa.setApproval(in.getApproval());
  492. in.setCheckNo(useEa.getCheckNo());
  493. in.setProcessStatus(useEa.getProcessStatus());
  494. //审核通知 获取发送人
  495. AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
  496. //项目推送流程及添加日志
  497. addExamineExpenseAccountLog(admin,in, useEa, newEa);
  498. //完成申请
  499. if (newEa.getStatus()==2){
  500. //如果是借支则订单新增
  501. List<ExpenseAccount> expenseAccounts1 = expenseAccountMapper.selectListByMainId(in.getId());
  502. for (ExpenseAccount e : expenseAccounts1) {
  503. if (e.getType()!=4){
  504. //不然就看是否挂载借支订单进行抵扣
  505. if (e.getDebitId()!=null){
  506. ExpenseAccount useDebit=expenseAccountMapper.selectByPrimaryKey(e.getDebitId());
  507. if (useDebit.getLiquidationStatus()==2){
  508. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByDebitId(e.getDebitId());
  509. boolean flag=true;
  510. for (ExpenseAccount expenseAccount : expenseAccounts) {
  511. if(!expenseAccount.getId().equals(in.getId())&&expenseAccount.getStatus()!=2){
  512. flag=false;
  513. break;
  514. }
  515. }
  516. if (flag){
  517. ExpenseAccount debit=new ExpenseAccount();
  518. debit.setId(e.getDebitId());
  519. debit.setLiquidationStatus(3);
  520. expenseAccountMapper.updateByPrimaryKeySelective(debit);
  521. }
  522. }
  523. }
  524. }
  525. ExpenseAccount updateSon=new ExpenseAccount();
  526. updateSon.setId(e.getId());
  527. updateSon.setStatus(2);
  528. expenseAccountMapper.updateByPrimaryKeySelective(updateSon);
  529. }
  530. }else if (newEa.getStatus()==1){
  531. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  532. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),0);
  533. //处理金额修改
  534. if(in.getRealList()!=null){
  535. List<Map> maps = JSONObject.parseArray(in.getRealList(), Map.class);
  536. for (Map map: maps) {
  537. Integer type= (Integer) map.get("type");
  538. Integer id= (Integer) map.get("id");
  539. BigDecimal amount= new BigDecimal(map.get("amount").toString());
  540. //type=1总计,type=2报销金额
  541. if(type==1){
  542. ExpenseAccount ea =new ExpenseAccount();
  543. ea.setId(id);
  544. ea.setRealAmount(amount);
  545. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  546. }else if (type==2){
  547. ExpenseAccountDetails ead=new ExpenseAccountDetails();
  548. ead.setId(id);
  549. ead.setRealAmount(amount);
  550. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ead);
  551. }
  552. }
  553. }
  554. }else if (newEa.getProcessStatus()==EAProcessStatus.CWSH.getCode()){
  555. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),1);
  556. }
  557. }else if (newEa.getStatus()==3){
  558. if (useEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  559. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),2);
  560. }else if (newEa.getProcessStatus()>EAProcessStatus.CWSH.getCode()){
  561. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),3);
  562. }
  563. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),null,0,0);
  564. }
  565. expenseAccountMapper.updateByPrimaryKeySelective(newEa);
  566. expenseAccountMapper.updateSonByMainId(newEa.getId());
  567. return 1;
  568. }
  569. private void addFinanceCount(String aid,Date startTime ) {
  570. String forDate=DateUtils.formatDate(startTime,AFTConstants.YYYYMMDD);
  571. addFinanceCount(aid,forDate);
  572. }
  573. private void addFinanceCount(String aid,String startTime ) {
  574. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  575. if (financeCount ==null){
  576. financeCount =FinanceCount.initialization(aid, startTime);
  577. financeCount.setExpenseCount(1);
  578. financeCount.setExpenseUnauditedCount(1);
  579. financeCountMapper.insertSelective(financeCount);
  580. }else {
  581. FinanceCount newFinanceCount =new FinanceCount();
  582. newFinanceCount.setId(financeCount.getId());
  583. newFinanceCount.setExpenseCount(financeCount.getExpenseCount()+1);
  584. newFinanceCount.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  585. financeCountMapper.updateByPrimaryKeySelective(newFinanceCount);
  586. }
  587. }
  588. private void addExamineExpenseAccountLog(AdminListBo admin,InputExpenseAccount in, ExpenseAccount useEa, ExpenseAccount newEa) {
  589. List<Admin> aids=new ArrayList<>();
  590. StringBuffer str=new StringBuffer();
  591. Integer status=in.getStatus();
  592. if (status==1){
  593. //审核处理审核表
  594. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,0);
  595. str=str.append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  596. newEa.setAid(useEa.getAid());
  597. newEa.setCreateTime(useEa.getCreateTime());
  598. newEa.setApplyDep(useEa.getApplyDep());
  599. //在跳入董事长审核的时候非特批直接跳过,原则上下个流程不可再跳过
  600. OrganizationListOut dep = departmentMapper.selectAllById(newEa.getApplyDep());
  601. List<ExpenseConfigDetails> configDetailsList = expenseConfigDetailsMapper.selectByDepId(newEa.getApplyDep());
  602. if(useEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  603. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,1);
  604. boolean expenseExamine = pushExpenseExamine(configDetailsList, newEa, EAProcessStatus.CNSH.getCode());
  605. if (expenseExamine){
  606. //完成后的流程
  607. status =2;
  608. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  609. newEa.setStatus(status);
  610. newEa.setExamineName("");
  611. }else {
  612. status =1;
  613. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), useEa.getProcessStatus());
  614. StringBuffer aname =new StringBuffer();
  615. for (ExpenseAccountExamine e : list) {
  616. if (e.getStatus()==0){
  617. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  618. aids.add(ad);
  619. aname=aname.append(ad.getName()).append(",");
  620. }
  621. }
  622. newEa.setExamineName(aname.substring(0,aname.length()-1));
  623. }
  624. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  625. }else {
  626. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  627. newEa.setStatus(1);
  628. if (useEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  629. newEa.setProcessStatus(useEa.getProcessStatus()+1);
  630. }else {
  631. newEa.setProcessStatus(useEa.getProcessStatus());
  632. }
  633. if (newEa.getApproval()==null)newEa.setApproval(useEa.getApproval());
  634. //流程的推动
  635. examineByprocess(newEa,admin,dep,configDetailsList);
  636. //推动到出纳如果设置无需则完成不设置下个人,否则就要设置
  637. if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  638. if(dep.getCashierExamine()==1){
  639. pushExamineName(newEa, aids);
  640. }else {
  641. //完成后的流程
  642. status =2;
  643. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  644. newEa.setStatus(status);
  645. newEa.setExamineName("");
  646. }
  647. }else {
  648. pushExamineName(newEa, aids);
  649. }
  650. }
  651. }else {
  652. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  653. newEa.setStatus(3);
  654. newEa.setProcessStatus(0);
  655. str.setLength(0);
  656. addExpenseAccountLog(in.getId(),newEa.getStatus(),useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  657. str=str.append("您的报销审核已驳回,报销编号[").append(in.getCheckNo()).append("],请注意查看。");
  658. }
  659. if (newEa.getStatus()==null)newEa.setStatus(1);
  660. addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
  661. }
  662. private void pushExamineName(ExpenseAccount newEa, List<Admin> aids) {
  663. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  664. StringBuffer aname =new StringBuffer();
  665. for (ExpenseAccountExamine e : list) {
  666. if (e.getProcessStatus()== newEa.getProcessStatus()&&e.getStatus()==0){
  667. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  668. aids.add(ad);
  669. aname=aname.append(ad.getName()).append(",");
  670. }
  671. }
  672. newEa.setExamineName(aname.substring(0,aname.length()-1));
  673. }
  674. /**
  675. *
  676. * @param aid
  677. * @param createTime
  678. * @param type 0 双新增 1 未审核减一 2双减 3总数减一
  679. */
  680. private void pushFinanceCount(String aid, Date createTime, Integer type) {
  681. String startTime= DateUtils.formatDate(createTime,AFTConstants.YYYYMMDD);
  682. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  683. FinanceCount newFinance=new FinanceCount();
  684. if (financeCount==null){
  685. newFinance=FinanceCount.initialization(aid,createTime);
  686. newFinance.setExpenseCount(1);
  687. newFinance.setExpenseUnauditedCount(1);
  688. financeCountMapper.insertSelective(newFinance);
  689. }else {
  690. newFinance.setId(financeCount.getId());
  691. if(type==0){
  692. newFinance.setExpenseCount(financeCount.getExpenseCount()+1);
  693. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  694. }else if(type==1){
  695. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  696. }else if(type==2){
  697. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  698. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  699. }else if(type==3){
  700. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  701. }
  702. financeCountMapper.updateByPrimaryKeySelective(newFinance);
  703. }
  704. }
  705. /**
  706. * 审核流程推送,只要不是完成状态就继续判断是否跳过
  707. * @param newEa
  708. */
  709. private void examineByprocess( ExpenseAccount newEa,AdminListBo admin,OrganizationListOut dep,List<ExpenseConfigDetails> list) {
  710. List<ExpenseAccountExamine> examineList=new ArrayList<>();
  711. //小于财务复审的,走单审核
  712. if (newEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  713. examineList = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  714. boolean flag=false;
  715. String aid="";
  716. if (examineList.size()>0){
  717. for (ExpenseAccountExamine e : examineList) {
  718. if (e.getStatus()==1){
  719. flag=true;
  720. aid=e.getAuditor();
  721. break;
  722. }
  723. }
  724. }
  725. //如果当前审核人已经审核,则跳过当前审核
  726. if (flag){
  727. String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
  728. Date date=new Date();
  729. date.setTime(date.getTime()+1000l);
  730. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date);
  731. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  732. addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
  733. }
  734. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  735. examineByprocess(newEa,admin,dep,list);
  736. }
  737. }else {
  738. //大于等于财务复审的,走多审核
  739. String str=null;
  740. //跳过标记
  741. boolean flag2= false;
  742. //审核通过标记
  743. boolean flag3= false;
  744. Date date2=new Date();
  745. date2.setTime(date2.getTime()+1000l);
  746. String tip=null;
  747. String aid=null;
  748. if (newEa.getProcessStatus()==EAProcessStatus.CWFS.getCode()){
  749. //财务复审财务复审
  750. if (dep.getExpenseRetrialFinanceExamine()==0){
  751. flag2=true;
  752. tip=EAProcessStatus.CWFS.getDesc();
  753. }else {
  754. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWFS.getCode());
  755. if (expenseExamine){
  756. flag3=true;
  757. }
  758. }
  759. }else if (newEa.getProcessStatus()==EAProcessStatus.DSZSH.getCode()){
  760. if (newEa.getApproval()!=1){
  761. flag2=true;
  762. tip="特批(财务选择)";
  763. }else {
  764. if (dep.getCeoExamine()==1){
  765. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.DSZSH.getCode());
  766. if (expenseExamine){
  767. flag3=true;
  768. }
  769. }else {
  770. flag2=true;
  771. tip="特批(部门设置)";
  772. }
  773. }
  774. }else if (newEa.getProcessStatus()==EAProcessStatus.CWGGLYSH.getCode()){
  775. if (dep.getExpenseRetrialFinanceExamine()==0){
  776. flag2=true;
  777. tip=EAProcessStatus.CWGGLYSH.getDesc();
  778. aid=null;
  779. }else {
  780. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWGGLYSH.getCode());
  781. if (expenseExamine){
  782. flag3=true;
  783. }
  784. }
  785. }else if (newEa.getProcessStatus()==EAProcessStatus.GSFSSH.getCode()){
  786. if (dep.getExpenseRetrialFinanceExamine()==0){
  787. flag2=true;
  788. tip=EAProcessStatus.GSFSSH.getDesc();
  789. }else {
  790. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.GSFSSH.getCode());
  791. if (expenseExamine){
  792. flag3=true;
  793. }
  794. }
  795. }else if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  796. if (dep.getExpenseRetrialFinanceExamine()==0){
  797. flag2=true;
  798. tip=EAProcessStatus.CNSH.getDesc();
  799. }else {
  800. //财务出纳在审核时不与前置审核做同步
  801. pushExpenseExamine(list, newEa, EAProcessStatus.CNSH.getCode());
  802. }
  803. }
  804. if (flag2){
  805. if (str==null)str=String.format("未设置[%s]审核,跳过此流程",tip);
  806. if (newEa.getProcessStatus()<EAProcessStatus.CNSH.getCode()){
  807. date2.setTime(date2.getTime()+100);
  808. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date2);
  809. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  810. examineByprocess(newEa,admin,dep,list);
  811. }else {
  812. date2.setTime(date2.getTime()+100);
  813. addExpenseAccountLog(newEa.getId(),2,newEa.getProcessStatus(),aid,str,date2);
  814. newEa.setProcessStatus(newEa.getProcessStatus());
  815. newEa.setStatus(2);
  816. }
  817. }else if (flag3){
  818. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  819. examineByprocess(newEa,admin,dep,list);
  820. }
  821. }
  822. }
  823. private boolean pushExpenseExamine(List<ExpenseConfigDetails> list, ExpenseAccount newEa, Integer status) {
  824. int configDetails=0;
  825. if (status==EAProcessStatus.CWFS.getCode())configDetails=1;
  826. else if (status==EAProcessStatus.DSZSH.getCode())configDetails=2;
  827. else if (status==EAProcessStatus.CWGGLYSH.getCode())configDetails=3;
  828. else if (status==EAProcessStatus.GSFSSH.getCode())configDetails=4;
  829. else if (status==EAProcessStatus.CNSH.getCode())configDetails=5;
  830. int finalConfigDetails = configDetails;
  831. //查询审核表,如果为空就新增,不然直接判定审核
  832. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), status);
  833. int count = 0;
  834. int size=10;
  835. if (expenseAccountExamines.isEmpty()){
  836. List<ExpenseConfigDetails> collect = list.stream().filter(e -> e.getType() == finalConfigDetails).collect(Collectors.toList());
  837. size= collect.size();
  838. for (ExpenseConfigDetails e : collect) {
  839. ExpenseAccountExamine eae=new ExpenseAccountExamine(newEa.getId(),status);
  840. eae.setAuditor(e.getAid());
  841. eae.setAuditorname(e.getAdminName());
  842. eae.setStatus(0);
  843. Integer i = expenseAccountExamineMapper.selectYesByParam(newEa.getId(), e.getAid());
  844. if (status==EAProcessStatus.CNSH.getCode()){
  845. eae.setStatus(0);
  846. count++;
  847. }else {
  848. if (i>0||e.getAid().equals(TokenManager.getAdminId())) {
  849. eae.setStatus(1);
  850. count++;
  851. }
  852. }
  853. expenseAccountExamineMapper.insertSelective(eae);
  854. }
  855. }else {
  856. size = expenseAccountExamines.size();
  857. for (ExpenseAccountExamine e : expenseAccountExamines) {
  858. if (e.getStatus()==1){
  859. count++;
  860. }
  861. }
  862. }
  863. if (count==size){
  864. return true;
  865. }
  866. return false;
  867. }
  868. private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
  869. Date date= new Date();
  870. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  871. if (status==2){
  872. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  873. }
  874. List<Notice> list=new ArrayList<>();
  875. if (aids!=null){
  876. for (Admin a : aids) {
  877. Notice notice=new Notice();
  878. notice.setId(UUID.randomUUID().toString());
  879. notice.setNoticeType(noticeStatus);
  880. notice.setType(NoticeTypes.getType(noticeStatus));
  881. notice.setAid(a.getId());
  882. notice.setCreateTime(date);
  883. notice.setContent(str);
  884. notice.setReaded(0);
  885. list.add(notice);
  886. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  887. asyncUtils.send(emailBo);
  888. try {
  889. weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
  890. }catch (Exception e){
  891. throw new BusinessException("网络通信异常,请稍后再试。");
  892. }
  893. }
  894. asyncUtils.addNoticeBatch(list);
  895. }
  896. }
  897. @Override
  898. public Pagination<?> pageList(InputPageListBo in) {
  899. Map<String ,Object> param=new HashMap<>();
  900. addParam(in, param);
  901. Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
  902. "selectExpenseAccountCount",
  903. "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
  904. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
  905. for (OutExpenseAccountBo e : list) {
  906. e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
  907. }
  908. return pagePlus;
  909. }
  910. @Override
  911. public Object selectByPrid(InputExpenseAccount in) {
  912. in.setAid(TokenManager.getAdminId());
  913. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  914. return useEa;
  915. }
  916. @Override
  917. public Object selectById(Integer id) {
  918. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  919. //判断当前角色是否审核
  920. useEa.setExamine(pushExpenseAccountGetExamine( id, useEa.getProcessStatus()));;
  921. if (useEa.getDebitId()!=null){
  922. pushExpenseAccountGetDebitAmount(useEa);
  923. }
  924. return useEa;
  925. }
  926. @Override
  927. public Object selectByCheckNo(String checkNo) {
  928. checkNo=checkNo.trim();
  929. OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
  930. if (useEa==null){
  931. throw new BusinessException("报销编号不存在,请客对后再查询。");
  932. }
  933. if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
  934. throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
  935. }
  936. return useEa;
  937. }
  938. @Override
  939. public Object pushMerge(List<ExpenseAccount> list) {
  940. //设置付款部门和支付部门
  941. InputExpenseAccount in =new InputExpenseAccount();
  942. in.setCheckNo(idGenerator.getNOgenerateId());
  943. if (in.getAid()==null){
  944. in.setAid(TokenManager.getAdminId());
  945. }
  946. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  947. in.setAname(admin.getName());
  948. in.setApplyDep(admin.getDepartmentId());
  949. in.setPayDep(admin.getDepartmentId());
  950. Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
  951. in.setEaaid(eaaid);
  952. BigDecimal count = new BigDecimal(0);
  953. BigDecimal amount = new BigDecimal(0);
  954. BigDecimal realAmount = new BigDecimal(0);
  955. List<String> typeList = new ArrayList<String>();
  956. for (ExpenseAccount e : list) {
  957. count=count.add(e.getTotalAmount());
  958. amount=amount.add(e.getAmount());
  959. realAmount=realAmount.add(e.getRealAmount());
  960. StringBuffer types=new StringBuffer();
  961. if (e.getType()!=0){
  962. types=types.append(EATypes.getDescByCode(e.getType()));
  963. }else {
  964. types=types.append(e.getTypeOther());
  965. }
  966. if (e.getType()==2){
  967. if (e.getSecondaryType()==0){
  968. types=types.append("-").append(e.getSecondaryTypeOther());
  969. }else{
  970. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  971. types=types.append("-").append(descByCode);
  972. }
  973. }
  974. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  975. }
  976. in.setTotalAmount(count);
  977. in.setAmount(amount);
  978. in.setRealAmount(realAmount);
  979. in.setExpenseMain(1);
  980. in.setTypeOther(String.join(",",typeList));
  981. expenseAccountMapper.insertSelective(in);
  982. List<OutExpenseAccountLog> newLog=new ArrayList<>();
  983. list.stream().forEach(e -> {
  984. ExpenseRelationship er=new ExpenseRelationship();
  985. er.setId(in.getId());
  986. er.setEaId(e.getId());
  987. expenseRelationshipMapper.insertSelective(er);
  988. List<OutExpenseAccountLog> listLog = expenseAccountLogMapper.selectByEaid(e.getId());
  989. for (OutExpenseAccountLog log : listLog) {
  990. if (!newLog.contains(log)){
  991. log.setEaid(in.getId());
  992. newLog.add(log);
  993. }
  994. }
  995. expenseAccountLogMapper.deleteByeaid(e.getId());
  996. });
  997. if (!newLog.isEmpty())expenseAccountLogMapper.insertBatch(newLog);
  998. expenseAccountMapper.updateByIds(list,1);
  999. return in.getId();
  1000. }
  1001. @Override
  1002. public MainExpenseAccount mainExpense(Integer id) {
  1003. MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
  1004. res.setExamine(0);
  1005. if (res.getAid().equals(TokenManager.getAdminId())){
  1006. res.setExamine(2);
  1007. }else {
  1008. res.setExamine(pushExpenseAccountGetExamine( id, res.getProcessStatus()));;
  1009. }
  1010. return res;
  1011. }
  1012. @Override
  1013. public Object updateMain(MainExpenseAccount in) {
  1014. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  1015. if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
  1016. throw new BusinessException("主项目已发起,不可修改!");
  1017. }
  1018. ExpenseAccount update =new ExpenseAccount();
  1019. if (in.getStatus()==null)in.setStatus(1);
  1020. if (in.getStatus()==1){
  1021. if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
  1022. if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
  1023. if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
  1024. if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
  1025. addExpenseAccountExamine(in.getId(),update);
  1026. if (outExpenseAccount.getStatus()==0){
  1027. addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
  1028. }else if (outExpenseAccount.getStatus()==3){
  1029. addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
  1030. }
  1031. update.setStatus(in.getStatus());
  1032. update.setProcessStatus(outExpenseAccount.getProcessStatus());
  1033. update.setId(in.getId());
  1034. update.setExamineName(outExpenseAccount.getExamineName());
  1035. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1036. }else if (in.getStatus()==4){
  1037. expenseAccountMapper.updateByMainId(in.getId(),0);
  1038. addExpenseAccountLog(in.getId(),4,0,TokenManager.getAdminId(),"撤销报销审核");
  1039. List<ExpenseRelationship> list = expenseRelationshipMapper.selectById(in.getId());
  1040. //撤销日志处理,先将日志改在挂子编号上,在新发起的时候再从自编号加到新编号上
  1041. if (list.size()==1){
  1042. ExpenseRelationship e =list.get(0);
  1043. expenseAccountLogMapper.updateUseLogByUseId(e.getEaId(),e.getId());
  1044. }else {
  1045. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountLogMapper.selectByEaid(in.getId());
  1046. for (int i=0;i<list.size();i++){
  1047. ExpenseRelationship e =list.get(i);
  1048. for (OutExpenseAccountLog eal : outExpenseAccountLogs) {
  1049. eal.setEaid(e.getEaId());
  1050. }
  1051. expenseAccountLogMapper.insertBatch(outExpenseAccountLogs);
  1052. }
  1053. }
  1054. expenseAccountLogMapper.deleteByeaid(in.getId());
  1055. expenseRelationshipMapper.deleteByPrimaryKey(in.getId());
  1056. expenseAccountMapper.deleteByPrimaryKey(in.getId());
  1057. }
  1058. return 1;
  1059. }
  1060. @Override
  1061. public Object mainList(ExpenseMainListInput in) {
  1062. Map<String,Object> params = new HashMap<>();
  1063. if (in.getStatus()!=null) params.put("status",in.getStatus());
  1064. if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
  1065. if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
  1066. if (in.getUsername() != null)params.put("username",in.getUsername());
  1067. if (in.getStartTime()!=null && in.getEndTime() !=null) {
  1068. params.put("startTime",in.getStartTime());
  1069. params.put("endTime",in.getEndTime()+" 23:59:59");
  1070. }
  1071. //1-3s是不同人的审核
  1072. if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
  1073. // 财务审核,复审,出纳都是财务与经理
  1074. if (TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1075. in.setProcessStatus(3);
  1076. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)){
  1077. in.setProcessStatus(1);
  1078. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  1079. in.setProcessStatus(2);
  1080. }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
  1081. in.setProcessStatus(5);
  1082. }else if(TokenManager.hasRole(AFTConstants.VICE_CEO)){
  1083. //先不做财务查看权限
  1084. in.setProcessStatus(7);
  1085. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)){
  1086. in.setProcessStatus(6);
  1087. }
  1088. }else {
  1089. in.setProcessStatus(0);
  1090. }
  1091. if (in.getProcessStatus()!=null){
  1092. params.put("aid",TokenManager.getAdminId());
  1093. params.put("roleType",in.getProcessStatus());
  1094. if (in.getProcessStatus()==3){
  1095. params.put("deps",departmentService.selectMyDeps());
  1096. }
  1097. }
  1098. Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
  1099. List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
  1100. if (!list.isEmpty()){
  1101. List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
  1102. List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
  1103. for (MainExpenseAccount e : list) {
  1104. for (MainExpenseAccount me : mainExpenseAccounts) {
  1105. if (e.getId().equals(me.getId())){
  1106. e.setSonList(me.getSonList());
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return page;
  1112. }
  1113. @Override
  1114. public Pagination<?> detailsList(InputDetailsListBo in) {
  1115. Map<String,Object> params = new HashMap<>();
  1116. if(in.getStatus()!=null)params.put("status",in.getStatus());
  1117. if(in.getType()!=null)params.put("type",in.getType());
  1118. if (in.getDepId()!=null)params.put("depId",in.getDepId());
  1119. if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
  1120. if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
  1121. if (in.getAname()!=null)params.put("aname",in.getAname());
  1122. if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
  1123. if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
  1124. if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
  1125. if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
  1126. if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
  1127. //0=自己 1=财务 2=财务经理 3=超管
  1128. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  1129. params.put("roleType",3);
  1130. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1131. params.put("roleType",2);
  1132. params.put("aid",TokenManager.getAdminId());
  1133. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1134. params.put("roleType",1);
  1135. params.put("aid",TokenManager.getAdminId());
  1136. }else{
  1137. params.put("roleType",0);
  1138. }
  1139. return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
  1140. }
  1141. @Override
  1142. public List<ExpenseAccount> selectByIds(List<String> list) {
  1143. return expenseAccountMapper.selectByIds(list);
  1144. }
  1145. @Override
  1146. public int selectCountByIdsAndType(List<String> list, Integer i) {
  1147. return expenseAccountMapper.selectCountByIdsAndType(list,i);
  1148. }
  1149. @Override
  1150. public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
  1151. ExpenseAccountDetails ea= new ExpenseAccountDetails();
  1152. ea.setId(id);
  1153. ea.setRealAmount(amount);
  1154. String name=TokenManager.getAdminToken().getName();
  1155. Integer eaid = expenseAccountDetailsMapper.selectExpenseAccountById(id);
  1156. addExpenseAccountLog(eaid,5,3,TokenManager.getAdminId(),String.format("财务[%s]修改实际报销金额为%s。",name,amount));
  1157. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
  1158. expenseAccountMapper.updateSonByDetId(id);
  1159. expenseAccountMapper.updateMainByDetId(id);
  1160. return 1;
  1161. }
  1162. /**
  1163. * 计算当前报销显示抵扣金额
  1164. * @param useEa
  1165. */
  1166. private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
  1167. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
  1168. List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
  1169. BigDecimal count =debit.getRealAmount();
  1170. for (ExpenseAccount e : list1) {
  1171. if (!e.getId().equals(useEa.getId())){
  1172. count=count.subtract(e.getSettlementAmount());
  1173. }
  1174. }
  1175. if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
  1176. useEa.setDebitTotalAmount(count);
  1177. }
  1178. /**
  1179. * 判断角色是否已经审核
  1180. * @param id 编号
  1181. * @param processStatus 审核状态
  1182. * @return 0 无需审核 1 需要审核
  1183. */
  1184. private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
  1185. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
  1186. boolean flag=false;
  1187. for (ExpenseAccountExamine e : list) {
  1188. if (e.getAuditor().equals(TokenManager.getAdminId())){
  1189. if (e.getStatus()==0){
  1190. flag=true;
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. if (flag){
  1196. return 1;
  1197. }else {
  1198. return 0;
  1199. }
  1200. }
  1201. @Override
  1202. public Object updateType(InputExpenseAccount in) {
  1203. expenseAccountDetailsMapper.deleteByeaid(in.getId());
  1204. if (in.getType()!=2)in.setSecondaryType(0);
  1205. in.setSettlementAmount(new BigDecimal(0));
  1206. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  1207. }
  1208. @Override
  1209. public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
  1210. String aid= TokenManager.getAdminId();
  1211. List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
  1212. return list;
  1213. }
  1214. private void addParam(InputPageListBo in, Map<String, Object> param) {
  1215. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  1216. param.put("startTime",in.getStartTime());
  1217. param.put("endTime",in.getEndTime()+" 23:59:59");
  1218. }
  1219. if (in.getStatus()!=null)param.put("status",in.getStatus());
  1220. //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
  1221. if (in.getProcessStatus()==null) in.setProcessStatus(0);
  1222. if(in.getProcessStatus()==2){
  1223. if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1224. //财务经理查看权限
  1225. in.setProcessStatus(5);
  1226. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  1227. TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  1228. //财务管理员和超级管理员查看全部
  1229. in.setProcessStatus(6);
  1230. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1231. //0 设置为财务查看
  1232. param.put("roleType",0);
  1233. }
  1234. if (in.getAid()!=null){
  1235. param.put("aid",in.getAid());
  1236. }
  1237. param.put("auditor",TokenManager.getAdminId());
  1238. }else if(in.getProcessStatus()==1) {
  1239. param.put("auditor",TokenManager.getAdminId());
  1240. if (in.getAid()!=null){
  1241. param.put("aid",in.getAid());
  1242. }
  1243. }else {
  1244. param.put("aid",TokenManager.getAdminId());
  1245. }
  1246. param.put("processStatus",in.getProcessStatus());
  1247. if (in.getExamineStatus()!=null){
  1248. param.put("examineStatus",in.getExamineStatus());
  1249. }else {
  1250. param.put("examineStatus",0);
  1251. }
  1252. if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
  1253. if (in.getDepId()!=null)param.put("depId",in.getDepId());
  1254. if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
  1255. if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
  1256. if (in.getType()!=null)param.put("type",in.getType());
  1257. if (in.getUsername()!=null)param.put("username",in.getUsername());
  1258. if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
  1259. if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
  1260. //固定传0查看子列表
  1261. if (in.getExpenseMain()==null)in.setExpenseMain(0);
  1262. if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
  1263. }
  1264. /**
  1265. * 检查权限判断是否是总裁、董事长或超级管理员权限
  1266. * @return
  1267. */
  1268. private boolean checkShiroCED() {
  1269. if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
  1270. TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
  1271. ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  1272. return true;
  1273. }
  1274. return false;
  1275. }
  1276. @Override
  1277. @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
  1278. public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
  1279. if (endTime != null) endTime = endTime + " 23:59:59";
  1280. List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
  1281. List<OutExpenseAccountStatistics> results = new ArrayList<>();
  1282. Map<String, Object> map = new HashMap<>();
  1283. for (OutMyEAStatistics e : list) {
  1284. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
  1285. out.setAname(e.getAname());
  1286. if (e.getStatus() == 2) {
  1287. if (e.getType() < 4) {
  1288. out.setBx(1);
  1289. out.setBxAmount(e.getTotalAmount());
  1290. if (!e.getDebitId().equals(0)) {
  1291. out.setDk(1);
  1292. out.setDkAmount(e.getBxdkAmount());
  1293. }
  1294. } else if (e.getType() == 4) {
  1295. out.setJz(1);
  1296. out.setJzAmount(e.getTotalAmount());
  1297. } else if (e.getType() == 5) {
  1298. out.setDk(1);
  1299. out.setDkAmount(e.getTotalAmount());
  1300. }
  1301. if (e.getTargetType() == 0) {
  1302. out.setGdfyAmount(e.getTotalAmount());
  1303. } else if (e.getTargetType() == 1) {
  1304. out.setBxddAmount(e.getTotalAmount());
  1305. }
  1306. } else if (e.getStatus() == 1) {
  1307. out.setWshs(1);
  1308. } else if (e.getStatus() == 3) {
  1309. out.setBhs(1);
  1310. }
  1311. //如果不存在就新增
  1312. if (!map.keySet().contains(out.getAid())) {
  1313. List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
  1314. list2.add(out);
  1315. map.put(out.getAid(), list2);
  1316. } else {
  1317. List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
  1318. list2.add(out);
  1319. }
  1320. }
  1321. for (String s : map.keySet()) {
  1322. List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
  1323. if (!list3.isEmpty()) {
  1324. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
  1325. for (OutExpenseAccountStatistics e : list3) {
  1326. if (out.getAname() == null) out.setAname(e.getAname());
  1327. if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
  1328. if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
  1329. if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
  1330. if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
  1331. if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
  1332. if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
  1333. if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
  1334. if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
  1335. if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
  1336. if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
  1337. }
  1338. BigDecimal totalAmount = new BigDecimal(0);
  1339. totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
  1340. out.setTotalAmount(totalAmount);
  1341. results.add(out);
  1342. }
  1343. }
  1344. return results;
  1345. }
  1346. @Override
  1347. @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
  1348. public void statisticsEvict(String name, String depId, String startTime, String endTime) {
  1349. LoggerUtils.debug(getClass(), "报销统计缓存清除。");
  1350. }
  1351. @Override
  1352. public Object pushSupplementCheckNo() {
  1353. List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
  1354. if (!list.isEmpty()){
  1355. list.forEach(e ->{
  1356. ExpenseAccount ea=new ExpenseAccount();
  1357. ea.setId(e.getId());
  1358. ea.setCheckNo(idGenerator.getNOgenerateId());
  1359. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  1360. });
  1361. return 1;
  1362. }
  1363. return 0;
  1364. }
  1365. @Override
  1366. public void pushAll() {
  1367. List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
  1368. for (ExpenseAccount ea : list) {
  1369. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
  1370. List<String> typeList=new ArrayList<>();
  1371. for (ExpenseAccount e : expenseAccounts) {
  1372. StringBuffer types=new StringBuffer();
  1373. if (e.getType()!=0){
  1374. types=types.append(EATypes.getDescByCode(e.getType()));
  1375. }else {
  1376. types=types.append(e.getTypeOther());
  1377. }
  1378. if (e.getType()==2){
  1379. if (e.getSecondaryType()==0){
  1380. types=types.append("-").append(e.getSecondaryTypeOther());
  1381. }else{
  1382. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1383. types=types.append("-").append(descByCode);
  1384. }
  1385. }
  1386. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1387. }
  1388. String typeStr = String.join(",", typeList);
  1389. ExpenseAccount update=new ExpenseAccount();
  1390. update.setId(ea.getId());
  1391. update.setTypeOther(typeStr);
  1392. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1393. }
  1394. }
  1395. }