ExpenseAccountServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package com.goafanti.expenseAccount.service.impl;
  2. import com.goafanti.admin.bo.AdminListBo;
  3. import com.goafanti.admin.bo.NoticeBo;
  4. import com.goafanti.common.bo.EmailBo;
  5. import com.goafanti.common.constant.AFTConstants;
  6. import com.goafanti.common.dao.*;
  7. import com.goafanti.common.enums.NoticeStatus;
  8. import com.goafanti.common.enums.NoticeTypes;
  9. import com.goafanti.common.error.BusinessException;
  10. import com.goafanti.common.model.*;
  11. import com.goafanti.common.utils.AsyncUtils;
  12. import com.goafanti.common.utils.DateUtils;
  13. import com.goafanti.common.utils.WeChatUtils;
  14. import com.goafanti.core.mybatis.BaseMybatisDao;
  15. import com.goafanti.core.mybatis.page.Pagination;
  16. import com.goafanti.core.shiro.token.TokenManager;
  17. import com.goafanti.expenseAccount.Enums.EAProcessStatus;
  18. import com.goafanti.expenseAccount.bo.*;
  19. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  20. import com.sun.corba.se.spi.ior.iiop.IIOPFactories;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import java.util.*;
  24. @Service
  25. public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapper> implements ExpenseAccountService {
  26. @Autowired
  27. private AdminMapper adminMapper;
  28. @Autowired
  29. private ExpenseAccountMapper expenseAccountMapper;
  30. @Autowired
  31. private PublicReleaseMapper publicReleaseMapper;
  32. @Autowired
  33. private ExpenseAccountLogMapper expenseAccountLogMapper;
  34. @Autowired
  35. private AsyncUtils asyncUtils;
  36. @Autowired
  37. private WeChatUtils weChatUtils;
  38. @Autowired
  39. private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
  40. @Override
  41. public Integer add(InputExpenseAccount in) {
  42. if (in.getAid()!=null){
  43. Admin admin = adminMapper.selectByPrimaryKey(in.getAid());
  44. in.setAname(admin.getName());
  45. in.setApplyDep(admin.getDepartmentId());
  46. in.setPayDep(admin.getDepartmentId());
  47. }
  48. if (in.getPrid()!=null){
  49. PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid());
  50. in.setReleaseStart(pr.getReleaseStart());
  51. in.setReleaseEnd(pr.getReleaseEnd());
  52. in.setDistrictName(pr.getDistrictName());
  53. in.setUserNames(pr.getUserNames());
  54. in.setDuration(pr.getDuration());
  55. }
  56. expenseAccountMapper.insertSelective(in);
  57. addExpenseAccountLog(in.getId(),0,"创建报销");
  58. return in.getId();
  59. }
  60. /**
  61. *
  62. * @param eaid 报销编号
  63. * @param status 状态 0创建 1发起 2通过 3驳回 4修改
  64. * @param str 备注
  65. */
  66. private void addExpenseAccountLog(Integer eaid, Integer status, String str) {
  67. String aid=TokenManager.getAdminId();
  68. Date date=new Date();
  69. ExpenseAccountLog eaLog=new ExpenseAccountLog();
  70. eaLog.setEaid(eaid);
  71. eaLog.setStatus(status);
  72. eaLog.setRemarks(str);
  73. eaLog.setAuditor(aid);
  74. Admin admin = adminMapper.selectByPrimaryKey(aid);
  75. StringBuffer sb =new StringBuffer();
  76. if (status>0){
  77. if (status==1){
  78. sb.append(str).append("[").append(admin.getName()).append("]").append("发起报销申请,请及时审核。");
  79. }else if (status==4){
  80. sb.append(str).append("[").append(admin.getName()).append("]").append("修改并重新发起,请重新审核。");
  81. }
  82. asyncUtils.addNoticAndEmail(NoticeStatus.EXPENSE_NOTICE.getCode(), aid,sb.toString());
  83. weChatUtils.addExpenseAccountWeChatNotice(admin.getOpenId(), 1, eaid, date, admin.getName(),sb.toString());
  84. }
  85. expenseAccountLogMapper.insertSelective(eaLog);
  86. }
  87. @Override
  88. public int update(InputExpenseAccount in) {
  89. OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId());
  90. if (useEA.getStatus()!=0&&useEA.getStatus()!=3){
  91. throw new BusinessException("不能操作审核中与完成的订单");
  92. }
  93. if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){
  94. in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  95. in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS));
  96. }
  97. in.setStatus(1);
  98. in.setProcessStatus(1);
  99. //计算总金额
  100. in.setTotalAmount(expenseAccountDetailsMapper.selectAmountCountByEAid(in.getId()));
  101. if (useEA.getStatus()==0){
  102. addExpenseAccountLog(useEA.getId(),1,"发起报销审核");
  103. }else if (useEA.getStatus()==3){
  104. addExpenseAccountLog(useEA.getId(),4,"修改重新发起审核");
  105. }
  106. return expenseAccountMapper.updateByPrimaryKeySelective(in);
  107. }
  108. @Override
  109. public int addDetails(InputExpenseAccountDetails in) {
  110. return expenseAccountDetailsMapper.insertSelective(in);
  111. }
  112. @Override
  113. public int deleteDetails(Integer id) {
  114. return expenseAccountDetailsMapper.deleteByPrimaryKey(id);
  115. }
  116. @Override
  117. public List<OutExpenseAccountDetails> detailsList(Integer eaid) {
  118. return expenseAccountDetailsMapper.selectByEAid(eaid);
  119. }
  120. @Override
  121. public Object logList(Integer eaid) {
  122. return expenseAccountLogMapper.selectByEaid(eaid);
  123. }
  124. @Override
  125. public ExpenseAccountExamineLog examineLog(Integer eaid) {
  126. return expenseAccountLogMapper.selectExamineLog(eaid);
  127. }
  128. @Override
  129. public int updateExamine(InputExpenseAccount in) {
  130. ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId());
  131. ExpenseAccount newEa=new ExpenseAccount();
  132. newEa.setId(useEa.getId());
  133. if (useEa.getStatus()!=1)throw new BusinessException("审核状态错误");
  134. if (useEa.getProcessStatus()!=in.getProcessStatus())throw new BusinessException("审核流程错误");
  135. //审核通知 获取发送人
  136. List<Admin> aids=new ArrayList<>();
  137. Integer status=1;
  138. StringBuffer str=new StringBuffer();
  139. str=str.append("您有报销需要审核,请查看并审核。");
  140. AdminListBo admin = adminMapper.getDeptNameByAid(useEa.getAid());
  141. if(useEa.getProcessStatus()== EAProcessStatus.FQ.getCode()){
  142. //获取上级
  143. aids.add(adminMapper.selectByPrimaryKey(admin.getSuperiorId()));
  144. newEa.setProcessStatus(EAProcessStatus.SJSH.getCode());
  145. }else if (useEa.getProcessStatus()== EAProcessStatus.SJSH.getCode()){
  146. //获取负责人
  147. List<Admin> list = adminMapper.listAdminBydepIdAndRoleType(admin.getId(), admin.getDepartmentId());
  148. if (!list.isEmpty())aids.addAll(list);
  149. newEa.setProcessStatus(EAProcessStatus.ZJLSH.getCode());
  150. }else if (useEa.getProcessStatus()== EAProcessStatus.ZJLSH.getCode()){
  151. //获取负责人
  152. aids.add(adminMapper.selectByPrimaryKey(admin.getDepFinance()));
  153. newEa.setProcessStatus(EAProcessStatus.CWSH.getCode());
  154. }else if (useEa.getProcessStatus()== EAProcessStatus.CWSH.getCode()){
  155. //获取负责人
  156. List<Admin> admins = adminMapper.selectAdminByRoleType(AFTConstants.All_CED_AND_CHAIRMAN);
  157. if (!admins.isEmpty())aids.addAll(admins);
  158. newEa.setProcessStatus(EAProcessStatus.DSZSH.getCode());
  159. }else if (useEa.getProcessStatus()== EAProcessStatus.DSZSH.getCode()){
  160. //获取负责人
  161. status=2;
  162. aids.add(adminMapper.selectByPrimaryKey(admin.getId()));
  163. newEa.setStatus(status);
  164. str=new StringBuffer("您的报销审核已通过,请注意查看。");
  165. }
  166. addLogAndNoticeAndEmail(in,useEa,status,str.toString(),admin.getName(),aids);
  167. expenseAccountMapper.updateByPrimaryKeySelective(newEa);
  168. return 1;
  169. }
  170. private void addLogAndNoticeAndEmail(InputExpenseAccount in, ExpenseAccount useEa, Integer status, String str,String aname, List<Admin> aids) {
  171. addExpenseAccountLog(useEa.getId(),status,in.getReason());
  172. Date date= new Date();
  173. Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
  174. if (status==2){
  175. noticeStatus=NoticeStatus.EXPENSE_COMPLETE.getCode();
  176. }
  177. List<Notice> list=new ArrayList<>();
  178. if (aids!=null){
  179. for (Admin a : aids) {
  180. Notice notice=new Notice();
  181. notice.setId(UUID.randomUUID().toString());
  182. notice.setNoticeType(noticeStatus);
  183. notice.setType(NoticeTypes.getType(noticeStatus));
  184. notice.setAid(a.getId());
  185. notice.setCreateTime(date);
  186. notice.setContent(str);
  187. notice.setReaded(0);
  188. list.add(notice);
  189. EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
  190. asyncUtils.send(emailBo);
  191. weChatUtils.addNotice(a.getOpenId(),status,in.getId(),date,aname,str);
  192. }
  193. asyncUtils.addNoticeBatch(list);
  194. }
  195. }
  196. @Override
  197. public Object pageList(InputPageListBo in) {
  198. Map<String ,Object> param=new HashMap<>();
  199. addParam(in, param);
  200. return findPage("selectExpenseAccountList", "selectExpenseAccountCount", param, in.getPageNo(), in.getPageSize());
  201. }
  202. @Override
  203. public Object selectByPrid(InputExpenseAccount in) {
  204. Integer id=null;
  205. in.setAid(TokenManager.getAdminId());
  206. OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in);
  207. if (useEa!=null&&useEa.getId()!=null)id=useEa.getId();
  208. return id;
  209. }
  210. @Override
  211. public Object selectById(Integer id) {
  212. OutExpenseAccount useEa = expenseAccountMapper.selectByid(id);
  213. return useEa;
  214. }
  215. private void addParam(InputPageListBo in, Map<String, Object> param) {
  216. param.put("aid",TokenManager.getAdminId());
  217. if (in.getStartTime()!=null&&in.getEndTime()!=null){
  218. param.put("startTime",in.getStartTime());
  219. param.put("endTime",in.getEndTime()+" 23:59:59");
  220. }
  221. if (in.getStatus()!=null)param.put("status",in.getStatus());
  222. if (in.getProcessStatus()!=null){
  223. Integer processStatus=in.getProcessStatus();
  224. //默认自己 设置上级,判断管理员与总裁等顶级审核
  225. if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  226. processStatus=2;
  227. }else if (checkShiroCED()){
  228. processStatus=4;
  229. }
  230. param.put("processStatus",processStatus);
  231. }else {
  232. param.put("processStatus",0);
  233. }
  234. }
  235. /**
  236. * 检查权限判断是否是总裁、董事长或超级管理员权限
  237. * @return
  238. */
  239. private boolean checkShiroCED() {
  240. if (TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)||
  241. TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)
  242. ||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  243. return true;
  244. }
  245. return false;
  246. }
  247. }