ExpenseAccountServiceImpl.java 71 KB

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