PublicReleaseServiceImpl.java 74 KB

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