ExpenseAccountServiceImpl.java 87 KB

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