PublicReleaseServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package com.goafanti.admin.service.impl;
  2. import java.io.UnsupportedEncodingException;
  3. import java.text.ParseException;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.UUID;
  9. import javax.mail.MessagingException;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import com.goafanti.admin.bo.AdminListBo;
  13. import com.goafanti.admin.bo.InputPublicDtails;
  14. import com.goafanti.admin.bo.InputPublicRelease;
  15. import com.goafanti.admin.bo.InputPublicReleaseList;
  16. import com.goafanti.admin.bo.InputPublicStatistics;
  17. import com.goafanti.admin.bo.OutPublicDtails;
  18. import com.goafanti.admin.bo.OutPublicRelease;
  19. import com.goafanti.admin.bo.OutPublicReleaseList;
  20. import com.goafanti.admin.bo.OutPublicStatistics;
  21. import com.goafanti.admin.bo.outPublicReleaseLog;
  22. import com.goafanti.admin.service.PublicReleaseService;
  23. import com.goafanti.common.bo.EmailBo;
  24. import com.goafanti.common.constant.AFTConstants;
  25. import com.goafanti.common.dao.AdminMapper;
  26. import com.goafanti.common.dao.PublicReleaseLogMapper;
  27. import com.goafanti.common.dao.PublicReleaseMapper;
  28. import com.goafanti.common.error.BusinessException;
  29. import com.goafanti.common.model.Admin;
  30. import com.goafanti.common.model.PublicRelease;
  31. import com.goafanti.common.model.PublicReleaseLog;
  32. import com.goafanti.common.utils.AsyncUtils;
  33. import com.goafanti.common.utils.DateUtils;
  34. import com.goafanti.common.utils.SendEmailUtil;
  35. import com.goafanti.common.utils.WeChatUtils;
  36. import com.goafanti.core.mybatis.BaseMybatisDao;
  37. import com.goafanti.core.mybatis.page.Pagination;
  38. import com.goafanti.core.shiro.token.TokenManager;
  39. import com.goafanti.customer.bo.FollowBusinessBo;
  40. import com.goafanti.customer.service.CustomerService;
  41. import cn.jiguang.common.utils.StringUtils;
  42. @Service
  43. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  44. @Autowired
  45. private PublicReleaseMapper publicReleaseMapper;
  46. @Autowired
  47. private PublicReleaseLogMapper publicReleaseLogMapper;
  48. @Autowired
  49. private CustomerService customerService;
  50. @Autowired
  51. private WeChatUtils weChatUtils;
  52. @Autowired
  53. private AdminMapper adminMapper;
  54. @Autowired
  55. private AsyncUtils asyncUtils;
  56. @Override
  57. public int addPublicRelease(InputPublicRelease in) {
  58. Date date =new Date();
  59. in.setCreateTime(date);
  60. in.setStatus(1);
  61. in.setAid(TokenManager.getAdminId());
  62. try {
  63. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  64. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  65. } catch (ParseException e) {
  66. e.printStackTrace();
  67. throw new BusinessException("转换异常");
  68. }
  69. publicReleaseMapper.insertSelectiveGetId(in);
  70. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  71. Admin a=adminMapper.selectByPrimaryKey(my.getSuperiorId());
  72. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),1,"发起外出申请",new Date());
  73. publicReleaseLogMapper.insertSelective(log);
  74. String openid=a.getOpenId();
  75. if (openid!=null) {
  76. Integer res= weChatUtils.addNotice(openid, in.getStatus(),date,my.getName(),"["+my.getName()+"]发起外出审核");
  77. if (res!=0) {
  78. senEmail(my, a,1);
  79. }
  80. return res;
  81. }else {
  82. //成功但是对方收不到消息
  83. return 2;
  84. }
  85. }
  86. private void senEmail(AdminListBo my, Admin a,Integer type) {
  87. String title="外出申请提醒";
  88. if (type==0) title="外出申请驳回提醒";
  89. else if (type==2) title="外出申请同意提醒";
  90. if (SendEmailUtil.isEmail(a.getEmail())) {
  91. EmailBo email=new EmailBo(title,a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  92. try {
  93. asyncUtils.send(email);
  94. } catch (UnsupportedEncodingException | MessagingException e) {
  95. e.printStackTrace();
  96. }
  97. }
  98. }
  99. @Override
  100. public int updatePublicRelease(InputPublicRelease in) {
  101. try {
  102. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  103. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  104. } catch (ParseException e) {
  105. e.printStackTrace();
  106. throw new BusinessException("转换异常");
  107. }
  108. in.setStatus(1);
  109. publicReleaseMapper.updateByPrimaryKeySelective(in);
  110. return 1;
  111. }
  112. @SuppressWarnings("unchecked")
  113. @Override
  114. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  115. Map<String,Object> map =new HashMap<String, Object>();
  116. map.put("type", in.getType()==null?0:in.getType());
  117. map.put("aid", TokenManager.getAdminId());
  118. if (StringUtils.isNotEmpty(in.getClockTime())) {
  119. map.put("clockTime", in.getClockTime());
  120. }
  121. return (Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  122. }
  123. @Override
  124. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Double duration) {
  125. PublicRelease p=new PublicRelease();
  126. Date date =new Date();
  127. p.setId(id);
  128. p.setStatus(status);
  129. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  130. if (use.getStatus()!=1) {
  131. throw new BusinessException("只能修改已发起的状态");
  132. }
  133. publicReleaseMapper.updateByPrimaryKeySelective(p);
  134. PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),status,remarks,new Date());
  135. publicReleaseLogMapper.insertSelective(log);
  136. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  137. Admin a=adminMapper.selectByPrimaryKey(use.getAid());
  138. if (my.getOpenId()!=null) {
  139. Integer res=weChatUtils.addNotice(a.getOpenId(),p.getStatus(),date,my.getName(),remarks);
  140. if (res!=0) {
  141. senEmail( my, a, status);
  142. }
  143. return res;
  144. }
  145. return 1;
  146. }
  147. @Override
  148. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id) {
  149. return publicReleaseLogMapper.listPublicReleaseLog(id);
  150. }
  151. @Override
  152. public int pushPublicReleaseClockIn(Integer id,String photoUrl) {
  153. PublicRelease p=new PublicRelease();
  154. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  155. p.setId(id);
  156. p.setClockIn(1);
  157. p.setPhotoUrl(photoUrl);
  158. p.setClockInTime(new Date());
  159. if (use.getClockIn()==0) {
  160. FollowBusinessBo fbb=new FollowBusinessBo();
  161. fbb.setUid(use.getUid());
  162. fbb.setContactType("0");
  163. fbb.setResult(use.getRemarks());
  164. fbb.setFollowTime(DateUtils.formatDate(p.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  165. String ufid=UUID.randomUUID().toString();
  166. p.setUfid(ufid);
  167. customerService.addFollow(fbb,ufid);
  168. }
  169. publicReleaseMapper.updateByPrimaryKeySelective(p);
  170. return 1;
  171. }
  172. @Override
  173. public OutPublicRelease dtails(Integer id) {
  174. return publicReleaseMapper.selectByid(id);
  175. }
  176. @Override
  177. public OutPublicRelease followDtails(String id) {
  178. return publicReleaseMapper.selectByUfid(id);
  179. }
  180. @SuppressWarnings("unchecked")
  181. @Override
  182. public Object publicReleaseStatistics(InputPublicStatistics in) {
  183. Map<String,Object> map =new HashMap<String, Object>();
  184. if(in.getAid()!=null)map.put("aid", in.getAid());
  185. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  186. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  187. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  188. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  189. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  190. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  191. }
  192. @SuppressWarnings("unchecked")
  193. @Override
  194. public Object publicReleaseListDtails(InputPublicDtails in) {
  195. Map<String,Object> map =new HashMap<String, Object>();
  196. if(in.getAid()!=null)map.put("aid", in.getAid());
  197. if(in.getReleaseStart()!=null)map.put("releaseStart", in.getReleaseStart());
  198. if(in.getReleaseEnd()!=null)map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  199. if(in.getUid()!=null)map.put("uid", in.getUid());
  200. if(in.getStatus()!=null)map.put("status", in.getStatus());
  201. return (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  202. }
  203. }