PublicReleaseServiceImpl.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. package com.goafanti.weChat.service.impl;
  2. import java.text.ParseException;
  3. import java.util.*;
  4. import com.goafanti.common.dao.*;
  5. import com.goafanti.order.service.OrderService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.cache.annotation.Cacheable;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.web.socket.TextMessage;
  10. import com.goafanti.admin.bo.AdminListBo;
  11. import com.goafanti.common.bo.EmailBo;
  12. import com.goafanti.common.constant.AFTConstants;
  13. import com.goafanti.common.enums.NoticeStatus;
  14. import com.goafanti.common.error.BusinessException;
  15. import com.goafanti.common.model.Admin;
  16. import com.goafanti.common.model.Notice;
  17. import com.goafanti.common.model.OrganizationContactBook;
  18. import com.goafanti.common.model.PublicRelease;
  19. import com.goafanti.common.model.PublicReleaseLog;
  20. import com.goafanti.common.model.User;
  21. import com.goafanti.common.utils.AsyncUtils;
  22. import com.goafanti.common.utils.DateUtils;
  23. import com.goafanti.common.utils.SendEmailUtil;
  24. import com.goafanti.common.utils.WeChatUtils;
  25. import com.goafanti.core.mybatis.BaseMybatisDao;
  26. import com.goafanti.core.mybatis.page.Pagination;
  27. import com.goafanti.core.shiro.token.TokenManager;
  28. import com.goafanti.customer.bo.FollowBusinessBo;
  29. import com.goafanti.customer.service.CustomerService;
  30. import com.goafanti.weChat.bo.InputPublicDtails;
  31. import com.goafanti.weChat.bo.InputPublicRelease;
  32. import com.goafanti.weChat.bo.InputPublicReleaseList;
  33. import com.goafanti.weChat.bo.InputPublicStatistics;
  34. import com.goafanti.weChat.bo.OutPublicDtails;
  35. import com.goafanti.weChat.bo.OutPublicRelease;
  36. import com.goafanti.weChat.bo.OutPublicReleaseList;
  37. import com.goafanti.weChat.bo.OutPublicStatistics;
  38. import com.goafanti.weChat.bo.outPublicReleaseLog;
  39. import com.goafanti.weChat.service.PublicReleaseService;
  40. import com.goafanti.core.websocket.SystemWebSocketHandler;
  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 OrderService orderService;
  52. @Autowired
  53. private WeChatUtils weChatUtils;
  54. @Autowired
  55. private AdminMapper adminMapper;
  56. @Autowired
  57. private AsyncUtils asyncUtils;
  58. @Autowired
  59. private UserMapper userMapper;
  60. @Autowired
  61. private OrganizationContactBookMapper organizationContactBookMapper;
  62. @Autowired
  63. private SystemWebSocketHandler systemWebSocketHandler;
  64. @Autowired
  65. private TOrderNewMapper tOrderNewMapper;
  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. in.setNewUser(0);
  73. User u=userMapper.selectByPrimaryKey(in.getUid());
  74. if (u!=null&&u.getShareType()==2){
  75. in.setNewUser(1);
  76. }
  77. if (u.getAid().equals(TokenManager.getAdminId())){
  78. in.setMainStatus(1);
  79. }
  80. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  81. if (in.getAssist()==1){
  82. in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  83. in.setMainName(my.getName());
  84. }
  85. publicReleaseMapper.insertSelective(in);
  86. addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
  87. Map<String, Object> map=addPublicReleaseLog(my, in,u.getNickname(),date);
  88. return map;
  89. }
  90. /**
  91. *
  92. * @param my 我的相关人员
  93. * @param in 公出信息
  94. * @param nickname 客户名称
  95. * @param date 时间
  96. */
  97. private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date ) {
  98. Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
  99. String openid=a.getOpenId();
  100. String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
  101. sendNoticeAndSoucket(a.getId(),NoticeStatus.PUBLIC_RELEASE_START.getCode(),str);
  102. Map<String, Object>map=new HashMap<String, Object>();
  103. map.put("data", publicReleaseMapper.selectDtails(in.getId(),null));
  104. if (openid!=null) {
  105. Integer res= weChatUtils.addNotice(openid, in.getStatus(),in.getId(),date,my.getName(),"["+my.getName()+"]发起外出申请");
  106. if (res!=0) {
  107. sendEmail(my, a,1);
  108. }
  109. map.put("code", res);
  110. }else {
  111. sendEmail(my, a,1);
  112. map.put("code", 2);
  113. }
  114. return map;
  115. }
  116. private String getAssistAidName(String assistAid) {
  117. String [] ss=assistAid.split(",");
  118. StringBuffer sb=new StringBuffer();
  119. for (String s : ss) {
  120. Admin a=adminMapper.selectByPrimaryKey(s);
  121. if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
  122. }
  123. if (sb.length()<1)return "";
  124. return sb.deleteCharAt(sb.length() - 1).toString();
  125. }
  126. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  127. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  128. Notice n =new Notice();
  129. n.setId(UUID.randomUUID().toString());
  130. n.setAid(id);
  131. n.setNoticeType(type);
  132. n.setContent(content);
  133. n.setReaded(0);//未读
  134. asyncUtils.addNotice(n);
  135. }
  136. /**
  137. *
  138. * @param my 发送人
  139. * @param a 接受者
  140. * @param type 类型
  141. */
  142. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  143. String title="外出申请提醒";
  144. if (type==0) title="外出申请驳回提醒";
  145. else if (type==2) title="外出申请同意提醒";
  146. if (SendEmailUtil.isEmail(a.getEmail())) {
  147. EmailBo email=new EmailBo(title,a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  148. asyncUtils.send(email);
  149. }
  150. }
  151. @Override
  152. public int updatePublicRelease(InputPublicRelease in) {
  153. Date date = new Date();
  154. try {
  155. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  156. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  157. } catch (ParseException e) {
  158. e.printStackTrace();
  159. throw new BusinessException("转换异常");
  160. }
  161. User u=userMapper.selectByPrimaryKey(in.getUid());
  162. if (u!=null&&u.getShareType()==2){
  163. in.setNewUser(1);
  164. }
  165. if (u!=null&&u.getAid().equals(TokenManager.getAdminId())){
  166. in.setMainStatus(1);
  167. }
  168. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
  169. if(in.getStatus()==null||in.getStatus()!=3) {
  170. in.setStatus(1);
  171. log.setStatus(PublicReleaseLog.states.xg.getCode());
  172. in.setUpdateStatus(1);
  173. if(in.getAssist()==1){
  174. in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  175. }else{
  176. in.setAssistAidName("");
  177. }
  178. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  179. //新增修改日志
  180. publicReleaseLogMapper.insertSelective(log);
  181. //重新发起
  182. addPublicReleaseLog(my,in,u.getNickname(),date);
  183. }else {
  184. log.setStatus(PublicReleaseLog.states.cx.getCode());
  185. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId());
  186. for (PublicRelease out : list) {
  187. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
  188. }
  189. }
  190. return publicReleaseMapper.updateByPrimaryKeySelective(in);
  191. }
  192. @SuppressWarnings("unchecked")
  193. @Override
  194. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  195. Map<String,Object> map =new HashMap<String, Object>();
  196. map.put("type", in.getType()==null?0:in.getType());
  197. if (in.getType()==3) {
  198. in.setAssist(2);
  199. if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
  200. }else{
  201. map.put("aid",TokenManager.getAdminId());
  202. }
  203. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  204. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  205. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  206. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  207. if(in.getStatus()!=null) map.put("status", in.getStatus());
  208. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  209. map.put("assist",in.getAssist()==null?0:in.getAssist());
  210. Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  211. return p;
  212. }
  213. @Override
  214. public int pushExaminePublicRelease(Integer id, Integer status, String remarks) {
  215. PublicRelease p=new PublicRelease();
  216. Date date =new Date();
  217. String aid=TokenManager.getAdminId();
  218. p.setId(id);
  219. p.setStatus(status);
  220. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  221. if (use.getStatus()!=1) {
  222. throw new BusinessException("只能修改发起的状态公出");
  223. }
  224. StringBuffer str=new StringBuffer();
  225. Admin ad=adminMapper.selectByPrimaryKey(aid);
  226. str=str.append("(").append(ad.getName()).append(")");
  227. if (status==0){
  228. str=str.append("驳回,");
  229. }else if(status==2){
  230. str=str.append("同意,");
  231. //如果是协单公出主公出,在审核通过
  232. if (use.getAssist()==1){
  233. pushPublicReleaseAssist(use,status,date);
  234. }else if (use.getAssist()==0){
  235. publicReleaseMapper.updateStatusByMainId(3,use.getId());
  236. }
  237. }
  238. str=str.append(remarks);
  239. p.setAuditInfo(str.toString());
  240. p.setRejectName(ad.getName());
  241. publicReleaseMapper.updateByPrimaryKeySelective(p);
  242. addpublicLog(id, status, remarks);
  243. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  244. Admin a=adminMapper.selectByPrimaryKey(use.getAid());
  245. Integer type=0;
  246. String content="";
  247. User u=userMapper.selectByPrimaryKey(use.getUid());
  248. if (status==0) {
  249. type=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  250. if (use.getAssist()==2){
  251. content="["+u.getNickname()+"]公司的外出申请,技术协单被["+ad.getName()+"]拒绝!";
  252. }else {
  253. content="["+u.getNickname()+"]公司的外出申请,未通过公出审核!";
  254. }
  255. }else if(status==2) {
  256. type=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  257. content="["+u.getNickname()+"]公司的外出申请,已通过审核!";
  258. }
  259. sendNoticeAndSoucket(a.getId(),type,content);
  260. if (my.getOpenId()!=null) {
  261. if (remarks.length()>19) {
  262. remarks=remarks.substring(0, 15)+"...";
  263. }
  264. Integer res=weChatUtils.addNotice(a.getOpenId(),p.getStatus(),p.getId(),date,my.getName(),remarks);
  265. if (res!=0) {
  266. sendEmail( my, a, status);
  267. }
  268. return res;
  269. }
  270. return 1;
  271. }
  272. private void addpublicLog(Integer id, Integer status, String remarks) {
  273. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  274. publicReleaseLogMapper.insertSelective(log);
  275. }
  276. @Override
  277. public int pushTechReject(Integer id, String remarks) {
  278. Integer status=0;
  279. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  280. PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
  281. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  282. StringBuffer str=new StringBuffer();
  283. str=str.append("(").append(ad.getName()).append(")");
  284. if (use.getAssist()!=2){
  285. throw new BusinessException("只有技术公出能发起技术驳回");
  286. }
  287. str=str.append("拒绝技术协单,").append(remarks);
  288. PublicRelease newMain=new PublicRelease();
  289. newMain.setId(mainPublic.getId());
  290. newMain.setStatus(4);
  291. newMain.setRejectName(ad.getName());
  292. newMain.setAuditInfo(str.toString());
  293. addpublicLog(mainPublic.getId(), status, remarks);
  294. publicReleaseMapper.updateByPrimaryKeySelective(newMain);
  295. PublicRelease up=new PublicRelease();
  296. up.setId(id);
  297. up.setAuditInfo(str.toString());
  298. up.setStatus(3);
  299. addpublicLog(id, status, remarks);
  300. publicReleaseMapper.updateByPrimaryKeySelective(up);
  301. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  302. }
  303. /**
  304. * 新增日志、站内信、微信提醒
  305. * @param id 日志公出编号
  306. * @param aid 接受者
  307. * @param remarks 日志内容
  308. * @param status 0驳回
  309. * @return
  310. */
  311. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  312. Integer noticeType=0;
  313. if (status ==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  314. sendNoticeAndSoucket(aid,noticeType, remarks);
  315. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  316. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  317. if (my.getOpenId()!=null) {
  318. if (remarks.length()>19) {
  319. remarks=remarks.substring(0, 15)+"...";
  320. }
  321. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  322. }else {
  323. sendEmail( my, a, status);
  324. return 1;
  325. }
  326. }
  327. private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date) {
  328. Integer useId=use.getId();
  329. if (use.getAssistAid()!=null){
  330. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId());
  331. String []ss=use.getAssistAid().split(",");
  332. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  333. for (PublicRelease out : list) {
  334. boolean flag=false;
  335. for (String s : ss) {
  336. if (out.getAid().equals(s)){
  337. flag=true;
  338. break;
  339. }
  340. }
  341. if (!flag){
  342. PublicRelease in = new PublicRelease();
  343. in.setId(out.getId());
  344. in.setStatus(3);
  345. publicReleaseMapper.updateByPrimaryKeySelective(in);
  346. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), "同意修改,撤销此协单", date);
  347. publicReleaseLogMapper.insertSelective(log);
  348. }else {
  349. use.setId(out.getId());
  350. use.setAid(out.getAid());
  351. use.setMainId(null);
  352. use.setClockIn(null);
  353. use.setClockInTime(null);
  354. use.setType(null);
  355. use.setAssist(2);
  356. use.setStatus(status);
  357. publicReleaseMapper.updateByPrimaryKeySelective(use);
  358. PublicReleaseLog log = new PublicReleaseLog(out.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), "同意协单信息", date);
  359. publicReleaseLogMapper.insertSelective(log);
  360. }
  361. }
  362. for (String s : ss) {
  363. boolean flag2 = false;
  364. for (PublicRelease o : list) {
  365. if (s.equals(o.getAid())) {
  366. flag2 = true;
  367. }
  368. }
  369. if (!flag2) {
  370. use.setAssist(2);
  371. use.setAid(s);
  372. use.setStatus(2);
  373. use.setType(3);
  374. use.setMainId(useId);
  375. use.setId(null);
  376. publicReleaseMapper.insert(use);
  377. PublicReleaseLog log = new PublicReleaseLog(use.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), "同意协单信息", date);
  378. publicReleaseLogMapper.insertSelective(log);
  379. }
  380. }
  381. }
  382. }
  383. @Override
  384. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  385. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  386. return list;
  387. }
  388. @Override
  389. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ) {
  390. if(clockIn==null)clockIn=1;
  391. PublicRelease p=new PublicRelease();
  392. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  393. String aid=TokenManager.getAdminId();
  394. p.setId(id);
  395. p.setClockIn(clockIn);
  396. p.setClockInRemarks(clockInRemarks);
  397. p.setPhotoUrl(photoUrl);
  398. p.setClockInTime(new Date());
  399. String str="";
  400. if (use.getClockIn()==0) {
  401. FollowBusinessBo fbb=new FollowBusinessBo();
  402. fbb.setUid(use.getUid());
  403. fbb.setContactType("5");
  404. fbb.setResult(use.getRemarks());
  405. OrganizationContactBook ub=organizationContactBookMapper.getMajor(use.getUid(),aid);
  406. if (ub !=null) {
  407. fbb.setOcbId(ub.getId());
  408. }
  409. fbb.setFollowTime(DateUtils.formatDate(p.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  410. String ufid=UUID.randomUUID().toString();
  411. p.setUfid(ufid);
  412. customerService.addFollow(fbb,ufid,use.getMainStatus());
  413. if (clockIn==1)str="公出人员打卡";
  414. else if(clockIn==2)str="公出人员异常打卡";
  415. }else {
  416. str="刷新打卡";
  417. }
  418. PublicReleaseLog log=new PublicReleaseLog(id,aid,PublicReleaseLog.states.dk.getCode(),str,new Date());
  419. log.setPhotoUrl(photoUrl);
  420. publicReleaseLogMapper.insertSelective(log);
  421. publicReleaseMapper.updateByPrimaryKeySelective(p);
  422. return 1;
  423. }
  424. @Override
  425. public OutPublicRelease dtails(Integer id) {
  426. //如果不是本人和审核人员则不返回信息
  427. OutPublicRelease out=publicReleaseMapper.selectDtails(id,null);
  428. if(out!=null){
  429. boolean flag=false;
  430. //自己、审核人员与部门负责人可以查看
  431. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  432. if (!TokenManager.getAdminId().equals( out.getAid())&&
  433. !TokenManager.getAdminId().equals(out.getReviewer())&&
  434. !TokenManager.getAdminId().equals(ab.getDepManager())&&
  435. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  436. flag=true;
  437. }
  438. if(flag){
  439. out=null;
  440. }else {
  441. if(TokenManager.getAdminId().equals(out.getAid())) {
  442. out.setPermission(0);
  443. }else {
  444. out.setPermission(1);
  445. }
  446. }
  447. }
  448. return out;
  449. }
  450. @Override
  451. public OutPublicRelease followDtails(String id) {
  452. return publicReleaseMapper.selectDtails(null,id);
  453. }
  454. @SuppressWarnings("unchecked")
  455. @Override
  456. @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  457. "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  458. "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  459. "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  460. public Object publicReleaseStatistics(InputPublicStatistics in) {
  461. Map<String,Object> map =new HashMap<String, Object>();
  462. if(in.getAid()!=null)map.put("aid", in.getAid());
  463. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  464. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  465. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  466. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  467. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  468. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  469. }
  470. @SuppressWarnings("unchecked")
  471. @Override
  472. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  473. Map<String,Object> map =new HashMap<String, Object>();
  474. if(in.getAid()!=null)map.put("aid", in.getAid());
  475. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  476. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  477. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  478. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  479. }
  480. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  481. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  482. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  483. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  484. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  485. }
  486. @SuppressWarnings("unchecked")
  487. @Override
  488. public Object publicReleaseListDtails(InputPublicDtails in) {
  489. Map<String,Object> map =new HashMap<String, Object>();
  490. addParams(in, map);
  491. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  492. return page;
  493. }
  494. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  495. if(in.getAid()!=null) map.put("aid", in.getAid());
  496. if(in.getSid()!=null) map.put("sid", in.getSid());
  497. if(in.getDepId()!=null) map.put("depId", in.getDepId());
  498. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  499. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  500. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  501. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  502. if(in.getUid()!=null) map.put("uid", in.getUid());
  503. if(in.getStatus()!=null) map.put("status", in.getStatus());
  504. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  505. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  506. //type 0私有 1管理权限 2所有权限
  507. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  508. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  509. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  510. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  511. //添加财务和财务经理。查看客户所有公出
  512. in.setType(2);
  513. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)){
  514. in.setType(1);
  515. map.put("deps", orderService.selectMyDeps());
  516. }else{
  517. in.setType(0);
  518. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  519. }
  520. map.put("type", in.getType());
  521. }
  522. @SuppressWarnings("unchecked")
  523. @Override
  524. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  525. Map<String,Object> map =new HashMap<String, Object>();
  526. addParams(in, map);
  527. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  528. }
  529. @Override
  530. public int addSupplement(Integer id, String supplement, String nextPlan) {
  531. PublicRelease pr=new PublicRelease();
  532. pr.setId(id);
  533. pr.setSupplement(supplement);
  534. pr.setNextPlan(nextPlan);
  535. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  536. }
  537. @Override
  538. public boolean checkTime(InputPublicRelease in) {
  539. try {
  540. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  541. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  542. } catch (ParseException e) {
  543. e.printStackTrace();
  544. throw new BusinessException("转换异常");
  545. }
  546. List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  547. if (is.size()>1) {
  548. return true;
  549. }else if(is.size()==1){
  550. if (in.getId()!=null && !in.getId().equals(is.get(0))){
  551. return true;
  552. }
  553. }
  554. return false;
  555. }
  556. @Override
  557. public List<Map<String, Object>> selectOrderByUid(String uid) {
  558. return tOrderNewMapper.selectOrderByuid(uid);
  559. }
  560. @Override
  561. public List<OutPublicRelease> publicByOrder(String orderNo) {
  562. return publicReleaseMapper.publicByOrder(orderNo);
  563. }
  564. @Override
  565. public Object getMyNewPublic() {
  566. List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  567. if (myPublic.isEmpty()){
  568. List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  569. if (!myPublic2.isEmpty()){
  570. return myPublic2.get(0);
  571. }
  572. }else {
  573. return myPublic.get(0);
  574. }
  575. return null;
  576. }
  577. /**
  578. *
  579. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  580. * @param dateType 是否含打卡时间 0否 1是
  581. * @return
  582. */
  583. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  584. Map<String, Object> map = new HashMap<>();
  585. if (type==null)type=0;
  586. map.put("type",type);
  587. if (dateType==1){
  588. Date date = new Date();
  589. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  590. map.put("clockTime",clockTime);
  591. }
  592. map.put("assistType",1);
  593. map.put("aid",TokenManager.getAdminId());
  594. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  595. return list;
  596. }
  597. }