PublicReleaseServiceImpl.java 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. package com.goafanti.weChat.service.impl;
  2. import java.text.ParseException;
  3. import java.util.*;
  4. import java.util.concurrent.atomic.AtomicReference;
  5. import com.goafanti.admin.service.DepartmentService;
  6. import com.goafanti.common.dao.*;
  7. import com.goafanti.common.model.*;
  8. import com.goafanti.weChat.bo.*;
  9. import org.springframework.beans.BeanUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  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.utils.AsyncUtils;
  20. import com.goafanti.common.utils.DateUtils;
  21. import com.goafanti.common.utils.SendEmailUtil;
  22. import com.goafanti.common.utils.WeChatUtils;
  23. import com.goafanti.core.mybatis.BaseMybatisDao;
  24. import com.goafanti.core.mybatis.page.Pagination;
  25. import com.goafanti.core.shiro.token.TokenManager;
  26. import com.goafanti.customer.bo.FollowBusinessBo;
  27. import com.goafanti.customer.service.CustomerService;
  28. import com.goafanti.weChat.service.PublicReleaseService;
  29. import com.goafanti.core.websocket.SystemWebSocketHandler;
  30. import cn.jiguang.common.utils.StringUtils;
  31. @Service
  32. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  33. @Autowired
  34. private PublicReleaseMapper publicReleaseMapper;
  35. @Autowired
  36. private PublicReleaseLogMapper publicReleaseLogMapper;
  37. @Autowired
  38. private CustomerService customerService;
  39. @Autowired
  40. private PublicReleaseDetailsMapper publicReleaseDetailsMapper;
  41. @Autowired
  42. private WeChatUtils weChatUtils;
  43. @Autowired
  44. private AdminMapper adminMapper;
  45. @Autowired
  46. private AsyncUtils asyncUtils;
  47. @Autowired
  48. private UserMapper userMapper;
  49. @Autowired
  50. private OrganizationContactBookMapper organizationContactBookMapper;
  51. @Autowired
  52. private SystemWebSocketHandler systemWebSocketHandler;
  53. @Autowired
  54. private TOrderNewMapper tOrderNewMapper;
  55. @Autowired
  56. private DepartmentService departmentService;
  57. @Autowired
  58. private PublicExamineMapper publicExamineMapper;
  59. @Override
  60. @Transactional
  61. public Map<String, Object> addPublicRelease(InputPublicRelease in) {
  62. Date date =new Date();
  63. if (in.getPublicAgain()==null)in.setPublicAgain(0);
  64. in.setCreateTime(date);
  65. in.setPublicType(0);
  66. in.setStatus(1);
  67. in.setAid(TokenManager.getAdminId());
  68. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  69. if (in.getAssist()==1){
  70. // in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  71. in.setMainName(my.getName());
  72. }
  73. publicReleaseMapper.insertSelective(in);
  74. List<PublicReleaseDetails> prdList=new ArrayList<>();
  75. List<User> users=new ArrayList<>();
  76. StringBuffer str =new StringBuffer();
  77. if (in.getUids()!=null){
  78. List<String> split = Arrays.asList(in.getUids().split(","));
  79. int userCount=split.size();
  80. Double duration = in.getDuration();
  81. //计算平均
  82. double d = durationSum(duration, userCount);
  83. Integer index=1;
  84. //获取非已企业公出需要的审核人员
  85. for (String s : split) {
  86. PublicReleaseDetails prd=new PublicReleaseDetails();
  87. User u=userMapper.selectByPrimaryKey(s);
  88. users.add(u);
  89. str.append(u.getNickname()).append(",");
  90. if (u!=null&&u.getShareType()==2){
  91. prd.setNewUser(1);
  92. }else {
  93. prd.setNewUser(0);
  94. }
  95. if (u.getAid().equals(in.getAid())){
  96. prd.setMainStatus(1);
  97. }else {
  98. prd.setMainStatus(0);
  99. if(in.getPublicType()==null||in.getPublicType()==0)in.setPublicType(1);
  100. }
  101. prd.setPrid(in.getId());
  102. prd.setUid(s);
  103. prd.setSignSum(0);
  104. prd.setClockIn(0);
  105. prd.setDistrictName(in.getDistrictName());
  106. prd.setLatitude(in.getLatitude());
  107. prd.setLongitude(in.getLongitude());
  108. if (index<userCount){
  109. if (duration==0){
  110. prd.setDuration(duration);
  111. } else {
  112. prd.setDuration(d);
  113. duration=duration-d;
  114. }
  115. index++;
  116. }else {
  117. prd.setDuration(duration);
  118. }
  119. prdList.add(prd);
  120. }
  121. publicReleaseDetailsMapper.insertBatch(prdList);
  122. }
  123. String userNames=str.substring(0,str.length()-1);
  124. PublicRelease upName=new PublicRelease();
  125. upName.setId(in.getId());
  126. upName.setUserNames(userNames);
  127. if (in.getPublicType()==1){
  128. upName.setPublicType(1);
  129. }
  130. addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
  131. Map<String, Object> map=addPublicReleaseLog(my, in,userNames,date,users);
  132. publicReleaseMapper.updateByPrimaryKeySelective(upName);
  133. return map;
  134. }
  135. private void addPublicExamine(Integer id, String aid) {
  136. Admin admin = adminMapper.selectByPrimaryKey(aid);
  137. addPublicExamine(id,admin);
  138. }
  139. private void addPublicExamine(Integer id, Admin a) {
  140. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
  141. boolean flag=false;
  142. for (PublicExamine pe : publicExamines) {
  143. if (pe.getAid().equals(a.getId())){
  144. flag=true;
  145. }
  146. }
  147. if (!flag){
  148. PublicExamine pe=new PublicExamine();
  149. pe.setPrid(id);
  150. pe.setAid(a.getId());
  151. pe.setAname(a.getName());
  152. pe.setStatus(0);
  153. publicExamineMapper.insertSelective(pe);
  154. }
  155. }
  156. private double durationSum(Double duration, Integer sum) {
  157. Double counts= Math.floor(duration/0.5);
  158. //计算当前时间
  159. Double my=Math.floor(counts/sum)*0.5;
  160. if (my<0.5)return 0.5;
  161. return my;
  162. }
  163. /**
  164. *
  165. * @param my 我的相关人员
  166. * @param in 公出信息
  167. * @param nickname 客户名称
  168. * @param date 时间
  169. */
  170. private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users) {
  171. //获取公出审核人
  172. Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
  173. String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
  174. //默认上级审核
  175. AtomicReference<Integer> status= new AtomicReference<>(1);
  176. Map<String, Object>map=new HashMap<String, Object>();
  177. if (my.getPublicPurview()==0){
  178. users.forEach(u->{
  179. if (!u.getAid().equals(my.getId())){
  180. StringBuffer str2=new StringBuffer();
  181. str2=str2.append(my.getName()).append("(需审核),准备公出您的企业");
  182. str2=str2.append("[").append(u.getNickname()).append("]!!!。");
  183. sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
  184. Admin admin = adminMapper.selectByPrimaryKey(u.getAid());
  185. //不是自己的企业则需要审核并设置非自己客户待审核
  186. addPublicExamine(in.getId(), admin);
  187. if(in.getPublicType()==null|| in.getPublicType()==0) in.setPublicType(1);
  188. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  189. status.set(0);
  190. }
  191. });
  192. }else {
  193. users.forEach(u->{
  194. if (!u.getAid().equals(my.getId())){
  195. StringBuffer str2=new StringBuffer();
  196. str2=str2.append("业务员").append(my.getName()).append("(无需审核),准备公出您的企业");
  197. str2=str2.append("[").append(u.getNickname()).append("]!!!");
  198. sendNoticeAndSoucket(u.getAid(),3,str2.toString());
  199. }
  200. });
  201. }
  202. if (status.get()==1){
  203. pushNoticeAndSoucketAndEmail(my, in, date, a, str, map);
  204. }
  205. map.put("data", publicReleaseMapper.selectDtails(in.getId()));
  206. return map;
  207. }
  208. /**
  209. *
  210. * @param my 发送人信息
  211. * @param in 公出信息
  212. * @param date 时间
  213. * @param a 接受者信息
  214. * @param str 站内信内容
  215. * @param map 返回实体
  216. */
  217. private void pushNoticeAndSoucketAndEmail(AdminListBo my, PublicRelease in, Date date, Admin a, String str, Map<String, Object> map) {
  218. sendNoticeAndSoucket(a.getId(),1, str);
  219. if (a.getOpenId() !=null) {
  220. Integer res= weChatUtils.addNotice(a.getOpenId(), in.getStatus(), in.getId(), date, my.getName(),"["+ my.getName()+"]发起外出申请");
  221. if (res!=0) {
  222. sendEmail(my, a,1);
  223. }
  224. map.put("code", res);
  225. }else {
  226. sendEmail(my, a,1);
  227. map.put("code", 2);
  228. }
  229. }
  230. private String getAssistAidName(String assistAid) {
  231. String [] ss=assistAid.split(",");
  232. StringBuffer sb=new StringBuffer();
  233. for (String s : ss) {
  234. Admin a=adminMapper.selectByPrimaryKey(s);
  235. if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
  236. }
  237. if (sb.length()<1)return "";
  238. return sb.deleteCharAt(sb.length() - 1).toString();
  239. }
  240. private void sendEmailAndNoticeAndSoucket(String id,Integer type,String content){
  241. sendNoticeAndSoucket(id,type,content);
  242. Admin admin = adminMapper.selectByPrimaryKey(id);
  243. String title="暂无标题";
  244. if (type==3)title=NoticeStatus.PUBLIC_OTHERS_USER.getDesc();
  245. EmailBo emailBo=new EmailBo(title,admin.getEmail(),content);
  246. asyncUtils.send(emailBo);
  247. }
  248. /**
  249. *
  250. * @param id 接受者编号
  251. * @param type 状态 0驳回 1发起 2同意 3 公出他人企业
  252. * @param content 内容
  253. */
  254. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  255. Integer noticeType=NoticeStatus.PUBLIC_RELEASE_START.getCode();
  256. if(type==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  257. else if (type==2)noticeType=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  258. else if (type==3)noticeType=NoticeStatus.PUBLIC_OTHERS_USER.getCode();
  259. //触发通知有未读消息
  260. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  261. Notice n =new Notice();
  262. n.setId(UUID.randomUUID().toString());
  263. n.setAid(id);
  264. n.setNoticeType(noticeType);
  265. n.setContent(content);
  266. n.setReaded(0);//未读
  267. asyncUtils.addNotice(n);
  268. }
  269. /**
  270. *
  271. * @param my 发送人
  272. * @param a 接受者
  273. * @param type 类型
  274. */
  275. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  276. StringBuffer title=new StringBuffer();
  277. if (type==0) title=title.append("外出申请驳回提醒");
  278. else if (type==1) title=title.append("外出申请提醒");
  279. else if (type==2) title=title.append("外出申请同意提醒");
  280. if (SendEmailUtil.isEmail(a.getEmail())) {
  281. EmailBo email=new EmailBo(title.toString(),a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  282. asyncUtils.send(email);
  283. }
  284. }
  285. @Override
  286. public int updatePublicRelease(InputPublicRelease in) {
  287. Date date = new Date();
  288. try {
  289. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  290. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  291. } catch (ParseException e) {
  292. e.printStackTrace();
  293. throw new BusinessException("转换异常");
  294. }
  295. List<User> uses=null;
  296. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(in.getId());
  297. if (in.getUids()!=null){
  298. List<String> split = Arrays.asList(in.getUids().split(","));
  299. List<OutPublicReleaseDetails> prList = publicReleaseDetailsMapper.selectByPCid(in.getId());
  300. uses=pushPublicReleaseDetails(split,prList,use,in);
  301. }
  302. String userNames=publicReleaseDetailsMapper.getNamesByPrid(in.getId());
  303. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
  304. in.setUserNames(userNames);
  305. if(in.getStatus()==null||in.getStatus()!=3) {
  306. in.setStatus(1);
  307. log.setStatus(PublicReleaseLog.states.xg.getCode());
  308. in.setUpdateStatus(1);
  309. if(in.getPublicType()==2||in.getPublicType()==3){
  310. in.setPublicType(1);
  311. PublicExamine pe=new PublicExamine();
  312. pe.setPrid(in.getId());
  313. pe.setStatus(0);
  314. publicExamineMapper.updatePrid(pe);
  315. }
  316. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  317. //新增修改日志
  318. //重新发起
  319. addPublicReleaseLog(my,in,in.getUserNames(),date,uses);
  320. }else {
  321. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
  322. List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
  323. log.setStatus(PublicReleaseLog.states.cx.getCode());
  324. for (PublicRelease out : list) {
  325. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
  326. out.setStatus(3);
  327. publicReleaseMapper.updateByPrimaryKeySelective(out);
  328. }
  329. for (PublicRelease out : list2) {
  330. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单助手");
  331. out.setStatus(3);
  332. publicReleaseMapper.updateByPrimaryKeySelective(out);
  333. }
  334. }
  335. publicReleaseLogMapper.insertSelective(log);
  336. publicReleaseMapper.updateByPrimaryKeySelective(in);
  337. return 1;
  338. }
  339. private List<User> pushPublicReleaseDetails(List<String> split, List<OutPublicReleaseDetails> prList, PublicRelease use, InputPublicRelease in) {
  340. //先删除,再修改个,再新增,有利于减少计算
  341. deletePRD(split,prList);
  342. publicReleaseDetailsMapper.updateDistrictByPrid(in);
  343. return addPRD(split,prList,use);
  344. }
  345. private void deletePRD(List<String> split, List<OutPublicReleaseDetails> prdList) {
  346. for (OutPublicReleaseDetails prd : prdList) {
  347. boolean flag=true;
  348. for (String s : split) {
  349. if (prd.getUid().equals(s)){
  350. flag=false;
  351. }
  352. }
  353. if (flag){
  354. publicReleaseDetailsMapper.deleteByPrimaryKey(prd.getId());
  355. }
  356. }
  357. }
  358. /**
  359. * @param split 修改后客户集
  360. * @param prdList 修改前客户集
  361. * @param use 原订单信息
  362. */
  363. private List<User> addPRD(List<String> split, List<OutPublicReleaseDetails> prdList, PublicRelease use) {
  364. List<PublicReleaseDetails> addPrdList=new ArrayList<>();
  365. List<User> users=new ArrayList<>();
  366. Integer publicType = use.getPublicType();
  367. for (String s : split) {
  368. User u=userMapper.selectByPrimaryKey(s);
  369. users.add(u);
  370. boolean flag=true;
  371. Integer id=null;
  372. String districtName=null,latitude=null,longitude=null;
  373. for (OutPublicReleaseDetails prd : prdList) {
  374. if (id==null)id=prd.getPrid();
  375. if (districtName==null)districtName=prd.getDistrictName();
  376. if (latitude==null)latitude=prd.getLatitude();
  377. if (longitude==null)longitude=prd.getLongitude();
  378. if (s.equals(prd.getUid())){
  379. flag=false;
  380. }
  381. }
  382. if (flag){
  383. PublicReleaseDetails prd=new PublicReleaseDetails();
  384. if (u!=null&&u.getShareType()==2){
  385. prd.setNewUser(1);
  386. }else {
  387. prd.setNewUser(0);
  388. }
  389. if (u.getAid().equals(use.getAid())){
  390. prd.setMainStatus(1);
  391. }else {
  392. prd.setMainStatus(0);
  393. }
  394. prd.setPrid(id);
  395. prd.setUid(s);
  396. prd.setSignSum(0);
  397. prd.setDistrictName(districtName);
  398. prd.setLatitude(latitude);
  399. prd.setLongitude(longitude);
  400. prd.setClockIn(0);
  401. addPrdList.add(prd);
  402. if (!use.getAid().equals(u.getAid())){
  403. addPublicExamine(use.getId(), u.getAid());
  404. if (publicType==1)publicType=1;
  405. }
  406. }
  407. }
  408. if (publicType!=use.getPublicType()){
  409. PublicRelease newP=new PublicRelease();
  410. newP.setId(use.getId());
  411. newP.setPublicType(publicType);
  412. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  413. }
  414. if (!addPrdList.isEmpty())publicReleaseDetailsMapper.insertBatch(addPrdList);
  415. return users;
  416. }
  417. @SuppressWarnings("unchecked")
  418. @Override
  419. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  420. Map<String,Object> map =new HashMap<String, Object>();
  421. map.put("type", in.getType()==null?0:in.getType());
  422. if (in.getType()==3) {
  423. in.setAssist(2);
  424. if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
  425. }else{
  426. map.put("aid",TokenManager.getAdminId());
  427. }
  428. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  429. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  430. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  431. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  432. if(in.getStatus()!=null) map.put("status", in.getStatus());
  433. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  434. map.put("assist",in.getAssist()==null?0:in.getAssist());
  435. Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  436. if(in.getType()==0||in.getType()==4){
  437. pushExamines(p);
  438. }
  439. return p;
  440. }
  441. private void pushExamines(Pagination<OutPublicReleaseList> p) {
  442. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
  443. if (!list.isEmpty()){
  444. List<Integer> ids=new ArrayList<>();
  445. list.forEach(e ->{ ids.add(e.getId()); });
  446. List<PublicExamine> publicExamines = publicExamineMapper.selectByIds(ids);
  447. for (OutPublicReleaseList e : list) {
  448. if (!publicExamines.isEmpty()){
  449. StringBuffer str =new StringBuffer();
  450. for (PublicExamine pe : publicExamines) {
  451. if (e.getId().equals(pe.getPrid())){
  452. str=str.append(pe.getAname());
  453. if (pe.getStatus()==0)str=str.append(" 未审核,");
  454. if (pe.getStatus()==1)str=str.append(" 已审核,");
  455. }
  456. if (str.length()>1) e.setAdminExamine(str.substring(0,str.length()-1));
  457. }
  458. }
  459. }
  460. }
  461. }
  462. @Override
  463. @Transactional
  464. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Integer examineType) {
  465. PublicRelease p=new PublicRelease();
  466. Date date =new Date();
  467. boolean flag=false;
  468. String aid=TokenManager.getAdminId();
  469. p.setId(id);
  470. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  471. if (use.getStatus()!=1) {
  472. throw new BusinessException("只能修改发起的状态公出");
  473. }
  474. //当前审核人员
  475. Admin ad=adminMapper.selectByPrimaryKey(aid);
  476. //公出负责人
  477. Admin a;
  478. Admin publicAdmin =adminMapper.selectByPrimaryKey(use.getAid());
  479. a=publicAdmin;
  480. StringBuffer str=new StringBuffer();
  481. str=str.append("(").append(ad.getName()).append(")");
  482. StringBuffer content=new StringBuffer().append("[").append(use.getUserNames()).append("]公司的外出申请,");
  483. //上级审核
  484. if(examineType==0){
  485. p.setStatus(status);
  486. if (status==0){
  487. str=str.append("驳回,");
  488. if (use.getAssist()==2){
  489. content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
  490. }else {
  491. content=content.append("未通过公出审核!");
  492. }
  493. if(use.getPublicType()>1){
  494. p.setPublicType(1);
  495. PublicExamine inpe=new PublicExamine();
  496. inpe.setStatus(0);
  497. inpe.setPrid(use.getId());
  498. publicExamineMapper.updatePrid(inpe);
  499. }
  500. }else if(status==2){
  501. str=str.append("同意,");
  502. //如果是协单公出主公出,在审核通过
  503. if (use.getAssist()==1){
  504. pushPublicReleaseAssist(use,status,date,a);
  505. }else if (use.getAssist()==0){
  506. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  507. }
  508. content=content.append("已通过审核!");
  509. }
  510. str=str.append(remarks);
  511. p.setAuditInfo(str.toString());
  512. p.setAuditTime(date);
  513. p.setRejectName(ad.getName());
  514. addpublicLog(id, status, remarks);
  515. flag=true;
  516. //营销员审核
  517. }else if (examineType==1){
  518. //通知公出人切换成公出人审核人
  519. a=adminMapper.selectByPrimaryKey(a.getReviewer());
  520. if (status==2){//审核通过
  521. str=str.append("同意公出我的企业,").append(remarks);
  522. content=content.append("已通过审核,请尽快审核。");
  523. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  524. int x=0;
  525. for (PublicExamine pe : publicExamines) {
  526. if (pe.getAid().equals(aid)){
  527. pe.setStatus(1);
  528. PublicExamine newp=new PublicExamine();
  529. newp.setId(pe.getId());
  530. newp.setStatus(1);
  531. publicExamineMapper.updateByPrimaryKeySelective(newp);
  532. x++;
  533. }else {
  534. if (pe.getStatus()==1){
  535. x++;
  536. }
  537. }
  538. }
  539. if (x==publicExamines.size()){
  540. p.setPublicType(2);
  541. flag=true;
  542. }
  543. addpublicLog(id, status, str.toString());
  544. }else if (status==0){//审核驳回
  545. //切换通知人公出负责人
  546. a=publicAdmin;
  547. str=str.append("不同意公出我的企业,").append(remarks);;
  548. content=content.append("未通过审核,请修改后重新发起。");
  549. p.setPublicType(3);
  550. p.setStatus(0);
  551. p.setAuditInfo(str.toString());
  552. p.setRejectName(ad.getName());
  553. addpublicLog(id, 0, str.toString());
  554. }
  555. }
  556. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  557. if (flag){
  558. sendNoticeAndSoucket(a.getId(),status,content.toString());
  559. }
  560. if (p.getStatus()!=null||p.getPublicType()!=null){
  561. publicReleaseMapper.updateByPrimaryKeySelective(p);
  562. }
  563. if (a.getOpenId()!=null) {
  564. if (remarks.length()>19) {
  565. remarks=remarks.substring(0, 15)+"...";
  566. }
  567. Integer res=weChatUtils.addNotice(a.getOpenId(),status,p.getId(),date,my.getName(),remarks);
  568. if (res!=0) {
  569. sendEmail( my, a, status);
  570. }
  571. return res;
  572. }else {
  573. }
  574. return 1;
  575. }
  576. private void addpublicLog(Integer id, Integer status, String remarks) {
  577. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  578. publicReleaseLogMapper.insertSelective(log);
  579. }
  580. @Override
  581. public int pushTechReject(Integer id, String remarks) {
  582. Integer status=0;
  583. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  584. PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
  585. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  586. StringBuffer str=new StringBuffer();
  587. if (use.getAssist()!=2){
  588. throw new BusinessException("只有技术公出能发起技术驳回");
  589. }
  590. str=str.append("拒绝技术协单,").append(remarks);
  591. PublicRelease newMain=new PublicRelease();
  592. newMain.setId(mainPublic.getId());
  593. newMain.setStatus(4);
  594. newMain.setRejectName(ad.getName());
  595. newMain.setAuditInfo(str.toString());
  596. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  597. publicReleaseMapper.updateByPrimaryKeySelective(newMain);
  598. PublicRelease up=new PublicRelease();
  599. up.setId(id);
  600. up.setAuditInfo(str.toString());
  601. up.setStatus(3);
  602. addpublicLog(id, status, remarks);
  603. publicReleaseMapper.updateByPrimaryKeySelective(up);
  604. deleteAssistantPulicRelease(use,null);
  605. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  606. }
  607. /**
  608. * 新增日志、站内信、微信提醒
  609. * @param id 日志公出编号
  610. * @param aid 接受者
  611. * @param remarks 日志内容
  612. * @param status 0驳回
  613. * @return
  614. */
  615. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  616. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  617. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  618. if (my.getOpenId()!=null) {
  619. if (remarks.length()>19) {
  620. remarks=remarks.substring(0, 15)+"...";
  621. }
  622. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  623. }else {
  624. sendEmail( my, a, status);
  625. return 1;
  626. }
  627. }
  628. /**
  629. *
  630. * @param use 原始公出信息
  631. * @param status 状态
  632. * @param date 时间
  633. * @param a
  634. */
  635. private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date,Admin a) {
  636. if (use.getAssistAid()!=null){
  637. updatePushassist(use, status, date,a);
  638. if(use.getAssistantAid()!=null){
  639. updatepushAssistant(use,a);
  640. }
  641. }
  642. }
  643. /**
  644. * 处理技术协单
  645. * @param use
  646. * @param status
  647. * @param date
  648. */
  649. private void updatePushassist(PublicRelease use, Integer status, Date date, Admin a) {
  650. //协单
  651. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  652. String []ss= use.getAssistAid().split(",");
  653. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  654. for (PublicRelease out : list) {
  655. boolean flag=false;
  656. for (String s : ss) {
  657. if (out.getAid().equals(s)){
  658. flag=true;
  659. break;
  660. }
  661. }
  662. if (!flag){
  663. PublicRelease in = new PublicRelease();
  664. in.setId(out.getId());
  665. in.setStatus(3);
  666. publicReleaseMapper.updateByPrimaryKeySelective(in);
  667. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  668. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  669. publicReleaseLogMapper.insertSelective(log);
  670. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  671. }else {
  672. PublicRelease np = new PublicRelease();
  673. BeanUtils.copyProperties(use,np);
  674. np.setId(out.getId());
  675. np.setMainId(null);
  676. np.setType(null);
  677. np.setAssist(2);
  678. np.setStatus(status);
  679. np.setAid(null);
  680. publicReleaseMapper.updateByPrimaryKeySelective(np);
  681. updatePublicReleaseDtails(use,np.getId());
  682. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  683. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  684. publicReleaseLogMapper.insertSelective(log);
  685. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  686. }
  687. }
  688. for (String s : ss) {
  689. boolean flag2 = false;
  690. for (PublicRelease o : list) {
  691. if (s.equals(o.getAid())) {
  692. flag2 = true;
  693. }
  694. }
  695. if (!flag2) {
  696. PublicRelease np = new PublicRelease();
  697. BeanUtils.copyProperties(use,np);
  698. np.setAssist(2);
  699. np.setAid(s);
  700. np.setStatus(2);
  701. np.setType(3);
  702. np.setMainId(use.getId());
  703. np.setId(null);
  704. publicReleaseMapper.insertSelective(np);
  705. //补充客户表
  706. addpublicReleaseDtails(use,np.getId());
  707. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  708. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  709. sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
  710. publicReleaseLogMapper.insertSelective(log);
  711. }
  712. }
  713. }
  714. private void updatePublicReleaseDtails(PublicRelease use, Integer id) {
  715. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  716. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPCid(id);
  717. //查找新增的
  718. for (OutPublicReleaseDetails out : list) {
  719. boolean flag=true;
  720. for (OutPublicReleaseDetails out2 : list2) {
  721. if (out.getUid().equals(out2.getUid())){
  722. flag=false;
  723. }
  724. }
  725. if (flag){
  726. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  727. BeanUtils.copyProperties(out,prd);
  728. prd.setPrid(id);
  729. prd.setClockIn(0);
  730. prd.setClockInTime(null);
  731. prd.setClockInRemarks(null);
  732. prd.setUfid(null);
  733. publicReleaseDetailsMapper.insertSelective(prd);
  734. }
  735. }
  736. for (OutPublicReleaseDetails out2 : list2) {
  737. boolean flag=true;
  738. for (OutPublicReleaseDetails out : list) {
  739. if (out2.getUid().equals(out.getUid())){
  740. flag=false;
  741. }
  742. }
  743. if (flag){
  744. publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
  745. }
  746. }
  747. }
  748. private void addpublicReleaseDtails(PublicRelease use, Integer id) {
  749. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  750. for (OutPublicReleaseDetails out : list) {
  751. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  752. BeanUtils.copyProperties(out,prd);
  753. prd.setPrid(id);
  754. prd.setClockIn(0);
  755. prd.setClockInTime(null);
  756. prd.setMainStatus(0);
  757. publicReleaseDetailsMapper.insertSelective(prd);
  758. }
  759. }
  760. /**
  761. * 处理技术助手
  762. * @param use
  763. */
  764. private void updatepushAssistant(PublicRelease use,Admin a) {
  765. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  766. for (PublicRelease p : uselist) {
  767. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  768. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  769. p.setStatus(2);
  770. p.setAssistantAid(use.getAssistantAid());
  771. p.setAssistantName(use.getAssistantName());
  772. p.setUserNames(use.getUserNames());
  773. publicReleaseMapper.updateByPrimaryKeySelective(p);
  774. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  775. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  776. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  777. publicReleaseLogMapper.insertSelective(log);
  778. }
  779. }
  780. @Override
  781. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  782. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  783. return list;
  784. }
  785. @Override
  786. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  787. if (clockIn == null) clockIn = 1;
  788. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(id);
  789. if (use.getPublicType()==1||use.getPublicType()==3){
  790. return -1;
  791. }
  792. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPCid(id);
  793. String str = "";
  794. boolean flag=false;
  795. Integer clockCount=0;
  796. for (OutPublicReleaseDetails prd : prdList) {
  797. if (prd.getUid().equals(uid)){
  798. String aid = TokenManager.getAdminId();
  799. prd.setClockInRemarks(clockInRemarks);
  800. prd.setPhotoUrl(photoUrl);
  801. prd.setClockInTime(new Date());
  802. if (prd.getClockIn() == 0) {
  803. prd.setClockIn(clockIn);
  804. //获取列表
  805. FollowBusinessBo fbb = new FollowBusinessBo();
  806. fbb.setUid(prd.getUid());
  807. fbb.setContactType("5");
  808. fbb.setResult(use.getRemarks());
  809. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  810. if (ub != null) {
  811. fbb.setOcbId(ub.getId());
  812. }
  813. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  814. String ufid = UUID.randomUUID().toString();
  815. prd.setUfid(ufid);
  816. customerService.addFollow(fbb, ufid, prd.getMainStatus());
  817. str = "公出人员打卡";
  818. }else if (clockIn == 2){
  819. str = "公出人员异常打卡";
  820. }else {
  821. str = "刷新打卡";
  822. }
  823. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  824. log.setPhotoUrl(photoUrl);
  825. publicReleaseLogMapper.insertSelective(log);
  826. publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
  827. flag=true;
  828. clockCount++;
  829. }else if (prd.getClockIn()==1){
  830. clockCount++;
  831. }
  832. }
  833. if (prdList.size()==clockCount){
  834. PublicRelease newp=new PublicRelease();
  835. newp.setId(id);
  836. newp.setClockIn(1);
  837. publicReleaseMapper.updateByPrimaryKeySelective(newp);
  838. }
  839. if (!flag){
  840. return 0;
  841. }
  842. return 1;
  843. }
  844. @Override
  845. public OutPublicRelease dtails(Integer id) {
  846. String aid=TokenManager.getAdminId();
  847. //如果不是本人和审核人员则不返回信息
  848. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  849. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  850. out.setPeList(ps);
  851. if(out!=null){
  852. boolean flag=false;
  853. //自己、审核人员与部门负责人可以查看
  854. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  855. if (!aid.equals( out.getAid())&&
  856. !aid.equals(out.getReviewer())&&
  857. !aid.equals(ab.getDepManager())&&
  858. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  859. flag=true;
  860. }
  861. //是否可以查看
  862. if (!ps.isEmpty()){
  863. for (PublicExamine p : ps) {
  864. if (p.getAid().equals(aid)){
  865. if (p.getStatus()==1)out.setMyExamine(1);
  866. else out.setMyExamine(0);
  867. flag=false;
  868. break;
  869. }
  870. }
  871. }
  872. if(flag){
  873. out=null;
  874. return out;
  875. }else {
  876. if (out.getPublicType()==1){
  877. if (aid.equals(out.getAid())){
  878. out.setPermission(0);
  879. }else {
  880. out.setPermission(1);
  881. }
  882. }else {
  883. if(aid.equals(out.getAid())) {
  884. out.setPermission(0);
  885. }else {
  886. out.setPermission(1);
  887. }
  888. }
  889. }
  890. }
  891. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  892. return out;
  893. }
  894. @Override
  895. public OutPublicReleaseAndDetails followDtails(String id) {
  896. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  897. return out;
  898. }
  899. @SuppressWarnings("unchecked")
  900. @Override
  901. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  902. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  903. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  904. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  905. public Object publicReleaseStatistics(InputPublicStatistics in) {
  906. Map<String,Object> map =new HashMap<String, Object>();
  907. if(in.getAid()!=null)map.put("aid", in.getAid());
  908. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  909. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  910. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  911. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  912. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  913. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  914. }
  915. @SuppressWarnings("unchecked")
  916. @Override
  917. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  918. Map<String,Object> map =new HashMap<String, Object>();
  919. if(in.getAid()!=null)map.put("aid", in.getAid());
  920. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  921. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  922. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  923. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  924. }
  925. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  926. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  927. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  928. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  929. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  930. }
  931. @SuppressWarnings("unchecked")
  932. @Override
  933. public Object publicReleaseListDtails(InputPublicDtails in) {
  934. Map<String,Object> map =new HashMap<String, Object>();
  935. addParams(in, map);
  936. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  937. return page;
  938. }
  939. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  940. if(in.getAid()!=null) map.put("aid", in.getAid());
  941. if(in.getSid()!=null) map.put("sid", in.getSid());
  942. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  943. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  944. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  945. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  946. if(in.getUid()!=null) map.put("uid", in.getUid());
  947. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  948. if(in.getStatus()!=null) map.put("status", in.getStatus());
  949. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  950. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  951. //type 0私有 1管理权限 2所有权限
  952. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  953. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  954. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  955. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  956. //添加财务和财务经理。查看客户所有公出
  957. in.setType(2);
  958. if(in.getDeps()!=null){
  959. map.put("deps", departmentService.parseArray(in.getDeps()));
  960. }
  961. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  962. in.setType(1);
  963. if (in.getDeps()!=null){
  964. List<String> list = departmentService.selectSubDeps(in.getDeps());
  965. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  966. map.put("deps", list);
  967. }else {
  968. map.put("deps",departmentService.selectMyDeps());
  969. }
  970. }else{
  971. in.setType(0);
  972. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  973. if(in.getDeps()!=null){
  974. map.put("deps", departmentService.parseArray(in.getDeps()));
  975. }
  976. }
  977. map.put("type", in.getType());
  978. }
  979. @SuppressWarnings("unchecked")
  980. @Override
  981. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  982. Map<String,Object> map =new HashMap<String, Object>();
  983. addParams(in, map);
  984. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  985. }
  986. @Override
  987. public int addSupplement(Integer id, String supplement, String nextPlan) {
  988. PublicRelease pr=new PublicRelease();
  989. pr.setId(id);
  990. pr.setSupplement(supplement);
  991. pr.setNextPlan(nextPlan);
  992. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  993. }
  994. @Override
  995. public boolean checkTime(InputPublicRelease in) {
  996. try {
  997. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  998. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  999. } catch (ParseException e) {
  1000. e.printStackTrace();
  1001. throw new BusinessException("转换异常");
  1002. }
  1003. List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  1004. if (is.size()>1) {
  1005. return true;
  1006. }else if(is.size()==1){
  1007. //如果id为新增那么直接不允许时间重复
  1008. if (in.getId()==null){
  1009. return true;
  1010. }else {
  1011. //如果有id,与获取id一直,则为当前修改可以
  1012. if (in.getId().equals(is.get(0))){
  1013. return false;
  1014. }else {
  1015. return true;
  1016. }
  1017. }
  1018. }
  1019. return false;
  1020. }
  1021. @Override
  1022. public List<Map<String, Object>> selectOrderByUid(String uid) {
  1023. return tOrderNewMapper.selectOrderByuid(uid);
  1024. }
  1025. @Override
  1026. public List<OutPublicRelease> publicByOrder(String orderNo) {
  1027. return publicReleaseMapper.publicByOrder(orderNo);
  1028. }
  1029. @Override
  1030. public Object getMyNewPublic() {
  1031. List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  1032. if (myPublic.isEmpty()){
  1033. List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  1034. if (!myPublic2.isEmpty()){
  1035. return myPublic2.get(0);
  1036. }
  1037. }else {
  1038. return myPublic.get(0);
  1039. }
  1040. return null;
  1041. }
  1042. /**
  1043. *
  1044. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  1045. * @param dateType 是否含打卡时间 0否 1是
  1046. * @return
  1047. */
  1048. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  1049. Map<String, Object> map = new HashMap<>();
  1050. if (type==null)type=0;
  1051. map.put("type",type);
  1052. //statusType=1情况下
  1053. map.put("statusType",1);
  1054. if (dateType==1){
  1055. Date date = new Date();
  1056. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  1057. map.put("clockTime",clockTime);
  1058. }
  1059. map.put("aid",TokenManager.getAdminId());
  1060. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  1061. for (OutPublicReleaseList out : list) {
  1062. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1063. }
  1064. return list;
  1065. }
  1066. @Override
  1067. public int addAssistant(Integer id,String aid) {
  1068. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1069. List<String> list=new ArrayList<>();
  1070. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  1071. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1072. }
  1073. String sname = pushAssistant(aid, list,0);
  1074. String said =String.join(",",list);
  1075. p.setAssistantAid(said);
  1076. p.setAssistantName(sname);
  1077. addAssistantPublicRelease(p,aid);
  1078. return updateAssistant(p, said, sname);
  1079. }
  1080. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  1081. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1082. PublicRelease newP= new PublicRelease();
  1083. if(list.isEmpty()){
  1084. BeanUtils.copyProperties(p,newP);
  1085. newP.setId(null);
  1086. newP.setAid(aid);
  1087. newP.setAssist(3);
  1088. newP.setType(4);
  1089. publicReleaseMapper.insertSelective(newP);
  1090. addpublicReleaseDtails(p,newP.getId());
  1091. StringBuffer str=new StringBuffer();
  1092. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  1093. addWeChatNotice( aid,1,str.toString(),newP.getId());
  1094. }else {
  1095. for (PublicRelease pr : list) {
  1096. newP.setId(pr.getId());
  1097. newP.setAssistantAid(p.getAssistantAid());
  1098. newP.setAssistantName(p.getAssistantName());
  1099. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  1100. updatePublicReleaseDtails(p,newP.getId());
  1101. }
  1102. }
  1103. }
  1104. /**
  1105. * 添加微信提示和站内消息
  1106. * @param aid 接受者
  1107. * @param type 状态 0驳回 1发起 2同意 3撤销
  1108. * @param str 备注
  1109. * @param prid 公出编号
  1110. */
  1111. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  1112. Admin recipient = adminMapper.selectByPrimaryKey(aid);
  1113. addWeChatNotice( recipient, type, str, prid);
  1114. }
  1115. /**
  1116. * 添加微信提示和站内消息
  1117. * @param recipient 接受者
  1118. * @param type 状态 0驳回 1发起 2同意 3撤销
  1119. * @param str
  1120. */
  1121. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  1122. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  1123. String openid=recipient.getOpenId();
  1124. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  1125. if(type==3){
  1126. addpublicLog(prid,4,str);
  1127. }else {
  1128. addpublicLog(prid,type,str);
  1129. }
  1130. sendNoticeAndSoucket(recipient.getId(),type,str);
  1131. if (type==0||type==2){
  1132. if (openid!=null) {
  1133. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  1134. return res;
  1135. }else {
  1136. sendEmail(my, recipient,type);
  1137. }
  1138. }
  1139. return 0;
  1140. }
  1141. private int updateAssistant(PublicRelease p, String said, String sname) {
  1142. PublicRelease newPr=new PublicRelease();
  1143. newPr.setId(p.getId());
  1144. newPr.setAssistantAid(said);
  1145. newPr.setAssistantName(sname);
  1146. if (p.getMainId()!=null){
  1147. PublicRelease mianPr=new PublicRelease();
  1148. mianPr.setId(p.getMainId());
  1149. mianPr.setAssistantAid(said);
  1150. mianPr.setAssistantName(sname);
  1151. publicReleaseMapper.updateByPrimaryKeySelective(mianPr);
  1152. }
  1153. return publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1154. }
  1155. /**
  1156. *
  1157. * @param aid 元素
  1158. * @param list 集合
  1159. * @param type 0新增 1删除
  1160. * @return
  1161. */
  1162. private String pushAssistant(String aid, List<String> list,Integer type) {
  1163. StringBuffer sb=new StringBuffer();
  1164. if(type==0){
  1165. list.add(aid);
  1166. }else if (type==1){
  1167. Iterator<String > it =list.iterator();
  1168. while (it.hasNext()){
  1169. if (it.next().equals(aid))
  1170. it.remove();
  1171. }
  1172. }
  1173. for (String s : list) {
  1174. sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
  1175. }
  1176. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  1177. }
  1178. @Override
  1179. public int deleteAssistant(Integer id, String aid) {
  1180. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1181. if (p.getAssistantAid()==null){
  1182. throw new BusinessException("人员不存在");
  1183. }
  1184. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1185. if (!list.contains(aid)){
  1186. throw new BusinessException("人员不存在");
  1187. }
  1188. String sname = pushAssistant(aid, list,1);
  1189. String said =String.join(",",list);
  1190. p.setAssistantAid(said);
  1191. p.setAssistantName(sname);
  1192. deleteAssistantPulicRelease(p,aid);
  1193. return updateAssistant(p, said, sname);
  1194. }
  1195. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  1196. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  1197. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1198. StringBuffer str=new StringBuffer();
  1199. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  1200. for (PublicRelease pr : list) {
  1201. if (pr.getAid().equals(aid)){
  1202. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  1203. }else {
  1204. PublicRelease newPr=new PublicRelease();
  1205. newPr.setId(pr.getId());
  1206. newPr.setAssistantAid(p.getAssistantAid());
  1207. newPr.setAssistantName(p.getAssistantName());
  1208. publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1209. }
  1210. }
  1211. }
  1212. @Override
  1213. public boolean checkdeleteAssistant(Integer id, String aid) {
  1214. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1215. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1216. for (PublicRelease use : list) {
  1217. // if (use.getClockIn()==1){
  1218. // return true;
  1219. // }
  1220. }
  1221. return false;
  1222. }
  1223. @Override
  1224. public boolean checkaddAssistant(Integer id, String aid) {
  1225. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1226. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1227. for (PublicRelease use : list) {
  1228. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  1229. return true;
  1230. }
  1231. }
  1232. return false;
  1233. }
  1234. @Override
  1235. public int updateLocation(InputPublicRelease in) {
  1236. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  1237. if (prd==null){
  1238. throw new BusinessException("公出企业不存在");
  1239. }
  1240. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  1241. updateprd.setId(prd.getId());
  1242. updateprd.setLatitude(in.getLatitude());
  1243. updateprd.setLongitude(in.getLongitude());
  1244. updateprd.setDistrictName(in.getDistrictName());
  1245. updateprd.setClockIn(0);
  1246. addpublicLog(in.getId(),5,"发起公出地点修改");
  1247. return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
  1248. }
  1249. }