PublicReleaseServiceImpl.java 68 KB

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