PublicReleaseServiceImpl.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. in.setNewUser(0);
  78. User u=userMapper.selectByPrimaryKey(in.getUid());
  79. if (u!=null&&u.getShareType()==2){
  80. in.setNewUser(1);
  81. }
  82. if (u.getAid().equals(TokenManager.getAdminId())){
  83. in.setMainStatus(1);
  84. }
  85. publicReleaseMapper.insertSelective(in);
  86. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  87. Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
  88. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),1,"发起外出申请",new Date());
  89. publicReleaseLogMapper.insertSelective(log);
  90. String openid=a.getOpenId();
  91. String str="["+my.getName()+"]发起["+u.getNickname()+"]的外出申请,请及时审核。";
  92. sendNoticeAndSoucket(a.getId(),NoticeStatus.PUBLIC_RELEASE_START.getCode(),str);
  93. Map<String, Object>map=new HashMap<String, Object>();
  94. map.put("data", publicReleaseMapper.selectDtails(in.getId(),null));
  95. if (openid!=null) {
  96. Integer res= weChatUtils.addNotice(openid, in.getStatus(),in.getId(),date,my.getName(),"["+my.getName()+"]发起外出申请");
  97. if (res!=0) {
  98. sendEmail(my, a,1);
  99. }
  100. map.put("code", res);
  101. }else {
  102. sendEmail(my, a,1);
  103. map.put("code", 2);
  104. }
  105. return map;
  106. }
  107. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  108. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  109. Notice n =new Notice();
  110. n.setId(UUID.randomUUID().toString());
  111. n.setAid(id);
  112. n.setNoticeType(type);
  113. n.setContent(content);
  114. n.setReaded(0);//未读
  115. asyncUtils.addNotice(n);
  116. }
  117. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  118. String title="外出申请提醒";
  119. if (type==0) title="外出申请驳回提醒";
  120. else if (type==2) title="外出申请同意提醒";
  121. if (SendEmailUtil.isEmail(a.getEmail())) {
  122. EmailBo email=new EmailBo(title,a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  123. asyncUtils.send(email);
  124. }
  125. }
  126. @Override
  127. public int updatePublicRelease(InputPublicRelease in) {
  128. try {
  129. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  130. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  131. } catch (ParseException e) {
  132. e.printStackTrace();
  133. throw new BusinessException("转换异常");
  134. }
  135. if(in.getStatus()==null||in.getStatus()!=3) {
  136. in.setStatus(1);
  137. }else {
  138. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),4,in.getReason(),new Date());
  139. publicReleaseLogMapper.insertSelective(log);
  140. }
  141. return publicReleaseMapper.updateByPrimaryKeySelective(in);
  142. }
  143. @SuppressWarnings("unchecked")
  144. @Override
  145. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  146. Map<String,Object> map =new HashMap<String, Object>();
  147. map.put("type", in.getType()==null?0:in.getType());
  148. map.put("aid", TokenManager.getAdminId());
  149. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  150. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  151. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  152. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  153. if(in.getStatus()!=null) map.put("status", in.getStatus());
  154. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  155. return (Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  156. }
  157. @Override
  158. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Double duration) {
  159. PublicRelease p=new PublicRelease();
  160. Date date =new Date();
  161. String aid=TokenManager.getAdminId();
  162. p.setId(id);
  163. p.setStatus(status);
  164. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  165. if (use.getStatus()!=1) {
  166. throw new BusinessException("只能修改已发起的状态");
  167. }
  168. StringBuffer str=new StringBuffer();
  169. Admin ad=adminMapper.selectByPrimaryKey(aid);
  170. str=str.append("(").append(ad.getName()).append(")");
  171. if (status==0){str=str.append("驳回,");}
  172. else if(status==2){str=str.append("同意,");}
  173. str=str.append(remarks);
  174. p.setAuditInfo(str.toString());
  175. publicReleaseMapper.updateByPrimaryKeySelective(p);
  176. PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),status,remarks,new Date());
  177. publicReleaseLogMapper.insertSelective(log);
  178. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  179. Admin a=adminMapper.selectByPrimaryKey(use.getAid());
  180. Integer type=0;
  181. String content="";
  182. User u=userMapper.selectByPrimaryKey(use.getUid());
  183. if (status==0) {
  184. type=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  185. content="["+u.getNickname()+"]公司的外出申请,未通过审核!";
  186. }else if(status==2) {
  187. type=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  188. content="["+u.getNickname()+"]公司的外出申请,已通过审核!";
  189. }
  190. sendNoticeAndSoucket(a.getId(),type,content);
  191. if (my.getOpenId()!=null) {
  192. if (remarks.length()>19) {
  193. remarks=remarks.substring(0, 15)+"...";
  194. }
  195. Integer res=weChatUtils.addNotice(a.getOpenId(),p.getStatus(),p.getId(),date,my.getName(),remarks);
  196. if (res!=0) {
  197. sendEmail( my, a, status);
  198. }
  199. return res;
  200. }
  201. return 1;
  202. }
  203. @Override
  204. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  205. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  206. return list;
  207. }
  208. @Override
  209. public int pushPublicReleaseClockIn(Integer id,String photoUrl) {
  210. PublicRelease p=new PublicRelease();
  211. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  212. String aid=TokenManager.getAdminId();
  213. p.setId(id);
  214. p.setClockIn(1);
  215. p.setPhotoUrl(photoUrl);
  216. p.setClockInTime(new Date());
  217. String str="";
  218. if (use.getClockIn()==0) {
  219. FollowBusinessBo fbb=new FollowBusinessBo();
  220. fbb.setUid(use.getUid());
  221. fbb.setContactType("5");
  222. fbb.setResult(use.getRemarks());
  223. OrganizationContactBook ub=organizationContactBookMapper.getMajor(use.getUid(),aid);
  224. if (ub !=null) {
  225. fbb.setOcbId(ub.getId());
  226. }
  227. fbb.setFollowTime(DateUtils.formatDate(p.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  228. String ufid=UUID.randomUUID().toString();
  229. p.setUfid(ufid);
  230. customerService.addFollow(fbb,ufid,use.getMainStatus());
  231. str="公出人员打卡";
  232. }else {
  233. str="刷新打卡";
  234. }
  235. PublicReleaseLog log=new PublicReleaseLog(id,aid,3,str,new Date());
  236. log.setPhotoUrl(photoUrl);
  237. publicReleaseLogMapper.insertSelective(log);
  238. publicReleaseMapper.updateByPrimaryKeySelective(p);
  239. return 1;
  240. }
  241. @Override
  242. public OutPublicRelease dtails(Integer id) {
  243. //如果不是本人和审核人员则不返回信息
  244. OutPublicRelease out=publicReleaseMapper.selectDtails(id,null);
  245. if(out!=null){
  246. boolean flag=false;
  247. //自己、审核人员与部门负责人可以查看
  248. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  249. if (!TokenManager.getAdminId().equals( out.getAid())&&
  250. !TokenManager.getAdminId().equals(out.getReviewer())&&
  251. !TokenManager.getAdminId().equals(ab.getDepManager())){
  252. flag=true;
  253. }
  254. if(flag)out=null;
  255. }else if(TokenManager.getAdminId().equals(out.getAid())) {
  256. out.setPermission(0);
  257. }else {
  258. out.setPermission(1);
  259. }
  260. return out;
  261. }
  262. @Override
  263. public OutPublicRelease followDtails(String id) {
  264. return publicReleaseMapper.selectDtails(null,id);
  265. }
  266. @SuppressWarnings("unchecked")
  267. @Override
  268. public Object publicReleaseStatistics(InputPublicStatistics in) {
  269. Map<String,Object> map =new HashMap<String, Object>();
  270. if(in.getAid()!=null)map.put("aid", in.getAid());
  271. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  272. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  273. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  274. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  275. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  276. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  277. }
  278. @SuppressWarnings("unchecked")
  279. @Override
  280. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  281. Map<String,Object> map =new HashMap<String, Object>();
  282. if(in.getAid()!=null)map.put("aid", in.getAid());
  283. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  284. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  285. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  286. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  287. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  288. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  289. }
  290. @SuppressWarnings("unchecked")
  291. @Override
  292. public Object publicReleaseListDtails(InputPublicDtails in) {
  293. Map<String,Object> map =new HashMap<String, Object>();
  294. addParams(in, map);
  295. return (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  296. }
  297. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  298. if(in.getAid()!=null) map.put("aid", in.getAid());
  299. if(in.getSid()!=null) map.put("sid", in.getSid());
  300. if(in.getDepId()!=null) map.put("depId", in.getDepId());
  301. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  302. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  303. if(in.getUid()!=null) map.put("uid", in.getUid());
  304. if(in.getStatus()!=null) map.put("status", in.getStatus());
  305. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  306. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  307. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  308. in.setType(2);}
  309. else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)){
  310. in.setType(1);
  311. map.put("deps", orderService.selectMyDeps());
  312. } else{
  313. in.setType(0);
  314. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  315. }
  316. map.put("type", in.getType());
  317. }
  318. @SuppressWarnings("unchecked")
  319. @Override
  320. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  321. Map<String,Object> map =new HashMap<String, Object>();
  322. addParams(in, map);
  323. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  324. }
  325. @Override
  326. public int addSupplement(Integer id, String supplement, String nextPlan) {
  327. PublicRelease pr=new PublicRelease();
  328. pr.setId(id);
  329. pr.setSupplement(supplement);
  330. pr.setNextPlan(nextPlan);
  331. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  332. }
  333. @Override
  334. public boolean checkTime(InputPublicRelease in) {
  335. try {
  336. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  337. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  338. } catch (ParseException e) {
  339. e.printStackTrace();
  340. throw new BusinessException("转换异常");
  341. }
  342. int i=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  343. if (i>0) {
  344. return true;
  345. }
  346. return false;
  347. }
  348. }