PublicReleaseServiceImpl.java 14 KB

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