PublicReleaseServiceImpl.java 65 KB

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