ExpenseAccountServiceImpl.java 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  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.FileUtils;
  15. import com.goafanti.common.utils.excel.NewExcelUtil;
  16. import com.goafanti.common.utils.pdf.PDFUtils;
  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 com.goafanti.order.service.OrderNewService;
  27. import com.goafanti.organization.bo.OrganizationListOut;
  28. import com.itextpdf.text.Document;
  29. import com.itextpdf.text.DocumentException;
  30. import com.itextpdf.text.Paragraph;
  31. import com.itextpdf.text.Phrase;
  32. import com.itextpdf.text.pdf.PdfPCell;
  33. import com.itextpdf.text.pdf.PdfPRow;
  34. import com.itextpdf.text.pdf.PdfPTable;
  35. import com.itextpdf.text.pdf.PdfWriter;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.beans.factory.annotation.Value;
  38. import org.springframework.cache.annotation.CacheEvict;
  39. import org.springframework.cache.annotation.Cacheable;
  40. import org.springframework.http.MediaType;
  41. import org.springframework.stereotype.Service;
  42. import org.springframework.transaction.annotation.Transactional;
  43. import javax.servlet.http.HttpServletResponse;
  44. import java.io.FileOutputStream;
  45. import java.io.IOException;
  46. import java.math.BigDecimal;
  47. import java.time.LocalDate;
  48. import java.util.*;
  49. import java.util.stream.Collectors;
  50. @Service
  51. public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
  52. @Autowired
  53. private AdminMapper adminMapper;
  54. @Autowired
  55. private ExpenseAccountMapper expenseAccountMapper;
  56. @Autowired
  57. private PublicReleaseMapper publicReleaseMapper;
  58. @Autowired
  59. private ExpenseAccountLogMapper expenseAccountLogMapper;
  60. @Autowired
  61. private AsyncUtils asyncUtils;
  62. @Autowired
  63. private WeChatUtils weChatUtils;
  64. @Autowired
  65. private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
  66. @Autowired
  67. private ExpenseAccountPrivateMapper expenseAccountPrivateMapper;
  68. @Autowired
  69. private ExpenseAccountExamineMapper expenseAccountExamineMapper;
  70. @Autowired
  71. private JDBCIdGenerator idGenerator;
  72. @Autowired
  73. private FinanceCountMapper financeCountMapper;
  74. @Autowired
  75. private ExpenseRelationshipMapper expenseRelationshipMapper;
  76. @Autowired
  77. private DepartmentService departmentService;
  78. @Autowired
  79. private DepartmentMapper departmentMapper;
  80. @Autowired
  81. private ExpenseConfigDetailsMapper expenseConfigDetailsMapper;
  82. @Autowired
  83. private TOrderPublicReleaseCountMapper tOrderPublicReleaseCountMapper;
  84. @Autowired
  85. private OrderNewService orderNewService;
  86. @Autowired
  87. private OrderYearMaxDurationMapper orderYearMaxDurationMapper;
  88. @Autowired
  89. private UserMapper userMapper;
  90. @Autowired
  91. private TOrderMidMapper tOrderMidMapper;
  92. @Value(value = "${upload.path}")
  93. private final String uploadPath = null;
  94. @Override
  95. public Integer add(InputExpenseAccount in) {
  96. //如果关联公出,获取公出信息
  97. if (in.getPrid()!=null){
  98. PublicRelease pr = publicReleaseMapper.queryById(in.getPrid());
  99. in.setReleaseStart(pr.getReleaseStart());
  100. in.setReleaseEnd(pr.getReleaseEnd());
  101. in.setDistrictName(pr.getDistrictName());
  102. in.setUserNames(pr.getUserNames());
  103. in.setDuration(pr.getDuration());
  104. if (in.getOrderNo()==null)in.setOrderNo(pr.getOrderNo());
  105. }
  106. //判断报销类型,0=固定费用,1=报销到订单
  107. if (in.getOrderNo()==null){
  108. in.setTargetType(0);
  109. }else {
  110. in.setTargetType(1);
  111. }
  112. if (in.getAid()==null)in.setAid(TokenManager.getAdminId());
  113. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  114. in.setAname(admin.getName());
  115. in.setApplyDep(admin.getDepartmentId());
  116. in.setPayDep(admin.getDepartmentId());
  117. expenseAccountMapper.insertSelective(in);
  118. return in.getId();
  119. }
  120. /**
  121. * 新增报销审核流程
  122. */
  123. private void addExpenseAccountExamine(Integer id,ExpenseAccount ea) {
  124. List<ExpenseAccountExamine> list=new ArrayList<>();
  125. expenseAccountExamineMapper.deleteByEaid(ea.getId());
  126. String aid = TokenManager.getAdminId();
  127. OrganizationListOut dep = departmentMapper.selectAllById(ea.getApplyDep());
  128. AdminNoticeBo a = adminMapper.selectMyAndSuperBySuperId(aid);
  129. //暂时只发起到财务
  130. for (int i=1;i<4;i++){
  131. ExpenseAccountExamine eae=new ExpenseAccountExamine(id,i);
  132. if (i==1){
  133. if (a.getExpenseSuperExamine()==1){
  134. //新增一级
  135. String examineId=null;
  136. String examineName=null;
  137. //正常用上级,没有的情况下就是自己
  138. if (a.getSuperId()!=null){
  139. examineId=a.getSuperId();
  140. examineName=a.getSuperName();
  141. }else {
  142. examineId=a.getId();
  143. examineName=a.getName();
  144. }
  145. eae.setAuditor(examineId);
  146. eae.setAuditorname(examineName);
  147. ea.setExamineName(examineName);
  148. }
  149. if(a.getExpenseSuperExamine()==1) {
  150. eae.setStatus(0);
  151. } else {
  152. eae.setStatus(1);
  153. }
  154. }else if (i==2){
  155. if (StringUtils.isBlank(dep.getManagerName())){
  156. throw new BusinessException("报销申请部门[管理员]不存在。");
  157. }
  158. eae.setAuditor(dep.getManagerId());
  159. eae.setAuditorname(dep.getManagerName());
  160. }else if (i==3){
  161. if (StringUtils.isBlank(dep.getExpenseFinanceName()))throw new BusinessException("报销部门财务审核人不存在。");
  162. eae.setAuditor(dep.getExpenseFinanceId());
  163. eae.setAuditorname(dep.getExpenseFinanceName());
  164. }
  165. if (StringUtils.isNotEmpty(eae.getAuditor())){
  166. if (eae.getAuditor().equals(aid))eae.setStatus(1);
  167. else eae.setStatus(0);
  168. list.add(eae);
  169. }
  170. }
  171. expenseAccountExamineMapper.insertBatch(list);
  172. }
  173. /**
  174. * 新增报销日志
  175. * @param eaid 报销编号
  176. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  177. * @param str 备注
  178. */
  179. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str) {
  180. addExpenseAccountLog(eaid,status,processStatus,aid,str,null);
  181. }
  182. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str,Date date){
  183. addExpenseAccountLog(eaid,status,processStatus,aid,str,date,null);
  184. }
  185. /**
  186. * 新增报销日志
  187. * @param eaid 报销编号
  188. * @param status 状态 0发起 1通过 2完成 3驳回 4修改
  189. * @param str 备注
  190. */
  191. private void addExpenseAccountLog(Integer eaid, Integer status,Integer processStatus,String aid, String str,Date date,Integer showStatus) {
  192. ExpenseAccountLog eaLog=new ExpenseAccountLog();
  193. eaLog.setEaid(eaid);
  194. eaLog.setStatus(status);
  195. eaLog.setRemarks(str);
  196. eaLog.setProcessStatus(processStatus);
  197. eaLog.setAuditor(aid);
  198. if (showStatus!=null){
  199. eaLog.setShowStatus(showStatus);
  200. }else {
  201. eaLog.setShowStatus(0);
  202. }
  203. if (date !=null)eaLog.setCreateTime(date);
  204. expenseAccountLogMapper.insertSelective(eaLog);
  205. }
  206. /**
  207. * 发起、驳回发起流程切换和日志站内信发送
  208. */
  209. private void addExpenseAccountLogAndNoticEmail(ExpenseAccount in, Integer status, String str) {
  210. String aid=TokenManager.getAdminId();
  211. addExpenseAccountLog(in.getId(),status,in.getProcessStatus(),aid,str);
  212. if (status==0)in.setProcessStatus(1);
  213. Admin admin = adminMapper.selectByPrimaryKey(aid);
  214. if (admin.getExpenseSuperExamine()==0){
  215. String str2=String.format("未设置[%s]审核。",EAProcessStatus.getDesc(in.getProcessStatus()));
  216. Date date=new Date();
  217. date.setTime(date.getTime()+1000L);
  218. addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date,2);
  219. in.setProcessStatus(in.getProcessStatus()+1);
  220. }else {
  221. if (admin.getSuperiorId()==null||admin.getId().equals(admin.getSuperiorId())){
  222. String str2=String.format("%s跳过[%s]。",admin.getSuperiorId()==null?"发起人无上级":"发起人与上级同人",EAProcessStatus.getDesc(in.getProcessStatus()));
  223. Date date=new Date();
  224. date.setTime(date.getTime()+1000L);
  225. addExpenseAccountLog(in.getId(),1,in.getProcessStatus(),aid,str2,date,2);
  226. in.setProcessStatus(in.getProcessStatus()+1);
  227. }
  228. }
  229. createExamineByProcess(in);
  230. }
  231. /**
  232. * 判断审核流程与发送日志与邮件
  233. */
  234. private void createExamineByProcess(ExpenseAccount in) {
  235. //审核流程推送到最新
  236. AdminListBo admin = adminMapper.getDeptNameByAid(in.getAid());
  237. OrganizationListOut dep = departmentMapper.selectAllById(in.getApplyDep());
  238. List<ExpenseConfigDetails> configDetailsList = expenseConfigDetailsMapper.selectByDepId(in.getApplyDep());
  239. if (in.getApproval()==null)in.setApproval(0);
  240. examineByprocess(in,admin,dep,configDetailsList);
  241. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(in.getId(), in.getProcessStatus());
  242. List<Admin> aids=new ArrayList<>();
  243. StringBuffer aname =new StringBuffer();
  244. for (ExpenseAccountExamine e : list) {
  245. if (e.getProcessStatus()==in.getProcessStatus()&&e.getStatus()==0){
  246. Admin ad = adminMapper.selectByPrimaryKey(e.getAuditor());
  247. aids.add(ad);
  248. aname=aname.append(ad.getName()).append(",");
  249. }
  250. }
  251. in.setExamineName(aname.substring(0,aname.length()-1));
  252. StringBuffer str=new StringBuffer().append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  253. addNoticeAndEmail(in, EAProcessStatus.SJSH.getCode(),str.toString(), admin.getName(),aids);
  254. }
  255. @Override
  256. @Transactional
  257. public int update(InputExpenseAccount in) {
  258. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  259. if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
  260. throw new BusinessException("不能操作审核中与完成的订单");
  261. }
  262. if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
  263. in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  264. in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  265. }
  266. //计算总金额
  267. if (in.getTotalAmount()==null){
  268. pushExpenseAccountAmount(in);
  269. }
  270. in.setProcessStatus(0);
  271. if (in.getOrderNo()==null){
  272. in.setTargetType(0);
  273. }else {
  274. in.setTargetType(1);
  275. }
  276. //计算本单已扣金额 如果有选择借支单,则需要修改借支状态
  277. if (in.getDebitId()!=null){
  278. //如果以前没有选择借支,修改报销和借支数据
  279. if (useEA.getDebitId()==null){
  280. pushExpenseAccountDebit(in);
  281. }else if (useEA.getDebitId()!=in.getDebitId()) {
  282. //如果是修改编号
  283. pushExpenseAccountDebit(in);
  284. //并且要处理原编号的问题
  285. pushResettingDebit(in,useEA.getDebitId());
  286. }
  287. }
  288. if (in.getSettlementAmount()==null)in.setSettlementAmount(useEA.getSettlementAmount());
  289. in.setStatus(0);
  290. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  291. }
  292. private void pushExpenseAccountAmount(ExpenseAccount in) {
  293. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  294. List<OutExpenseAccountDetails> list = expenseAccountDetailsMapper.selectByEAid(in.getId());
  295. BigDecimal totalAmount = BigDecimal.ZERO;
  296. BigDecimal realAmount = BigDecimal.ZERO;
  297. for (OutExpenseAccountDetails e : list) {
  298. totalAmount=totalAmount.add(e.getAmount());
  299. realAmount=realAmount.add(e.getRealAmount());
  300. }
  301. in.setTotalAmount(totalAmount);
  302. if (useEA==null||useEA.getSettlementAmount()==null){
  303. in.setAmount(realAmount);
  304. }else {
  305. in.setAmount(realAmount.subtract(useEA.getSettlementAmount()));
  306. }
  307. in.setRealAmount(in.getAmount());
  308. }
  309. @Override
  310. public Object updateDebitId(InputExpenseAccount in) {
  311. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  312. if (useEA.getDebitId()!=null)pushResettingDebit(in,useEA.getDebitId());
  313. expenseAccountMapper.updateDeleteDebitId(in.getId());
  314. return 1;
  315. }
  316. @Override
  317. public Object delete(String ids) {
  318. String[] split = ids.split(",");
  319. for (String s : split) {
  320. Integer id=Integer.valueOf(s);
  321. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(id);
  322. if (expenseAccount.getStatus()!=0&&expenseAccount.getStatus()!=3){
  323. throw new BusinessException("该费用单状态无法删除");
  324. }
  325. List<OutExpenseAccountLog> logs = expenseAccountLogMapper.selectByEaid(id);
  326. if (logs.isEmpty()){
  327. expenseAccountMapper.deleteByPrimaryKey(id);
  328. }else {
  329. ExpenseAccount update =new ExpenseAccount();
  330. update.setId(id);
  331. update.setStatus(4);
  332. expenseAccountMapper.updateByPrimaryKeySelective(update);
  333. }
  334. }
  335. return 1;
  336. }
  337. @Override
  338. public Object pageListExport(InputPageListBo in) {
  339. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pageList(in).getList();
  340. for (OutExpenseAccountBo e : list) {
  341. if (e.getType()!=0){
  342. e.setTypeOther(EATypes.getDescByCode(e.getType()));
  343. }else{
  344. e.setTypeOther(String.format("其他(%s)",e.getTypeOther()));
  345. }
  346. }
  347. NewExcelUtil excelUtil=new NewExcelUtil(OutExpenseAccountBo.class);
  348. return excelUtil.exportExcel(list,"费用单列表",uploadPath);
  349. }
  350. @Override
  351. public Object detailsListExport(InputDetailsListBo in) {
  352. List<OutExpenseAccountDetailsList> list = (List<OutExpenseAccountDetailsList>) detailsList(in).getList();
  353. for (OutExpenseAccountDetailsList e : list) {
  354. if (e.getTargetType()!=null){
  355. if (e.getTargetType()==0){
  356. e.setTargetName("固定费用");
  357. }else {
  358. e.setTargetName(e.getContractNo()+"/"+e.getBuyerName());
  359. }
  360. }
  361. if (e.getType()!=0){
  362. e.setTypeOther(EAsecondaryTypes.getDescByCode(e.getType()));
  363. }else{
  364. //如果是其他,又说明显示说明,没有说明显示费用类型
  365. if (StringUtils.isBlank(e.getTypeOther())){
  366. if (e.getSonType()!=0){
  367. e.setTypeOther(EATypes.getDescByCode(e.getSonType()));
  368. }else{
  369. e.setTypeOther(String.format("其他(%s)",e.getSonTypeOther()));
  370. }
  371. }else {
  372. e.setTypeOther(String.format("其他(%s)",e.getTypeOther()));
  373. }
  374. }
  375. if(e.getReleaseStart()!=null&&e.getReleaseEnd()!=null){
  376. e.setReleaseTimeStr(DateUtils.formatDate(e.getReleaseStart(),AFTConstants.YYYYMMDDHHMM)+"~"+DateUtils.formatDate(e.getReleaseEnd(),AFTConstants.YYYYMMDDHHMM));
  377. }
  378. }
  379. NewExcelUtil excelUtil=new NewExcelUtil(OutExpenseAccountDetailsList.class);
  380. return excelUtil.exportExcel(list,"费用详细列表",uploadPath);
  381. }
  382. @Override
  383. public Object getDepDetails(Integer id) {
  384. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(id);
  385. OrganizationListOut organizationListOut = departmentMapper.selectAllById(outExpenseAccount.getApplyDep());
  386. return organizationListOut;
  387. }
  388. @Override
  389. public Object updateTypeOther(Integer id, String typeOther,String remarks,String orderNo) {
  390. ExpenseAccount ea = new ExpenseAccount();
  391. ea.setId(id);
  392. if (StringUtils.isNotEmpty(typeOther)){
  393. ea.setTypeOther(typeOther);
  394. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  395. }
  396. if (StringUtils.isNotEmpty(remarks)){
  397. ea.setRemarks(remarks);
  398. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  399. }
  400. if (StringUtils.isBlank(orderNo)){
  401. ea.setTargetType(0);
  402. expenseAccountMapper.updateRemoveOrderNo(ea);
  403. }else {
  404. ea.setOrderNo(orderNo);
  405. ea.setTargetType(1);
  406. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  407. }
  408. if (StringUtils.isNotEmpty(typeOther)){
  409. MainExpenseAccount mainExpenseAccount = expenseAccountMapper.selectbySonId(id);
  410. StringBuffer types=new StringBuffer();
  411. for (SonExpenseAccount e : mainExpenseAccount.getSonList()) {
  412. if (e.getType()!=0){
  413. types.append(EATypes.getDescByCode(e.getType()));
  414. }else {
  415. types.append(e.getTypeOther());
  416. }
  417. if (e.getType()==2){
  418. if (e.getSecondaryType()==0){
  419. types.append("-").append(e.getSecondaryTypeOther());
  420. }else{
  421. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  422. types.append("-").append(descByCode);
  423. }
  424. }
  425. types.append(",");
  426. }
  427. expenseAccountMapper.updateSonTypeOther(id,types.substring(0,types.length()-1));
  428. }
  429. return 1;
  430. }
  431. @Override
  432. public Object updateDetailsTypeOther(Integer id, String typeOther) {
  433. ExpenseAccountDetails in =new ExpenseAccountDetails();
  434. in.setId(id);
  435. in.setTypeOther(typeOther);
  436. return expenseAccountDetailsMapper.updateByPrimaryKeySelective(in);
  437. }
  438. @Override
  439. public Object mainExpenseExport(Integer id, HttpServletResponse response) {
  440. MainExpenseAccount mainExpenseAccount = mainExpense(id);
  441. pushMainExpenseExport(mainExpenseAccount,response,uploadPath);
  442. return 1;
  443. }
  444. @Override
  445. public void pushExpenseTotalAmount() {
  446. // orderNewService.pushOrderPublicReleaseCount("800326086952370176");
  447. List<TOrderNew> tOrderNews = orderNewService.selectGetAll();
  448. for (TOrderNew e : tOrderNews) {
  449. orderNewService.pushOrderPublicReleaseCount(e);
  450. }
  451. }
  452. public void pushMainExpenseExport(MainExpenseAccount mainExpenseAccount,HttpServletResponse response, String uploadPath) {
  453. String title = "报销明细表";
  454. String attName = String.format("报销明细表_%s.pdf",new Date().getTime());
  455. String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
  456. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  457. Document document=new Document();
  458. try {
  459. FileUtils.setAttachmentResponseHeader(response, title,attName);
  460. FileOutputStream outputStream = new FileOutputStream(realFileName);
  461. PdfWriter.getInstance(document, outputStream);
  462. document.open();
  463. Paragraph paragraph = new Paragraph(title, PDFUtils.getTitleFont());
  464. paragraph.setAlignment(1);
  465. document.add(paragraph);
  466. //默认算60
  467. PDFUtils.pushExpenseTitle(document,mainExpenseAccount);
  468. PdfPTable table = new PdfPTable(12);
  469. table.setWidthPercentage(100);
  470. ArrayList<PdfPRow> rows = table.getRows();
  471. float[] columnWidths ={12,24,14,50,50,42,28,18,12,12,50,50};
  472. table.setWidths(columnWidths);
  473. table.setSpacingBefore(10f);
  474. table.setSpacingAfter(10f);
  475. //填充表格头部
  476. addTitle(rows);
  477. //获取填充数据
  478. List<Map<Integer,String>> mapList = pushMainExpenseAccount(mainExpenseAccount);
  479. //填充数据写入表格
  480. pushTable(rows,mapList);
  481. document.add(table);
  482. document.close();
  483. outputStream.close();
  484. // FileUtils.writeBytes(realFileName, response.getOutputStream());
  485. // FileUtils.deleteFile(realFileName);
  486. } catch (DocumentException | IOException e) {
  487. e.printStackTrace();
  488. }
  489. }
  490. private static void addTitle(ArrayList<PdfPRow> rows) {
  491. PdfPCell[] cells =new PdfPCell[12];
  492. PdfPRow row=new PdfPRow(cells);
  493. cells[0] = new PdfPCell(new Phrase("序号",PDFUtils.getFont(8)));
  494. cells[1] = new PdfPCell(new Phrase("费用时间",PDFUtils.getFont(8)));
  495. cells[2] = new PdfPCell(new Phrase("时长",PDFUtils.getFont(8)));
  496. cells[3] = new PdfPCell(new Phrase("出差地址",PDFUtils.getFont(8)));
  497. cells[4] = new PdfPCell(new Phrase("出差企业",PDFUtils.getFont(8)));
  498. cells[5] = new PdfPCell(new Phrase("合同编号",PDFUtils.getFont(8)));
  499. cells[6] = new PdfPCell(new Phrase("类型",PDFUtils.getFont(8)));
  500. cells[7] = new PdfPCell(new Phrase("详情",PDFUtils.getFont(8)));
  501. cells[8] = new PdfPCell(new Phrase("费用",PDFUtils.getFont(8)));
  502. cells[9] = new PdfPCell(new Phrase("实报",PDFUtils.getFont(8)));
  503. cells[10] = new PdfPCell(new Phrase("出差事由",PDFUtils.getFont(8)));
  504. cells[11] = new PdfPCell(new Phrase("报销订单/部门",PDFUtils.getFont(8)));
  505. rows.add(row);
  506. }
  507. private void pushTable(ArrayList<PdfPRow> rows, List<Map<Integer, String>> mapList) {
  508. for (Map<Integer, String> map : mapList) {
  509. PdfPCell[] cells =new PdfPCell[12];
  510. PdfPRow row=new PdfPRow(cells);
  511. for (int i = 0; i < 12; i++) {
  512. cells[i] = new PdfPCell(new Phrase(map.get(i),PDFUtils.getFont(8)));
  513. }
  514. rows.add(row);
  515. }
  516. }
  517. private List<Map<Integer, String>> pushMainExpenseAccount(MainExpenseAccount mainExpenseAccount) {
  518. List<Map<Integer,String>> mapList = new ArrayList<>();
  519. if (mainExpenseAccount.getSonList()!=null){
  520. int index=0;
  521. for (SonExpenseAccount e : mainExpenseAccount.getSonList()) {
  522. List<SonExpenseAccountDetails> detList = e.getDetList();
  523. //详情计算,详情完成后需要一个统计
  524. int detIndex = 0;
  525. for (SonExpenseAccountDetails det : detList) {
  526. index++;
  527. detIndex++;
  528. Map<Integer, String> map = new HashMap<>();
  529. map.put(0, String.valueOf(index));
  530. if (detIndex==1){
  531. if (e.getPublicReleaseType()!=null){
  532. map.put(1,DateUtils.formatDate(e.getReleaseStart(),AFTConstants.YYYYMMDDHHMM)+"~"+DateUtils.formatDate(e.getReleaseEnd(),AFTConstants.YYYYMMDDHHMM));
  533. map.put(2,e.getDuration());
  534. map.put(3,e.getDistrictName());
  535. map.put(4,e.getUserNames());
  536. map.put(6,getExpenseType(e));
  537. }else {
  538. map.put(1,det.getAgreeTime());
  539. map.put(2,"");
  540. map.put(3,"");
  541. map.put(4,"");
  542. map.put(6,"");
  543. }
  544. }else {
  545. map.put(1,det.getAgreeTime());
  546. map.put(2,"");
  547. map.put(3,"");
  548. map.put(4,"");
  549. map.put(6,"");
  550. }
  551. map.put(5,e.getContractNo());
  552. map.put(7,getExpenseSecondaryType(e,det));
  553. map.put(8,getBigDecimalZeros(det.getAmount()));
  554. map.put(9,getBigDecimalZeros(det.getRealAmount()));
  555. map.put(10,e.getPlan());
  556. if (index==1){
  557. map.put(11,getOrderNoAndDepartment(e,mainExpenseAccount.getApplyDepName()));
  558. }else {
  559. map.put(11,"");
  560. }
  561. mapList.add(map);
  562. if (detIndex==detList.size()){
  563. index++;
  564. addCount(e.getAmount(),e.getRealAmount(),mapList,index);
  565. }
  566. }
  567. }
  568. //循环结束新增合计
  569. index++;
  570. addCount(mainExpenseAccount.getAmount(),mainExpenseAccount.getRealAmount(),mapList,index,1);
  571. }
  572. return mapList;
  573. }
  574. private String getBigDecimalZeros(BigDecimal amount) {
  575. return amount.stripTrailingZeros().toEngineeringString();
  576. }
  577. private void addCount(BigDecimal amount,BigDecimal realAmount,List<Map<Integer, String>> mapList,int index) {
  578. addCount(amount,realAmount,mapList,index,0);
  579. }
  580. private void addCount(BigDecimal amount,BigDecimal realAmount,List<Map<Integer, String>> mapList,int index,int type) {
  581. String str="小计";
  582. if (type==1)str="合计";
  583. Map<Integer, String> map = new HashMap<>();
  584. for (int i = 0; i < 12; i++){
  585. if (i==0){
  586. map.put(i, String.valueOf(index));
  587. }else if (i==7){
  588. map.put(i, str);
  589. }else if (i==8){
  590. map.put(i, getBigDecimalZeros(amount));
  591. }else if (i==9){
  592. map.put(i, getBigDecimalZeros(realAmount));
  593. }else {
  594. map.put(i, "");
  595. }
  596. }
  597. mapList.add(map);
  598. }
  599. private String getOrderNoAndDepartment(SonExpenseAccount e,String applyDepName) {
  600. return e.getOrderNo()+"\n"+applyDepName;
  601. }
  602. private String getExpenseSecondaryType(SonExpenseAccount e,SonExpenseAccountDetails det) {
  603. if (e.getType()==1){
  604. if (det.getType()==1){
  605. //交通工具待完善
  606. }
  607. }
  608. if (e.getSecondaryType()==0){
  609. return EAsecondaryTypes.getDescByCode(e.getSecondaryType())+"("+e.getSecondaryTypeOther()+")";
  610. }
  611. return EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  612. }
  613. private String getExpenseType(SonExpenseAccount e) {
  614. if (e.getType()==0){
  615. return EATypes.getDescByCode(e.getType())+"("+e.getTypeOther()+")";
  616. }
  617. return EATypes.getDescByCode(e.getType());
  618. }
  619. private void pushResettingDebit(InputExpenseAccount in, Integer debitId) {
  620. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(debitId);
  621. List<ExpenseAccount> list = expenseAccountMapper.selectByDebitId(debitId);
  622. ExpenseAccount newDebit=new ExpenseAccount();
  623. newDebit.setId(debitId);
  624. //计算除开当前单,已选择抵扣金额
  625. BigDecimal count=new BigDecimal(0);
  626. for (ExpenseAccount e : list) {
  627. if (!in.getId().equals(e.getId())){
  628. count=count.add(e.getSettlementAmount());
  629. }
  630. }
  631. newDebit.setSettlementAmount(count);
  632. if (count.compareTo(new BigDecimal(0))==0){
  633. newDebit.setLiquidationStatus(0);
  634. }else if (count.compareTo(debit.getRealAmount())<0){
  635. newDebit.setLiquidationStatus(1);
  636. }else if (count.compareTo(debit.getRealAmount())==0){
  637. newDebit.setLiquidationStatus(2);
  638. }
  639. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  640. }
  641. private void pushExpenseAccountDebit(InputExpenseAccount in) {
  642. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(in.getDebitId());
  643. ExpenseAccount newDebit=new ExpenseAccount();
  644. newDebit.setId(debit.getId());
  645. //计算剩余需要支付金额
  646. BigDecimal decbitAmount=debit.getRealAmount().subtract(debit.getSettlementAmount());
  647. //本次金额大于等于需要抵扣金额,则变成完全抵扣,抵扣金额变成本次已付金额
  648. if (in.getRealAmount().compareTo(decbitAmount)>=0){
  649. in.setSettlementAmount(decbitAmount);
  650. newDebit.setSettlementAmount(debit.getRealAmount());
  651. newDebit.setLiquidationStatus(2);
  652. }else {
  653. // 本次金额小于需要抵扣,则本次变更全抵扣,借支已付加上本次金额
  654. in.setSettlementAmount(in.getRealAmount());
  655. BigDecimal setAmount=new BigDecimal(0).add(debit.getSettlementAmount()).add(in.getRealAmount());
  656. newDebit.setSettlementAmount(setAmount);
  657. newDebit.setLiquidationStatus(1);
  658. }
  659. expenseAccountMapper.updateByPrimaryKeySelective(newDebit);
  660. }
  661. @Override
  662. public int addDetails(InputExpenseAccountDetails in) {
  663. if (in.getAgreeTimes()!=null){
  664. in.setAgreeTime(DateUtils.StringToDate(in.getAgreeTimes(),AFTConstants.YYYYMMDD));
  665. }
  666. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(in.getEaid());
  667. if (expenseAccount.getType()==2){
  668. in.setType(expenseAccount.getSecondaryType());
  669. if (in.getType()==0){
  670. in.setTypeOther(expenseAccount.getSecondaryTypeOther());
  671. }
  672. }
  673. in.setRealAmount(in.getAmount());
  674. expenseAccountDetailsMapper.insertSelective(in);
  675. ExpenseAccount ea =new ExpenseAccount();
  676. ea.setId(in.getEaid());
  677. pushExpenseAccountAmount(ea);
  678. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  679. return 1;
  680. }
  681. @Override
  682. public int deleteDetails(Integer id) {
  683. ExpenseAccountDetails expenseAccountDetails = expenseAccountDetailsMapper.selectByPrimaryKey(id);
  684. Integer eaid=expenseAccountDetails.getEaid();
  685. expenseAccountDetailsMapper.deleteByPrimaryKey(id);
  686. ExpenseAccount ea =new ExpenseAccount();
  687. ea.setId(eaid);
  688. pushExpenseAccountAmount(ea);
  689. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  690. return 1;
  691. }
  692. @Override
  693. public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
  694. return expenseAccountDetailsMapper.selectByEAid(eaid);
  695. }
  696. @Override
  697. public Object logList(Integer eaid) {
  698. List<OutExpenseAccountLog> list = expenseAccountLogMapper.selectByEaid(eaid);
  699. if (!list.isEmpty()) {
  700. OutExpenseAccountLog lastout = list.get(list.size() - 1);
  701. ExpenseAccount expenseAccount = expenseAccountMapper.selectByPrimaryKey(eaid);
  702. Integer processStatus = lastout.getProcessStatus();
  703. if (lastout.getStatus() < 2) {
  704. if (processStatus <3){
  705. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountExamineMapper.selectNotExamineByEaidAndProcessStatus(eaid, processStatus);
  706. list.addAll(outExpenseAccountLogs);
  707. }else {
  708. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(eaid, processStatus);
  709. for (ExpenseAccountExamine e : expenseAccountExamines) {
  710. if (e.getStatus()==0){
  711. OutExpenseAccountLog out =new OutExpenseAccountLog();
  712. out.setEaid(eaid);
  713. out.setProcessStatus(e.getProcessStatus());
  714. out.setAuditorName(e.getAuditorname());
  715. list.add(out);
  716. }
  717. }
  718. }
  719. if (processStatus<8)addDetailsLog(list, expenseAccount,processStatus);
  720. }
  721. }
  722. return list;
  723. }
  724. private void addDetailsLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount,Integer useStatus) {
  725. OrganizationListOut dep = departmentMapper.selectAllById(expenseAccount.getApplyDep());
  726. List<ExpenseConfigDetails> configDetails = expenseConfigDetailsMapper.selectByDepId(expenseAccount.getApplyDep());
  727. for (int processStatus = useStatus; processStatus < 8; processStatus++) {
  728. if (processStatus ==3){
  729. if (dep.getExpenseRetrialFinanceExamine()==1){
  730. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  731. for (ExpenseConfigDetails e : collect) {
  732. addDetailsTypeLog(list, expenseAccount, e);
  733. }
  734. }
  735. }else if (processStatus ==4){
  736. if (expenseAccount.getApproval()==1&&dep.getCeoExamine()==1){
  737. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 2).collect(Collectors.toList());
  738. for (ExpenseConfigDetails e : collect) {
  739. addDetailsTypeLog(list, expenseAccount, e);
  740. }
  741. }
  742. }else if (processStatus ==5){
  743. if (dep.getCfoExamine()==1){
  744. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 3).collect(Collectors.toList());
  745. for (ExpenseConfigDetails e : collect) {
  746. addDetailsTypeLog(list, expenseAccount, e);
  747. }
  748. }
  749. }else if (processStatus ==6){
  750. if (dep.getViceCeoExamine()==1){
  751. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  752. for (ExpenseConfigDetails e : collect) {
  753. addDetailsTypeLog(list, expenseAccount, e);
  754. }
  755. }
  756. }else if (processStatus ==7){
  757. if (dep.getCashierExamine()==1){
  758. List<ExpenseConfigDetails> collect = configDetails.stream().filter(e -> e.getType() == 5).collect(Collectors.toList());
  759. for (ExpenseConfigDetails e : collect) {
  760. addDetailsTypeLog(list, expenseAccount, e);
  761. }
  762. }
  763. }
  764. }
  765. }
  766. private static void addDetailsTypeLog(List<OutExpenseAccountLog> list, ExpenseAccount expenseAccount, ExpenseConfigDetails e) {
  767. OutExpenseAccountLog addLog=new OutExpenseAccountLog();
  768. addLog.setEaid(expenseAccount.getId());
  769. addLog.setAuditor(e.getAid());
  770. addLog.setAuditorName(e.getAdminName());
  771. list.add(addLog);
  772. }
  773. @Override
  774. public int updateExamine(InputExpenseAccount in) {
  775. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  776. ExpenseAccount newEa=new ExpenseAccount();
  777. newEa.setId(useEa.getId());
  778. newEa.setApproval(in.getApproval());
  779. in.setCheckNo(useEa.getCheckNo());
  780. in.setProcessStatus(useEa.getProcessStatus());
  781. //审核通知 获取发送人
  782. AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
  783. //项目推送流程及添加日志
  784. addExamineExpenseAccountLog(admin,in, useEa, newEa);
  785. //完成申请
  786. if (newEa.getStatus()==2){
  787. //如果是借支则订单新增
  788. List<ExpenseAccount> expenseAccounts1 = expenseAccountMapper.selectListByMainId(in.getId());
  789. for (ExpenseAccount e : expenseAccounts1) {
  790. if (e.getType()!=4){
  791. //不然就看是否挂载借支订单进行抵扣
  792. if (e.getDebitId()!=null){
  793. ExpenseAccount useDebit=expenseAccountMapper.selectByPrimaryKey(e.getDebitId());
  794. if (useDebit.getLiquidationStatus()==2){
  795. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByDebitId(e.getDebitId());
  796. boolean flag=true;
  797. for (ExpenseAccount expenseAccount : expenseAccounts) {
  798. if(!expenseAccount.getId().equals(in.getId())&&expenseAccount.getStatus()!=2){
  799. flag=false;
  800. break;
  801. }
  802. }
  803. if (flag){
  804. ExpenseAccount debit=new ExpenseAccount();
  805. debit.setId(e.getDebitId());
  806. debit.setLiquidationStatus(3);
  807. expenseAccountMapper.updateByPrimaryKeySelective(debit);
  808. }
  809. }
  810. }
  811. }
  812. ExpenseAccount updateSon=new ExpenseAccount();
  813. updateSon.setId(e.getId());
  814. updateSon.setStatus(2);
  815. expenseAccountMapper.updateByPrimaryKeySelective(updateSon);
  816. if (e.getOrderNo()!=null){
  817. tOrderMidMapper.updateOExpense(e.getOrderNo());
  818. }
  819. }
  820. }else if (newEa.getStatus()==1){
  821. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  822. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),0);
  823. //处理金额修改
  824. if(in.getRealList()!=null){
  825. List<Map> maps = JSONObject.parseArray(in.getRealList(), Map.class);
  826. for (Map map: maps) {
  827. Integer type= (Integer) map.get("type");
  828. Integer id= (Integer) map.get("id");
  829. BigDecimal amount= new BigDecimal(map.get("amount").toString());
  830. //type=1总计,type=2报销金额
  831. if(type==1){
  832. ExpenseAccount ea =new ExpenseAccount();
  833. ea.setId(id);
  834. ea.setRealAmount(amount);
  835. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  836. }else if (type==2){
  837. ExpenseAccountDetails ead=new ExpenseAccountDetails();
  838. ead.setId(id);
  839. ead.setRealAmount(amount);
  840. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ead);
  841. }
  842. }
  843. }
  844. }else if (newEa.getProcessStatus()==EAProcessStatus.CWSH.getCode()){
  845. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),1);
  846. }
  847. }else if (newEa.getStatus()==3){
  848. if (useEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  849. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),2);
  850. }else if (newEa.getProcessStatus()>EAProcessStatus.CWSH.getCode()){
  851. pushFinanceCount(admin.getDepFinance(),useEa.getCreateTime(),3);
  852. }
  853. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),null,0,0);
  854. }
  855. expenseAccountMapper.updateByPrimaryKeySelective(newEa);
  856. expenseAccountMapper.updateSonByMainId(newEa.getId());
  857. return 1;
  858. }
  859. private void addFinanceCount(String aid,Date startTime ) {
  860. String forDate=DateUtils.formatDate(startTime,AFTConstants.YYYYMMDD);
  861. addFinanceCount(aid,forDate);
  862. }
  863. private void addFinanceCount(String aid,String startTime ) {
  864. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  865. if (financeCount ==null){
  866. financeCount =FinanceCount.initialization(aid, startTime);
  867. financeCount.setExpenseCount(1);
  868. financeCount.setExpenseUnauditedCount(1);
  869. financeCountMapper.insertSelective(financeCount);
  870. }else {
  871. FinanceCount newFinanceCount =new FinanceCount();
  872. newFinanceCount.setId(financeCount.getId());
  873. newFinanceCount.setExpenseCount(financeCount.getExpenseCount()+1);
  874. newFinanceCount.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  875. financeCountMapper.updateByPrimaryKeySelective(newFinanceCount);
  876. }
  877. }
  878. private void addExamineExpenseAccountLog(AdminListBo admin,InputExpenseAccount in, ExpenseAccount useEa, ExpenseAccount newEa) {
  879. List<Admin> aids=new ArrayList<>();
  880. StringBuffer str=new StringBuffer();
  881. Integer status=in.getStatus();
  882. if (status==1){
  883. //审核处理审核表
  884. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,0);
  885. str=str.append("编号[").append(in.getCheckNo()).append("]需要审核").append(",请查看并审核。");
  886. newEa.setAid(useEa.getAid());
  887. newEa.setCreateTime(useEa.getCreateTime());
  888. newEa.setApplyDep(useEa.getApplyDep());
  889. //在跳入董事长审核的时候非特批直接跳过,原则上下个流程不可再跳过
  890. OrganizationListOut dep = departmentMapper.selectAllById(newEa.getApplyDep());
  891. List<ExpenseConfigDetails> configDetailsList = expenseConfigDetailsMapper.selectByDepId(newEa.getApplyDep());
  892. if(useEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  893. expenseAccountExamineMapper.updateStatusByEaidAndAid(in.getId(),TokenManager.getAdminId(),1,1);
  894. boolean expenseExamine = pushExpenseExamine(configDetailsList, newEa, EAProcessStatus.CNSH.getCode());
  895. if (expenseExamine){
  896. //完成后的流程
  897. status =2;
  898. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  899. newEa.setStatus(status);
  900. newEa.setExamineName("");
  901. }else {
  902. status =1;
  903. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), useEa.getProcessStatus());
  904. StringBuffer aname =new StringBuffer();
  905. for (ExpenseAccountExamine e : list) {
  906. if (e.getStatus()==0){
  907. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  908. aids.add(ad);
  909. aname=aname.append(ad.getName()).append(",");
  910. }
  911. }
  912. newEa.setExamineName(aname.substring(0,aname.length()-1));
  913. }
  914. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  915. }else {
  916. //小于为固定单审核,大于可能被配置多人审核
  917. if (useEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  918. boolean flag=false;
  919. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), useEa.getProcessStatus());
  920. for (ExpenseAccountExamine e : list) {
  921. if (e.getAuditor().equals(TokenManager.getAdminId())){
  922. flag=true;
  923. }
  924. }
  925. if (!flag)throw new BusinessException("审核角色错误。请刷新页面");
  926. newEa.setProcessStatus(useEa.getProcessStatus()+1);
  927. }else {
  928. newEa.setProcessStatus(useEa.getProcessStatus());
  929. }
  930. addExpenseAccountLog(in.getId(),status,useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  931. newEa.setStatus(1);
  932. if (newEa.getApproval()==null)newEa.setApproval(useEa.getApproval());
  933. //流程的推动
  934. examineByprocess(newEa,admin,dep,configDetailsList);
  935. //推动到出纳如果设置无需则完成不设置下个人,否则就要设置
  936. if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  937. if(dep.getCashierExamine()==1){
  938. pushExamineName(newEa, aids);
  939. }else {
  940. //完成后的流程
  941. status =2;
  942. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  943. newEa.setStatus(status);
  944. newEa.setExamineName("");
  945. }
  946. }else {
  947. pushExamineName(newEa, aids);
  948. }
  949. }
  950. }else {
  951. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  952. newEa.setStatus(3);
  953. newEa.setProcessStatus(0);
  954. str.setLength(0);
  955. addExpenseAccountLog(in.getId(),newEa.getStatus(),useEa.getProcessStatus(),TokenManager.getAdminId(),in.getReason());
  956. str=str.append("您的报销审核已驳回,报销编号[").append(in.getCheckNo()).append("],请注意查看。");
  957. }
  958. if (newEa.getStatus()==null)newEa.setStatus(1);
  959. addNoticeAndEmail(in, status,str.toString(),admin.getName(),aids);
  960. }
  961. private void pushExamineName(ExpenseAccount newEa, List<Admin> aids) {
  962. List<ExpenseAccountExamine> list=expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  963. StringBuffer aname =new StringBuffer();
  964. for (ExpenseAccountExamine e : list) {
  965. if (e.getProcessStatus()== newEa.getProcessStatus()&&e.getStatus()==0){
  966. Admin ad=adminMapper.selectByPrimaryKey(e.getAuditor());
  967. aids.add(ad);
  968. aname=aname.append(ad.getName()).append(",");
  969. }
  970. }
  971. newEa.setExamineName(aname.substring(0,aname.length()-1));
  972. }
  973. /**
  974. *
  975. * @param aid
  976. * @param createTime
  977. * @param type 0 双新增 1 未审核减一 2双减 3总数减一
  978. */
  979. private void pushFinanceCount(String aid, Date createTime, Integer type) {
  980. String startTime= DateUtils.formatDate(createTime,AFTConstants.YYYYMMDD);
  981. FinanceCount financeCount = financeCountMapper.selectByAidAndDates(aid, startTime);
  982. FinanceCount newFinance=new FinanceCount();
  983. if (financeCount==null){
  984. newFinance=FinanceCount.initialization(aid,createTime);
  985. newFinance.setExpenseCount(1);
  986. newFinance.setExpenseUnauditedCount(1);
  987. financeCountMapper.insertSelective(newFinance);
  988. }else {
  989. newFinance.setId(financeCount.getId());
  990. if(type==0){
  991. newFinance.setExpenseCount(financeCount.getExpenseCount()+1);
  992. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()+1);
  993. }else if(type==1){
  994. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  995. }else if(type==2){
  996. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  997. newFinance.setExpenseUnauditedCount(financeCount.getExpenseUnauditedCount()-1);
  998. }else if(type==3){
  999. newFinance.setExpenseCount(financeCount.getExpenseCount()-1);
  1000. }
  1001. financeCountMapper.updateByPrimaryKeySelective(newFinance);
  1002. }
  1003. }
  1004. /**
  1005. * 审核流程推送,只要不是完成状态就继续判断是否跳过
  1006. * @param newEa
  1007. */
  1008. private void examineByprocess( ExpenseAccount newEa,AdminListBo admin,OrganizationListOut dep,List<ExpenseConfigDetails> list) {
  1009. List<ExpenseAccountExamine> examineList=new ArrayList<>();
  1010. //小于财务复审的,走单审核
  1011. if (newEa.getProcessStatus()<EAProcessStatus.CWFS.getCode()){
  1012. examineList = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), newEa.getProcessStatus());
  1013. boolean flag=false;
  1014. String aid="";
  1015. if (examineList.size()>0){
  1016. for (ExpenseAccountExamine e : examineList) {
  1017. if (e.getStatus()==1){
  1018. flag=true;
  1019. aid=e.getAuditor();
  1020. break;
  1021. }
  1022. }
  1023. }
  1024. //如果当前审核人已经审核,则跳过当前审核
  1025. if (flag){
  1026. String str=String.format("重复审核人跳过[%s]。",EAProcessStatus.getDesc(newEa.getProcessStatus()));
  1027. Date date=new Date();
  1028. date.setTime(date.getTime()+1000l);
  1029. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date,2);
  1030. if (newEa.getProcessStatus()==EAProcessStatus.BMFZRSH.getCode()){
  1031. addFinanceCount(admin.getDepFinance(),newEa.getCreateTime());
  1032. }
  1033. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  1034. examineByprocess(newEa,admin,dep,list);
  1035. }
  1036. }else {
  1037. //大于等于财务复审的,走多审核
  1038. String str=null;
  1039. //跳过标记
  1040. boolean flag2= false;
  1041. //审核通过标记
  1042. boolean flag3= false;
  1043. Date date2=new Date();
  1044. date2.setTime(date2.getTime()+1000l);
  1045. String tip=null;
  1046. String aid=null;
  1047. if (newEa.getProcessStatus()==EAProcessStatus.CWFS.getCode()){
  1048. //财务复审财务复审
  1049. if (dep.getExpenseRetrialFinanceExamine()==0){
  1050. flag2=true;
  1051. tip=EAProcessStatus.CWFS.getDesc();
  1052. }else {
  1053. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWFS.getCode());
  1054. if (expenseExamine){
  1055. flag3=true;
  1056. }
  1057. }
  1058. }else if (newEa.getProcessStatus()==EAProcessStatus.DSZSH.getCode()){
  1059. if (newEa.getApproval()!=1){
  1060. flag2=true;
  1061. tip="特批(财务选择)";
  1062. }else {
  1063. if (dep.getCeoExamine()==1){
  1064. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.DSZSH.getCode());
  1065. if (expenseExamine){
  1066. flag3=true;
  1067. }
  1068. }else {
  1069. flag2=true;
  1070. tip="特批(部门设置)";
  1071. }
  1072. }
  1073. }else if (newEa.getProcessStatus()==EAProcessStatus.CWGGLYSH.getCode()){
  1074. if (dep.getExpenseRetrialFinanceExamine()==0){
  1075. flag2=true;
  1076. tip=EAProcessStatus.CWGGLYSH.getDesc();
  1077. aid=null;
  1078. }else {
  1079. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.CWGGLYSH.getCode());
  1080. if (expenseExamine){
  1081. flag3=true;
  1082. }
  1083. }
  1084. }else if (newEa.getProcessStatus()==EAProcessStatus.GSFSSH.getCode()){
  1085. if (dep.getExpenseRetrialFinanceExamine()==0){
  1086. flag2=true;
  1087. tip=EAProcessStatus.GSFSSH.getDesc();
  1088. }else {
  1089. boolean expenseExamine = pushExpenseExamine(list, newEa, EAProcessStatus.GSFSSH.getCode());
  1090. if (expenseExamine){
  1091. flag3=true;
  1092. }
  1093. }
  1094. }else if (newEa.getProcessStatus()==EAProcessStatus.CNSH.getCode()){
  1095. if (dep.getExpenseRetrialFinanceExamine()==0){
  1096. flag2=true;
  1097. tip=EAProcessStatus.CNSH.getDesc();
  1098. }else {
  1099. //财务出纳在审核时不与前置审核做同步
  1100. pushExpenseExamine(list, newEa, EAProcessStatus.CNSH.getCode());
  1101. }
  1102. }
  1103. if (flag2){
  1104. if (str==null)str=String.format("未设置[%s]审核,跳过此流程",tip);
  1105. if (newEa.getProcessStatus()<EAProcessStatus.CNSH.getCode()){
  1106. date2.setTime(date2.getTime()+100);
  1107. addExpenseAccountLog(newEa.getId(),1,newEa.getProcessStatus(),aid,str,date2,2);
  1108. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  1109. examineByprocess(newEa,admin,dep,list);
  1110. }else {
  1111. date2.setTime(date2.getTime()+100);
  1112. addExpenseAccountLog(newEa.getId(),2,newEa.getProcessStatus(),aid,str,date2,2);
  1113. newEa.setProcessStatus(newEa.getProcessStatus());
  1114. newEa.setStatus(2);
  1115. }
  1116. }else if (flag3){
  1117. newEa.setProcessStatus(newEa.getProcessStatus()+1);
  1118. examineByprocess(newEa,admin,dep,list);
  1119. }
  1120. }
  1121. }
  1122. private boolean pushExpenseExamine(List<ExpenseConfigDetails> list, ExpenseAccount newEa, Integer status) {
  1123. int configDetails=0;
  1124. if (status==EAProcessStatus.CWFS.getCode())configDetails=1;
  1125. else if (status==EAProcessStatus.DSZSH.getCode())configDetails=2;
  1126. else if (status==EAProcessStatus.CWGGLYSH.getCode())configDetails=3;
  1127. else if (status==EAProcessStatus.GSFSSH.getCode())configDetails=4;
  1128. else if (status==EAProcessStatus.CNSH.getCode())configDetails=5;
  1129. int finalConfigDetails = configDetails;
  1130. //查询审核表,如果为空就新增,不然直接判定审核
  1131. List<ExpenseAccountExamine> expenseAccountExamines = expenseAccountExamineMapper.selectByEaidAndProcessStatus(newEa.getId(), status);
  1132. int count = 0;
  1133. int size=10;
  1134. if (expenseAccountExamines.isEmpty()){
  1135. List<ExpenseConfigDetails> collect = list.stream().filter(e -> e.getType() == finalConfigDetails).collect(Collectors.toList());
  1136. size= collect.size();
  1137. for (ExpenseConfigDetails e : collect) {
  1138. ExpenseAccountExamine eae=new ExpenseAccountExamine(newEa.getId(),status);
  1139. eae.setAuditor(e.getAid());
  1140. eae.setAuditorname(e.getAdminName());
  1141. eae.setStatus(0);
  1142. Integer i = expenseAccountExamineMapper.selectYesByParam(newEa.getId(), e.getAid());
  1143. if (status==EAProcessStatus.CNSH.getCode()){
  1144. eae.setStatus(0);
  1145. count++;
  1146. }else {
  1147. if (i>0||e.getAid().equals(TokenManager.getAdminId())) {
  1148. eae.setStatus(1);
  1149. count++;
  1150. }
  1151. }
  1152. expenseAccountExamineMapper.insertSelective(eae);
  1153. }
  1154. }else {
  1155. size = expenseAccountExamines.size();
  1156. for (ExpenseAccountExamine e : expenseAccountExamines) {
  1157. if (e.getStatus()==1){
  1158. count++;
  1159. }
  1160. }
  1161. }
  1162. if (count==size){
  1163. return true;
  1164. }
  1165. return false;
  1166. }
  1167. private void addNoticeAndEmail(ExpenseAccount in, Integer status, String str,String aname, List<Admin> aids) {
  1168. Date date= new Date();
  1169. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  1170. if (status==2){
  1171. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  1172. str="您提交的费用报销单已通过审核,请及时查看。";
  1173. }
  1174. List<Notice> list=new ArrayList<>();
  1175. if (aids!=null){
  1176. for (Admin a : aids) {
  1177. Notice notice=new Notice();
  1178. notice.setId(UUID.randomUUID().toString());
  1179. notice.setNoticeType(noticeStatus);
  1180. notice.setType(NoticeTypes.getType(noticeStatus));
  1181. notice.setAid(a.getId());
  1182. notice.setCreateTime(date);
  1183. notice.setContent(str);
  1184. notice.setReaded(0);
  1185. list.add(notice);
  1186. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  1187. asyncUtils.send(emailBo);
  1188. try {
  1189. weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
  1190. }catch (Exception e){
  1191. throw new BusinessException("网络通信异常,请稍后再试。");
  1192. }
  1193. }
  1194. asyncUtils.addNoticeBatch(list);
  1195. }
  1196. }
  1197. @Override
  1198. public Pagination<?> pageList(InputPageListBo in) {
  1199. Map<String ,Object> param=new HashMap<>();
  1200. addParam(in, param);
  1201. Pagination<?> pagePlus = findPagePlus("selectExpenseAccountList",
  1202. "selectExpenseAccountCount",
  1203. "selectExpenseAccountTotalAmount", param, in.getPageNo(), in.getPageSize());
  1204. List<OutExpenseAccountBo> list = (List<OutExpenseAccountBo>) pagePlus.getList();
  1205. for (OutExpenseAccountBo e : list) {
  1206. e.setExamine(pushExpenseAccountGetExamine(e.getId(), e.getProcessStatus()));
  1207. }
  1208. return pagePlus;
  1209. }
  1210. @Override
  1211. public Object selectByPrid(InputExpenseAccount in) {
  1212. in.setAid(TokenManager.getAdminId());
  1213. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  1214. if (useEa!=null){
  1215. ExpenseRelationship er = expenseRelationshipMapper.selectSonId(useEa.getId());
  1216. if (er!=null){
  1217. throw new BusinessException("公出已经发起报销");
  1218. }
  1219. }
  1220. return useEa;
  1221. }
  1222. @Override
  1223. public Object selectById(Integer id) {
  1224. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  1225. //判断当前角色是否审核
  1226. useEa.setExamine(pushExpenseAccountGetExamine( id, useEa.getProcessStatus()));;
  1227. if (useEa.getDebitId()!=null){
  1228. pushExpenseAccountGetDebitAmount(useEa);
  1229. }
  1230. return useEa;
  1231. }
  1232. @Override
  1233. public Object selectByCheckNo(String checkNo) {
  1234. checkNo=checkNo.trim();
  1235. OutExpenseAccount useEa = expenseAccountMapper.selectByCheckNo(checkNo);
  1236. if (useEa==null){
  1237. throw new BusinessException("报销编号不存在,请客对后再查询。");
  1238. }
  1239. if (useEa.getProcessStatus()<3||useEa.getStatus()!=2){
  1240. throw new BusinessException("报销单财务未审核,不可以根据编号查看打印。");
  1241. }
  1242. return useEa;
  1243. }
  1244. @Override
  1245. public Object pushMerge(List<ExpenseAccount> list) {
  1246. //设置付款部门和支付部门
  1247. InputExpenseAccount in =new InputExpenseAccount();
  1248. in.setCheckNo(idGenerator.getNOgenerateId());
  1249. if (in.getAid()==null){
  1250. in.setAid(TokenManager.getAdminId());
  1251. }
  1252. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  1253. in.setAname(admin.getName());
  1254. in.setApplyDep(admin.getDepartmentId());
  1255. in.setPayDep(admin.getDepartmentId());
  1256. Integer eaaid = expenseAccountPrivateMapper.selectByaidDefault(TokenManager.getAdminId());
  1257. in.setEaaid(eaaid);
  1258. BigDecimal count = new BigDecimal(0);
  1259. BigDecimal amount = new BigDecimal(0);
  1260. BigDecimal realAmount = new BigDecimal(0);
  1261. List<String> typeList = new ArrayList<String>();
  1262. for (ExpenseAccount e : list) {
  1263. count=count.add(e.getTotalAmount());
  1264. amount=amount.add(e.getAmount());
  1265. realAmount=realAmount.add(e.getRealAmount());
  1266. StringBuffer types=new StringBuffer();
  1267. if (e.getType()!=0){
  1268. types=types.append(EATypes.getDescByCode(e.getType()));
  1269. }else {
  1270. types=types.append(e.getTypeOther());
  1271. }
  1272. if (e.getType()==2){
  1273. if (e.getSecondaryType()==0){
  1274. types=types.append("-").append(e.getSecondaryTypeOther());
  1275. }else{
  1276. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1277. types=types.append("-").append(descByCode);
  1278. }
  1279. }
  1280. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1281. }
  1282. in.setTotalAmount(count);
  1283. in.setAmount(amount);
  1284. in.setRealAmount(realAmount);
  1285. in.setExpenseMain(1);
  1286. in.setTypeOther(String.join(",",typeList));
  1287. expenseAccountMapper.insertSelective(in);
  1288. List<OutExpenseAccountLog> newLog=new ArrayList<>();
  1289. list.stream().forEach(e -> {
  1290. ExpenseRelationship er=new ExpenseRelationship();
  1291. er.setId(in.getId());
  1292. er.setEaId(e.getId());
  1293. expenseRelationshipMapper.insertSelective(er);
  1294. List<OutExpenseAccountLog> listLog = expenseAccountLogMapper.selectByEaid(e.getId());
  1295. for (OutExpenseAccountLog log : listLog) {
  1296. if (!newLog.contains(log)){
  1297. log.setEaid(in.getId());
  1298. log.setShowStatus(1);
  1299. newLog.add(log);
  1300. }
  1301. }
  1302. expenseAccountLogMapper.deleteByeaid(e.getId());
  1303. });
  1304. if (!newLog.isEmpty())expenseAccountLogMapper.insertBatch(newLog);
  1305. expenseAccountMapper.updateByIds(list,1);
  1306. return in.getId();
  1307. }
  1308. @Override
  1309. public MainExpenseAccount mainExpense(Integer id) {
  1310. MainExpenseAccount res = expenseAccountMapper.selectByMainId(id);
  1311. pushData(res);
  1312. res.setExamine(0);
  1313. if (res.getAid().equals(TokenManager.getAdminId())){
  1314. res.setExamine(2);
  1315. }else {
  1316. res.setExamine(pushExpenseAccountGetExamine( id, res.getProcessStatus()));;
  1317. }
  1318. return res;
  1319. }
  1320. private void pushData(MainExpenseAccount res) {
  1321. List<SonExpenseAccount> sonList = res.getSonList();
  1322. List<String> orderList = new ArrayList<>();
  1323. List<SonExpenseAccount> orderSonList = new ArrayList<>();
  1324. sonList.stream().forEach(e -> {
  1325. if (!orderList.contains(e.getOrderNo())){
  1326. orderList.add(e.getOrderNo());
  1327. orderSonList.add(e);
  1328. }
  1329. });
  1330. orderList.clear();
  1331. for (SonExpenseAccount e : orderSonList) {
  1332. if (StringUtils.isNotEmpty(e.getUserNames())){
  1333. String userNames = e.getUserNames();
  1334. String districtName = e.getDistrictName();
  1335. int start=userNames.indexOf("[");
  1336. if (start>0){
  1337. userNames = userNames.substring(0,start);
  1338. districtName=districtName.replace(userNames,"");
  1339. e.setUserNames(userNames);
  1340. e.setDistrictName(districtName);
  1341. }else {
  1342. districtName=districtName.replace(userNames,"");
  1343. e.setDistrictName(districtName);
  1344. }
  1345. }
  1346. if (e.getOrderNo()!=null){
  1347. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectByOrderNo(e.getOrderNo());
  1348. int year = LocalDate.now().getYear();
  1349. BigDecimal count = BigDecimal.ZERO;
  1350. BigDecimal yxyCount = BigDecimal.ZERO;
  1351. BigDecimal zxsCount = BigDecimal.ZERO;
  1352. BigDecimal qtCount = BigDecimal.ZERO;
  1353. TOrderPublicReleaseCount out = tOrderPublicReleaseCountMapper.selectByOrderNo(e.getOrderNo());
  1354. if(!expenseAccounts.isEmpty()){
  1355. for (ExpenseAccount ea : expenseAccounts) {
  1356. count=count.add(ea.getRealAmount());
  1357. Admin admin = adminMapper.selectByPrimaryKey(ea.getAid());
  1358. if (admin.getPosition()!=null){
  1359. if (admin.getPosition().equals("1")){
  1360. yxyCount=yxyCount.add(ea.getRealAmount());
  1361. }else if (admin.getPosition().equals("0")){
  1362. zxsCount=zxsCount.add(ea.getRealAmount());
  1363. }else {
  1364. qtCount=qtCount.add(ea.getRealAmount());
  1365. }
  1366. }
  1367. }
  1368. }
  1369. List<OrderYearMaxDuration> yearMaxDurationList = orderYearMaxDurationMapper.selectByOrderNo(e.getOrderNo());
  1370. OrderYearMaxDuration useOyd = null;
  1371. for (int i = 0; i < yearMaxDurationList.size(); i++) {
  1372. OrderYearMaxDuration oyd = yearMaxDurationList.get(i);
  1373. //年份为0不是会员直接获取跳出循环,否则获取当前年份,获取不到获取最后一年
  1374. if (oyd.getYear()==0){
  1375. useOyd=oyd;
  1376. break;
  1377. }else {
  1378. if (oyd.getYear().equals(year)){
  1379. useOyd = oyd;
  1380. break;
  1381. }
  1382. if(i==yearMaxDurationList.size()-1&&useOyd==null){
  1383. useOyd = yearMaxDurationList.get(i);
  1384. }
  1385. }
  1386. }
  1387. //获取未归集的订单
  1388. List<BigDecimal> orderNoNotCountAmount = expenseAccountMapper.getOrderNoNotCountAmount(e.getOrderNo());
  1389. BigDecimal countAmount = orderNoNotCountAmount.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
  1390. String str = getString(e, out, count, yxyCount, zxsCount,qtCount,useOyd);
  1391. str=str+",未归集:"+countAmount.stripTrailingZeros().toPlainString()+"元";
  1392. orderList.add(str);
  1393. }else if (e.getPrid() !=null){
  1394. //获取未归集的订单
  1395. List<PublicReleaseDetails> list = publicReleaseMapper.selectDetailsByPrid(e.getPrid());
  1396. StringBuffer sb = new StringBuffer();
  1397. for (PublicReleaseDetails e2 : list) {
  1398. User user = userMapper.selectByPrimaryKey(e2.getUid());
  1399. List<BigDecimal> orderNoNotCountAmount = expenseAccountMapper.getUidNotCountAmount(e2.getUid());
  1400. BigDecimal countAmount = orderNoNotCountAmount.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
  1401. sb.append("[").append(user.getNickname()).append("]未归集:").append(countAmount.stripTrailingZeros().toPlainString()).append("元,");
  1402. }
  1403. orderList.add(sb.substring(0,sb.length()-1));
  1404. }
  1405. res.setStrList(orderList);
  1406. }
  1407. }
  1408. private String getString(SonExpenseAccount e, TOrderPublicReleaseCount out, BigDecimal count, BigDecimal yxyCount,
  1409. BigDecimal zxsCount, BigDecimal qtCount,OrderYearMaxDuration useOyd) {
  1410. TOrderPublicReleaseCountBo bo = new TOrderPublicReleaseCountBo();
  1411. if (out==null||useOyd==null)return String.format("订单%s统计信息不存在,请要营销员先将订单派单。",e.getOrderNo());
  1412. bo.setMaxDuration(useOyd.getMaxDuration());
  1413. bo.setExceedDuration(useOyd.getMaxDuration().subtract(BigDecimal.valueOf(out.getActualDuration())).abs());
  1414. bo.setActualDuration(out.getActualDuration());
  1415. bo.setFrequency(out.getFrequency());
  1416. bo.setPeopleCount(out.getPeopleCount());
  1417. String maxString=":应公出" + bo.getMaxDuration() +"小时["+useOyd.getYear()+"年]";
  1418. String actualString=",超过" + bo.getExceedDuration() + "小时,";
  1419. if (useOyd.getStatus()==1){
  1420. maxString=":不限制公出小时["+useOyd.getYear()+"年]";
  1421. actualString="";
  1422. }
  1423. StringBuilder expenseString=new StringBuilder().append("报销").append(count.stripTrailingZeros().toPlainString()).append("元");
  1424. if (yxyCount.compareTo(BigDecimal.ZERO)>0 || zxsCount.compareTo(BigDecimal.ZERO)>0||qtCount.compareTo(BigDecimal.ZERO)>0){
  1425. expenseString.append("(");
  1426. if (zxsCount.compareTo(BigDecimal.ZERO) > 0) {
  1427. expenseString.append("技术").append(zxsCount.stripTrailingZeros().toPlainString()).append("元,");
  1428. }
  1429. if (yxyCount.compareTo(BigDecimal.ZERO) > 0){
  1430. expenseString.append("营销").append(yxyCount.stripTrailingZeros().toPlainString()).append("元,");
  1431. }
  1432. if (qtCount.compareTo(BigDecimal.ZERO) > 0){
  1433. expenseString.append("其他").append(qtCount.stripTrailingZeros().toPlainString()).append("元,");
  1434. }
  1435. expenseString.deleteCharAt(expenseString.length() - 1);
  1436. expenseString.append(")");
  1437. }
  1438. if (bo.getMaxDuration().compareTo(BigDecimal.valueOf(bo.getActualDuration()))>0){
  1439. actualString="";
  1440. }
  1441. return e.getBuyerName() + e.getContractNo() +
  1442. maxString +
  1443. ",已" + out.getPeopleCount() + "人公出," +
  1444. out.getFrequency() + "次" +
  1445. "," + out.getActualDuration() + "小时" +
  1446. actualString+expenseString;
  1447. }
  1448. @Override
  1449. public Object updateMain(MainExpenseAccount in) {
  1450. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  1451. if (outExpenseAccount != null&&outExpenseAccount.getStatus()!=0&&outExpenseAccount.getStatus()!=3) {
  1452. throw new BusinessException("主项目已发起,不可修改!");
  1453. }
  1454. ExpenseAccount update =new ExpenseAccount();
  1455. if (in.getStatus()==null)in.setStatus(1);
  1456. if (in.getStatus()==1){
  1457. if (in.getPayDep()!=null)update.setPayDep(in.getPayDep());
  1458. if (in.getApplyDep()!=null)update.setApplyDep(in.getApplyDep());
  1459. if (in.getRemarks()!=null)update.setRemarks(in.getRemarks());
  1460. if (in.getEaaid()!=null)update.setEaaid(in.getEaaid());
  1461. addExpenseAccountExamine(in.getId(),update);
  1462. if (outExpenseAccount.getStatus()==0){
  1463. addExpenseAccountLogAndNoticEmail(outExpenseAccount,outExpenseAccount.getStatus(),"发起报销审核");
  1464. }else if (outExpenseAccount.getStatus()==3){
  1465. addExpenseAccountLogAndNoticEmail(outExpenseAccount,4,"修改并发起审核");
  1466. }
  1467. update.setStatus(in.getStatus());
  1468. update.setProcessStatus(outExpenseAccount.getProcessStatus());
  1469. update.setId(in.getId());
  1470. update.setExamineName(outExpenseAccount.getExamineName());
  1471. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1472. // expenseAccountMapper.updateByOrderRemarks(in.getId());
  1473. }else if (in.getStatus()==4){
  1474. expenseAccountMapper.updateByMainId(in.getId(),0);
  1475. addExpenseAccountLog(in.getId(),4,0,TokenManager.getAdminId(),"撤销报销审核");
  1476. List<ExpenseRelationship> list = expenseRelationshipMapper.selectById(in.getId());
  1477. //撤销日志处理,先将日志改在挂子编号上,在新发起的时候再从自编号加到新编号上
  1478. if (list.size()==1){
  1479. ExpenseRelationship e =list.get(0);
  1480. expenseAccountLogMapper.updateUseLogByUseId(e.getEaId(),e.getId());
  1481. }else {
  1482. List<OutExpenseAccountLog> outExpenseAccountLogs = expenseAccountLogMapper.selectByEaid(in.getId());
  1483. for (int i=0;i<list.size();i++){
  1484. ExpenseRelationship e =list.get(i);
  1485. for (OutExpenseAccountLog eal : outExpenseAccountLogs) {
  1486. eal.setEaid(e.getEaId());
  1487. }
  1488. expenseAccountLogMapper.insertBatch(outExpenseAccountLogs);
  1489. }
  1490. }
  1491. expenseAccountLogMapper.deleteByeaid(in.getId());
  1492. expenseRelationshipMapper.deleteByPrimaryKey(in.getId());
  1493. expenseAccountMapper.deleteByPrimaryKey(in.getId());
  1494. }
  1495. return 1;
  1496. }
  1497. @Override
  1498. public Object mainList(ExpenseMainListInput in) {
  1499. Map<String,Object> params = new HashMap<>();
  1500. if (in.getStatus()!=null) params.put("status",in.getStatus());
  1501. if (in.getCheckNo()!=null) params.put("checkNo",in.getCheckNo());
  1502. if (in.getListStatus()!=null) params.put("listStatus",in.getListStatus());
  1503. if (in.getUsername() != null)params.put("username",in.getUsername());
  1504. if (in.getStartTime()!=null && in.getEndTime() !=null) {
  1505. params.put("startTime",in.getStartTime());
  1506. params.put("endTime",in.getEndTime()+" 23:59:59");
  1507. }
  1508. //1-3s是不同人的审核
  1509. if (in.getProcessStatus()!=null&&in.getProcessStatus()==1){
  1510. // 财务审核,复审,出纳都是财务与经理
  1511. if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)){
  1512. in.setProcessStatus(6);
  1513. }else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)){
  1514. in.setProcessStatus(5);
  1515. }else if(TokenManager.hasRole(AFTConstants.VICE_CEO)){
  1516. //先不做财务查看权限
  1517. in.setProcessStatus(7);
  1518. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)){
  1519. in.setProcessStatus(1);
  1520. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  1521. in.setProcessStatus(2);
  1522. }else if (TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1523. in.setProcessStatus(3);
  1524. }
  1525. }else {
  1526. in.setProcessStatus(0);
  1527. }
  1528. if (in.getProcessStatus()!=null){
  1529. params.put("aid",TokenManager.getAdminId());
  1530. params.put("roleType",in.getProcessStatus());
  1531. if (in.getProcessStatus()==3){
  1532. params.put("deps",departmentService.selectMyDeps());
  1533. }
  1534. }
  1535. Pagination<?> page = findPage("ExpenseMainList", "ExpenseMainCount", params, in.getPageNo(), in.getPageSize());
  1536. List<MainExpenseAccount> list = (List<MainExpenseAccount>) page.getList();
  1537. if (!list.isEmpty()){
  1538. List<Integer> collect = list.stream().map(MainExpenseAccount::getId).collect(Collectors.toList());
  1539. List<MainExpenseAccount> mainExpenseAccounts = expenseAccountMapper.selectSonByMainIds(collect);
  1540. for (MainExpenseAccount e : list) {
  1541. for (MainExpenseAccount me : mainExpenseAccounts) {
  1542. if (e.getId().equals(me.getId())){
  1543. e.setSonList(me.getSonList());
  1544. }
  1545. }
  1546. }
  1547. }
  1548. return page;
  1549. }
  1550. @Override
  1551. public Pagination<?> detailsList(InputDetailsListBo in) {
  1552. Map<String,Object> params = new HashMap<>();
  1553. if(in.getStatus()!=null)params.put("status",in.getStatus());
  1554. if(in.getType()!=null)params.put("type",in.getType());
  1555. if (in.getDepId()!=null){
  1556. ArrayList<Object> deps = new ArrayList<>();
  1557. deps.add(in.getDepId());
  1558. params.put("deps",deps);
  1559. }
  1560. if (in.getContractNo()!=null)params.put("contractNo",in.getContractNo());
  1561. if (in.getBuyerName()!=null)params.put("buyerName",in.getBuyerName());
  1562. if (in.getAid()!=null)params.put("aid",in.getAid());
  1563. if (in.getApplyDep()!=null)params.put("applyDep",in.getApplyDep());
  1564. if (in.getPayDep() != null)params.put("payDep",in.getPayDep());
  1565. if (in.getStartTime()!=null)params.put("startTime",in.getStartTime());
  1566. if (in.getEndTime()!=null)params.put("endTime",in.getEndTime());
  1567. if (in.getCheckNo()!=null)params.put("checkNo",in.getCheckNo());
  1568. params.put("current",TokenManager.getAdminId());
  1569. if (in.getMyType()!=null){
  1570. params.put("myType",in.getMyType());
  1571. }else {
  1572. params.put("myType",0);
  1573. }
  1574. //0=自己 1=财务 2=财务经理 3=超管
  1575. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)){
  1576. params.put("roleType",3);
  1577. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1578. params.put("roleType",2);
  1579. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1580. params.put("roleType",1);
  1581. params.put("current",TokenManager.getAdminId());
  1582. }else{
  1583. params.put("roleType",0);
  1584. params.put("aid",TokenManager.getAdminId());
  1585. }
  1586. return findPagePlus("ExpenseDetailsList","ExpenseDetailsCount","ExpenseDetailsTotalAmount",params,in.getPageNo(),in.getPageSize());
  1587. }
  1588. @Override
  1589. public List<ExpenseAccount> selectByIds(List<String> list) {
  1590. return expenseAccountMapper.selectByIds(list);
  1591. }
  1592. @Override
  1593. public int selectCountByIdsAndType(List<String> list, Integer i) {
  1594. return expenseAccountMapper.selectCountByIdsAndType(list,i);
  1595. }
  1596. @Override
  1597. public Object updateRealAmount(Integer type, Integer id, BigDecimal amount) {
  1598. ExpenseAccountDetails ea= new ExpenseAccountDetails();
  1599. ea.setId(id);
  1600. ea.setRealAmount(amount);
  1601. String name=TokenManager.getAdminToken().getName();
  1602. Integer eaid = expenseAccountDetailsMapper.selectExpenseAccountById(id);
  1603. addExpenseAccountLog(eaid,5,3,TokenManager.getAdminId(),String.format("财务[%s]修改实际报销金额为%s。",name,amount));
  1604. expenseAccountDetailsMapper.updateByPrimaryKeySelective(ea);
  1605. expenseAccountMapper.updateSonByDetId(id);
  1606. expenseAccountMapper.updateMainByDetId(id);
  1607. return 1;
  1608. }
  1609. /**
  1610. * 计算当前报销显示抵扣金额
  1611. * @param useEa
  1612. */
  1613. private void pushExpenseAccountGetDebitAmount(OutExpenseAccount useEa) {
  1614. ExpenseAccount debit = expenseAccountMapper.selectByPrimaryKey(useEa.getDebitId());
  1615. List<ExpenseAccount> list1 = expenseAccountMapper.selectByDebitId(useEa.getDebitId());
  1616. BigDecimal count =debit.getRealAmount();
  1617. for (ExpenseAccount e : list1) {
  1618. if (!e.getId().equals(useEa.getId())){
  1619. count=count.subtract(e.getSettlementAmount());
  1620. }
  1621. }
  1622. if (count.compareTo(new BigDecimal(0))<0)count=new BigDecimal(0);
  1623. useEa.setDebitTotalAmount(count);
  1624. }
  1625. /**
  1626. * 判断角色是否已经审核
  1627. * @param id 编号
  1628. * @param processStatus 审核状态
  1629. * @return 0 无需审核 1 需要审核
  1630. */
  1631. private Integer pushExpenseAccountGetExamine(Integer id,Integer processStatus) {
  1632. List<ExpenseAccountExamine> list = expenseAccountExamineMapper.selectByEaidAndProcessStatus(id, processStatus);
  1633. boolean flag=false;
  1634. for (ExpenseAccountExamine e : list) {
  1635. if (e.getAuditor().equals(TokenManager.getAdminId())){
  1636. if (e.getStatus()==0){
  1637. flag=true;
  1638. break;
  1639. }
  1640. }
  1641. }
  1642. if (flag){
  1643. return 1;
  1644. }else {
  1645. return 0;
  1646. }
  1647. }
  1648. @Override
  1649. public Object updateType(InputExpenseAccount in) {
  1650. expenseAccountDetailsMapper.deleteByeaid(in.getId());
  1651. if (in.getType()!=2)in.setSecondaryType(0);
  1652. in.setSettlementAmount(new BigDecimal(0));
  1653. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  1654. }
  1655. @Override
  1656. public List<OutExpenseAccount> selectDebitOrder(String depId,Integer id) {
  1657. String aid= TokenManager.getAdminId();
  1658. List<OutExpenseAccount> list = expenseAccountMapper.selectByaidAndType(aid, depId, 4,id);
  1659. return list;
  1660. }
  1661. private void addParam(InputPageListBo in, Map<String, Object> param) {
  1662. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  1663. param.put("startTime",in.getStartTime());
  1664. param.put("endTime",in.getEndTime()+" 23:59:59");
  1665. }
  1666. if (in.getStatus()!=null)param.put("status",in.getStatus());
  1667. //如果前端未传 0自己 1审核的参数,默认自己,在审核列表的时候判断Aid,在
  1668. param.put("auditor",TokenManager.getAdminId());
  1669. if(in.getProcessStatus()==null){
  1670. if(TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1671. //财务经理查看权限
  1672. in.setProcessStatus(5);
  1673. param.put("auditor",TokenManager.getAdminId());
  1674. }else if(TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  1675. TokenManager.hasRole(AFTConstants.VICE_CEO)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  1676. //财务管理员和超级管理员查看全部
  1677. in.setProcessStatus(6);
  1678. param.put("auditor",TokenManager.getAdminId());
  1679. if(StringUtils.isNotBlank(in.getAid()))param.put("aid",in.getAid());
  1680. }else if (TokenManager.hasRole(AFTConstants.FINANCE)){
  1681. //0 设置为财务查看
  1682. param.put("auditor",TokenManager.getAdminId());
  1683. //如果是空设置为
  1684. if (in.getProcessStatus()==null)in.setProcessStatus(2);
  1685. }else {
  1686. in.setProcessStatus(0);
  1687. }
  1688. }
  1689. param.put("processStatus",in.getProcessStatus());
  1690. if (in.getRoleType()==null){
  1691. param.put("roleType",0);
  1692. }else {
  1693. param.put("roleType",in.getRoleType());
  1694. }
  1695. if(in.getProcessStatus()==2||in.getProcessStatus()==1){
  1696. if (in.getAid()!=null){
  1697. param.put("aid",in.getAid());
  1698. }
  1699. }
  1700. if (in.getExamineStatus()!=null){
  1701. param.put("examineStatus",in.getExamineStatus());
  1702. }else {
  1703. param.put("examineStatus",0);
  1704. }
  1705. if (in.getContractNo()!=null)param.put("contractNo",in.getContractNo());
  1706. if (in.getDepId()!=null)param.put("depId",in.getDepId());
  1707. if (in.getApplyDep()!=null)param.put("applyDep",in.getApplyDep());
  1708. if (in.getPayDep()!=null)param.put("payDep",in.getPayDep());
  1709. if (in.getType()!=null)param.put("type",in.getType());
  1710. if (in.getUsername()!=null)param.put("username",in.getUsername());
  1711. if (in.getCheckNo()!=null)param.put("checkNo",in.getCheckNo());
  1712. if (in.getSecondaryType()!=null)param.put("secondaryType",in.getSecondaryType());
  1713. //固定传0查看子列表
  1714. if (in.getExpenseMain()==null)in.setExpenseMain(0);
  1715. if (in.getExpenseMain()!=null)param.put("expenseMain",in.getExpenseMain());
  1716. }
  1717. @Override
  1718. @Cacheable(value = "expenseAccountStatistics#300", key = "'page:'+#name+',depId'+#depId+',startTime'+#startTime+',endTime'+#endTime+'lander'+#lander")
  1719. public List<OutExpenseAccountStatistics> statistics(String name,String depId,String startTime,String endTime,String lander) {
  1720. if (endTime != null) endTime = endTime + " 23:59:59";
  1721. List<OutMyEAStatistics> list = expenseAccountMapper.selectStatistics(name, depId, startTime, endTime, lander);
  1722. List<OutExpenseAccountStatistics> results = new ArrayList<>();
  1723. Map<String, Object> map = new HashMap<>();
  1724. for (OutMyEAStatistics e : list) {
  1725. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(e.getAid());
  1726. out.setAname(e.getAname());
  1727. if (e.getStatus() == 2) {
  1728. if (e.getType() < 4) {
  1729. out.setBx(1);
  1730. out.setBxAmount(e.getTotalAmount());
  1731. if (!e.getDebitId().equals(0)) {
  1732. out.setDk(1);
  1733. out.setDkAmount(e.getBxdkAmount());
  1734. }
  1735. } else if (e.getType() == 4) {
  1736. out.setJz(1);
  1737. out.setJzAmount(e.getTotalAmount());
  1738. } else if (e.getType() == 5) {
  1739. out.setDk(1);
  1740. out.setDkAmount(e.getTotalAmount());
  1741. }
  1742. if (e.getTargetType() == 0) {
  1743. out.setGdfyAmount(e.getTotalAmount());
  1744. } else if (e.getTargetType() == 1) {
  1745. out.setBxddAmount(e.getTotalAmount());
  1746. }
  1747. } else if (e.getStatus() == 1) {
  1748. out.setWshs(1);
  1749. } else if (e.getStatus() == 3) {
  1750. out.setBhs(1);
  1751. }
  1752. //如果不存在就新增
  1753. if (!map.keySet().contains(out.getAid())) {
  1754. List<OutExpenseAccountStatistics> list2 = new ArrayList<>();
  1755. list2.add(out);
  1756. map.put(out.getAid(), list2);
  1757. } else {
  1758. List<OutExpenseAccountStatistics> list2 = (List<OutExpenseAccountStatistics>) map.get(e.getAid());
  1759. list2.add(out);
  1760. }
  1761. }
  1762. for (String s : map.keySet()) {
  1763. List<OutExpenseAccountStatistics> list3 = (List<OutExpenseAccountStatistics>) map.get(s);
  1764. if (!list3.isEmpty()) {
  1765. OutExpenseAccountStatistics out = new OutExpenseAccountStatistics(s);
  1766. for (OutExpenseAccountStatistics e : list3) {
  1767. if (out.getAname() == null) out.setAname(e.getAname());
  1768. if (e.getBx() != null) out.setBx(out.getBx() + e.getBx());
  1769. if (e.getJz() != null) out.setJz(out.getJz() + e.getJz());
  1770. if (e.getDk() != null) out.setDk(out.getDk() + e.getDk());
  1771. if (e.getBxAmount() != null) out.setBxAmount(out.getBxAmount().add(e.getBxAmount()));
  1772. if (e.getJzAmount() != null) out.setJzAmount(out.getJzAmount().add(e.getJzAmount()));
  1773. if (e.getDkAmount() != null) out.setDkAmount(out.getDkAmount().add(e.getDkAmount()));
  1774. if (e.getGdfyAmount() != null) out.setGdfyAmount(out.getGdfyAmount().add(e.getGdfyAmount()));
  1775. if (e.getBxddAmount() != null) out.setBxddAmount(out.getBxddAmount().add(e.getBxddAmount()));
  1776. if (e.getWshs() != null) out.setWshs(out.getWshs() + e.getWshs());
  1777. if (e.getBhs() != null) out.setBhs(out.getBhs() + e.getBhs());
  1778. }
  1779. BigDecimal totalAmount = new BigDecimal(0);
  1780. totalAmount = totalAmount.add(out.getBxAmount()).add(out.getJzAmount()).subtract(out.getDkAmount());
  1781. out.setTotalAmount(totalAmount);
  1782. results.add(out);
  1783. }
  1784. }
  1785. return results;
  1786. }
  1787. @Override
  1788. @CacheEvict(value = "expenseAccountStatistics#300", allEntries = true)
  1789. public void statisticsEvict(String name, String depId, String startTime, String endTime) {
  1790. LoggerUtils.debug(getClass(), "报销统计缓存清除。");
  1791. }
  1792. @Override
  1793. public Object pushSupplementCheckNo() {
  1794. List<ExpenseAccount> list = expenseAccountMapper.selectByCheckNoNot();
  1795. if (!list.isEmpty()){
  1796. list.forEach(e ->{
  1797. ExpenseAccount ea=new ExpenseAccount();
  1798. ea.setId(e.getId());
  1799. ea.setCheckNo(idGenerator.getNOgenerateId());
  1800. expenseAccountMapper.updateByPrimaryKeySelective(ea);
  1801. });
  1802. return 1;
  1803. }
  1804. return 0;
  1805. }
  1806. @Override
  1807. public void pushAll() {
  1808. List<ExpenseAccount> list = expenseAccountMapper.selectAllMain();
  1809. for (ExpenseAccount ea : list) {
  1810. List<ExpenseAccount> expenseAccounts = expenseAccountMapper.selectListByMainId(ea.getId());
  1811. List<String> typeList=new ArrayList<>();
  1812. for (ExpenseAccount e : expenseAccounts) {
  1813. StringBuffer types=new StringBuffer();
  1814. if (e.getType()!=0){
  1815. types=types.append(EATypes.getDescByCode(e.getType()));
  1816. }else {
  1817. types=types.append(e.getTypeOther());
  1818. }
  1819. if (e.getType()==2){
  1820. if (e.getSecondaryType()==0){
  1821. types=types.append("-").append(e.getSecondaryTypeOther());
  1822. }else{
  1823. String descByCode = EAsecondaryTypes.getDescByCode(e.getSecondaryType());
  1824. types=types.append("-").append(descByCode);
  1825. }
  1826. }
  1827. if (!typeList.contains(types.toString()))typeList.add(types.toString());
  1828. }
  1829. String typeStr = String.join(",", typeList);
  1830. ExpenseAccount update=new ExpenseAccount();
  1831. update.setId(ea.getId());
  1832. update.setTypeOther(typeStr);
  1833. expenseAccountMapper.updateByPrimaryKeySelective(update);
  1834. }
  1835. }
  1836. }