ExpenseAccountServiceImpl.java 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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. deduplication(list);
  414. if (!list.isEmpty()) {
  415. OutExpenseAccountLog lastout = list.get(list.size() - 1);
  416. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(eaid);
  417. Integer processStatus = lastout.getProcessStatus();
  418. if (processStatus <3){
  419. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountExamineMapper.selectNotExamineByEaidAndProcessStatus(eaid, processStatus);
  420. list.addAll(outExpenseAccountLogs);
  421. }
  422. if (lastout.getStatus() != 3) {
  423. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(eaid, processStatus);
  424. for (ExpenseAccountExamine e : expenseAccountExamines) {
  425. if (e.getStatus()==0){
  426. OutExpenseAccountLog out =new OutExpenseAccountLog();
  427. out.setEaid(eaid);
  428. out.setProcessStatus(e.getProcessStatus());
  429. out.setAuditorName(e.getAuditorname());
  430. list.add(out);
  431. }
  432. }
  433. if (processStatus<8)addDetailsLog(list, expenseAccount,processStatus);
  434. }
  435. }
  436. return list;
  437. }
  438. private void deduplication(List<OutExpenseAccountLog> list) {
  439. List<OutExpenseAccountLog> newList=new ArrayList<>();
  440. if (!list.isEmpty()){
  441. for (OutExpenseAccountLog e : list) {
  442. int count=0;
  443. for (OutExpenseAccountLog e2 : list) {
  444. if (e.getAuditor().equals(e2.getAuditor())
  445. &&e.getStatus().equals(e2.getStatus())
  446. &&e.getCreateTime().getTime()==e2.getCreateTime().getTime()){
  447. count++;
  448. }
  449. }
  450. if (count==1)newList.add(e);
  451. }
  452. list.clear();
  453. list.addAll(newList);
  454. }
  455. }
  456. private void addDetailsLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount,Integer useStatus) {
  457. OrganizationListOut dep = departmentMapper.selectAllById(expenseAccount.getApplyDep());
  458. List<ExpenseConfigDetails> configDetails = expenseConfigDetailsMapper.selectByDepId(expenseAccount.getApplyDep());
  459. for (int processStatus = useStatus; processStatus < 8; processStatus++) {
  460. if (processStatus ==3){
  461. if (dep.getExpenseRetrialFinanceExamine()==1){
  462. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  463. for (ExpenseConfigDetails e : collect) {
  464. addDetailsTypeLog(list, expenseAccount, e);
  465. }
  466. }
  467. }else if (processStatus ==4){
  468. if (expenseAccount.getApproval()==1&&dep.getCeoExamine()==1){
  469. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 2).collect(Collectors.toList());
  470. for (ExpenseConfigDetails e : collect) {
  471. addDetailsTypeLog(list, expenseAccount, e);
  472. }
  473. }
  474. }else if (processStatus ==5){
  475. if (dep.getCfoExamine()==1){
  476. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 3).collect(Collectors.toList());
  477. for (ExpenseConfigDetails e : collect) {
  478. addDetailsTypeLog(list, expenseAccount, e);
  479. }
  480. }
  481. }else if (processStatus ==6){
  482. if (dep.getViceCeoExamine()==1){
  483. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  484. for (ExpenseConfigDetails e : collect) {
  485. addDetailsTypeLog(list, expenseAccount, e);
  486. }
  487. }
  488. }else if (processStatus ==7){
  489. if (dep.getCashierExamine()==1){
  490. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 5).collect(Collectors.toList());
  491. for (ExpenseConfigDetails e : collect) {
  492. addDetailsTypeLog(list, expenseAccount, e);
  493. }
  494. }
  495. }
  496. }
  497. }
  498. private static void addDetailsTypeLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount, ExpenseConfigDetails e) {
  499. OutExpenseAccountLog addLog=new OutExpenseAccountLog();
  500. addLog.setEaid(expenseAccount.getId());
  501. addLog.setAuditor(e.getAid());
  502. addLog.setAuditorName(e.getAdminName());
  503. list.add(addLog);
  504. }
  505. @Override
  506. public int updateExamine(InputExpenseAccount in) {
  507. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  508. ExpenseAccount newEa=new ExpenseAccount();
  509. newEa.setId(useEa.getId());
  510. newEa.setApproval(in.getApproval());
  511. in.setCheckNo(useEa.getCheckNo());
  512. in.setProcessStatus(useEa.getProcessStatus());
  513. //审核通知 获取发送人
  514. AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
  515. //项目推送流程及添加日志
  516. addExamineExpenseAccountLog(admin,in, useEa, newEa);
  517. //完成申请
  518. if (newEa.getStatus()==2){
  519. //如果是借支则订单新增
  520. List<ExpenseAccount> expenseAccounts1 = expenseAccountMapper.selectListByMainId(in.getId());
  521. for (ExpenseAccount e : expenseAccounts1) {
  522. if (e.getType()!=4){
  523. //不然就看是否挂载借支订单进行抵扣
  524. if (e.getDebitId()!=null){
  525. ExpenseAccount useDebit=expenseAccountMapper.selectByPrimaryKey(e.getDebitId());
  526. if (useDebit.getLiquidationStatus()==2){
  527. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByDebitId(e.getDebitId());
  528. boolean flag=true;
  529. for (ExpenseAccount expenseAccount : expenseAccounts) {
  530. if(!expenseAccount.getId().equals(in.getId())&&expenseAccount.getStatus()!=2){
  531. flag=false;
  532. break;
  533. }
  534. }
  535. if (flag){
  536. ExpenseAccount debit=new ExpenseAccount();
  537. debit.setId(e.getDebitId());
  538. debit.setLiquidationStatus(3);
  539. expenseAccountMapper.updateByPrimaryKeySelective(debit);
  540. }
  541. }
  542. }
  543. }
  544. ExpenseAccount updateSon=new ExpenseAccount();
  545. updateSon.setId(e.getId());
  546. updateSon.setStatus(2);
  547. expenseAccountMapper.updateByPrimaryKeySelective(updateSon);
  548. }
  549. }else if (newEa.getStatus()==1){
  550. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  551. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),0);
  552. //处理金额修改
  553. if(in.getRealList()!=null){
  554. List<Map> maps = JSONObject.parseArray(in.getRealList(), Map.class);
  555. for (Map map: maps) {
  556. Integer type= (Integer) map.get("type");
  557. Integer id= (Integer) map.get("id");
  558. BigDecimal amount= new BigDecimal(map.get("amount").toString());
  559. //type=1总计,type=2报销金额
  560. if(type==1){
  561. ExpenseAccount ea =new ExpenseAccount();
  562. ea.setId(id);
  563. ea.setRealAmount(amount);
  564. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  565. }else if (type==2){
  566. ExpenseAccountDetails ead=new ExpenseAccountDetails();
  567. ead.setId(id);
  568. ead.setRealAmount(amount);
  569. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ead);
  570. }
  571. }
  572. }
  573. }else if (newEa.getProcessStatus()==EAProcessStatus.CWSH.getCode()){
  574. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),1);
  575. }
  576. }else if (newEa.getStatus()==3){
  577. if (useEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  578. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),2);
  579. }else if (newEa.getProcessStatus()>EAProcessStatus.CWSH.getCode()){
  580. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),3);
  581. }
  582. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),null,0,0);
  583. }
  584. expenseAccountMapper.updateByPrimaryKeySelective(newEa);
  585. expenseAccountMapper.updateSonByMainId(newEa.getId());
  586. return 1;
  587. }
  588. private void addFinanceCount(String aid,Date startTime ) {
  589. String forDate=DateUtils.formatDate(startTime,AFTConstants.YYYYMMDD);
  590. addFinanceCount(aid,forDate);
  591. }
  592. private void addFinanceCount(String aid,String startTime ) {
  593. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  594. if (financeCount ==null){
  595. financeCount =FinanceCount.initialization(aid, startTime);
  596. financeCount.setExpenseCount(1);
  597. financeCount.setExpenseUnauditedCount(1);
  598. financeCountMapper.insertSelective(financeCount);
  599. }else {
  600. FinanceCount newFinanceCount =new FinanceCount();
  601. newFinanceCount.setId(financeCount.getId());
  602. newFinanceCount.setExpenseCount(financeCount.getExpenseCount()+1);
  603. newFinanceCount.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  604. financeCountMapper.updateByPrimaryKeySelective(newFinanceCount);
  605. }
  606. }
  607. private void addExamineExpenseAccountLog(AdminListBo admin,InputExpenseAccount in, ExpenseAccount useEa, ExpenseAccount newEa) {
  608. List<Admin> aids=new ArrayList<>();
  609. StringBuffer str=new StringBuffer();
  610. Integer status=in.getStatus();
  611. if (status==1){
  612. //审核处理审核表
  613. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,0);
  614. str=str.append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  615. newEa.setAid(useEa.getAid());
  616. newEa.setCreateTime(useEa.getCreateTime());
  617. newEa.setApplyDep(useEa.getApplyDep());
  618. //在跳入董事长审核的时候非特批直接跳过,原则上下个流程不可再跳过
  619. OrganizationListOut dep = departmentMapper.selectAllById(newEa.getApplyDep());
  620. List<ExpenseConfigDetails> configDetailsList = expenseConfigDetailsMapper.selectByDepId(newEa.getApplyDep());
  621. if(useEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  622. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,1);
  623. boolean expenseExamine = pushExpenseExamine(configDetailsList, newEa, EAProcessStatus.CNSH.getCode());
  624. if (expenseExamine){
  625. //完成后的流程
  626. status =2;
  627. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  628. newEa.setStatus(status);
  629. newEa.setExamineName("");
  630. }else {
  631. status =1;
  632. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), useEa.getProcessStatus());
  633. StringBuffer aname =new StringBuffer();
  634. for (ExpenseAccountExamine e : list) {
  635. if (e.getStatus()==0){
  636. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  637. aids.add(ad);
  638. aname=aname.append(ad.getName()).append(",");
  639. }
  640. }
  641. newEa.setExamineName(aname.substring(0,aname.length()-1));
  642. }
  643. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  644. }else {
  645. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  646. newEa.setStatus(1);
  647. if (useEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  648. newEa.setProcessStatus(useEa.getProcessStatus()+1);
  649. }else {
  650. newEa.setProcessStatus(useEa.getProcessStatus());
  651. }
  652. if (newEa.getApproval()==null)newEa.setApproval(useEa.getApproval());
  653. //流程的推动
  654. examineByprocess(newEa,admin,dep,configDetailsList);
  655. //推动到出纳如果设置无需则完成不设置下个人,否则就要设置
  656. if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  657. if(dep.getCashierExamine()==1){
  658. pushExamineName(newEa, aids);
  659. }else {
  660. //完成后的流程
  661. status =2;
  662. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  663. newEa.setStatus(status);
  664. newEa.setExamineName("");
  665. }
  666. }else {
  667. pushExamineName(newEa, aids);
  668. }
  669. }
  670. }else {
  671. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  672. newEa.setStatus(3);
  673. newEa.setProcessStatus(0);
  674. str.setLength(0);
  675. addExpenseAccountLog(in.getId(),newEa.getStatus(),useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  676. str=str.append("您的报销审核已驳回,报销编号[").append(in.getCheckNo()).append("],请注意查看。");
  677. }
  678. if (newEa.getStatus()==null)newEa.setStatus(1);
  679. addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
  680. }
  681. private void pushExamineName(ExpenseAccount newEa, List<Admin> aids) {
  682. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  683. StringBuffer aname =new StringBuffer();
  684. for (ExpenseAccountExamine e : list) {
  685. if (e.getProcessStatus()== newEa.getProcessStatus()&&e.getStatus()==0){
  686. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  687. aids.add(ad);
  688. aname=aname.append(ad.getName()).append(",");
  689. }
  690. }
  691. newEa.setExamineName(aname.substring(0,aname.length()-1));
  692. }
  693. /**
  694. *
  695. * @param aid
  696. * @param createTime
  697. * @param type 0 双新增 1 未审核减一 2双减 3总数减一
  698. */
  699. private void pushFinanceCount(String aid, Date createTime, Integer type) {
  700. String startTime= DateUtils.formatDate(createTime,AFTConstants.YYYYMMDD);
  701. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  702. FinanceCount newFinance=new FinanceCount();
  703. if (financeCount==null){
  704. newFinance=FinanceCount.initialization(aid,createTime);
  705. newFinance.setExpenseCount(1);
  706. newFinance.setExpenseUnauditedCount(1);
  707. financeCountMapper.insertSelective(newFinance);
  708. }else {
  709. newFinance.setId(financeCount.getId());
  710. if(type==0){
  711. newFinance.setExpenseCount(financeCount.getExpenseCount()+1);
  712. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  713. }else if(type==1){
  714. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  715. }else if(type==2){
  716. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  717. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  718. }else if(type==3){
  719. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  720. }
  721. financeCountMapper.updateByPrimaryKeySelective(newFinance);
  722. }
  723. }
  724. /**
  725. * 审核流程推送,只要不是完成状态就继续判断是否跳过
  726. * @param newEa
  727. */
  728. private void examineByprocess( ExpenseAccount newEa,AdminListBo admin,OrganizationListOut dep,List<ExpenseConfigDetails> list) {
  729. List<ExpenseAccountExamine> examineList=new ArrayList<>();
  730. //小于财务复审的,走单审核
  731. if (newEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  732. examineList = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  733. boolean flag=false;
  734. String aid="";
  735. if (examineList.size()>0){
  736. for (ExpenseAccountExamine e : examineList) {
  737. if (e.getStatus()==1){
  738. flag=true;
  739. aid=e.getAuditor();
  740. break;
  741. }
  742. }
  743. }
  744. //如果当前审核人已经审核,则跳过当前审核
  745. if (flag){
  746. String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
  747. Date date=new Date();
  748. date.setTime(date.getTime()+1000l);
  749. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date);
  750. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  751. addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
  752. }
  753. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  754. examineByprocess(newEa,admin,dep,list);
  755. }
  756. }else {
  757. //大于等于财务复审的,走多审核
  758. String str=null;
  759. //跳过标记
  760. boolean flag2= false;
  761. //审核通过标记
  762. boolean flag3= false;
  763. Date date2=new Date();
  764. date2.setTime(date2.getTime()+1000l);
  765. String tip=null;
  766. String aid=null;
  767. if (newEa.getProcessStatus()==EAProcessStatus.CWFS.getCode()){
  768. //财务复审财务复审
  769. if (dep.getExpenseRetrialFinanceExamine()==0){
  770. flag2=true;
  771. tip=EAProcessStatus.CWFS.getDesc();
  772. }else {
  773. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWFS.getCode());
  774. if (expenseExamine){
  775. flag3=true;
  776. }
  777. }
  778. }else if (newEa.getProcessStatus()==EAProcessStatus.DSZSH.getCode()){
  779. if (newEa.getApproval()!=1){
  780. flag2=true;
  781. tip="特批(财务选择)";
  782. }else {
  783. if (dep.getCeoExamine()==1){
  784. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.DSZSH.getCode());
  785. if (expenseExamine){
  786. flag3=true;
  787. }
  788. }else {
  789. flag2=true;
  790. tip="特批(部门设置)";
  791. }
  792. }
  793. }else if (newEa.getProcessStatus()==EAProcessStatus.CWGGLYSH.getCode()){
  794. if (dep.getExpenseRetrialFinanceExamine()==0){
  795. flag2=true;
  796. tip=EAProcessStatus.CWGGLYSH.getDesc();
  797. aid=null;
  798. }else {
  799. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWGGLYSH.getCode());
  800. if (expenseExamine){
  801. flag3=true;
  802. }
  803. }
  804. }else if (newEa.getProcessStatus()==EAProcessStatus.GSFSSH.getCode()){
  805. if (dep.getExpenseRetrialFinanceExamine()==0){
  806. flag2=true;
  807. tip=EAProcessStatus.GSFSSH.getDesc();
  808. }else {
  809. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.GSFSSH.getCode());
  810. if (expenseExamine){
  811. flag3=true;
  812. }
  813. }
  814. }else if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  815. if (dep.getExpenseRetrialFinanceExamine()==0){
  816. flag2=true;
  817. tip=EAProcessStatus.CNSH.getDesc();
  818. }else {
  819. //财务出纳在审核时不与前置审核做同步
  820. pushExpenseExamine(list, newEa, EAProcessStatus.CNSH.getCode());
  821. }
  822. }
  823. if (flag2){
  824. if (str==null)str=String.format("未设置[%s]审核,跳过此流程",tip);
  825. if (newEa.getProcessStatus()<EAProcessStatus.CNSH.getCode()){
  826. date2.setTime(date2.getTime()+100);
  827. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date2);
  828. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  829. examineByprocess(newEa,admin,dep,list);
  830. }else {
  831. date2.setTime(date2.getTime()+100);
  832. addExpenseAccountLog(newEa.getId(),2,newEa.getProcessStatus(),aid,str,date2);
  833. newEa.setProcessStatus(newEa.getProcessStatus());
  834. newEa.setStatus(2);
  835. }
  836. }else if (flag3){
  837. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  838. examineByprocess(newEa,admin,dep,list);
  839. }
  840. }
  841. }
  842. private boolean pushExpenseExamine(List<ExpenseConfigDetails> list, ExpenseAccount newEa, Integer status) {
  843. int configDetails=0;
  844. if (status==EAProcessStatus.CWFS.getCode())configDetails=1;
  845. else if (status==EAProcessStatus.DSZSH.getCode())configDetails=2;
  846. else if (status==EAProcessStatus.CWGGLYSH.getCode())configDetails=3;
  847. else if (status==EAProcessStatus.GSFSSH.getCode())configDetails=4;
  848. else if (status==EAProcessStatus.CNSH.getCode())configDetails=5;
  849. int finalConfigDetails = configDetails;
  850. //查询审核表,如果为空就新增,不然直接判定审核
  851. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), status);
  852. int count = 0;
  853. int size=10;
  854. if (expenseAccountExamines.isEmpty()){
  855. List<ExpenseConfigDetails> collect = list.stream().filter(e -> e.getType() == finalConfigDetails).collect(Collectors.toList());
  856. size= collect.size();
  857. for (ExpenseConfigDetails e : collect) {
  858. ExpenseAccountExamine eae=new ExpenseAccountExamine(newEa.getId(),status);
  859. eae.setAuditor(e.getAid());
  860. eae.setAuditorname(e.getAdminName());
  861. eae.setStatus(0);
  862. Integer i = expenseAccountExamineMapper.selectYesByParam(newEa.getId(), e.getAid());
  863. if (status==EAProcessStatus.CNSH.getCode()){
  864. eae.setStatus(0);
  865. count++;
  866. }else {
  867. if (i>0||e.getAid().equals(TokenManager.getAdminId())) {
  868. eae.setStatus(1);
  869. count++;
  870. }
  871. }
  872. expenseAccountExamineMapper.insertSelective(eae);
  873. }
  874. }else {
  875. size = expenseAccountExamines.size();
  876. for (ExpenseAccountExamine e : expenseAccountExamines) {
  877. if (e.getStatus()==1){
  878. count++;
  879. }
  880. }
  881. }
  882. if (count==size){
  883. return true;
  884. }
  885. return false;
  886. }
  887. private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
  888. Date date= new Date();
  889. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  890. if (status==2){
  891. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  892. }
  893. List<Notice> list=new ArrayList<>();
  894. if (aids!=null){
  895. for (Admin a : aids) {
  896. Notice notice=new Notice();
  897. notice.setId(UUID.randomUUID().toString());
  898. notice.setNoticeType(noticeStatus);
  899. notice.setType(NoticeTypes.getType(noticeStatus));
  900. notice.setAid(a.getId());
  901. notice.setCreateTime(date);
  902. notice.setContent(str);
  903. notice.setReaded(0);
  904. list.add(notice);
  905. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  906. asyncUtils.send(emailBo);
  907. try {
  908. weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
  909. }catch (Exception e){
  910. throw new BusinessException("网络通信异常,请稍后再试。");
  911. }
  912. }
  913. asyncUtils.addNoticeBatch(list);
  914. }
  915. }
  916. @Override
  917. public Pagination<?> pageList(InputPageListBo in) {
  918. Map<String ,Object> param=new HashMap<>();
  919. addParam(in, param);
  920. Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
  921. "selectExpenseAccountCount",
  922. "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
  923. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
  924. for (OutExpenseAccountBo e : list) {
  925. e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
  926. }
  927. return pagePlus;
  928. }
  929. @Override
  930. public Object selectByPrid(InputExpenseAccount in) {
  931. in.setAid(TokenManager.getAdminId());
  932. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  933. return useEa;
  934. }
  935. @Override
  936. public Object selectById(Integer id) {
  937. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  938. //判断当前角色是否审核
  939. useEa.setExamine(pushExpenseAccountGetExamine( id, useEa.getProcessStatus()));;
  940. if (useEa.getDebitId()!=null){
  941. pushExpenseAccountGetDebitAmount(useEa);
  942. }
  943. return useEa;
  944. }
  945. @Override
  946. public Object selectByCheckNo(String checkNo) {
  947. checkNo=checkNo.trim();
  948. OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
  949. if (useEa==null){
  950. throw new BusinessException("报销编号不存在,请客对后再查询。");
  951. }
  952. if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
  953. throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
  954. }
  955. return useEa;
  956. }
  957. @Override
  958. public Object pushMerge(List<ExpenseAccount> list) {
  959. //设置付款部门和支付部门
  960. InputExpenseAccount in =new InputExpenseAccount();
  961. in.setCheckNo(idGenerator.getNOgenerateId());
  962. if (in.getAid()==null){
  963. in.setAid(TokenManager.getAdminId());
  964. }
  965. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  966. in.setAname(admin.getName());
  967. in.setApplyDep(admin.getDepartmentId());
  968. in.setPayDep(admin.getDepartmentId());
  969. Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
  970. in.setEaaid(eaaid);
  971. BigDecimal count = new BigDecimal(0);
  972. BigDecimal amount = new BigDecimal(0);
  973. BigDecimal realAmount = new BigDecimal(0);
  974. List<String> typeList = new ArrayList<String>();
  975. for (ExpenseAccount e : list) {
  976. count=count.add(e.getTotalAmount());
  977. amount=amount.add(e.getAmount());
  978. realAmount=realAmount.add(e.getRealAmount());
  979. StringBuffer types=new StringBuffer();
  980. if (e.getType()!=0){
  981. types=types.append(EATypes.getDescByCode(e.getType()));
  982. }else {
  983. types=types.append(e.getTypeOther());
  984. }
  985. if (e.getType()==2){
  986. if (e.getSecondaryType()==0){
  987. types=types.append("-").append(e.getSecondaryTypeOther());
  988. }else{
  989. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  990. types=types.append("-").append(descByCode);
  991. }
  992. }
  993. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  994. }
  995. in.setTotalAmount(count);
  996. in.setAmount(amount);
  997. in.setRealAmount(realAmount);
  998. in.setExpenseMain(1);
  999. in.setTypeOther(String.join(",",typeList));
  1000. expenseAccountMapper.insertSelective(in);
  1001. list.stream().forEach(e -> {
  1002. ExpenseRelationship er=new ExpenseRelationship();
  1003. er.setId(in.getId());
  1004. er.setEaId(e.getId());
  1005. expenseRelationshipMapper.insertSelective(er);
  1006. expenseAccountLogMapper.updateUseLogByUseId(in.getId(),e.getId());
  1007. });
  1008. expenseAccountMapper.updateByIds(list,1);
  1009. return in.getId();
  1010. }
  1011. @Override
  1012. public MainExpenseAccount mainExpense(Integer id) {
  1013. MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
  1014. res.setExamine(0);
  1015. if (res.getAid().equals(TokenManager.getAdminId())){
  1016. res.setExamine(2);
  1017. }else {
  1018. res.setExamine(pushExpenseAccountGetExamine( id, res.getProcessStatus()));;
  1019. }
  1020. return res;
  1021. }
  1022. @Override
  1023. public Object updateMain(MainExpenseAccount in) {
  1024. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  1025. if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
  1026. throw new BusinessException("主项目已发起,不可修改!");
  1027. }
  1028. ExpenseAccount update =new ExpenseAccount();
  1029. if (in.getStatus()==null)in.setStatus(1);
  1030. if (in.getStatus()==1){
  1031. if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
  1032. if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
  1033. if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
  1034. if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
  1035. addExpenseAccountExamine(in.getId(),update);
  1036. if (outExpenseAccount.getStatus()==0){
  1037. addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
  1038. }else if (outExpenseAccount.getStatus()==3){
  1039. addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
  1040. }
  1041. update.setStatus(in.getStatus());
  1042. update.setProcessStatus(outExpenseAccount.getProcessStatus());
  1043. update.setId(in.getId());
  1044. update.setExamineName(outExpenseAccount.getExamineName());
  1045. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1046. }else if (in.getStatus()==4){
  1047. expenseAccountMapper.updateByMainId(in.getId(),0);
  1048. addExpenseAccountLog(in.getId(),4,0,TokenManager.getAdminId(),"撤销报销审核");
  1049. List<ExpenseRelationship> list = expenseRelationshipMapper.selectById(in.getId());
  1050. //撤销日志处理,先将日志改在挂子编号上,在新发起的时候再从自编号加到新编号上
  1051. if (list.size()==1){
  1052. ExpenseRelationship e =list.get(0);
  1053. expenseAccountLogMapper.updateUseLogByUseId(e.getEaId(),e.getId());
  1054. }else {
  1055. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountLogMapper.selectByEaid(in.getId());
  1056. for (int i=0;i<list.size();i++){
  1057. ExpenseRelationship e =list.get(i);
  1058. for (OutExpenseAccountLog eal : outExpenseAccountLogs) {
  1059. eal.setEaid(e.getEaId());
  1060. }
  1061. expenseAccountLogMapper.insertBatch(outExpenseAccountLogs);
  1062. }
  1063. }
  1064. expenseAccountLogMapper.deleteByeaid(in.getId());
  1065. expenseRelationshipMapper.deleteByPrimaryKey(in.getId());
  1066. expenseAccountMapper.deleteByPrimaryKey(in.getId());
  1067. }
  1068. return 1;
  1069. }
  1070. @Override
  1071. public Object mainList(ExpenseMainListInput in) {
  1072. Map<String,Object> params = new HashMap<>();
  1073. if (in.getStatus()!=null) params.put("status",in.getStatus());
  1074. if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
  1075. if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
  1076. if (in.getUsername() != null)params.put("username",in.getUsername());
  1077. if (in.getStartTime()!=null && in.getEndTime() !=null) {
  1078. params.put("startTime",in.getStartTime());
  1079. params.put("endTime",in.getEndTime()+" 23:59:59");
  1080. }
  1081. //1-3s是不同人的审核
  1082. if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
  1083. // 财务审核,复审,出纳都是财务与经理
  1084. if (TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1085. in.setProcessStatus(3);
  1086. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)){
  1087. in.setProcessStatus(1);
  1088. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  1089. in.setProcessStatus(2);
  1090. }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
  1091. in.setProcessStatus(5);
  1092. }else if(TokenManager.hasRole(AFTConstants.VICE_CEO)){
  1093. //先不做财务查看权限
  1094. in.setProcessStatus(7);
  1095. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)){
  1096. in.setProcessStatus(6);
  1097. }
  1098. }else {
  1099. in.setProcessStatus(0);
  1100. }
  1101. if (in.getProcessStatus()!=null){
  1102. params.put("aid",TokenManager.getAdminId());
  1103. params.put("roleType",in.getProcessStatus());
  1104. if (in.getProcessStatus()==3){
  1105. params.put("deps",departmentService.selectMyDeps());
  1106. }
  1107. }
  1108. Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
  1109. List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
  1110. if (!list.isEmpty()){
  1111. List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
  1112. List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
  1113. for (MainExpenseAccount e : list) {
  1114. for (MainExpenseAccount me : mainExpenseAccounts) {
  1115. if (e.getId().equals(me.getId())){
  1116. e.setSonList(me.getSonList());
  1117. }
  1118. }
  1119. }
  1120. }
  1121. return page;
  1122. }
  1123. @Override
  1124. public Pagination<?> detailsList(InputDetailsListBo in) {
  1125. Map<String,Object> params = new HashMap<>();
  1126. if(in.getStatus()!=null)params.put("status",in.getStatus());
  1127. if(in.getType()!=null)params.put("type",in.getType());
  1128. if (in.getDepId()!=null)params.put("depId",in.getDepId());
  1129. if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
  1130. if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
  1131. if (in.getAname()!=null)params.put("aname",in.getAname());
  1132. if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
  1133. if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
  1134. if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
  1135. if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
  1136. if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
  1137. //0=自己 1=财务 2=财务经理 3=超管
  1138. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  1139. params.put("roleType",3);
  1140. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1141. params.put("roleType",2);
  1142. params.put("aid",TokenManager.getAdminId());
  1143. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1144. params.put("roleType",1);
  1145. params.put("aid",TokenManager.getAdminId());
  1146. }else{
  1147. params.put("roleType",0);
  1148. }
  1149. return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
  1150. }
  1151. @Override
  1152. public List<ExpenseAccount> selectByIds(List<String> list) {
  1153. return expenseAccountMapper.selectByIds(list);
  1154. }
  1155. @Override
  1156. public int selectCountByIdsAndType(List<String> list, Integer i) {
  1157. return expenseAccountMapper.selectCountByIdsAndType(list,i);
  1158. }
  1159. @Override
  1160. public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
  1161. ExpenseAccountDetails ea= new ExpenseAccountDetails();
  1162. ea.setId(id);
  1163. ea.setRealAmount(amount);
  1164. String name=TokenManager.getAdminToken().getName();
  1165. Integer eaid = expenseAccountDetailsMapper.selectExpenseAccountById(id);
  1166. addExpenseAccountLog(eaid,5,3,TokenManager.getAdminId(),String.format("财务[%s]修改实际报销金额为%s。",name,amount));
  1167. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
  1168. expenseAccountMapper.updateSonByDetId(id);
  1169. expenseAccountMapper.updateMainByDetId(id);
  1170. return 1;
  1171. }
  1172. /**
  1173. * 计算当前报销显示抵扣金额
  1174. * @param useEa
  1175. */
  1176. private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
  1177. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
  1178. List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
  1179. BigDecimal count =debit.getRealAmount();
  1180. for (ExpenseAccount e : list1) {
  1181. if (!e.getId().equals(useEa.getId())){
  1182. count=count.subtract(e.getSettlementAmount());
  1183. }
  1184. }
  1185. if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
  1186. useEa.setDebitTotalAmount(count);
  1187. }
  1188. /**
  1189. * 判断角色是否已经审核
  1190. * @param id 编号
  1191. * @param processStatus 审核状态
  1192. * @return 0 无需审核 1 需要审核
  1193. */
  1194. private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
  1195. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
  1196. boolean flag=false;
  1197. for (ExpenseAccountExamine e : list) {
  1198. if (e.getAuditor().equals(TokenManager.getAdminId())){
  1199. if (e.getStatus()==0){
  1200. flag=true;
  1201. break;
  1202. }
  1203. }
  1204. }
  1205. if (flag){
  1206. return 1;
  1207. }else {
  1208. return 0;
  1209. }
  1210. }
  1211. @Override
  1212. public Object updateType(InputExpenseAccount in) {
  1213. expenseAccountDetailsMapper.deleteByeaid(in.getId());
  1214. if (in.getType()!=2)in.setSecondaryType(0);
  1215. in.setSettlementAmount(new BigDecimal(0));
  1216. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  1217. }
  1218. @Override
  1219. public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
  1220. String aid= TokenManager.getAdminId();
  1221. List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
  1222. return list;
  1223. }
  1224. private void addParam(InputPageListBo in, Map<String, Object> param) {
  1225. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  1226. param.put("startTime",in.getStartTime());
  1227. param.put("endTime",in.getEndTime()+" 23:59:59");
  1228. }
  1229. if (in.getStatus()!=null)param.put("status",in.getStatus());
  1230. //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
  1231. if (in.getProcessStatus()==null) in.setProcessStatus(0);
  1232. if(in.getProcessStatus()==2){
  1233. if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1234. //财务经理查看权限
  1235. in.setProcessStatus(5);
  1236. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  1237. TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  1238. //财务管理员和超级管理员查看全部
  1239. in.setProcessStatus(6);
  1240. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1241. //0 设置为财务查看
  1242. param.put("roleType",0);
  1243. }
  1244. if (in.getAid()!=null){
  1245. param.put("aid",in.getAid());
  1246. }
  1247. param.put("auditor",TokenManager.getAdminId());
  1248. }else if(in.getProcessStatus()==1) {
  1249. param.put("auditor",TokenManager.getAdminId());
  1250. if (in.getAid()!=null){
  1251. param.put("aid",in.getAid());
  1252. }
  1253. }else {
  1254. param.put("aid",TokenManager.getAdminId());
  1255. }
  1256. param.put("processStatus",in.getProcessStatus());
  1257. if (in.getExamineStatus()!=null){
  1258. param.put("examineStatus",in.getExamineStatus());
  1259. }else {
  1260. param.put("examineStatus",0);
  1261. }
  1262. if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
  1263. if (in.getDepId()!=null)param.put("depId",in.getDepId());
  1264. if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
  1265. if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
  1266. if (in.getType()!=null)param.put("type",in.getType());
  1267. if (in.getUsername()!=null)param.put("username",in.getUsername());
  1268. if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
  1269. if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
  1270. //固定传0查看子列表
  1271. if (in.getExpenseMain()==null)in.setExpenseMain(0);
  1272. if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
  1273. }
  1274. /**
  1275. * 检查权限判断是否是总裁、董事长或超级管理员权限
  1276. * @return
  1277. */
  1278. private boolean checkShiroCED() {
  1279. if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
  1280. TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
  1281. ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  1282. return true;
  1283. }
  1284. return false;
  1285. }
  1286. @Override
  1287. @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
  1288. public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
  1289. if (endTime != null) endTime = endTime + " 23:59:59";
  1290. List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
  1291. List<OutExpenseAccountStatistics> results = new ArrayList<>();
  1292. Map<String, Object> map = new HashMap<>();
  1293. for (OutMyEAStatistics e : list) {
  1294. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
  1295. out.setAname(e.getAname());
  1296. if (e.getStatus() == 2) {
  1297. if (e.getType() < 4) {
  1298. out.setBx(1);
  1299. out.setBxAmount(e.getTotalAmount());
  1300. if (!e.getDebitId().equals(0)) {
  1301. out.setDk(1);
  1302. out.setDkAmount(e.getBxdkAmount());
  1303. }
  1304. } else if (e.getType() == 4) {
  1305. out.setJz(1);
  1306. out.setJzAmount(e.getTotalAmount());
  1307. } else if (e.getType() == 5) {
  1308. out.setDk(1);
  1309. out.setDkAmount(e.getTotalAmount());
  1310. }
  1311. if (e.getTargetType() == 0) {
  1312. out.setGdfyAmount(e.getTotalAmount());
  1313. } else if (e.getTargetType() == 1) {
  1314. out.setBxddAmount(e.getTotalAmount());
  1315. }
  1316. } else if (e.getStatus() == 1) {
  1317. out.setWshs(1);
  1318. } else if (e.getStatus() == 3) {
  1319. out.setBhs(1);
  1320. }
  1321. //如果不存在就新增
  1322. if (!map.keySet().contains(out.getAid())) {
  1323. List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
  1324. list2.add(out);
  1325. map.put(out.getAid(), list2);
  1326. } else {
  1327. List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
  1328. list2.add(out);
  1329. }
  1330. }
  1331. for (String s : map.keySet()) {
  1332. List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
  1333. if (!list3.isEmpty()) {
  1334. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
  1335. for (OutExpenseAccountStatistics e : list3) {
  1336. if (out.getAname() == null) out.setAname(e.getAname());
  1337. if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
  1338. if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
  1339. if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
  1340. if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
  1341. if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
  1342. if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
  1343. if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
  1344. if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
  1345. if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
  1346. if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
  1347. }
  1348. BigDecimal totalAmount = new BigDecimal(0);
  1349. totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
  1350. out.setTotalAmount(totalAmount);
  1351. results.add(out);
  1352. }
  1353. }
  1354. return results;
  1355. }
  1356. @Override
  1357. @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
  1358. public void statisticsEvict(String name, String depId, String startTime, String endTime) {
  1359. LoggerUtils.debug(getClass(), "报销统计缓存清除。");
  1360. }
  1361. @Override
  1362. public Object pushSupplementCheckNo() {
  1363. List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
  1364. if (!list.isEmpty()){
  1365. list.forEach(e ->{
  1366. ExpenseAccount ea=new ExpenseAccount();
  1367. ea.setId(e.getId());
  1368. ea.setCheckNo(idGenerator.getNOgenerateId());
  1369. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  1370. });
  1371. return 1;
  1372. }
  1373. return 0;
  1374. }
  1375. @Override
  1376. public void pushAll() {
  1377. List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
  1378. for (ExpenseAccount ea : list) {
  1379. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
  1380. List<String> typeList=new ArrayList<>();
  1381. for (ExpenseAccount e : expenseAccounts) {
  1382. StringBuffer types=new StringBuffer();
  1383. if (e.getType()!=0){
  1384. types=types.append(EATypes.getDescByCode(e.getType()));
  1385. }else {
  1386. types=types.append(e.getTypeOther());
  1387. }
  1388. if (e.getType()==2){
  1389. if (e.getSecondaryType()==0){
  1390. types=types.append("-").append(e.getSecondaryTypeOther());
  1391. }else{
  1392. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1393. types=types.append("-").append(descByCode);
  1394. }
  1395. }
  1396. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1397. }
  1398. String typeStr = String.join(",", typeList);
  1399. ExpenseAccount update=new ExpenseAccount();
  1400. update.setId(ea.getId());
  1401. update.setTypeOther(typeStr);
  1402. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1403. }
  1404. }
  1405. }