ExpenseAccountServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.goafanti.expenseAccount.service.impl;
  2. import com.goafanti.common.constant.AFTConstants;
  3. import com.goafanti.common.dao.*;
  4. import com.goafanti.common.error.BusinessException;
  5. import com.goafanti.common.model.Admin;
  6. import com.goafanti.common.model.ExpenseAccount;
  7. import com.goafanti.common.model.ExpenseAccountLog;
  8. import com.goafanti.common.model.PublicRelease;
  9. import com.goafanti.common.utils.DateUtils;
  10. import com.goafanti.core.mybatis.BaseMybatisDao;
  11. import com.goafanti.core.mybatis.page.Pagination;
  12. import com.goafanti.core.shiro.token.TokenManager;
  13. import com.goafanti.expenseAccount.bo.*;
  14. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. @Service
  21. public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
  22. @Autowired
  23. private AdminMapper adminMapper;
  24. @Autowired
  25. private ExpenseAccountMapper expenseAccountMapper;
  26. @Autowired
  27. private PublicReleaseMapper publicReleaseMapper;
  28. @Autowired
  29. private ExpenseAccountLogMapper expenseAccountLogMapper;
  30. @Autowired
  31. private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
  32. @Override
  33. public OutExpenseAccount add(InputExpenseAccount in) {
  34. if (in.getAid()!=null){
  35. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  36. in.setAname(admin.getName());
  37. in.setApplyDep(admin.getDepartmentId());
  38. in.setPayDep(admin.getDepartmentId());
  39. }
  40. if (in.getPrid()!=null){
  41. PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid());
  42. in.setReleaseStart(pr.getReleaseStart());
  43. in.setReleaseEnd(pr.getReleaseEnd());
  44. in.setDistrictName(pr.getDistrictName());
  45. in.setUserNames(pr.getUserNames());
  46. }
  47. expenseAccountMapper.insertSelective(in);
  48. addExpenseAccountLog(in.getId(),0,"创建报销");
  49. OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId());
  50. return outExpenseAccount;
  51. }
  52. /**
  53. *
  54. * @param eaid 报销编号
  55. * @param status 状态 0创建 1发起 2通过 3驳回 4修改
  56. * @param str 备注
  57. */
  58. private void addExpenseAccountLog(Integer eaid, Integer status, String str) {
  59. ExpenseAccountLog eaLog=new ExpenseAccountLog();
  60. eaLog.setEaid(eaid);
  61. eaLog.setStatus(status);
  62. eaLog.setRemarks(str);
  63. eaLog.setAuditor(TokenManager.getAdminId());
  64. expenseAccountLogMapper.insertSelective(eaLog);
  65. }
  66. @Override
  67. public int update(InputExpenseAccount in) {
  68. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  69. if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
  70. throw new BusinessException("不能操作审核中与完成的订单");
  71. }
  72. if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
  73. in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  74. in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  75. }
  76. in.setStatus(1);
  77. //计算总金额
  78. in.setTotalAmount(expenseAccountDetailsMapper.selectAmountCountByEAid(in.getId()));
  79. if (useEA.getStatus()==0){
  80. addExpenseAccountLog(useEA.getId(),1,"发起报销审核");
  81. }else if (useEA.getStatus()==3){
  82. addExpenseAccountLog(useEA.getId(),4,"修改重新发起审核");
  83. }
  84. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  85. }
  86. @Override
  87. public int addDetails(InputExpenseAccountDetails in) {
  88. return expenseAccountDetailsMapper.insertSelective(in);
  89. }
  90. @Override
  91. public int deleteDetails(Integer id) {
  92. return expenseAccountDetailsMapper.deleteByPrimaryKey(id);
  93. }
  94. @Override
  95. public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
  96. return expenseAccountDetailsMapper.selectByEAid(eaid);
  97. }
  98. @Override
  99. public Object logList(Integer eaid) {
  100. return expenseAccountLogMapper.selectByEaid(eaid);
  101. }
  102. @Override
  103. public ExpenseAccountExamineLog examineLog(Integer eaid) {
  104. return expenseAccountLogMapper.selectExamineLog(eaid);
  105. }
  106. @Override
  107. public int updateExamine(InputExpenseAccount in) {
  108. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  109. if (useEa.getStatus()!=1)throw new BusinessException("审核状态错误");
  110. if (useEa.getProcessStatus()!=in.getProcessStatus())throw new BusinessException("审核流程错误");
  111. //审核通知
  112. return 0;
  113. }
  114. @Override
  115. public Object pageList(InputPageListBo in) {
  116. Map<String ,Object> param=new HashMap<>();
  117. addParam(in, param);
  118. return findPage("selectExpenseAccountList", "selectExpenseAccountCount", param, in.getPageNo(), in.getPageSize());
  119. }
  120. @Override
  121. public Object selectByPrid(InputExpenseAccount in) {
  122. in.setAid(TokenManager.getAdminId());
  123. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  124. return useEa;
  125. }
  126. private void addParam(InputPageListBo in, Map<String, Object> param) {
  127. param.put("aid",TokenManager.getAdminId());
  128. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  129. param.put("startTime",in.getStartTime());
  130. param.put("endTime",in.getEndTime()+" 23:59:59");
  131. }
  132. if (in.getStatus()!=null)param.put("status",in.getStatus());
  133. if (in.getProcessStatus()!=null){
  134. param.put("processStatus", in.getProcessStatus());
  135. }else {
  136. param.put("processStatus",0);
  137. }
  138. }
  139. }