PublicReleaseServiceImpl.java 15 KB

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