PublicReleaseServiceImpl.java 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  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. private void updateAdminUserCountPublicRelease(String aid, Date transferTime) {
  829. String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
  830. String endTime=startTime+" 23:59:59";
  831. AdminUserCount adminUserCount = customerService.getAdminUserCount(aid,startTime);
  832. Integer count = publicReleaseMapper.selectCountByaidAndDate(aid, startTime, endTime);
  833. if (count==null){
  834. count=0;
  835. }
  836. if (adminUserCount==null){
  837. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  838. if (selectAUC==null)selectAUC=new AdminUserCount();
  839. selectAUC.setPublicReleaseCount(count);
  840. selectAUC.setAid(aid);
  841. selectAUC.setDateTime(transferTime);
  842. adminUserCountMapper.insertSelective(selectAUC);
  843. }else {
  844. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  845. AdminUserCount newAUC=new AdminUserCount();
  846. newAUC.setId(adminUserCount.getId());
  847. newAUC.setPublicReleaseCount(count);
  848. if (selectAUC==null){
  849. newAUC.setPrivateCount(0);
  850. newAUC.setChannelCount(0);
  851. newAUC.setSignCount(0);
  852. }else {
  853. if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
  854. if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
  855. if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
  856. newAUC.setPrivateCount(selectAUC.getPrivateCount());
  857. newAUC.setChannelCount(selectAUC.getChannelCount());
  858. newAUC.setSignCount(selectAUC.getSignCount());
  859. }
  860. adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
  861. }
  862. }
  863. private void addpublicLog(Integer id, Integer status, String remarks) {
  864. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  865. publicReleaseLogMapper.insertSelective(log);
  866. }
  867. @Override
  868. public int pushTechReject(Integer id, String remarks) {
  869. Integer status=0;
  870. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  871. PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
  872. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  873. StringBuffer str=new StringBuffer();
  874. if (use.getAssist()!=2){
  875. throw new BusinessException("只有技术公出能发起技术驳回");
  876. }
  877. str=str.append("拒绝技术协单,").append(remarks);
  878. PublicRelease newMain=new PublicRelease();
  879. newMain.setId(mainPublic.getId());
  880. newMain.setStatus(4);
  881. newMain.setRejectName(ad.getName());
  882. newMain.setAuditInfo(str.toString());
  883. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  884. publicReleaseMapper.updateByPrimaryKeySelective(newMain);
  885. PublicRelease up=new PublicRelease();
  886. up.setId(id);
  887. up.setAuditInfo(str.toString());
  888. up.setStatus(3);
  889. addpublicLog(id, status, remarks);
  890. publicReleaseMapper.updateByPrimaryKeySelective(up);
  891. deleteAssistantPulicRelease(use,null);
  892. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  893. }
  894. /**
  895. * 新增日志、站内信、微信提醒
  896. * @param id 日志公出编号
  897. * @param aid 接受者
  898. * @param remarks 日志内容
  899. * @param status 0驳回
  900. * @return
  901. */
  902. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  903. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  904. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  905. if (my.getOpenId()!=null) {
  906. if (remarks.length()>19) {
  907. remarks=remarks.substring(0, 15)+"...";
  908. }
  909. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  910. }else {
  911. sendEmail( my, a, status);
  912. return 1;
  913. }
  914. }
  915. /**
  916. *
  917. * @param use 原始公出信息
  918. * @param status 状态
  919. * @param date 时间
  920. * @param a
  921. */
  922. private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date,Admin a) {
  923. if (use.getAssistAid()!=null){
  924. updatePushassist(use, status, date,a);
  925. if(use.getAssistantAid()!=null){
  926. updatepushAssistant(use,a);
  927. }
  928. }
  929. }
  930. /**
  931. * 处理技术协单
  932. * @param use
  933. * @param status
  934. * @param date
  935. */
  936. private void updatePushassist(PublicRelease use, Integer status, Date date, Admin a) {
  937. //协单
  938. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  939. String []ss= use.getAssistAid().split(",");
  940. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  941. for (PublicRelease out : list) {
  942. boolean flag=false;
  943. for (String s : ss) {
  944. if (out.getAid().equals(s)){
  945. flag=true;
  946. break;
  947. }
  948. }
  949. if (!flag){
  950. PublicRelease in = new PublicRelease();
  951. in.setId(out.getId());
  952. in.setStatus(3);
  953. publicReleaseMapper.updateByPrimaryKeySelective(in);
  954. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  955. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  956. publicReleaseLogMapper.insertSelective(log);
  957. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  958. }else {
  959. PublicRelease np = new PublicRelease();
  960. BeanUtils.copyProperties(use,np);
  961. np.setId(out.getId());
  962. np.setMainId(null);
  963. np.setType(null);
  964. np.setAssist(2);
  965. //以前是直接公出通过,现在是通过了,就出现一条需要协单审核的
  966. np.setStatus(1);
  967. np.setAid(null);
  968. publicReleaseMapper.updateByPrimaryKeySelective(np);
  969. updatePublicReleaseDtails(use,np);
  970. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  971. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  972. publicReleaseLogMapper.insertSelective(log);
  973. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  974. }
  975. }
  976. for (String s : ss) {
  977. boolean flag2 = false;
  978. for (PublicRelease o : list) {
  979. if (s.equals(o.getAid())) {
  980. flag2 = true;
  981. }
  982. }
  983. if (!flag2) {
  984. PublicRelease np = new PublicRelease();
  985. BeanUtils.copyProperties(use,np);
  986. np.setAssist(2);
  987. np.setAid(s);
  988. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(s);
  989. if (!adminPublicReviewerBos.isEmpty()){
  990. np.setStatus(1);
  991. }else {
  992. np.setStatus(2);
  993. }
  994. np.setType(3);
  995. np.setMainId(use.getId());
  996. np.setId(null);
  997. publicReleaseMapper.insertSelective(np);
  998. //补充客户表
  999. addpublicReleaseDtails(use,np);
  1000. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  1001. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  1002. sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
  1003. publicReleaseLogMapper.insertSelective(log);
  1004. if (np.getStatus()==2){
  1005. PublicReleaseLog log2 = new PublicReleaseLog(np.getId(), "1", PublicReleaseLog.states.ty.getCode(), "协单无需审核自动通过", new Date());
  1006. publicReleaseLogMapper.insertSelective(log);
  1007. }
  1008. }
  1009. }
  1010. }
  1011. private void updatePublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1012. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1013. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPrid(in.getId());
  1014. //打卡信息重新梳理
  1015. //查找新增的
  1016. for (OutPublicReleaseDetails out : list) {
  1017. boolean flag=true;
  1018. for (OutPublicReleaseDetails out2 : list2) {
  1019. if (out.getUid().equals(out2.getUid())){
  1020. flag=false;
  1021. }
  1022. }
  1023. if (flag){
  1024. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1025. BeanUtils.copyProperties(out,prd);
  1026. prd.setId(null);
  1027. prd.setPrid(in.getId());
  1028. prd.setClockIn(0);
  1029. prd.setClockInTime(null);
  1030. prd.setClockInRemarks(null);
  1031. prd.setUfid(null);
  1032. publicReleaseDetailsMapper.insertSelective(prd);
  1033. }
  1034. }
  1035. for (OutPublicReleaseDetails out2 : list2) {
  1036. boolean flag=true;
  1037. for (OutPublicReleaseDetails out : list) {
  1038. if (out2.getUid().equals(out.getUid())){
  1039. flag=false;
  1040. }
  1041. }
  1042. if (flag){
  1043. publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
  1044. }
  1045. }
  1046. //信息补充,修改时没有打卡信息
  1047. if(in.getValidDate()==null)in.setValidDate(use.getValidDate());
  1048. //最后再来处理打卡信息
  1049. addPublicReleaseDateClock(in);
  1050. }
  1051. private void addpublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1052. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1053. for (OutPublicReleaseDetails out : list) {
  1054. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1055. BeanUtils.copyProperties(out,prd);
  1056. prd.setId(null);
  1057. prd.setPrid(in.getId());
  1058. prd.setClockIn(0);
  1059. prd.setClockInTime(null);
  1060. prd.setMainStatus(0);
  1061. publicReleaseDetailsMapper.insertSelective(prd);
  1062. }
  1063. addPublicReleaseDateClock(in);
  1064. }
  1065. /**
  1066. * 处理技术助手
  1067. * @param use
  1068. */
  1069. private void updatepushAssistant(PublicRelease use,Admin a) {
  1070. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  1071. for (PublicRelease p : uselist) {
  1072. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  1073. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  1074. p.setStatus(2);
  1075. p.setAssistantAid(use.getAssistantAid());
  1076. p.setAssistantName(use.getAssistantName());
  1077. p.setUserNames(use.getUserNames());
  1078. publicReleaseMapper.updateByPrimaryKeySelective(p);
  1079. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  1080. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  1081. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  1082. publicReleaseLogMapper.insertSelective(log);
  1083. }
  1084. }
  1085. @Override
  1086. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  1087. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  1088. return list;
  1089. }
  1090. @Override
  1091. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  1092. if (clockIn == null) clockIn = 1;
  1093. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(id);
  1094. if (use.getPublicType()==1||use.getPublicType()==3) {
  1095. return -1;
  1096. }
  1097. if (use.getStatus()!=2){
  1098. return -2;
  1099. }
  1100. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  1101. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  1102. pushDateClockDetails(prdList,prdcList);
  1103. String str = "";
  1104. Date date = new Date();
  1105. boolean flag=false;
  1106. Integer clockCount=0;
  1107. PublicReleaseClock pc=new PublicReleaseClock();
  1108. pc.setPrid(id);
  1109. pc.setPhotoUrl(photoUrl);
  1110. pc.setClockInTime(date);
  1111. for (OutPublicReleaseDetails prd : prdList) {
  1112. if (prd.getUid().equals(uid)){
  1113. String aid = TokenManager.getAdminId();
  1114. pc.setPrdid(prd.getId());
  1115. prd.setClockInRemarks(clockInRemarks);
  1116. prd.setPhotoUrl(photoUrl);
  1117. prd.setClockInTime(date);
  1118. int count=0;
  1119. for (PublicReleaseDateClock ep : prd.getPrdcList()) {
  1120. if (DateUtils.isSameDay(prd.getClockInTime(), ep.getClockInTime())){
  1121. if (ep.getStatus()==0){
  1122. ep.setStatus(1);
  1123. FollowBusinessBo fbb = new FollowBusinessBo();
  1124. fbb.setUid(prd.getUid());
  1125. fbb.setContactType("5");
  1126. fbb.setResult(use.getRemarks());
  1127. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  1128. if (ub != null) {
  1129. fbb.setOcbId(ub.getId());
  1130. }
  1131. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  1132. String ufid = UUID.randomUUID().toString();
  1133. prd.setUfid(ufid);
  1134. customerService.addFollow(fbb, ufid, prd.getMainStatus(),0,null);
  1135. if (clockIn==1){
  1136. str = "公出人员打卡";
  1137. }else if (clockIn==2) {
  1138. str = "公出人员异常打卡";
  1139. }
  1140. count++;
  1141. publicReleaseDateClockMapper.updateByPrimaryKeySelective(ep);
  1142. }else {
  1143. if (clockIn==1){
  1144. str = "刷新打卡";
  1145. }else if (clockIn==2) {
  1146. str = "刷新打卡,公出人员异常打卡";
  1147. }
  1148. count++;
  1149. }
  1150. }else {
  1151. if (ep.getStatus()==1){
  1152. count++;
  1153. }
  1154. }
  1155. }
  1156. if(prd.getPrdcList().size() == count){
  1157. prd.setClockIn(1);
  1158. }
  1159. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  1160. log.setPhotoUrl(photoUrl);
  1161. publicReleaseLogMapper.insertSelective(log);
  1162. publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
  1163. flag=true;
  1164. clockCount++;
  1165. }else if (prd.getClockIn()==1){
  1166. clockCount++;
  1167. }
  1168. }
  1169. if (prdList.size()==clockCount){
  1170. PublicRelease newp=new PublicRelease();
  1171. newp.setId(id);
  1172. newp.setClockIn(1);
  1173. publicReleaseMapper.updateByPrimaryKeySelective(newp);
  1174. }
  1175. publicReleaseClockMapper.insertSelective(pc);
  1176. if (!flag){
  1177. return 0;
  1178. }
  1179. return 1;
  1180. }
  1181. @Override
  1182. public OutPublicRelease dtails(Integer id) {
  1183. String aid=TokenManager.getAdminId();
  1184. //如果不是本人和审核人员则不返回信息
  1185. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  1186. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  1187. out.setPeList(ps);
  1188. if(out!=null){
  1189. boolean flag=false;
  1190. //自己、审核人员与部门负责人可以查看
  1191. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  1192. if (!aid.equals( out.getAid())&&
  1193. !aid.equals(out.getReviewer())&&
  1194. !aid.equals(ab.getDepManager())&&
  1195. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  1196. flag=true;
  1197. }
  1198. //是否可以审核
  1199. if (!ps.isEmpty()){
  1200. for (PublicExamine p : ps) {
  1201. if (p.getAid().equals(aid)){
  1202. if (p.getStatus()==1)out.setMyExamine(1);
  1203. else out.setMyExamine(0);
  1204. flag=false;
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. //处理返回
  1210. if(flag){
  1211. out=null;
  1212. return out;
  1213. }else {
  1214. if (out.getPublicType()==1){
  1215. if (aid.equals(out.getAid())){
  1216. out.setPermission(0);
  1217. }else {
  1218. out.setPermission(1);
  1219. }
  1220. }else {
  1221. if(aid.equals(out.getAid())) {
  1222. out.setPermission(0);
  1223. }else {
  1224. out.setPermission(1);
  1225. }
  1226. }
  1227. }
  1228. }
  1229. if (out.getStatus()==1&&
  1230. ((out.getPublicType()==0||out.getPublicType()==2)&&(out.getTechStartProcess()==0||out.getTechStartProcess()==2))
  1231. ){
  1232. out.setAdminExamine(out.getReviewerName()+" 未审核");
  1233. }else if (out.getStatus()==0) {
  1234. out.setAdminExamine("");
  1235. }else {
  1236. if (!ps.isEmpty()){
  1237. StringBuffer str =new StringBuffer();
  1238. for (PublicExamine e : ps) {
  1239. if (out.getId().equals(e.getPrid())){
  1240. str.append(e.getAname());
  1241. if (e.getStatus()==0) str.append(" 未审核,");
  1242. if (e.getStatus()==1) str.append(" 已审核,");
  1243. }
  1244. if (str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1));
  1245. }
  1246. }
  1247. }
  1248. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  1249. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  1250. pushDateClockDetailsToday(prdList,prdcList);
  1251. out.setPrdList(prdList);
  1252. return out;
  1253. }
  1254. @Override
  1255. public OutPublicReleaseAndDetails followDtails(String id) {
  1256. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  1257. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(out.getId());
  1258. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(out.getId());
  1259. pushDateClockDetails(prdList,prdcList);
  1260. out.setPrdList(prdList);
  1261. return out;
  1262. }
  1263. @SuppressWarnings("unchecked")
  1264. @Override
  1265. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  1266. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  1267. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  1268. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  1269. public Object publicReleaseStatistics(InputPublicStatistics in) {
  1270. Map<String,Object> map =new HashMap<String, Object>();
  1271. if(in.getAid()!=null)map.put("aid", in.getAid());
  1272. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1273. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1274. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1275. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1276. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1277. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  1278. }
  1279. @SuppressWarnings("unchecked")
  1280. @Override
  1281. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  1282. Map<String,Object> map =new HashMap<String, Object>();
  1283. if(in.getAid()!=null)map.put("aid", in.getAid());
  1284. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  1285. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  1286. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1287. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  1288. }
  1289. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1290. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1291. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1292. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1293. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  1294. }
  1295. @SuppressWarnings("unchecked")
  1296. @Override
  1297. public Object publicReleaseListDtails(InputPublicDtails in) {
  1298. Map<String,Object> map =new HashMap<String, Object>();
  1299. addParams(in, map);
  1300. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  1301. List<OutPublicDtails> list = (List<OutPublicDtails>)page.getList();
  1302. List<Integer> collect = list.stream().map(OutPublicDtails::getId).collect(Collectors.toList());
  1303. if (!collect.isEmpty()){
  1304. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(collect);
  1305. pushiClockInTime(list, publicReleaseClocks);
  1306. }
  1307. return page;
  1308. }
  1309. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  1310. if(in.getAid()!=null) map.put("aid", in.getAid());
  1311. if(in.getSid()!=null) map.put("sid", in.getSid());
  1312. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  1313. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  1314. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  1315. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1316. if(in.getUid()!=null) map.put("uid", in.getUid());
  1317. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  1318. if(in.getStatus()!=null) map.put("status", in.getStatus());
  1319. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  1320. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  1321. //type 0私有 1管理权限 2所有权限
  1322. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  1323. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  1324. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  1325. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1326. //添加财务和财务经理。查看客户所有公出
  1327. in.setType(2);
  1328. if(in.getDeps()!=null){
  1329. map.put("deps", departmentService.parseArray(in.getDeps()));
  1330. }
  1331. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
  1332. ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  1333. in.setType(1);
  1334. if (in.getDeps()!=null){
  1335. List<String> list = departmentService.selectSubDeps(in.getDeps());
  1336. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  1337. map.put("deps", list);
  1338. }else {
  1339. map.put("deps",departmentService.selectMyDeps());
  1340. }
  1341. }else{
  1342. in.setType(0);
  1343. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  1344. if(in.getDeps()!=null){
  1345. map.put("deps", departmentService.parseArray(in.getDeps()));
  1346. }
  1347. }
  1348. map.put("type", in.getType());
  1349. if(in.getStatusType()!=null) map.put("statusType", in.getStatusType());
  1350. }
  1351. @SuppressWarnings("unchecked")
  1352. @Override
  1353. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  1354. Map<String,Object> map =new HashMap<String, Object>();
  1355. addParams(in, map);
  1356. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  1357. }
  1358. @Override
  1359. public int addSupplement(Integer id, String supplement, String nextPlan) {
  1360. PublicRelease pr=new PublicRelease();
  1361. pr.setId(id);
  1362. pr.setSupplement(supplement);
  1363. pr.setNextPlan(nextPlan);
  1364. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  1365. }
  1366. @Override
  1367. public boolean checkTime(InputPublicRelease in) {
  1368. try {
  1369. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  1370. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  1371. } catch (ParseException e) {
  1372. e.printStackTrace();
  1373. throw new BusinessException("转换异常");
  1374. }
  1375. List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  1376. if (is.size()>1) {
  1377. return true;
  1378. }else if(is.size()==1){
  1379. //如果id为新增那么直接不允许时间重复
  1380. if (in.getId()==null){
  1381. return true;
  1382. }else {
  1383. //如果有id,与获取id一直,则为当前修改可以
  1384. if (in.getId().equals(is.get(0))){
  1385. return false;
  1386. }else {
  1387. return true;
  1388. }
  1389. }
  1390. }
  1391. return false;
  1392. }
  1393. @Override
  1394. public List<Map<String, Object>> selectOrderByUid(String uid) {
  1395. return tOrderNewMapper.selectOrderByuid(uid);
  1396. }
  1397. @Override
  1398. public List<OutPublicRelease> publicByOrder(String orderNo) {
  1399. return publicReleaseMapper.publicByOrder(orderNo);
  1400. }
  1401. @Override
  1402. public Object getMyNewPublic() {
  1403. List<PublicRelease> myPublic=publicReleaseMapper.selectMyNewPublic(TokenManager.getAdminId());
  1404. if(myPublic.isEmpty())return null;
  1405. Integer id=null;
  1406. long count=999999;
  1407. for (PublicRelease e : myPublic) {
  1408. long nowTime=System.currentTimeMillis();
  1409. long time = Math.abs(nowTime-e.getReleaseStart().getTime())/(1000*60);
  1410. long time2 = Math.abs(e.getReleaseEnd().getTime()-nowTime)/(1000*60);
  1411. //距离当前时间近的开始时间,不大于当前时间
  1412. if (time<count&&e.getReleaseStart().getTime()<nowTime){
  1413. count=time;
  1414. id=e.getId();
  1415. }
  1416. //距离当前时间近的结束时间,不小于当前时间
  1417. if (time2<count&&e.getReleaseEnd().getTime()>nowTime){
  1418. count=time2;
  1419. id=e.getId();
  1420. }
  1421. }
  1422. if (id==null)id=myPublic.get(0).getId();
  1423. OutPublicReleaseList out = publicReleaseMapper.selectOutListBoById(id);
  1424. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  1425. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  1426. pushDateClockDetails(prdList,prdcList);
  1427. pushDateClockDetailsToday(prdList,prdcList);
  1428. out.setPrdList(prdList);
  1429. return out;
  1430. // List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  1431. // if (myPublic.isEmpty()){
  1432. // List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  1433. // if (!myPublic2.isEmpty()){
  1434. // return myPublic2.get(0);
  1435. // }
  1436. // }else {
  1437. // return myPublic.get(0);
  1438. // }
  1439. }
  1440. private void pushDateClockDetailsToday(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  1441. for (OutPublicReleaseDetails out : prdList) {
  1442. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  1443. for (PublicReleaseDateClock prdc : prdcList) {
  1444. if (prdc.getPrdid().equals(out.getId())&&DateUtils.isSameDay(new Date(), prdc.getClockInTime())){
  1445. elist.add(prdc);
  1446. }
  1447. }
  1448. out.setPrdcList(elist);
  1449. }
  1450. }
  1451. private void pushDateClockDetails(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  1452. for (OutPublicReleaseDetails out : prdList) {
  1453. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  1454. for (PublicReleaseDateClock prdc : prdcList) {
  1455. if (prdc.getPrdid().equals(out.getId())){
  1456. elist.add(prdc);
  1457. }
  1458. }
  1459. out.setPrdcList(elist);
  1460. }
  1461. }
  1462. /**
  1463. *
  1464. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  1465. * @param dateType 是否含打卡时间 0否 1是
  1466. * @return
  1467. */
  1468. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  1469. Map<String, Object> map = new HashMap<>();
  1470. if (type==null)type=0;
  1471. map.put("type",type);
  1472. //statusType=1情况下
  1473. map.put("statusType",1);
  1474. if (dateType==1){
  1475. Date date = new Date();
  1476. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  1477. map.put("clockTime",clockTime);
  1478. }
  1479. map.put("aid",TokenManager.getAdminId());
  1480. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  1481. for (OutPublicReleaseList out : list) {
  1482. out.setPrdList(publicReleaseDetailsMapper.selectByPrid(out.getId()));
  1483. }
  1484. return list;
  1485. }
  1486. @Override
  1487. public int addAssistant(Integer id,String aid) {
  1488. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1489. List<String> list=new ArrayList<>();
  1490. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  1491. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1492. }
  1493. String sname = pushAssistant(aid, list,0);
  1494. String said =String.join(",",list);
  1495. p.setAssistantAid(said);
  1496. p.setAssistantName(sname);
  1497. addAssistantPublicRelease(p,aid);
  1498. return updateAssistant(p, said, sname);
  1499. }
  1500. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  1501. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1502. PublicRelease newP= new PublicRelease();
  1503. if(list.isEmpty()){
  1504. BeanUtils.copyProperties(p,newP);
  1505. newP.setId(null);
  1506. newP.setAid(aid);
  1507. newP.setAssist(3);
  1508. newP.setType(4);
  1509. publicReleaseMapper.insertSelective(newP);
  1510. addpublicReleaseDtails(p,newP);
  1511. StringBuffer str=new StringBuffer();
  1512. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  1513. addWeChatNotice( aid,1,str.toString(),newP.getId());
  1514. }else {
  1515. for (PublicRelease pr : list) {
  1516. newP.setId(pr.getId());
  1517. newP.setAssistantAid(p.getAssistantAid());
  1518. newP.setAssistantName(p.getAssistantName());
  1519. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  1520. updatePublicReleaseDtails(p,newP);
  1521. }
  1522. }
  1523. }
  1524. /**
  1525. * 添加微信提示和站内消息
  1526. * @param aid 接受者
  1527. * @param type 状态 0驳回 1发起 2同意 3撤销
  1528. * @param str 备注
  1529. * @param prid 公出编号
  1530. */
  1531. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  1532. Admin recipient = adminMapper.selectByPrimaryKey(aid);
  1533. addWeChatNotice( recipient, type, str, prid);
  1534. }
  1535. /**
  1536. * 添加微信提示和站内消息
  1537. * @param recipient 接受者
  1538. * @param type 状态 0驳回 1发起 2同意 3撤销
  1539. * @param str
  1540. */
  1541. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  1542. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  1543. String openid=recipient.getOpenId();
  1544. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  1545. if(type==3){
  1546. addpublicLog(prid,4,str);
  1547. }else {
  1548. addpublicLog(prid,type,str);
  1549. }
  1550. sendNoticeAndSoucket(recipient.getId(),type,str);
  1551. if (type==0||type==2){
  1552. if (openid!=null) {
  1553. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  1554. return res;
  1555. }else {
  1556. sendEmail(my, recipient,type);
  1557. }
  1558. }
  1559. return 0;
  1560. }
  1561. private int updateAssistant(PublicRelease p, String said, String sname) {
  1562. PublicRelease newPr=new PublicRelease();
  1563. newPr.setId(p.getId());
  1564. newPr.setAssistantAid(said);
  1565. newPr.setAssistantName(sname);
  1566. if (p.getMainId()!=null){
  1567. PublicRelease mianPr=new PublicRelease();
  1568. mianPr.setId(p.getMainId());
  1569. mianPr.setAid(said);
  1570. mianPr.setAssistantAid(said);
  1571. mianPr.setAssistantName(sname);
  1572. publicReleaseMapper.updateByPrimaryKeySelective(mianPr);
  1573. }
  1574. return publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1575. }
  1576. /**
  1577. *
  1578. * @param aid 元素
  1579. * @param list 集合
  1580. * @param type 0新增 1删除
  1581. * @return
  1582. */
  1583. private String pushAssistant(String aid, List<String> list,Integer type) {
  1584. StringBuffer sb=new StringBuffer();
  1585. if(type==0){
  1586. list.add(aid);
  1587. }else if (type==1){
  1588. Iterator<String > it =list.iterator();
  1589. while (it.hasNext()){
  1590. if (it.next().equals(aid))
  1591. it.remove();
  1592. }
  1593. }
  1594. for (String s : list) {
  1595. sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
  1596. }
  1597. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  1598. }
  1599. @Override
  1600. public int deleteAssistant(Integer id, String aid) {
  1601. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1602. if (p.getAssistantAid()==null){
  1603. throw new BusinessException("人员不存在");
  1604. }
  1605. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1606. if (!list.contains(aid)){
  1607. throw new BusinessException("人员不存在");
  1608. }
  1609. String sname = pushAssistant(aid, list,1);
  1610. String said =String.join(",",list);
  1611. p.setAssistantAid(said);
  1612. p.setAssistantName(sname);
  1613. deleteAssistantPulicRelease(p,aid);
  1614. return updateAssistant(p, said, sname);
  1615. }
  1616. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  1617. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  1618. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1619. StringBuffer str=new StringBuffer();
  1620. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  1621. for (PublicRelease pr : list) {
  1622. if (pr.getAid().equals(aid)){
  1623. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  1624. }else {
  1625. PublicRelease newPr=new PublicRelease();
  1626. newPr.setId(pr.getId());
  1627. newPr.setAssistantAid(p.getAssistantAid());
  1628. newPr.setAssistantName(p.getAssistantName());
  1629. publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1630. }
  1631. }
  1632. }
  1633. @Override
  1634. public boolean checkdeleteAssistant(Integer id, String aid) {
  1635. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1636. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1637. for (PublicRelease use : list) {
  1638. // if (use.getClockIn()==1){
  1639. // return true;
  1640. // }
  1641. }
  1642. return false;
  1643. }
  1644. @Override
  1645. public boolean checkaddAssistant(Integer id, String aid) {
  1646. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1647. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1648. for (PublicRelease use : list) {
  1649. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  1650. return true;
  1651. }
  1652. }
  1653. return false;
  1654. }
  1655. @Override
  1656. public int updateLocation(InputPublicRelease in) {
  1657. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  1658. if (prd==null){
  1659. throw new BusinessException("公出企业不存在");
  1660. }
  1661. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  1662. updateprd.setId(prd.getId());
  1663. updateprd.setLatitude(in.getLatitude());
  1664. updateprd.setLongitude(in.getLongitude());
  1665. updateprd.setDistrictName(in.getDistrictName());
  1666. updateprd.setClockIn(0);
  1667. addpublicLog(in.getId(),5,"发起公出地点修改");
  1668. return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
  1669. }
  1670. @Override
  1671. public Object publicReleaseAndCount(InputPublicDtails in) {
  1672. List<OutPublicDtails> list = publicReleaseListDtailsList(in);
  1673. Map<String,Object> map=new HashMap<String, Object>();
  1674. if (list.isEmpty()){
  1675. map.put("list",list);
  1676. map.put("count",0);
  1677. map.put("durationCount",0);
  1678. map.put("peopleCount",0);
  1679. }else {
  1680. //公出次数
  1681. int count=0;
  1682. BigDecimal durationCount=BigDecimal.ZERO;
  1683. List<String> aList =new ArrayList<>();
  1684. for (OutPublicDtails e : list) {
  1685. if (e.getType()==0||e.getType()==1||e.getType()==2){
  1686. count++;
  1687. if (e.getDuration()!=null){
  1688. durationCount=durationCount.add(new BigDecimal(e.getDuration()));
  1689. }
  1690. if (!aList.contains(e.getAname())){
  1691. aList.add(e.getAname());
  1692. }
  1693. if (StringUtils.isNotEmpty(e.getAssistAidName())){
  1694. String[] split = e.getAssistAidName().split(",");
  1695. for (String s : split) {
  1696. if (!aList.contains(s)){
  1697. aList.add(s);
  1698. }
  1699. }
  1700. }
  1701. if (StringUtils.isNotEmpty(e.getAssistantName())){
  1702. String[] split = e.getAssistantName().split(",");
  1703. for (String s : split) {
  1704. if (!aList.contains(s)){
  1705. aList.add(s);
  1706. }
  1707. }
  1708. }
  1709. }
  1710. }
  1711. map.put("list",list);
  1712. map.put("count",count);
  1713. map.put("durationCount",durationCount);
  1714. map.put("peopleCount",aList.size());
  1715. }
  1716. return map;
  1717. }
  1718. /**
  1719. *
  1720. * @param in 公出参数
  1721. * @param a 新增时需哟额外知道当前任务
  1722. * @param type 0查询 1新增 2修改
  1723. * @return
  1724. */
  1725. public Map checkOrderNoDuration( InputPublicRelease in,AdminListBo a,int type) {
  1726. List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
  1727. TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
  1728. OutPublicRelease outPublicRelease=null;
  1729. //实际公出
  1730. BigDecimal actualDuration = BigDecimal.ZERO;
  1731. //公出次数
  1732. int frequency=0;
  1733. List<String> peopleList = new ArrayList<>();
  1734. //判定是不是新增获取原数据,是新增数量加1
  1735. if (in.getId()!=null){
  1736. outPublicRelease= publicReleaseMapper.selectDtails(in.getId());
  1737. }else {
  1738. peopleList.add(TokenManager.getAdminId());
  1739. actualDuration=actualDuration.add(BigDecimal.valueOf(in.getDuration()));
  1740. frequency++;
  1741. }
  1742. for (PublicRelease e : list) {
  1743. //新增直接计算
  1744. if (in.getId()==null){
  1745. if (e.getDuration()!=null){
  1746. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  1747. if (!peopleList.contains(e.getAid())){
  1748. peopleList.add(e.getAid());
  1749. }
  1750. frequency++;
  1751. }
  1752. }else {
  1753. //修改当前数据要从修改后获取
  1754. if (!e.getId().equals(in.getId())){
  1755. if (e.getDuration()!=null){
  1756. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  1757. if (!peopleList.contains(e.getAid())){
  1758. peopleList.add(e.getAid());
  1759. }
  1760. frequency++;
  1761. }
  1762. }else {
  1763. if (outPublicRelease != null && outPublicRelease.getDuration() != null) {
  1764. actualDuration = actualDuration.add(BigDecimal.valueOf(outPublicRelease.getDuration()));
  1765. if (!peopleList.contains(outPublicRelease.getAid())) {
  1766. peopleList.add(outPublicRelease.getAid());
  1767. }
  1768. frequency++;
  1769. }
  1770. }
  1771. }
  1772. }
  1773. Map map=new HashMap();
  1774. CheckOrderNoOut data= new CheckOrderNoOut();
  1775. if (outPublicRelease!=null){
  1776. data.setPublicReleaseName(outPublicRelease.getAname());
  1777. }
  1778. //新增与修改,需要重新获取实际公出与人数与次数
  1779. if (type==1||type==2){
  1780. TOrderPublicReleaseCount update=new TOrderPublicReleaseCount();
  1781. update.setOrderNo(in.getOrderNo());
  1782. update.setFrequency(frequency);
  1783. update.setActualDuration(actualDuration.doubleValue());
  1784. update.setPeopleCount(peopleList.size());
  1785. tOrderPublicReleaseCountMapper.updateByOrderNo(update);
  1786. }
  1787. data.setTimesCount(frequency);
  1788. data.setPeopleCount(peopleList.size());
  1789. data.setUserName(t.getUserName());
  1790. data.setContractNo(t.getContractNo());
  1791. data.setAdminName(t.getSalesmanName());
  1792. data.setDurationCount(actualDuration);
  1793. //获取年份
  1794. List<OrderYearMaxDuration> yearMaxDurationList = orderYearMaxDurationMapper.selectByOrderNo(in.getOrderNo());
  1795. int year = LocalDate.now().getYear();
  1796. OrderYearMaxDuration useOyd = null;
  1797. for (int i = 0; i < yearMaxDurationList.size(); i++) {
  1798. OrderYearMaxDuration oyd = yearMaxDurationList.get(i);
  1799. //年份为0不是会员直接获取跳出循环,否则获取当前年份,获取不到获取最后一年
  1800. if (oyd.getYear()==0){
  1801. useOyd=oyd;
  1802. break;
  1803. }else {
  1804. if (oyd.getYear().equals(year)){
  1805. useOyd = oyd;
  1806. break;
  1807. }
  1808. if(i==yearMaxDurationList.size()-1&&useOyd==null){
  1809. useOyd = yearMaxDurationList.get(i);
  1810. }
  1811. }
  1812. }
  1813. data.setDurationMax(useOyd.getMaxDuration());
  1814. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(in.getOrderNo());
  1815. List<TTaskMember> tTaskMembers = tTaskMemberMapper.selectByOrderNo(tOrderNew.getOrderNo());
  1816. String amountName=null;
  1817. String amountType=null;
  1818. if (tTaskMembers.size()<1){
  1819. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(1))<0){
  1820. amountName="本合同低于1万";
  1821. amountType="原则上技术人员不可下户";
  1822. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0){
  1823. amountName="本合同在1~3万";
  1824. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1825. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0){
  1826. amountName="本合同在3~5万";
  1827. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1828. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0){
  1829. amountName="本合同在5~10万";
  1830. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1831. }
  1832. }else {
  1833. int yearSum=1;
  1834. for (TTaskMember tTaskMember : tTaskMembers) {
  1835. if (tTaskMember.getYearSum()!=null&&tTaskMember.getYearSum()>yearSum){
  1836. yearSum=tTaskMember.getYearSum();
  1837. }
  1838. }
  1839. BigDecimal divide =BigDecimal.ZERO;
  1840. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(0))>0&&yearSum>0){
  1841. divide=tOrderNew.getTotalAmount().divide(BigDecimal.valueOf(yearSum), BigDecimal.ROUND_HALF_UP);
  1842. }else {
  1843. divide=tOrderNew.getTotalAmount();
  1844. }
  1845. if (divide.compareTo(BigDecimal.valueOf(1))<0){
  1846. amountName="此会员订单,本年度金额低于1万";
  1847. amountType="原则上技术人员不可下户";
  1848. }else if (divide.compareTo(BigDecimal.valueOf(3))<0){
  1849. amountName="此会员订单,本年度金额1~3万";
  1850. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1851. }else if (divide.compareTo(BigDecimal.valueOf(5))<0){
  1852. amountName="此会员订单,本年度金额3~5万";
  1853. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1854. }else if (divide.compareTo(BigDecimal.valueOf(10))<0){
  1855. amountName="此会员订单,本年度金额5~10万";
  1856. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  1857. }
  1858. }
  1859. data.setAmountName(amountName);
  1860. data.setAmountType(amountType);
  1861. if(useOyd.getStatus()==1){
  1862. map.put("code",true);
  1863. map.put("data",null);
  1864. }else {
  1865. if (actualDuration.compareTo(data.getDurationMax())<1){
  1866. map.put("code",true);
  1867. map.put("data",null);
  1868. }else {
  1869. map.put("code",false);
  1870. map.put("data",data);
  1871. }
  1872. }
  1873. return map;
  1874. }
  1875. @Override
  1876. public Map checkOrderNoDuration( InputPublicRelease in){
  1877. return checkOrderNoDuration(in,null,0);
  1878. }
  1879. @Override
  1880. public void pushOutPublicDtails(List<OutPublicDtails> list) {
  1881. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(list.stream().map(OutPublicDtails::getId).collect(Collectors.toList()));
  1882. pushiClockInTime(list, publicReleaseClocks);
  1883. }
  1884. private void pushiClockInTime(List<OutPublicDtails> list, List<PublicReleaseClock> publicReleaseClocks) {
  1885. for (OutPublicDtails outPublicDtails : list) {
  1886. List<PublicReleaseClock> colokList =new ArrayList<>();
  1887. StringBuilder sb = new StringBuilder();
  1888. for (PublicReleaseClock e : publicReleaseClocks) {
  1889. if (outPublicDtails.getPrdId().equals(e.getPrdid())){
  1890. sb.append(DateUtils.formatDateYYYYMMddHHmm(e.getClockInTime())).append("\n");
  1891. colokList.add(e);
  1892. }
  1893. colokList.sort(Comparator.comparing(PublicReleaseClock::getClockInTime));
  1894. Collections.reverse(colokList);
  1895. outPublicDtails.setList(colokList);
  1896. }
  1897. outPublicDtails.setClockInTimes(sb.toString());
  1898. }
  1899. }
  1900. @Override
  1901. public Object pushDateClock() {
  1902. List<PublicRelease> publicReleases = publicReleaseMapper.selectAll();
  1903. for (PublicRelease e : publicReleases) {
  1904. addPublicReleaseDateClock(e);
  1905. }
  1906. return 1;
  1907. }
  1908. private void addPublicReleaseDateClock(PublicRelease e) {
  1909. publicReleaseDateClockMapper.deleteByPrid(e.getId());
  1910. List<PublicReleaseDateClock> list= new ArrayList<>();
  1911. if (e.getValidDate()!=null){
  1912. List<Map> maps = JSONArray.parseArray(e.getValidDate(), Map.class);
  1913. for (Map map : maps) {
  1914. String dates = (String) map.get("value");
  1915. if (dates!=null){
  1916. Date date = DateUtils.parseDate(dates);
  1917. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(e.getId());
  1918. for (OutPublicReleaseDetails det : outPublicReleaseDetails) {
  1919. PublicReleaseDateClock newPRDC = new PublicReleaseDateClock();
  1920. newPRDC.setClockInTime(date);
  1921. newPRDC.setPrid(e.getId());
  1922. newPRDC.setPrdid(det.getId());
  1923. newPRDC.setStatus(det.getClockIn());
  1924. list.add(newPRDC);
  1925. }
  1926. }
  1927. }
  1928. }
  1929. if(!list.isEmpty()){
  1930. publicReleaseDateClockMapper.insertBatch(list);
  1931. list.clear();
  1932. }
  1933. }
  1934. @Override
  1935. @Cacheable(value = "releaseAndExpenseCount#300", key = "'getCounts:key='+#in.buyerName+#in.contractNo+#in.aid+#in.depId+#in.allStatus+#in.startTime+#in.endTime")
  1936. public List<releaseAndExpenseCountOut> releaseAndExpenseCount(InputreleaseAndExpenseCount in) {
  1937. if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
  1938. List<releaseAndExpenseCountOut> expenseCountsOrders = publicReleaseMapper.releaseAndExpenseCount(in);
  1939. expenseCountsOrders.forEach(e->{
  1940. if (e.getExceedDuration()!=null){
  1941. double exceedDuration = Double.parseDouble(e.getExceedDuration());
  1942. if (exceedDuration>0){
  1943. e.setExceedType(1);
  1944. }
  1945. }
  1946. //获取年份
  1947. if (StringUtils.isNotEmpty(e.getOrderNo())){
  1948. List<OrderYearMaxDuration> yearMaxDurationList = orderYearMaxDurationMapper.selectByOrderNo(e.getOrderNo());
  1949. int year = LocalDate.now().getYear();
  1950. OrderYearMaxDuration useOyd = null;
  1951. for (int i = 0; i < yearMaxDurationList.size(); i++) {
  1952. OrderYearMaxDuration oyd = yearMaxDurationList.get(i);
  1953. //年份为0不是会员直接获取跳出循环,否则获取当前年份,获取不到获取最后一年
  1954. if (oyd.getYear()==0){
  1955. useOyd=oyd;
  1956. break;
  1957. }else {
  1958. if (oyd.getYear().equals(year)){
  1959. useOyd = oyd;
  1960. break;
  1961. }
  1962. if(i==yearMaxDurationList.size()-1&&useOyd==null){
  1963. useOyd = yearMaxDurationList.get(i);
  1964. }
  1965. }
  1966. }
  1967. if(useOyd.getStatus()==1){
  1968. e.setMaxDuration("不限制");
  1969. e.setExceedDuration("0");
  1970. }else {
  1971. e.setMaxDuration(useOyd.getMaxDuration().toString());
  1972. if (useOyd.getMaxDuration().compareTo(new BigDecimal(e.getActualDuration()))>=0){
  1973. e.setExceedDuration("0");
  1974. }else {
  1975. e.setExceedDuration(new BigDecimal(e.getActualDuration()).subtract(useOyd.getMaxDuration()).toString());
  1976. }
  1977. }
  1978. }
  1979. });
  1980. return expenseCountsOrders;
  1981. }
  1982. @Override
  1983. @CacheEvict(value = "releaseAndExpenseCount#300",allEntries = true)
  1984. public Object releaseAndExpenseCountClear() {
  1985. LoggerUtils.debug(getClass(),"公出&报销缓存清除。");
  1986. return 1;
  1987. }
  1988. }