PublicReleaseServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 org.springframework.web.socket.TextMessage;
  13. import com.goafanti.admin.bo.AdminListBo;
  14. import com.goafanti.admin.bo.InputPublicDtails;
  15. import com.goafanti.admin.bo.InputPublicRelease;
  16. import com.goafanti.admin.bo.InputPublicReleaseList;
  17. import com.goafanti.admin.bo.InputPublicStatistics;
  18. import com.goafanti.admin.bo.OutPublicDtails;
  19. import com.goafanti.admin.bo.OutPublicRelease;
  20. import com.goafanti.admin.bo.OutPublicReleaseList;
  21. import com.goafanti.admin.bo.OutPublicStatistics;
  22. import com.goafanti.admin.bo.outPublicReleaseLog;
  23. import com.goafanti.admin.service.PublicReleaseService;
  24. import com.goafanti.common.bo.EmailBo;
  25. import com.goafanti.common.constant.AFTConstants;
  26. import com.goafanti.common.dao.AdminMapper;
  27. import com.goafanti.common.dao.PublicReleaseLogMapper;
  28. import com.goafanti.common.dao.PublicReleaseMapper;
  29. import com.goafanti.common.dao.UserMapper;
  30. import com.goafanti.common.enums.NoticeStatus;
  31. import com.goafanti.common.error.BusinessException;
  32. import com.goafanti.common.model.Admin;
  33. import com.goafanti.common.model.Notice;
  34. import com.goafanti.common.model.PublicRelease;
  35. import com.goafanti.common.model.PublicReleaseLog;
  36. import com.goafanti.common.model.User;
  37. import com.goafanti.common.utils.AsyncUtils;
  38. import com.goafanti.common.utils.DateUtils;
  39. import com.goafanti.common.utils.SendEmailUtil;
  40. import com.goafanti.common.utils.WeChatUtils;
  41. import com.goafanti.core.mybatis.BaseMybatisDao;
  42. import com.goafanti.core.mybatis.page.Pagination;
  43. import com.goafanti.core.shiro.token.TokenManager;
  44. import com.goafanti.customer.bo.FollowBusinessBo;
  45. import com.goafanti.customer.service.CustomerService;
  46. import com.goafanti.core.websocket.SystemWebSocketHandler;
  47. import cn.jiguang.common.utils.StringUtils;
  48. @Service
  49. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  50. @Autowired
  51. private PublicReleaseMapper publicReleaseMapper;
  52. @Autowired
  53. private PublicReleaseLogMapper publicReleaseLogMapper;
  54. @Autowired
  55. private CustomerService customerService;
  56. @Autowired
  57. private WeChatUtils weChatUtils;
  58. @Autowired
  59. private AdminMapper adminMapper;
  60. @Autowired
  61. private AsyncUtils asyncUtils;
  62. @Autowired
  63. private UserMapper userMapper;
  64. @Autowired
  65. private SystemWebSocketHandler systemWebSocketHandler;
  66. @Override
  67. public Map<String, Object> addPublicRelease(InputPublicRelease in) {
  68. Date date =new Date();
  69. in.setCreateTime(date);
  70. in.setStatus(1);
  71. in.setAid(TokenManager.getAdminId());
  72. publicReleaseMapper.insertSelectiveGetId(in);
  73. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  74. Admin a=adminMapper.selectByPrimaryKey(my.getSuperiorId());
  75. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),1,"发起外出申请",new Date());
  76. publicReleaseLogMapper.insertSelective(log);
  77. String openid=a.getOpenId();
  78. User u=userMapper.selectByPrimaryKey(in.getUid());
  79. String str="["+my.getName()+"]发起["+u.getNickname()+"]的外出申请,请及时审核。";
  80. sendNoticeAndSoucket(a.getId(),NoticeStatus.PUBLIC_RELEASE_START.getCode(),str);
  81. Map<String, Object>map=new HashMap<String, Object>();
  82. map.put("id", in.getId());
  83. if (openid!=null) {
  84. Integer res= weChatUtils.addNotice(openid, in.getStatus(),date,my.getName(),"["+my.getName()+"]发起外出申请");
  85. if (res!=0) {
  86. sendEmail(my, a,1);
  87. }
  88. map.put("code", res);
  89. }else {
  90. sendEmail(my, a,1);
  91. map.put("code", 2);
  92. }
  93. return map;
  94. }
  95. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  96. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  97. Notice n =new Notice();
  98. n.setId(UUID.randomUUID().toString());
  99. n.setAid(id);
  100. n.setNoticeType(type);
  101. n.setContent(content);
  102. n.setReaded(0);//未读
  103. asyncUtils.addNotice(n);
  104. }
  105. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  106. String title="外出申请提醒";
  107. if (type==0) title="外出申请驳回提醒";
  108. else if (type==2) title="外出申请同意提醒";
  109. if (SendEmailUtil.isEmail(a.getEmail())) {
  110. EmailBo email=new EmailBo(title,a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  111. try {
  112. asyncUtils.send(email);
  113. } catch (UnsupportedEncodingException | MessagingException e) {
  114. e.printStackTrace();
  115. }
  116. }
  117. }
  118. @Override
  119. public int updatePublicRelease(InputPublicRelease in) {
  120. try {
  121. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  122. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  123. } catch (ParseException e) {
  124. e.printStackTrace();
  125. throw new BusinessException("转换异常");
  126. }
  127. if(in.getStatus()==null||in.getStatus()!=3) {
  128. in.setStatus(1);
  129. }else {
  130. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),4,in.getReason(),new Date());
  131. publicReleaseLogMapper.insertSelective(log);
  132. }
  133. publicReleaseMapper.updateByPrimaryKeySelective(in);
  134. return 1;
  135. }
  136. @SuppressWarnings("unchecked")
  137. @Override
  138. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  139. Map<String,Object> map =new HashMap<String, Object>();
  140. map.put("type", in.getType()==null?0:in.getType());
  141. map.put("aid", TokenManager.getAdminId());
  142. if (StringUtils.isNotEmpty(in.getClockTime())) {
  143. map.put("clockTime", in.getClockTime());
  144. }
  145. return (Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  146. }
  147. @Override
  148. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Double duration) {
  149. PublicRelease p=new PublicRelease();
  150. Date date =new Date();
  151. p.setId(id);
  152. p.setStatus(status);
  153. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  154. if (use.getStatus()!=1) {
  155. throw new BusinessException("只能修改已发起的状态");
  156. }
  157. publicReleaseMapper.updateByPrimaryKeySelective(p);
  158. PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),status,remarks,new Date());
  159. publicReleaseLogMapper.insertSelective(log);
  160. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  161. Admin a=adminMapper.selectByPrimaryKey(use.getAid());
  162. Integer type=0;
  163. String content="";
  164. User u=userMapper.selectByPrimaryKey(use.getUid());
  165. if (status==0) {
  166. type=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  167. content="["+u.getNickname()+"]的外出申请,未通过审核!";
  168. }else if(status==2) {
  169. type=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  170. content="["+u.getNickname()+"]的外出申请,已通过审核!";
  171. }
  172. sendNoticeAndSoucket(a.getId(),type,content);
  173. if (my.getOpenId()!=null) {
  174. if (remarks.length()>19) {
  175. remarks=remarks.substring(0, 15)+"...";
  176. }
  177. Integer res=weChatUtils.addNotice(a.getOpenId(),p.getStatus(),date,my.getName(),remarks);
  178. if (res!=0) {
  179. sendEmail( my, a, status);
  180. }
  181. return res;
  182. }
  183. return 1;
  184. }
  185. @Override
  186. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  187. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  188. return list;
  189. }
  190. @Override
  191. public int pushPublicReleaseClockIn(Integer id,String photoUrl) {
  192. PublicRelease p=new PublicRelease();
  193. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  194. p.setId(id);
  195. p.setClockIn(1);
  196. p.setPhotoUrl(photoUrl);
  197. p.setClockInTime(new Date());
  198. String str="";
  199. if (use.getClockIn()==0) {
  200. FollowBusinessBo fbb=new FollowBusinessBo();
  201. fbb.setUid(use.getUid());
  202. fbb.setContactType("0");
  203. fbb.setResult(use.getRemarks());
  204. fbb.setFollowTime(DateUtils.formatDate(p.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  205. String ufid=UUID.randomUUID().toString();
  206. p.setUfid(ufid);
  207. customerService.addFollow(fbb,ufid);
  208. str="公出人员打卡";
  209. }else {
  210. str="刷新打卡";
  211. }
  212. PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),3,str,new Date());
  213. log.setPhotoUrl(photoUrl);
  214. publicReleaseLogMapper.insertSelective(log);
  215. publicReleaseMapper.updateByPrimaryKeySelective(p);
  216. return 1;
  217. }
  218. @Override
  219. public OutPublicRelease dtails(Integer id) {
  220. OutPublicRelease out=publicReleaseMapper.selectDtails(id,null);
  221. //如果不是本人和审核人员则不返回信息
  222. if(out!=null&&!TokenManager.getAdminId().equals( out.getAid())&&!TokenManager.getAdminId().equals(out.getSuprId())) {
  223. out=null;
  224. }else if(TokenManager.getAdminId().equals(out.getSuprId())) {
  225. out.setPermission(1);
  226. }else {
  227. out.setPermission(0);
  228. }
  229. return out;
  230. }
  231. @Override
  232. public OutPublicRelease followDtails(String id) {
  233. return publicReleaseMapper.selectDtails(null,id);
  234. }
  235. @SuppressWarnings("unchecked")
  236. @Override
  237. public Object publicReleaseStatistics(InputPublicStatistics in) {
  238. Map<String,Object> map =new HashMap<String, Object>();
  239. if(in.getAid()!=null)map.put("aid", in.getAid());
  240. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  241. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  242. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  243. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  244. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  245. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  246. }
  247. @SuppressWarnings("unchecked")
  248. @Override
  249. public Object publicReleaseListDtails(InputPublicDtails in) {
  250. Map<String,Object> map =new HashMap<String, Object>();
  251. if(in.getAid()!=null)map.put("aid", in.getAid());
  252. if(in.getReleaseStart()!=null)map.put("releaseStart", in.getReleaseStart());
  253. if(in.getReleaseEnd()!=null)map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  254. if(in.getUid()!=null)map.put("uid", in.getUid());
  255. if(in.getStatus()!=null)map.put("status", in.getStatus());
  256. return (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  257. }
  258. @Override
  259. public boolean checkTime(InputPublicRelease in) {
  260. try {
  261. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  262. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  263. } catch (ParseException e) {
  264. e.printStackTrace();
  265. throw new BusinessException("转换异常");
  266. }
  267. int i=publicReleaseMapper.checkTime(in.getReleaseStart(),in.getReleaseEnd());
  268. if (i>0) {
  269. return true;
  270. }
  271. return false;
  272. }
  273. }