ExpenseAccountServiceImpl.java 91 KB

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