ExpenseAccountServiceImpl.java 50 KB

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