PublicReleaseServiceImpl.java 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  1. package com.goafanti.weChat.service.impl;
  2. import cn.jiguang.common.utils.StringUtils;
  3. import com.goafanti.admin.bo.AdminListBo;
  4. import com.goafanti.admin.service.DepartmentService;
  5. import com.goafanti.common.bo.EmailBo;
  6. import com.goafanti.common.constant.AFTConstants;
  7. import com.goafanti.common.dao.*;
  8. import com.goafanti.common.enums.NoticeStatus;
  9. import com.goafanti.common.error.BusinessException;
  10. import com.goafanti.common.model.*;
  11. import com.goafanti.common.utils.AsyncUtils;
  12. import com.goafanti.common.utils.DateUtils;
  13. import com.goafanti.common.utils.SendEmailUtil;
  14. import com.goafanti.common.utils.WeChatUtils;
  15. import com.goafanti.core.mybatis.BaseMybatisDao;
  16. import com.goafanti.core.mybatis.page.Pagination;
  17. import com.goafanti.core.shiro.token.TokenManager;
  18. import com.goafanti.core.websocket.SystemWebSocketHandler;
  19. import com.goafanti.customer.bo.FollowBusinessBo;
  20. import com.goafanti.customer.service.CustomerService;
  21. import com.goafanti.order.bo.TOrderNewBo;
  22. import com.goafanti.weChat.bo.*;
  23. import com.goafanti.weChat.service.PublicReleaseService;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import org.springframework.web.socket.TextMessage;
  29. import java.math.BigDecimal;
  30. import java.text.ParseException;
  31. import java.util.*;
  32. import java.util.concurrent.atomic.AtomicReference;
  33. import java.util.stream.Collectors;
  34. @Service
  35. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  36. @Autowired
  37. private PublicReleaseMapper publicReleaseMapper;
  38. @Autowired
  39. private PublicReleaseLogMapper publicReleaseLogMapper;
  40. @Autowired
  41. private CustomerService customerService;
  42. @Autowired
  43. private PublicReleaseDetailsMapper publicReleaseDetailsMapper;
  44. @Autowired
  45. private WeChatUtils weChatUtils;
  46. @Autowired
  47. private AdminMapper adminMapper;
  48. @Autowired
  49. private AsyncUtils asyncUtils;
  50. @Autowired
  51. private UserMapper userMapper;
  52. @Autowired
  53. private OrganizationContactBookMapper organizationContactBookMapper;
  54. @Autowired
  55. private SystemWebSocketHandler systemWebSocketHandler;
  56. @Autowired
  57. private TOrderNewMapper tOrderNewMapper;
  58. @Autowired
  59. private DepartmentService departmentService;
  60. @Autowired
  61. private PublicExamineMapper publicExamineMapper;
  62. @Autowired
  63. private AdminUserCountMapper adminUserCountMapper;
  64. @Autowired
  65. private PublicReleaseClockMapper publicReleaseClockMapper;
  66. @Override
  67. @Transactional
  68. public Map<String, Object> addPublicRelease(InputPublicRelease in) {
  69. Date date =new Date();
  70. if (in.getPublicAgain()==null)in.setPublicAgain(0);
  71. in.setCreateTime(date);
  72. in.setPublicType(0);
  73. in.setTechStartProcess(0);
  74. in.setStatus(1);
  75. in.setAid(TokenManager.getAdminId());
  76. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  77. if (in.getAssist()==1){
  78. // in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  79. in.setMainName(my.getName());
  80. }
  81. Map checkOrderNo =null;
  82. if (in.getType() == 1) {
  83. checkOrderNo = checkOrderNoDuration(in,my);
  84. boolean isValid = (boolean) checkOrderNo.get("code");
  85. if (isValid){
  86. in.setTechStartProcess(0);
  87. }else {
  88. in.setTechStartProcess(1);
  89. }
  90. }
  91. publicReleaseMapper.insertSelective(in);
  92. List<PublicReleaseDetails> prdList=new ArrayList<>();
  93. List<User> users=new ArrayList<>();
  94. StringBuilder str =new StringBuilder();
  95. if (in.getUids()!=null){
  96. List<String> split = Arrays.asList(in.getUids().split(","));
  97. int userCount=split.size();
  98. Double duration = in.getDuration();
  99. //计算平均
  100. double d = durationSum(duration, userCount);
  101. int index=1;
  102. //获取非已企业公出需要的审核人员
  103. for (String s : split) {
  104. PublicReleaseDetails prd=new PublicReleaseDetails();
  105. User u=userMapper.selectByPrimaryKey(s);
  106. users.add(u);
  107. str.append(u.getNickname()).append(",");
  108. if (u!=null&&u.getShareType()==2){
  109. prd.setNewUser(1);
  110. }else {
  111. prd.setNewUser(0);
  112. }
  113. if (u.getAid().equals(in.getAid())){
  114. prd.setMainStatus(1);
  115. }else {
  116. prd.setMainStatus(0);
  117. }
  118. prd.setPrid(in.getId());
  119. prd.setUid(s);
  120. prd.setSignSum(0);
  121. prd.setClockIn(0);
  122. prd.setDistrictName(in.getDistrictName());
  123. prd.setLatitude(in.getLatitude());
  124. prd.setLongitude(in.getLongitude());
  125. if (index<userCount){
  126. if (duration==0){
  127. prd.setDuration(duration);
  128. } else {
  129. prd.setDuration(d);
  130. duration=duration-d;
  131. }
  132. index++;
  133. }else {
  134. prd.setDuration(duration);
  135. }
  136. prdList.add(prd);
  137. }
  138. publicReleaseDetailsMapper.insertBatch(prdList);
  139. }
  140. String userNames=str.substring(0,str.length()-1);
  141. in.setUserNames(userNames);
  142. PublicRelease updateName=new PublicRelease();
  143. updateName.setId(in.getId());
  144. updateName.setUserNames(userNames);
  145. publicReleaseMapper.updateByPrimaryKeySelective(updateName);
  146. addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
  147. return (Map<String, Object>) addPublicReleaseLog(my, in,userNames,date,users,checkOrderNo);
  148. }
  149. private void addPublicExamine(Integer id, String aid) {
  150. Admin admin = adminMapper.selectByPrimaryKey(aid);
  151. addPublicExamine(id,admin);
  152. }
  153. private void addPublicExamine(Integer id, Admin a) {
  154. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
  155. boolean flag=false;
  156. for (PublicExamine pe : publicExamines) {
  157. if (pe.getAid().equals(a.getId())){
  158. flag=true;
  159. }
  160. }
  161. if (!flag){
  162. PublicExamine pe=new PublicExamine();
  163. pe.setPrid(id);
  164. pe.setAid(a.getId());
  165. pe.setAname(a.getName());
  166. pe.setStatus(0);
  167. publicExamineMapper.insertSelective(pe);
  168. }
  169. }
  170. private double durationSum(Double duration, Integer sum) {
  171. Double counts= Math.floor(duration/0.5);
  172. //计算当前时间
  173. Double my=Math.floor(counts/sum)*0.5;
  174. if (my<0.5)return 0.5;
  175. return my;
  176. }
  177. /**
  178. *
  179. * @param my 我的相关人员
  180. * @param in 公出信息
  181. * @param nickname 客户名称
  182. * @param date 时间
  183. */
  184. private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users,
  185. Map<String,Object> checkOrderNo) {
  186. Map<String, Object>map=new HashMap<String, Object>();
  187. //无需订单负责人审核
  188. if (in.getTechStartProcess()==0){
  189. //获取公出审核人
  190. Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
  191. String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
  192. //默认上级审核
  193. AtomicReference<Integer> status= new AtomicReference<>(1);
  194. String formatDate = DateUtils.formatDate(in.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS);
  195. //不是业务员
  196. if (in.getType()==0){
  197. if (my.getPublicPurview()==0){
  198. users.forEach(u->{
  199. if (!u.getAid().equals(my.getId())){
  200. StringBuffer str2=new StringBuffer();
  201. str2=str2.append(my.getName()).append("(需审核),准备公出您的企业");
  202. str2=str2.append("[").append(u.getNickname()).append("]!!!。");
  203. sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
  204. Admin admin = adminMapper.selectByPrimaryKey(u.getAid());
  205. if (in.getType()==0){
  206. //不是自己的企业则需要审核并设置非自己客户待审核
  207. addPublicExamine(in.getId(), admin);
  208. if(in.getPublicType()==null|| in.getPublicType()==0)in.setPublicType(1);
  209. }
  210. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  211. status.set(0);
  212. }
  213. });
  214. }else {
  215. users.forEach(u->{
  216. if (!u.getAid().equals(my.getId())){
  217. StringBuffer str2=new StringBuffer();
  218. str2=str2.append(my.getName()).append("计划公出您的企业").append(u.getNickname())
  219. .append(",").append(formatDate).append("【小程序端广播提示】");
  220. sendNoticeAndSoucket(u.getAid(),3,str2.toString());
  221. }
  222. });
  223. }
  224. }
  225. if (status.get()==1){
  226. pushNoticeAndSoucketAndEmail(my, in, date, a, str, map);
  227. }
  228. publicReleaseMapper.updateByPrimaryKeySelective(in);
  229. }else {
  230. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(in.getOrderNo());
  231. String salesmanId = tOrderNew.getSalesmanId();
  232. Admin a = adminMapper.selectByPrimaryKey(salesmanId);
  233. addPublicExamine(in.getId(),a);
  234. CheckOrderNoOut data = (CheckOrderNoOut) checkOrderNo.get("data");
  235. String format = getString(my, data);
  236. pushNoticeAndSoucketAndEmail(my, in, date, a, format, map);
  237. }
  238. map.put("data", publicReleaseMapper.selectDtails(in.getId()));
  239. return map;
  240. }
  241. private String getString(AdminListBo my, CheckOrderNoOut data) {
  242. String amountName="";
  243. String amountType="";
  244. if (data.getAmountType()==0){
  245. amountName="低于1万";
  246. amountType="原则上技术人员不可下户";
  247. }else if (data.getAmountType()==1){
  248. amountName="在1~3万";
  249. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  250. }else if (data.getAmountType()==2){
  251. amountName="在3~5万";
  252. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  253. }else if (data.getAmountType()==3){
  254. amountName="在5~10万";
  255. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  256. }
  257. String format = String.format("%s准备公出%s(%s)," +
  258. "总计公出:%s人,%s次,%s时。本合同%s,本次申请,%s。请确认是否同意本次公出?", my.getName(), data.getUserName(), data.getContractNo(),
  259. data.getPeopleCount(), data.getTimesCount(), data.getDurationCount().stripTrailingZeros().toPlainString(), amountName,
  260. amountType);
  261. return format;
  262. }
  263. /**
  264. *
  265. * @param my 发送人信息
  266. * @param in 公出信息
  267. * @param date 时间
  268. * @param a 接受者信息
  269. * @param str 站内信内容
  270. * @param map 返回实体
  271. */
  272. private void pushNoticeAndSoucketAndEmail(AdminListBo my, PublicRelease in, Date date, Admin a, String str, Map<String, Object> map) {
  273. sendNoticeAndSoucket(a.getId(),1, str);
  274. if (a.getOpenId() !=null) {
  275. Integer res= weChatUtils.addNotice(a.getOpenId(), in.getStatus(), in.getId(), date, my.getName(),"["+ my.getName()+"]发起外出申请");
  276. if (res!=0) {
  277. sendEmail(my, a,1);
  278. }
  279. map.put("code", res);
  280. }else {
  281. sendEmail(my, a,1);
  282. map.put("code", 2);
  283. }
  284. }
  285. private String getAssistAidName(String assistAid) {
  286. String [] ss=assistAid.split(",");
  287. StringBuffer sb=new StringBuffer();
  288. for (String s : ss) {
  289. Admin a=adminMapper.selectByPrimaryKey(s);
  290. if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
  291. }
  292. if (sb.length()<1)return "";
  293. return sb.deleteCharAt(sb.length() - 1).toString();
  294. }
  295. private void sendEmailAndNoticeAndSoucket(String id,Integer type,String content){
  296. sendNoticeAndSoucket(id,type,content);
  297. Admin admin = adminMapper.selectByPrimaryKey(id);
  298. String title="暂无标题";
  299. if (type==3)title=NoticeStatus.PUBLIC_OTHERS_USER.getDesc();
  300. EmailBo emailBo=new EmailBo(title,admin.getEmail(),content);
  301. asyncUtils.send(emailBo);
  302. }
  303. /**
  304. *
  305. * @param id 接受者编号
  306. * @param type 状态 0驳回 1发起 2同意 3 公出他人企业
  307. * @param content 内容
  308. */
  309. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  310. Integer noticeType=NoticeStatus.PUBLIC_RELEASE_START.getCode();
  311. if(type==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  312. else if (type==2)noticeType=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  313. else if (type==3)noticeType=NoticeStatus.PUBLIC_OTHERS_USER.getCode();
  314. //触发通知有未读消息
  315. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  316. Notice n =new Notice();
  317. n.setId(UUID.randomUUID().toString());
  318. n.setAid(id);
  319. n.setNoticeType(noticeType);
  320. n.setContent(content);
  321. n.setReaded(0);//未读
  322. asyncUtils.addNotice(n);
  323. }
  324. /**
  325. *
  326. * @param my 发送人
  327. * @param a 接受者
  328. * @param type 类型
  329. */
  330. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  331. StringBuffer title=new StringBuffer();
  332. if (type==0) title=title.append("外出申请驳回提醒");
  333. else if (type==1) title=title.append("外出申请提醒");
  334. else if (type==2) title=title.append("外出申请同意提醒");
  335. if (SendEmailUtil.isEmail(a.getEmail())) {
  336. EmailBo email=new EmailBo(title.toString(),a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  337. asyncUtils.send(email);
  338. }
  339. }
  340. @Override
  341. public int updatePublicRelease(InputPublicRelease in) {
  342. Date date = new Date();
  343. try {
  344. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  345. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  346. } catch (ParseException e) {
  347. e.printStackTrace();
  348. throw new BusinessException("转换异常");
  349. }
  350. Map checkOrderNo =null;
  351. List<User> uses=null;
  352. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(in.getId());
  353. in.setCreateTime(use.getCreateTime());
  354. String userNames=publicReleaseDetailsMapper.getNamesByPrid(in.getId());
  355. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
  356. in.setUserNames(userNames);
  357. if(in.getStatus()==null||in.getStatus()!=3) {
  358. if (in.getType() == 1) {
  359. checkOrderNo = checkOrderNoDuration(in);
  360. boolean isValid = (boolean) checkOrderNo.get("code");
  361. if (isValid){
  362. in.setTechStartProcess(0);
  363. }else {
  364. in.setTechStartProcess(1);
  365. }
  366. }
  367. if (in.getUids()!=null){
  368. List<String> split = Arrays.asList(in.getUids().split(","));
  369. List<OutPublicReleaseDetails> prList = publicReleaseDetailsMapper.selectByPCid(in.getId());
  370. uses=pushPublicReleaseDetails(split,prList,use,in);
  371. }
  372. in.setStatus(1);
  373. log.setStatus(PublicReleaseLog.states.xg.getCode());
  374. in.setUpdateStatus(1);
  375. //如果是业务切公出则撤销营销审核与审核人
  376. pushUpdateType(in,use);
  377. //如果是业务公出,切审核状态为其他,则重置审核
  378. if(in.getType()==0&&(use.getPublicType()==2||use.getPublicType()==3)){
  379. in.setPublicType(1);
  380. PublicExamine pe=new PublicExamine();
  381. pe.setPrid(in.getId());
  382. pe.setStatus(0);
  383. publicExamineMapper.updateByPridSelective(pe);
  384. }
  385. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  386. //重新发起
  387. addPublicReleaseLog(my,in,in.getUserNames(),date,uses,checkOrderNo);
  388. }else {
  389. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
  390. List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
  391. log.setStatus(PublicReleaseLog.states.cx.getCode());
  392. for (PublicRelease out : list) {
  393. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
  394. out.setStatus(3);
  395. publicReleaseMapper.updateByPrimaryKeySelective(out);
  396. }
  397. for (PublicRelease out : list2) {
  398. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单助手");
  399. out.setStatus(3);
  400. publicReleaseMapper.updateByPrimaryKeySelective(out);
  401. }
  402. }
  403. publicReleaseLogMapper.insertSelective(log);
  404. publicReleaseMapper.updateByPrimaryKeySelective(in);
  405. return 1;
  406. }
  407. private void pushUpdateType(InputPublicRelease in, PublicRelease use) {
  408. //营销切换成技术
  409. if(use.getType()==0&&in.getType()==1){
  410. in.setPublicType(0);
  411. }
  412. if(use.getType()==1&&in.getType()==0){
  413. in.setTechStartProcess(0);
  414. }
  415. publicExamineMapper.deletePrid(in.getId());
  416. }
  417. private List<User> pushPublicReleaseDetails(List<String> split, List<OutPublicReleaseDetails> prList, PublicRelease use, InputPublicRelease in) {
  418. //先删除,再修改个,再新增,有利于减少计算
  419. deletePRD(split,prList);
  420. publicReleaseDetailsMapper.updateDistrictByPrid(in);
  421. List<User> users = addPRD(split, prList, use,in);
  422. return users;
  423. }
  424. private void deletePRD(List<String> split, List<OutPublicReleaseDetails> prdList) {
  425. for (OutPublicReleaseDetails prd : prdList) {
  426. boolean flag=true;
  427. for (String s : split) {
  428. if (prd.getUid().equals(s)){
  429. flag=false;
  430. }
  431. }
  432. if (flag){
  433. publicReleaseDetailsMapper.deleteByPrimaryKey(prd.getId());
  434. }
  435. }
  436. }
  437. /**
  438. * @param split 修改后客户集
  439. * @param prdList 修改前客户集
  440. * @param use 原订单信息
  441. */
  442. private List<User> addPRD(List<String> split, List<OutPublicReleaseDetails> prdList, PublicRelease use, InputPublicRelease in) {
  443. List<PublicReleaseDetails> addPrdList=new ArrayList<>();
  444. List<User> users=new ArrayList<>();
  445. Integer publicType = use.getPublicType();
  446. //计算平均
  447. Integer userCount=split.size();
  448. Integer index=0;
  449. Double duration= in.getDuration();
  450. double d = durationSum(duration,userCount );
  451. for (String s : split) {
  452. User u=userMapper.selectByPrimaryKey(s);
  453. users.add(u);
  454. boolean flag=true;
  455. Integer id=null;
  456. String districtName=null,latitude=null,longitude=null;
  457. for (OutPublicReleaseDetails prd : prdList) {
  458. if (id==null)id=prd.getPrid();
  459. if (districtName==null)districtName=prd.getDistrictName();
  460. if (latitude==null)latitude=prd.getLatitude();
  461. if (longitude==null)longitude=prd.getLongitude();
  462. if (s.equals(prd.getUid())){
  463. flag=false;
  464. }
  465. }
  466. //计算下
  467. if (flag){
  468. PublicReleaseDetails prd=new PublicReleaseDetails();
  469. if (u!=null&&u.getShareType()==2){
  470. prd.setNewUser(1);
  471. }else {
  472. prd.setNewUser(0);
  473. }
  474. if (u.getAid().equals(use.getAid())){
  475. prd.setMainStatus(1);
  476. }else {
  477. prd.setMainStatus(0);
  478. }
  479. prd.setPrid(id);
  480. prd.setUid(s);
  481. prd.setSignSum(0);
  482. prd.setDistrictName(districtName);
  483. prd.setLatitude(latitude);
  484. prd.setLongitude(longitude);
  485. prd.setClockIn(0);
  486. addPrdList.add(prd);
  487. //设置时长
  488. if (index<userCount){
  489. if (in.getDuration()==0){
  490. prd.setDuration(in.getDuration());
  491. } else {
  492. prd.setDuration(d);
  493. duration=duration-d;
  494. }
  495. }else {
  496. prd.setDuration(duration);
  497. }
  498. index++;
  499. if (!use.getAid().equals(u.getAid())){
  500. addPublicExamine(use.getId(), u.getAid());
  501. if (publicType==1)publicType=1;
  502. }
  503. }else {
  504. InputPublicRelease inp=new InputPublicRelease();
  505. inp.setId(in.getId());
  506. inp.setUid(s);
  507. PublicReleaseDetails publicReleaseDetails = publicReleaseDetailsMapper.selectBypridAndUid(inp);
  508. PublicReleaseDetails newprd =new PublicReleaseDetails();
  509. newprd.setId(publicReleaseDetails.getId());
  510. //设置时长
  511. if (index<userCount){
  512. if (in.getDuration()==0){
  513. newprd.setDuration(in.getDuration());
  514. } else {
  515. newprd.setDuration(d);
  516. duration=duration-d;
  517. }
  518. }else {
  519. newprd.setDuration(duration);
  520. }
  521. index++;
  522. publicReleaseDetailsMapper.updateByPrimaryKeySelective(newprd);
  523. }
  524. }
  525. StringBuffer str=new StringBuffer();
  526. for (User u : users) {
  527. str=str.append(use.getUserNames()).append(",");
  528. }
  529. if (publicType!=use.getPublicType()){
  530. PublicRelease newP=new PublicRelease();
  531. newP.setId(use.getId());
  532. if (str.length()>1)newP.setUserNames(str.substring(0,str.length()-1));
  533. newP.setPublicType(publicType);
  534. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  535. }
  536. if (!addPrdList.isEmpty())publicReleaseDetailsMapper.insertBatch(addPrdList);
  537. return users;
  538. }
  539. @SuppressWarnings("unchecked")
  540. @Override
  541. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  542. Map<String,Object> map =new HashMap<String, Object>();
  543. map.put("type", in.getType()==null?0:in.getType());
  544. //先修改他人公出做测试
  545. // if(in.getType()==4)map.put("type", 5);
  546. if (in.getType()==3) {
  547. in.setAssist(2);
  548. if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
  549. }else{
  550. map.put("aid",TokenManager.getAdminId());
  551. }
  552. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  553. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  554. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  555. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  556. if(in.getStatus()!=null) map.put("status", in.getStatus());
  557. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  558. map.put("assist",in.getAssist()==null?0:in.getAssist());
  559. Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  560. if(in.getType()==0||in.getType()==4){
  561. pushExamines(p);
  562. }
  563. return p;
  564. }
  565. private void pushExamines(Pagination<OutPublicReleaseList> p) {
  566. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
  567. if (!list.isEmpty()){
  568. List<Integer> ids=new ArrayList<>();
  569. list.forEach(e ->{ ids.add(e.getId()); });
  570. List<PublicExamine> publicExamines = publicExamineMapper.selectByIds(ids);
  571. for (OutPublicReleaseList e : list) {
  572. if (e.getStatus()==1&&
  573. ((e.getPublicType()==0||e.getPublicType()==2)&&(e.getTechStartProcess()==0||e.getTechStartProcess()==2))
  574. ){
  575. e.setAdminExamine(e.getReviewerName()+" 未审核");
  576. }else if (e.getStatus()==0) {
  577. e.setAdminExamine("");
  578. }else {
  579. if (!publicExamines.isEmpty()){
  580. StringBuffer str =new StringBuffer();
  581. for (PublicExamine pe : publicExamines) {
  582. if (e.getId().equals(pe.getPrid())){
  583. str=str.append(pe.getAname());
  584. if (pe.getStatus()==0)str=str.append(" 未审核,");
  585. if (pe.getStatus()==1)str=str.append(" 已审核,");
  586. }
  587. if (str.length()>1) e.setAdminExamine(str.substring(0,str.length()-1));
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. @Override
  595. @Transactional
  596. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Integer examineType) {
  597. PublicRelease p=new PublicRelease();
  598. Date date =new Date();
  599. boolean flag=false;
  600. String aid=TokenManager.getAdminId();
  601. p.setId(id);
  602. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  603. if (use.getStatus()!=1) {
  604. throw new BusinessException("只能修改发起的状态公出");
  605. }
  606. if((use.getTechStartProcess()==1||use.getTechStartProcess()==3)&&(examineType==0||examineType==1)){
  607. if(use.getTechStartProcess()!=0) throw new BusinessException("技术公出先需营销审核。");
  608. }
  609. //当前审核人员
  610. Admin ad=adminMapper.selectByPrimaryKey(aid);
  611. //公出负责人
  612. Admin a;
  613. Admin publicAdmin =adminMapper.selectByPrimaryKey(use.getAid());
  614. a=publicAdmin;
  615. StringBuffer str=new StringBuffer();
  616. str=str.append("(").append(ad.getName()).append(")");
  617. StringBuffer content=new StringBuffer().append("[").append(use.getUserNames()).append("]公司的外出申请,");
  618. //上级审核
  619. if(examineType==0){
  620. p.setStatus(status);
  621. if (status==0){
  622. str=str.append("驳回,");
  623. if (use.getAssist()==2){
  624. content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
  625. }else {
  626. content=content.append("未通过公出审核!");
  627. }
  628. if(use.getPublicType()>1){
  629. p.setPublicType(1);
  630. PublicExamine inpe=new PublicExamine();
  631. inpe.setStatus(0);
  632. inpe.setPrid(use.getId());
  633. publicExamineMapper.updateStatusByPrid(inpe);
  634. }
  635. }else if(status==2){
  636. str=str.append("同意,");
  637. //如果是协单公出主公出,在审核通过
  638. if (use.getAssist()==1){
  639. pushPublicReleaseAssist(use,status,date,a);
  640. }else if (use.getAssist()==0){
  641. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  642. }
  643. content=content.append("已通过审核!");
  644. }
  645. str=str.append(remarks);
  646. p.setAuditInfo(str.toString());
  647. p.setAuditTime(date);
  648. p.setRejectName(ad.getName());
  649. addpublicLog(id, status, remarks);
  650. flag=true;
  651. //营销员审核
  652. }else if (examineType==1){
  653. //通知公出人切换成公出人审核人
  654. a=adminMapper.selectByPrimaryKey(a.getReviewer());
  655. if (status==2){//审核通过
  656. str=str.append("同意公出我的企业,").append(remarks);
  657. content=content.append("已通过审核,请尽快审核。");
  658. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  659. int x=0;
  660. for (PublicExamine pe : publicExamines) {
  661. if (pe.getAid().equals(aid)){
  662. pe.setStatus(1);
  663. PublicExamine newp=new PublicExamine();
  664. newp.setId(pe.getId());
  665. newp.setStatus(1);
  666. publicExamineMapper.updateByPrimaryKeySelective(newp);
  667. x++;
  668. }else {
  669. if (pe.getStatus()==1){
  670. x++;
  671. }
  672. }
  673. }
  674. if (x==publicExamines.size()){
  675. p.setPublicType(2);
  676. flag=true;
  677. }
  678. addpublicLog(id, status, str.toString());
  679. }else if (status==0){//审核驳回
  680. //切换通知人公出负责人
  681. a=publicAdmin;
  682. str=str.append("不同意公出我的企业,").append(remarks);;
  683. content=content.append("未通过审核,请修改后重新发起。");
  684. p.setPublicType(3);
  685. p.setStatus(0);
  686. p.setAuditInfo(str.toString());
  687. p.setRejectName(ad.getName());
  688. addpublicLog(id, 0, str.toString());
  689. flag=true;
  690. }
  691. }else if (examineType==2){
  692. //通知公出人切换成公出人审核人
  693. a=adminMapper.selectByPrimaryKey(a.getReviewer());
  694. if (status==2){//审核通过
  695. str=str.append("同意公出我的企业,").append(remarks);
  696. content=content.append("已通过审核,请尽快审核。");
  697. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  698. int x=0;
  699. for (PublicExamine pe : publicExamines) {
  700. if (pe.getAid().equals(aid)){
  701. pe.setStatus(1);
  702. PublicExamine newp=new PublicExamine();
  703. newp.setId(pe.getId());
  704. newp.setStatus(1);
  705. publicExamineMapper.updateByPrimaryKeySelective(newp);
  706. x++;
  707. }else {
  708. if (pe.getStatus()==1){
  709. x++;
  710. }
  711. }
  712. }
  713. if (x==publicExamines.size()){
  714. p.setTechStartProcess(2);
  715. flag=true;
  716. }
  717. addpublicLog(id, status, str.toString());
  718. }else if (status==0){//审核驳回
  719. //切换通知人公出负责人
  720. a=publicAdmin;
  721. str=str.append("不同意公出我的企业,").append(remarks);;
  722. content=content.append("未通过审核,请修改后重新发起。");
  723. p.setTechStartProcess(3);
  724. p.setStatus(0);
  725. p.setAuditInfo(str.toString());
  726. p.setRejectName(ad.getName());
  727. addpublicLog(id, 0, str.toString());
  728. flag=true;
  729. }
  730. }
  731. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  732. if (flag){
  733. sendNoticeAndSoucket(a.getId(),status,content.toString());
  734. }
  735. if (p.getStatus()!=null||p.getPublicType()!=null||p.getTechStartProcess()!=null){
  736. publicReleaseMapper.updateByPrimaryKeySelective(p);
  737. updateAdminUserCountPublicRelease(use.getAid(),use.getReleaseStart());
  738. }
  739. if (a.getOpenId()!=null) {
  740. if (remarks.length()>19) {
  741. remarks=remarks.substring(0, 15)+"...";
  742. }
  743. Integer res=weChatUtils.addNotice(a.getOpenId(),status,p.getId(),date,my.getName(),remarks);
  744. if (res!=0) {
  745. sendEmail( my, a, status);
  746. }
  747. return res;
  748. }
  749. return 1;
  750. }
  751. private void updateAdminUserCountPublicRelease(String aid, Date transferTime) {
  752. String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
  753. String endTime=startTime+" 23:59:59";
  754. AdminUserCount adminUserCount = customerService.getAdminUserCount(aid,startTime);
  755. Integer count = publicReleaseMapper.selectCountByaidAndDate(aid, startTime, endTime);
  756. if (count==null){
  757. count=0;
  758. }
  759. if (adminUserCount==null){
  760. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  761. if (selectAUC==null)selectAUC=new AdminUserCount();
  762. selectAUC.setPublicReleaseCount(count);
  763. selectAUC.setAid(aid);
  764. selectAUC.setDateTime(transferTime);
  765. adminUserCountMapper.insertSelective(selectAUC);
  766. }else {
  767. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  768. AdminUserCount newAUC=new AdminUserCount();
  769. newAUC.setId(adminUserCount.getId());
  770. newAUC.setPublicReleaseCount(count);
  771. if (selectAUC==null){
  772. newAUC.setPrivateCount(0);
  773. newAUC.setChannelCount(0);
  774. newAUC.setSignCount(0);
  775. }else {
  776. if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
  777. if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
  778. if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
  779. newAUC.setPrivateCount(selectAUC.getPrivateCount());
  780. newAUC.setChannelCount(selectAUC.getChannelCount());
  781. newAUC.setSignCount(selectAUC.getSignCount());
  782. }
  783. adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
  784. }
  785. }
  786. private void addpublicLog(Integer id, Integer status, String remarks) {
  787. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  788. publicReleaseLogMapper.insertSelective(log);
  789. }
  790. @Override
  791. public int pushTechReject(Integer id, String remarks) {
  792. Integer status=0;
  793. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  794. PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
  795. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  796. StringBuffer str=new StringBuffer();
  797. if (use.getAssist()!=2){
  798. throw new BusinessException("只有技术公出能发起技术驳回");
  799. }
  800. str=str.append("拒绝技术协单,").append(remarks);
  801. PublicRelease newMain=new PublicRelease();
  802. newMain.setId(mainPublic.getId());
  803. newMain.setStatus(4);
  804. newMain.setRejectName(ad.getName());
  805. newMain.setAuditInfo(str.toString());
  806. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  807. publicReleaseMapper.updateByPrimaryKeySelective(newMain);
  808. PublicRelease up=new PublicRelease();
  809. up.setId(id);
  810. up.setAuditInfo(str.toString());
  811. up.setStatus(3);
  812. addpublicLog(id, status, remarks);
  813. publicReleaseMapper.updateByPrimaryKeySelective(up);
  814. deleteAssistantPulicRelease(use,null);
  815. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  816. }
  817. /**
  818. * 新增日志、站内信、微信提醒
  819. * @param id 日志公出编号
  820. * @param aid 接受者
  821. * @param remarks 日志内容
  822. * @param status 0驳回
  823. * @return
  824. */
  825. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  826. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  827. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  828. if (my.getOpenId()!=null) {
  829. if (remarks.length()>19) {
  830. remarks=remarks.substring(0, 15)+"...";
  831. }
  832. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  833. }else {
  834. sendEmail( my, a, status);
  835. return 1;
  836. }
  837. }
  838. /**
  839. *
  840. * @param use 原始公出信息
  841. * @param status 状态
  842. * @param date 时间
  843. * @param a
  844. */
  845. private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date,Admin a) {
  846. if (use.getAssistAid()!=null){
  847. updatePushassist(use, status, date,a);
  848. if(use.getAssistantAid()!=null){
  849. updatepushAssistant(use,a);
  850. }
  851. }
  852. }
  853. /**
  854. * 处理技术协单
  855. * @param use
  856. * @param status
  857. * @param date
  858. */
  859. private void updatePushassist(PublicRelease use, Integer status, Date date, Admin a) {
  860. //协单
  861. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  862. String []ss= use.getAssistAid().split(",");
  863. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  864. for (PublicRelease out : list) {
  865. boolean flag=false;
  866. for (String s : ss) {
  867. if (out.getAid().equals(s)){
  868. flag=true;
  869. break;
  870. }
  871. }
  872. if (!flag){
  873. PublicRelease in = new PublicRelease();
  874. in.setId(out.getId());
  875. in.setStatus(3);
  876. publicReleaseMapper.updateByPrimaryKeySelective(in);
  877. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  878. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  879. publicReleaseLogMapper.insertSelective(log);
  880. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  881. }else {
  882. PublicRelease np = new PublicRelease();
  883. BeanUtils.copyProperties(use,np);
  884. np.setId(out.getId());
  885. np.setMainId(null);
  886. np.setType(null);
  887. np.setAssist(2);
  888. np.setStatus(status);
  889. np.setAid(null);
  890. publicReleaseMapper.updateByPrimaryKeySelective(np);
  891. updatePublicReleaseDtails(use,np.getId());
  892. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  893. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  894. publicReleaseLogMapper.insertSelective(log);
  895. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  896. }
  897. }
  898. for (String s : ss) {
  899. boolean flag2 = false;
  900. for (PublicRelease o : list) {
  901. if (s.equals(o.getAid())) {
  902. flag2 = true;
  903. }
  904. }
  905. if (!flag2) {
  906. PublicRelease np = new PublicRelease();
  907. BeanUtils.copyProperties(use,np);
  908. np.setAssist(2);
  909. np.setAid(s);
  910. np.setStatus(2);
  911. np.setType(3);
  912. np.setMainId(use.getId());
  913. np.setId(null);
  914. publicReleaseMapper.insertSelective(np);
  915. //补充客户表
  916. addpublicReleaseDtails(use,np.getId());
  917. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  918. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  919. sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
  920. publicReleaseLogMapper.insertSelective(log);
  921. }
  922. }
  923. }
  924. private void updatePublicReleaseDtails(PublicRelease use, Integer id) {
  925. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  926. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPCid(id);
  927. //查找新增的
  928. for (OutPublicReleaseDetails out : list) {
  929. boolean flag=true;
  930. for (OutPublicReleaseDetails out2 : list2) {
  931. if (out.getUid().equals(out2.getUid())){
  932. flag=false;
  933. }
  934. }
  935. if (flag){
  936. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  937. BeanUtils.copyProperties(out,prd);
  938. prd.setPrid(id);
  939. prd.setClockIn(0);
  940. prd.setClockInTime(null);
  941. prd.setClockInRemarks(null);
  942. prd.setUfid(null);
  943. publicReleaseDetailsMapper.insertSelective(prd);
  944. }
  945. }
  946. for (OutPublicReleaseDetails out2 : list2) {
  947. boolean flag=true;
  948. for (OutPublicReleaseDetails out : list) {
  949. if (out2.getUid().equals(out.getUid())){
  950. flag=false;
  951. }
  952. }
  953. if (flag){
  954. publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
  955. }
  956. }
  957. }
  958. private void addpublicReleaseDtails(PublicRelease use, Integer id) {
  959. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  960. for (OutPublicReleaseDetails out : list) {
  961. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  962. BeanUtils.copyProperties(out,prd);
  963. prd.setPrid(id);
  964. prd.setClockIn(0);
  965. prd.setClockInTime(null);
  966. prd.setMainStatus(0);
  967. publicReleaseDetailsMapper.insertSelective(prd);
  968. }
  969. }
  970. /**
  971. * 处理技术助手
  972. * @param use
  973. */
  974. private void updatepushAssistant(PublicRelease use,Admin a) {
  975. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  976. for (PublicRelease p : uselist) {
  977. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  978. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  979. p.setStatus(2);
  980. p.setAssistantAid(use.getAssistantAid());
  981. p.setAssistantName(use.getAssistantName());
  982. p.setUserNames(use.getUserNames());
  983. publicReleaseMapper.updateByPrimaryKeySelective(p);
  984. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  985. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  986. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  987. publicReleaseLogMapper.insertSelective(log);
  988. }
  989. }
  990. @Override
  991. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  992. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  993. return list;
  994. }
  995. @Override
  996. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  997. if (clockIn == null) clockIn = 1;
  998. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(id);
  999. if (use.getPublicType()==1||use.getPublicType()==3){
  1000. return -1;
  1001. }
  1002. if (use.getTechStartProcess()==1||use.getTechStartProcess()==3){
  1003. return -2;
  1004. }
  1005. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPCid(id);
  1006. String str = "";
  1007. Date date = new Date();
  1008. boolean flag=false;
  1009. Integer clockCount=0;
  1010. PublicReleaseClock pc=new PublicReleaseClock();
  1011. pc.setPrid(id);
  1012. pc.setPhotoUrl(photoUrl);
  1013. pc.setClockInTime(date);
  1014. for (OutPublicReleaseDetails prd : prdList) {
  1015. if (prd.getUid().equals(uid)){
  1016. String aid = TokenManager.getAdminId();
  1017. pc.setPrdid(prd.getId());
  1018. prd.setClockInRemarks(clockInRemarks);
  1019. prd.setPhotoUrl(photoUrl);
  1020. prd.setClockInTime(date);
  1021. if (prd.getClockIn() == 0) {
  1022. prd.setClockIn(clockIn);
  1023. //获取列表
  1024. FollowBusinessBo fbb = new FollowBusinessBo();
  1025. fbb.setUid(prd.getUid());
  1026. fbb.setContactType("5");
  1027. fbb.setResult(use.getRemarks());
  1028. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  1029. if (ub != null) {
  1030. fbb.setOcbId(ub.getId());
  1031. }
  1032. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  1033. String ufid = UUID.randomUUID().toString();
  1034. prd.setUfid(ufid);
  1035. customerService.addFollow(fbb, ufid, prd.getMainStatus());
  1036. str = "公出人员打卡";
  1037. }else if (clockIn == 2){
  1038. str = "公出人员异常打卡";
  1039. }else {
  1040. str = "刷新打卡";
  1041. }
  1042. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  1043. log.setPhotoUrl(photoUrl);
  1044. publicReleaseLogMapper.insertSelective(log);
  1045. publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
  1046. flag=true;
  1047. clockCount++;
  1048. }else if (prd.getClockIn()==1){
  1049. clockCount++;
  1050. }
  1051. }
  1052. if (prdList.size()==clockCount){
  1053. PublicRelease newp=new PublicRelease();
  1054. newp.setId(id);
  1055. newp.setClockIn(1);
  1056. publicReleaseMapper.updateByPrimaryKeySelective(newp);
  1057. }
  1058. publicReleaseClockMapper.insertSelective(pc);
  1059. if (!flag){
  1060. return 0;
  1061. }
  1062. return 1;
  1063. }
  1064. @Override
  1065. public OutPublicRelease dtails(Integer id) {
  1066. String aid=TokenManager.getAdminId();
  1067. //如果不是本人和审核人员则不返回信息
  1068. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  1069. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  1070. out.setPeList(ps);
  1071. if(out!=null){
  1072. boolean flag=false;
  1073. //自己、审核人员与部门负责人可以查看
  1074. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  1075. if (!aid.equals( out.getAid())&&
  1076. !aid.equals(out.getReviewer())&&
  1077. !aid.equals(ab.getDepManager())&&
  1078. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  1079. flag=true;
  1080. }
  1081. if(flag){
  1082. //是否可以查看
  1083. if (!ps.isEmpty()){
  1084. for (PublicExamine p : ps) {
  1085. if (p.getAid().equals(aid)){
  1086. if (p.getStatus()==1)out.setMyExamine(1);
  1087. else out.setMyExamine(0);
  1088. flag=false;
  1089. break;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. //处理返回
  1095. if(flag){
  1096. out=null;
  1097. return out;
  1098. }else {
  1099. if (out.getPublicType()==1){
  1100. if (aid.equals(out.getAid())){
  1101. out.setPermission(0);
  1102. }else {
  1103. out.setPermission(1);
  1104. }
  1105. }else {
  1106. if(aid.equals(out.getAid())) {
  1107. out.setPermission(0);
  1108. }else {
  1109. out.setPermission(1);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. if (out.getStatus()==1&&
  1115. ((out.getPublicType()==0||out.getPublicType()==2)&&(out.getTechStartProcess()==0||out.getTechStartProcess()==2))
  1116. ){
  1117. out.setAdminExamine(out.getReviewerName()+" 未审核");
  1118. }else if (out.getStatus()==0) {
  1119. out.setAdminExamine("");
  1120. }else {
  1121. if (!ps.isEmpty()){
  1122. StringBuffer str =new StringBuffer();
  1123. for (PublicExamine e : ps) {
  1124. if (out.getId().equals(e.getPrid())){
  1125. str.append(e.getAname());
  1126. if (e.getStatus()==0) str.append(" 未审核,");
  1127. if (e.getStatus()==1) str.append(" 已审核,");
  1128. }
  1129. if (str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1));
  1130. }
  1131. }
  1132. }
  1133. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1134. return out;
  1135. }
  1136. @Override
  1137. public OutPublicReleaseAndDetails followDtails(String id) {
  1138. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  1139. return out;
  1140. }
  1141. @SuppressWarnings("unchecked")
  1142. @Override
  1143. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  1144. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  1145. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  1146. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  1147. public Object publicReleaseStatistics(InputPublicStatistics in) {
  1148. Map<String,Object> map =new HashMap<String, Object>();
  1149. if(in.getAid()!=null)map.put("aid", in.getAid());
  1150. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1151. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1152. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1153. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1154. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1155. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  1156. }
  1157. @SuppressWarnings("unchecked")
  1158. @Override
  1159. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  1160. Map<String,Object> map =new HashMap<String, Object>();
  1161. if(in.getAid()!=null)map.put("aid", in.getAid());
  1162. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  1163. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  1164. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1165. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  1166. }
  1167. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1168. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1169. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1170. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1171. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  1172. }
  1173. @SuppressWarnings("unchecked")
  1174. @Override
  1175. public Object publicReleaseListDtails(InputPublicDtails in) {
  1176. Map<String,Object> map =new HashMap<String, Object>();
  1177. addParams(in, map);
  1178. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  1179. List<OutPublicDtails> list = (List<OutPublicDtails>)page.getList();
  1180. List<Integer> collect = list.stream().map(OutPublicDtails::getId).collect(Collectors.toList());
  1181. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(collect);
  1182. pushiClockInTime(list, publicReleaseClocks);
  1183. return page;
  1184. }
  1185. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  1186. if(in.getAid()!=null) map.put("aid", in.getAid());
  1187. if(in.getSid()!=null) map.put("sid", in.getSid());
  1188. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  1189. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  1190. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  1191. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1192. if(in.getUid()!=null) map.put("uid", in.getUid());
  1193. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  1194. if(in.getStatus()!=null) map.put("status", in.getStatus());
  1195. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  1196. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  1197. //type 0私有 1管理权限 2所有权限
  1198. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  1199. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  1200. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  1201. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1202. //添加财务和财务经理。查看客户所有公出
  1203. in.setType(2);
  1204. if(in.getDeps()!=null){
  1205. map.put("deps", departmentService.parseArray(in.getDeps()));
  1206. }
  1207. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
  1208. ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  1209. in.setType(1);
  1210. if (in.getDeps()!=null){
  1211. List<String> list = departmentService.selectSubDeps(in.getDeps());
  1212. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  1213. map.put("deps", list);
  1214. }else {
  1215. map.put("deps",departmentService.selectMyDeps());
  1216. }
  1217. }else{
  1218. in.setType(0);
  1219. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  1220. if(in.getDeps()!=null){
  1221. map.put("deps", departmentService.parseArray(in.getDeps()));
  1222. }
  1223. }
  1224. map.put("type", in.getType());
  1225. }
  1226. @SuppressWarnings("unchecked")
  1227. @Override
  1228. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  1229. Map<String,Object> map =new HashMap<String, Object>();
  1230. addParams(in, map);
  1231. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  1232. }
  1233. @Override
  1234. public int addSupplement(Integer id, String supplement, String nextPlan) {
  1235. PublicRelease pr=new PublicRelease();
  1236. pr.setId(id);
  1237. pr.setSupplement(supplement);
  1238. pr.setNextPlan(nextPlan);
  1239. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  1240. }
  1241. @Override
  1242. public boolean checkTime(InputPublicRelease in) {
  1243. try {
  1244. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  1245. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  1246. } catch (ParseException e) {
  1247. e.printStackTrace();
  1248. throw new BusinessException("转换异常");
  1249. }
  1250. List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  1251. if (is.size()>1) {
  1252. return true;
  1253. }else if(is.size()==1){
  1254. //如果id为新增那么直接不允许时间重复
  1255. if (in.getId()==null){
  1256. return true;
  1257. }else {
  1258. //如果有id,与获取id一直,则为当前修改可以
  1259. if (in.getId().equals(is.get(0))){
  1260. return false;
  1261. }else {
  1262. return true;
  1263. }
  1264. }
  1265. }
  1266. return false;
  1267. }
  1268. @Override
  1269. public List<Map<String, Object>> selectOrderByUid(String uid) {
  1270. return tOrderNewMapper.selectOrderByuid(uid);
  1271. }
  1272. @Override
  1273. public List<OutPublicRelease> publicByOrder(String orderNo) {
  1274. return publicReleaseMapper.publicByOrder(orderNo);
  1275. }
  1276. @Override
  1277. public Object getMyNewPublic() {
  1278. List<PublicRelease> myPublic=publicReleaseMapper.selectMyNewPublic(TokenManager.getAdminId());
  1279. if(myPublic.isEmpty())return null;
  1280. Integer id=null;
  1281. long count=999999;
  1282. for (PublicRelease e : myPublic) {
  1283. long nowTime=System.currentTimeMillis();
  1284. long time = Math.abs(nowTime-e.getReleaseStart().getTime())/(1000*60);
  1285. long time2 = Math.abs(e.getReleaseEnd().getTime()-nowTime)/(1000*60);
  1286. //距离当前时间近的开始时间,不大于当前时间
  1287. if (time<count&&e.getReleaseStart().getTime()<nowTime){
  1288. count=time;
  1289. id=e.getId();
  1290. }
  1291. //距离当前时间近的结束时间,不小于当前时间
  1292. if (time2<count&&e.getReleaseEnd().getTime()>nowTime){
  1293. count=time2;
  1294. id=e.getId();
  1295. }
  1296. }
  1297. if (id==null)id=myPublic.get(0).getId();
  1298. OutPublicReleaseList out = publicReleaseMapper.selectOutListBoById(id);
  1299. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1300. return out;
  1301. // List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  1302. // if (myPublic.isEmpty()){
  1303. // List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  1304. // if (!myPublic2.isEmpty()){
  1305. // return myPublic2.get(0);
  1306. // }
  1307. // }else {
  1308. // return myPublic.get(0);
  1309. // }
  1310. }
  1311. /**
  1312. *
  1313. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  1314. * @param dateType 是否含打卡时间 0否 1是
  1315. * @return
  1316. */
  1317. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  1318. Map<String, Object> map = new HashMap<>();
  1319. if (type==null)type=0;
  1320. map.put("type",type);
  1321. //statusType=1情况下
  1322. map.put("statusType",1);
  1323. if (dateType==1){
  1324. Date date = new Date();
  1325. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  1326. map.put("clockTime",clockTime);
  1327. }
  1328. map.put("aid",TokenManager.getAdminId());
  1329. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  1330. for (OutPublicReleaseList out : list) {
  1331. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1332. }
  1333. return list;
  1334. }
  1335. @Override
  1336. public int addAssistant(Integer id,String aid) {
  1337. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1338. List<String> list=new ArrayList<>();
  1339. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  1340. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1341. }
  1342. String sname = pushAssistant(aid, list,0);
  1343. String said =String.join(",",list);
  1344. p.setAssistantAid(said);
  1345. p.setAssistantName(sname);
  1346. addAssistantPublicRelease(p,aid);
  1347. return updateAssistant(p, said, sname);
  1348. }
  1349. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  1350. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1351. PublicRelease newP= new PublicRelease();
  1352. if(list.isEmpty()){
  1353. BeanUtils.copyProperties(p,newP);
  1354. newP.setId(null);
  1355. newP.setAid(aid);
  1356. newP.setAssist(3);
  1357. newP.setType(4);
  1358. publicReleaseMapper.insertSelective(newP);
  1359. addpublicReleaseDtails(p,newP.getId());
  1360. StringBuffer str=new StringBuffer();
  1361. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  1362. addWeChatNotice( aid,1,str.toString(),newP.getId());
  1363. }else {
  1364. for (PublicRelease pr : list) {
  1365. newP.setId(pr.getId());
  1366. newP.setAssistantAid(p.getAssistantAid());
  1367. newP.setAssistantName(p.getAssistantName());
  1368. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  1369. updatePublicReleaseDtails(p,newP.getId());
  1370. }
  1371. }
  1372. }
  1373. /**
  1374. * 添加微信提示和站内消息
  1375. * @param aid 接受者
  1376. * @param type 状态 0驳回 1发起 2同意 3撤销
  1377. * @param str 备注
  1378. * @param prid 公出编号
  1379. */
  1380. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  1381. Admin recipient = adminMapper.selectByPrimaryKey(aid);
  1382. addWeChatNotice( recipient, type, str, prid);
  1383. }
  1384. /**
  1385. * 添加微信提示和站内消息
  1386. * @param recipient 接受者
  1387. * @param type 状态 0驳回 1发起 2同意 3撤销
  1388. * @param str
  1389. */
  1390. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  1391. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  1392. String openid=recipient.getOpenId();
  1393. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  1394. if(type==3){
  1395. addpublicLog(prid,4,str);
  1396. }else {
  1397. addpublicLog(prid,type,str);
  1398. }
  1399. sendNoticeAndSoucket(recipient.getId(),type,str);
  1400. if (type==0||type==2){
  1401. if (openid!=null) {
  1402. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  1403. return res;
  1404. }else {
  1405. sendEmail(my, recipient,type);
  1406. }
  1407. }
  1408. return 0;
  1409. }
  1410. private int updateAssistant(PublicRelease p, String said, String sname) {
  1411. PublicRelease newPr=new PublicRelease();
  1412. newPr.setId(p.getId());
  1413. newPr.setAssistantAid(said);
  1414. newPr.setAssistantName(sname);
  1415. if (p.getMainId()!=null){
  1416. PublicRelease mianPr=new PublicRelease();
  1417. mianPr.setId(p.getMainId());
  1418. mianPr.setAssistantAid(said);
  1419. mianPr.setAssistantName(sname);
  1420. publicReleaseMapper.updateByPrimaryKeySelective(mianPr);
  1421. }
  1422. return publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1423. }
  1424. /**
  1425. *
  1426. * @param aid 元素
  1427. * @param list 集合
  1428. * @param type 0新增 1删除
  1429. * @return
  1430. */
  1431. private String pushAssistant(String aid, List<String> list,Integer type) {
  1432. StringBuffer sb=new StringBuffer();
  1433. if(type==0){
  1434. list.add(aid);
  1435. }else if (type==1){
  1436. Iterator<String > it =list.iterator();
  1437. while (it.hasNext()){
  1438. if (it.next().equals(aid))
  1439. it.remove();
  1440. }
  1441. }
  1442. for (String s : list) {
  1443. sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
  1444. }
  1445. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  1446. }
  1447. @Override
  1448. public int deleteAssistant(Integer id, String aid) {
  1449. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1450. if (p.getAssistantAid()==null){
  1451. throw new BusinessException("人员不存在");
  1452. }
  1453. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1454. if (!list.contains(aid)){
  1455. throw new BusinessException("人员不存在");
  1456. }
  1457. String sname = pushAssistant(aid, list,1);
  1458. String said =String.join(",",list);
  1459. p.setAssistantAid(said);
  1460. p.setAssistantName(sname);
  1461. deleteAssistantPulicRelease(p,aid);
  1462. return updateAssistant(p, said, sname);
  1463. }
  1464. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  1465. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  1466. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1467. StringBuffer str=new StringBuffer();
  1468. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  1469. for (PublicRelease pr : list) {
  1470. if (pr.getAid().equals(aid)){
  1471. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  1472. }else {
  1473. PublicRelease newPr=new PublicRelease();
  1474. newPr.setId(pr.getId());
  1475. newPr.setAssistantAid(p.getAssistantAid());
  1476. newPr.setAssistantName(p.getAssistantName());
  1477. publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1478. }
  1479. }
  1480. }
  1481. @Override
  1482. public boolean checkdeleteAssistant(Integer id, String aid) {
  1483. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1484. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1485. for (PublicRelease use : list) {
  1486. // if (use.getClockIn()==1){
  1487. // return true;
  1488. // }
  1489. }
  1490. return false;
  1491. }
  1492. @Override
  1493. public boolean checkaddAssistant(Integer id, String aid) {
  1494. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1495. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1496. for (PublicRelease use : list) {
  1497. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  1498. return true;
  1499. }
  1500. }
  1501. return false;
  1502. }
  1503. @Override
  1504. public int updateLocation(InputPublicRelease in) {
  1505. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  1506. if (prd==null){
  1507. throw new BusinessException("公出企业不存在");
  1508. }
  1509. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  1510. updateprd.setId(prd.getId());
  1511. updateprd.setLatitude(in.getLatitude());
  1512. updateprd.setLongitude(in.getLongitude());
  1513. updateprd.setDistrictName(in.getDistrictName());
  1514. updateprd.setClockIn(0);
  1515. addpublicLog(in.getId(),5,"发起公出地点修改");
  1516. return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
  1517. }
  1518. @Override
  1519. public Object publicReleaseAndCount(InputPublicDtails in) {
  1520. List<OutPublicDtails> list = publicReleaseListDtailsList(in);
  1521. Map<String,Object> map=new HashMap<String, Object>();
  1522. if (list.isEmpty()){
  1523. map.put("list",list);
  1524. map.put("count",0);
  1525. map.put("durationCount",0);
  1526. map.put("peopleCount",0);
  1527. }else {
  1528. //公出次数
  1529. int count=0;
  1530. BigDecimal durationCount=BigDecimal.ZERO;
  1531. List<String> aList =new ArrayList<>();
  1532. for (OutPublicDtails e : list) {
  1533. if (e.getType()==0||e.getType()==1||e.getType()==2){
  1534. count++;
  1535. if (e.getDuration()!=null){
  1536. durationCount=durationCount.add(new BigDecimal(e.getDuration()));
  1537. }
  1538. if (!aList.contains(e.getAname())){
  1539. aList.add(e.getAname());
  1540. }
  1541. if (StringUtils.isNotEmpty(e.getAssistAidName())){
  1542. String[] split = e.getAssistAidName().split(",");
  1543. for (String s : split) {
  1544. if (!aList.contains(s)){
  1545. aList.add(s);
  1546. }
  1547. }
  1548. }
  1549. if (StringUtils.isNotEmpty(e.getAssistantName())){
  1550. String[] split = e.getAssistantName().split(",");
  1551. for (String s : split) {
  1552. if (!aList.contains(s)){
  1553. aList.add(s);
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. map.put("list",list);
  1560. map.put("count",count);
  1561. map.put("durationCount",durationCount);
  1562. map.put("peopleCount",aList.size());
  1563. }
  1564. return map;
  1565. }
  1566. public Map checkOrderNoDuration( InputPublicRelease in,AdminListBo a) {
  1567. List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
  1568. TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
  1569. OutPublicRelease outPublicRelease=null;
  1570. BigDecimal count = BigDecimal.ZERO;
  1571. int timesCount=0;
  1572. List<String> peopleList = new ArrayList<>();
  1573. if (in.getId()!=null){
  1574. outPublicRelease= publicReleaseMapper.selectDtails(in.getId());
  1575. }else {
  1576. peopleList.add(TokenManager.getAdminId());
  1577. count=count.add(BigDecimal.valueOf(in.getDuration()));
  1578. timesCount++;
  1579. }
  1580. for (PublicRelease e : list) {
  1581. //新增直接计算
  1582. if (in.getId()==null){
  1583. if (e.getDuration()!=null){
  1584. count=count.add(BigDecimal.valueOf(e.getDuration()));
  1585. if (!peopleList.contains(e.getAid())){
  1586. peopleList.add(e.getAid());
  1587. }
  1588. timesCount++;
  1589. }
  1590. }else {
  1591. //修改当前数据要从修改后获取
  1592. if (!e.getId().equals(in.getId())){
  1593. if (e.getDuration()!=null){
  1594. count=count.add(BigDecimal.valueOf(e.getDuration()));
  1595. if (!peopleList.contains(e.getAid())){
  1596. peopleList.add(e.getAid());
  1597. }
  1598. timesCount++;
  1599. }
  1600. }else {
  1601. if (outPublicRelease != null && outPublicRelease.getDuration() != null) {
  1602. count = count.add(BigDecimal.valueOf(outPublicRelease.getDuration()));
  1603. if (!peopleList.contains(outPublicRelease.getAid())) {
  1604. peopleList.add(outPublicRelease.getAid());
  1605. }
  1606. timesCount++;
  1607. }
  1608. }
  1609. }
  1610. }
  1611. Map map=new HashMap();
  1612. CheckOrderNoOut data= new CheckOrderNoOut();
  1613. if (outPublicRelease!=null){
  1614. data.setPublicReleaseName(outPublicRelease.getAname());
  1615. }
  1616. data.setTimesCount(timesCount);
  1617. data.setPeopleCount(peopleList.size());
  1618. data.setUserName(t.getUserName());
  1619. data.setContractNo(t.getContractNo());
  1620. data.setAdminName(t.getSalesmanName());
  1621. data.setDurationCount(count);
  1622. // 0=0-1 1=1-3 2=3-5 3=5-10 4=10以上
  1623. if (t.getTotalAmount().compareTo(BigDecimal.valueOf(1)) < 0) {
  1624. data.setAmountType(0);
  1625. data.setDurationMax(BigDecimal.ZERO);
  1626. map.put("code",false);
  1627. map.put("data",data);
  1628. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0) {
  1629. data.setAmountType(1);
  1630. data.setDurationMax(BigDecimal.valueOf(15));
  1631. if (count.compareTo(data.getDurationMax())<1){
  1632. map.put("code",true);
  1633. map.put("data",null);
  1634. }else {
  1635. map.put("code",false);
  1636. map.put("data",data);
  1637. }
  1638. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0) {
  1639. data.setAmountType(2);
  1640. data.setDurationMax(BigDecimal.valueOf(45));
  1641. if (count.compareTo(data.getDurationMax())<1){
  1642. map.put("code",true);
  1643. map.put("data",null);
  1644. }else {
  1645. map.put("code",false);
  1646. map.put("data",data);
  1647. }
  1648. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0) {
  1649. data.setAmountType(3);
  1650. data.setDurationMax(BigDecimal.valueOf(120));
  1651. if (count.compareTo(data.getDurationMax())<1){
  1652. map.put("code",true);
  1653. map.put("data",null);
  1654. }else {
  1655. map.put("code",false);
  1656. map.put("data",data);
  1657. }
  1658. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))>=0) {
  1659. data.setAmountType(4);
  1660. map.put("code",true);
  1661. map.put("data",null);
  1662. }
  1663. return map;
  1664. }
  1665. @Override
  1666. public Map checkOrderNoDuration( InputPublicRelease in){
  1667. return checkOrderNoDuration(in,null);
  1668. }
  1669. @Override
  1670. public void pushOutPublicDtails(List<OutPublicDtails> list) {
  1671. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(list.stream().map(OutPublicDtails::getId).collect(Collectors.toList()));
  1672. pushiClockInTime(list, publicReleaseClocks);
  1673. }
  1674. private void pushiClockInTime(List<OutPublicDtails> list, List<PublicReleaseClock> publicReleaseClocks) {
  1675. for (OutPublicDtails outPublicDtails : list) {
  1676. List<PublicReleaseClock> colokList =new ArrayList<>();
  1677. StringBuilder sb = new StringBuilder();
  1678. for (PublicReleaseClock e : publicReleaseClocks) {
  1679. if (outPublicDtails.getPrdId().equals(e.getPrdid())){
  1680. sb.append(DateUtils.formatDateYYYYMMddHHmm(e.getClockInTime())).append("\n");
  1681. colokList.add(e);
  1682. }
  1683. colokList.sort(Comparator.comparing(PublicReleaseClock::getClockInTime));
  1684. Collections.reverse(colokList);
  1685. outPublicDtails.setList(colokList);
  1686. }
  1687. outPublicDtails.setClockInTimes(sb.toString());
  1688. }
  1689. }
  1690. }