PublicReleaseServiceImpl.java 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392
  1. package com.goafanti.weChat.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.goafanti.admin.bo.AdminListBo;
  4. import com.goafanti.admin.bo.AdminPublicReviewerBo;
  5. import com.goafanti.admin.service.DepartmentService;
  6. import com.goafanti.business.bo.InputRestrictProject;
  7. import com.goafanti.common.bo.EmailBo;
  8. import com.goafanti.common.constant.AFTConstants;
  9. import com.goafanti.common.dao.*;
  10. import com.goafanti.common.enums.NoticeStatus;
  11. import com.goafanti.common.error.BusinessException;
  12. import com.goafanti.common.model.*;
  13. import com.goafanti.common.utils.*;
  14. import com.goafanti.common.utils.weChat.WeChatUtils;
  15. import com.goafanti.core.mybatis.BaseMybatisDao;
  16. import com.goafanti.core.mybatis.page.Pagination;
  17. import com.goafanti.core.shiro.token.TokenManager;
  18. import com.goafanti.core.websocket.SystemWebSocketHandler;
  19. import com.goafanti.customer.bo.FollowBusinessBo;
  20. import com.goafanti.customer.service.CustomerService;
  21. import com.goafanti.order.bo.TOrderNewBo;
  22. import com.goafanti.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.util.*;
  35. import java.util.concurrent.atomic.AtomicInteger;
  36. import java.util.concurrent.atomic.AtomicReference;
  37. import java.util.stream.Collectors;
  38. import java.util.stream.Stream;
  39. @Service
  40. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  41. @Autowired
  42. private PublicReleaseMapper publicReleaseMapper;
  43. @Autowired
  44. private PublicReleaseLogMapper publicReleaseLogMapper;
  45. @Autowired
  46. private CustomerService customerService;
  47. @Autowired
  48. private PublicReleaseDetailsMapper publicReleaseDetailsMapper;
  49. @Autowired
  50. private WeChatUtils weChatUtils;
  51. @Autowired
  52. private AdminMapper adminMapper;
  53. @Autowired
  54. private AsyncUtils asyncUtils;
  55. @Autowired
  56. private UserMapper userMapper;
  57. @Autowired
  58. private OrganizationContactBookMapper organizationContactBookMapper;
  59. @Autowired
  60. private SystemWebSocketHandler systemWebSocketHandler;
  61. @Autowired
  62. private TOrderNewMapper tOrderNewMapper;
  63. @Autowired
  64. private DepartmentService departmentService;
  65. @Autowired
  66. private PublicExamineMapper publicExamineMapper;
  67. @Autowired
  68. private AdminUserCountMapper adminUserCountMapper;
  69. @Autowired
  70. private PublicReleaseClockMapper publicReleaseClockMapper;
  71. @Autowired
  72. private PublicReleaseDateClockMapper publicReleaseDateClockMapper;
  73. @Autowired
  74. private TOrderPublicReleaseCountMapper tOrderPublicReleaseCountMapper;
  75. @Autowired
  76. private RestrictProjectMapper restrictProjectMapper;
  77. @Autowired
  78. private OrderYearMaxDurationMapper orderYearMaxDurationMapper;
  79. @Autowired
  80. private TTaskMemberMapper tTaskMemberMapper;
  81. @Autowired
  82. private OrderNewService orderNewService;
  83. @Autowired
  84. private AdminPublicReviewerMapper adminPublicReviewerMapper;
  85. @Autowired
  86. private PublicAssistAdviceMapper publicAssistAdviceMapper;
  87. @Autowired
  88. private UserLimitCheckMapper userLimitCheckMapper;
  89. @Autowired
  90. private UserArchivesMapper userArchivesMapper;
  91. @Autowired
  92. private OrganizationIdentityMapper organizationIdentityMapper;
  93. @Autowired
  94. private UserSuperEvaluateMapper userSuperEvaluateMapper;
  95. @Autowired
  96. private OrderPublicReleaseLogMapper orderPublicReleaseLogMapper;
  97. @Autowired
  98. private PublicConfigMapper publicConfigMapper;
  99. @Autowired
  100. private UserFirstInterviewMapper userFirstInterviewMapper;
  101. @Autowired
  102. private UserArchivesInterviewMapper userArchivesInterviewMapper;
  103. @Autowired
  104. private UserInterviewProjectMapper userInterviewProjectMapper;
  105. @Override
  106. @Transactional
  107. public Map<String, Object> addPublicRelease(InputPublicRelease in) {
  108. Date date =new Date();
  109. if (in.getPublicAgain()==null)in.setPublicAgain(0);
  110. in.setCreateTime(date);
  111. in.setPublicType(0);
  112. in.setTechStartProcess(0);
  113. in.setStatus(1);
  114. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  115. Map checkOrderNo =null;
  116. List<PublicReleaseDetails> prdList=new ArrayList<>();
  117. List<User> users=new ArrayList<>();
  118. StringBuilder str =new StringBuilder();
  119. //判定是单独协单还是一起协单
  120. in.setAid(TokenManager.getAdminId());
  121. if (in.getAssist()==1){
  122. // in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  123. in.setMainName(my.getName());
  124. in.setAssistProcess(1);
  125. }
  126. if (in.getType() == 1) {
  127. //技术公出
  128. checkOrderNo = checkOrderNoDuration(in,my,1);
  129. boolean isValid = (boolean) checkOrderNo.get("code");
  130. if (isValid){
  131. in.setTechStartProcess(0);
  132. }else {
  133. in.setTechStartProcess(1);
  134. }
  135. }
  136. in.setProcessStatus(1);
  137. publicReleaseMapper.insertSelective(in);
  138. if (in.getType()==1&&in.getOrderNo()!=null){
  139. TOrderNew tOrderNew = tOrderNewMapper.queryById(in.getOrderNo());
  140. orderNewService.pushOrderPublicReleaseCount(tOrderNew);
  141. }
  142. addPRD(in, users, str, prdList);
  143. addPublicReleaseDateClock(in);
  144. if (in.getType()==0&&in.getUids()!=null){
  145. pushUserArchivesInterview(in);
  146. }
  147. String userNames=str.substring(0,str.length()-1);
  148. in.setUserNames(userNames);
  149. PublicRelease updateName=new PublicRelease();
  150. updateName.setId(in.getId());
  151. updateName.setUserNames(userNames);
  152. publicReleaseMapper.update(updateName);
  153. addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
  154. //公出信息抄送
  155. pushPublicCarbonCopy(in, my, userNames);
  156. //协单抄送
  157. if (in.getAssist()==1){
  158. pushPublicAssistCarbonCopy(in, my, userNames);
  159. }
  160. return (Map<String, Object>) addPublicReleaseLog(my, in,userNames,date,users,checkOrderNo);
  161. }
  162. private void pushPublicAssistCarbonCopy(InputPublicRelease in, AdminListBo my, String userNames) {
  163. String[] split = in.getAssistAid().split(",");
  164. for (String aid2 : split) {
  165. AdminListBo my2 = adminMapper.getDeptNameByAid(aid2);
  166. PublicRelease p=new PublicRelease();
  167. p.setId(in.getId());
  168. p.setAid(aid2);
  169. p.setReleaseStart(in.getReleaseStart());
  170. p.setReleaseEnd(in.getReleaseEnd());
  171. p.setPlan(in.getPlan());
  172. p.setType(3);
  173. pushPublicCarbonCopy(p, my2, userNames);
  174. }
  175. }
  176. private void pushUserArchivesInterview(InputPublicRelease in) {
  177. if (in.getUids()!=null){
  178. String[] split1 = in.getUais().split(",");
  179. if (split1.length>0&&StringUtils.isNotBlank(split1[0])){
  180. List<UserArchivesInterview> userArchivesInterviews = userArchivesInterviewMapper.selectByIds(split1);
  181. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(in.getId());
  182. //根据不同客户,绑定不同公出
  183. for (OutPublicReleaseDetails e : outPublicReleaseDetails) {
  184. for (UserArchivesInterview uai : userArchivesInterviews) {
  185. if (e.getUid().equals(uai.getUid())){
  186. uai.setPrdid(e.getId());
  187. userArchivesInterviewMapper.update(uai);
  188. }
  189. }
  190. //根据客户判定出来本次公出,如果有则标记有效
  191. List<UserInterviewProjectBo> userInterviewProjectBos = userInterviewProjectMapper.selectByAid(null, e.getUid());
  192. List<UserInterviewProjectBo> collect = userInterviewProjectBos.stream().filter(e2 -> e2.getType() == 0&&e2.getStatus()==0).collect(Collectors.toList());
  193. if (!collect.isEmpty()){
  194. OutPublicReleaseDetails newPRD=new OutPublicReleaseDetails();
  195. newPRD.setId(e.getId());
  196. newPRD.setInterviewStatus(1);
  197. publicReleaseDetailsMapper.update(newPRD);
  198. //需要添加首次面谈表
  199. UserFirstInterview userFirstInterview=new UserFirstInterview();
  200. userFirstInterview.setUid(e.getUid());
  201. userFirstInterview.setAid(TokenManager.getAdminId());
  202. userFirstInterview.setPrdid(e.getId());
  203. userFirstInterview.setFirstTime(in.getReleaseStart());
  204. userFirstInterviewMapper.insert(userFirstInterview);
  205. //将首次面谈项目状态改为非本次项目并添加绑定的公出详情
  206. for (UserInterviewProjectBo userInterviewProjectBo : collect) {
  207. UserInterviewProject userInterviewProject=new UserInterviewProject();
  208. userInterviewProject.setId(userInterviewProjectBo.getId());
  209. userInterviewProject.setPrdid(e.getId());
  210. userInterviewProject.setType(1);
  211. userInterviewProjectMapper.update(userInterviewProject);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. private void addPRD(InputPublicRelease in, List<User> users, StringBuilder str, List<PublicReleaseDetails> prdList) {
  219. if (in.getUids()!=null){
  220. List<String> split = Arrays.asList(in.getUids().split(","));
  221. int userCount=split.size();
  222. Double duration = in.getDuration();
  223. //计算平均
  224. double d = durationSum(duration, userCount);
  225. int index=1;
  226. //获取非已企业公出需要的审核人员
  227. for (String s : split) {
  228. PublicReleaseDetails prd=new PublicReleaseDetails();
  229. User u=userMapper.queryById(s);
  230. users.add(u);
  231. str.append(u.getNickname()).append(",");
  232. if (u!=null&&u.getShareType()==2){
  233. prd.setNewUser(1);
  234. }else {
  235. prd.setNewUser(0);
  236. }
  237. if (u.getAid().equals(in.getAid())){
  238. prd.setMainStatus(1);
  239. }else {
  240. prd.setMainStatus(0);
  241. }
  242. prd.setPrid(in.getId());
  243. prd.setUid(s);
  244. prd.setSignSum(0);
  245. prd.setClockIn(0);
  246. prd.setDistrictName(in.getDistrictName());
  247. prd.setLatitude(in.getLatitude());
  248. prd.setLongitude(in.getLongitude());
  249. prd.setAddressName(in.getAddressName());
  250. if (index<userCount){
  251. if (duration==0){
  252. prd.setDuration(duration);
  253. } else {
  254. prd.setDuration(d);
  255. duration=duration-d;
  256. }
  257. index++;
  258. }else {
  259. prd.setDuration(duration);
  260. }
  261. prdList.add(prd);
  262. }
  263. publicReleaseDetailsMapper.insertBatch(prdList);
  264. }
  265. }
  266. private void pushPublicCarbonCopy(PublicRelease p, AdminListBo my, String userNames) {
  267. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(my.getId())
  268. .stream().filter(e -> e.getType() == 3).collect(Collectors.toList());
  269. if (adminPublicReviewerBos.size()>0){
  270. for (AdminPublicReviewerBo e : adminPublicReviewerBos) {
  271. //公出信息
  272. if (StringUtils.isNotEmpty(e.getReviewerId())){
  273. String startTime = DateUtils.formatDateChineseYYYYMMddHH(p.getReleaseStart());
  274. String endTime = DateUtils.formatDateChineseYYYYMMddHH(p.getReleaseEnd());
  275. //分类 0业务 1技术 2行政 3 技术协单 4 技术助手
  276. String typeName=null;
  277. if(p.getType()==0)typeName="业务公出";
  278. else if(p.getType()==1)typeName="技术公出";
  279. else if(p.getType()==2)typeName="行政公出";
  280. else if(p.getType()==3)typeName="技术协单";
  281. String str=String.format("%s,%s - %s,将公出%s,请知悉!", my.getName(),
  282. startTime,
  283. endTime,
  284. userNames);
  285. String str2=String.format("协单%s,请知悉!",
  286. userNames);
  287. asyncUtils.addNoticAndEmail(NoticeStatus.PUBLIC_CARBON_COPY.getCode(), e.getReviewerId()
  288. ,str);
  289. asyncUtils.sendCarbonCopyWeChat(e.getReviewerId(), p.getId(),
  290. my.getName(), startTime,
  291. endTime,
  292. typeName,
  293. str2);
  294. }
  295. }
  296. }
  297. }
  298. private void pushPublicCarbonCopy(InputPublicRelease in, AdminListBo my, String userNames) {
  299. PublicRelease p=new PublicRelease();
  300. p.setId(in.getId());
  301. p.setAid(in.getAid());
  302. p.setReleaseStart(in.getReleaseStart());
  303. p.setReleaseEnd(in.getReleaseEnd());
  304. p.setPlan(in.getPlan());
  305. p.setType(in.getType());
  306. pushPublicCarbonCopy(p, my, userNames);
  307. }
  308. private void addPublicExamine(Integer id, String aid) {
  309. Admin admin = adminMapper.selectById(aid);
  310. addPublicExamine(id,admin);
  311. }
  312. private void addPublicExamine(Integer id, Admin a) {
  313. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
  314. boolean flag=false;
  315. for (PublicExamine pe : publicExamines) {
  316. if (pe.getAid().equals(a.getId())){
  317. flag=true;
  318. }
  319. }
  320. if (!flag){
  321. PublicExamine pe=new PublicExamine();
  322. pe.setPrid(id);
  323. pe.setAid(a.getId());
  324. pe.setAname(a.getName());
  325. pe.setStatus(0);
  326. publicExamineMapper.insertSelective(pe);
  327. }
  328. }
  329. private double durationSum(Double duration, Integer sum) {
  330. Double counts= Math.floor(duration/0.5);
  331. //计算当前时间
  332. Double my=Math.floor(counts/sum)*0.5;
  333. if (my<0.5)return 0.5;
  334. return my;
  335. }
  336. /**
  337. *
  338. * @param my 我的相关人员
  339. * @param in 公出信息
  340. * @param nickname 客户名称
  341. * @param date 时间
  342. */
  343. private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users,
  344. Map<String,Object> checkOrderNo) {
  345. Map<String, Object>map=new HashMap<String, Object>();
  346. //无需订单负责人审核
  347. if (in.getTechStartProcess()==0){
  348. // Admin a=adminMapper.selectById(my.getReviewer());
  349. //订单审核换成多人
  350. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(in.getAid());
  351. adminPublicReviewerBos=adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  352. String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
  353. //默认上级审核
  354. AtomicReference<Integer> status= new AtomicReference<>(1);
  355. String formatDate = DateUtils.formatDate(in.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS);
  356. //业务公出
  357. if (in.getType()==0||in.getType()==2){
  358. //不是业务员
  359. if (my.getPublicPurview()==0){
  360. for (User u : users) {
  361. //不是自己的客户
  362. if (!u.getAid().equals(my.getId())) {
  363. StringBuilder str2 = new StringBuilder();
  364. Admin admin = adminMapper.selectById(u.getAid());
  365. //业务公出限定项目直接公出,不是业务项目审核公出
  366. if(in.getType()==0){
  367. List<RestrictProject> list = restrictProjectMapper.selectListByParam(new InputRestrictProject(u.getId(), my.getId()));
  368. if (!list.isEmpty()){
  369. String start = DateUtils.formatDate(in.getReleaseStart(), AFTConstants.MMDDHHMM);
  370. String end = DateUtils.formatDate(in.getReleaseEnd(), AFTConstants.MMDDHHMM);
  371. str2.append("限定项目所属人营销员").append(my.getName()).append("于")
  372. .append(start).append("至").append(end).append("公出你的企业[").append(u.getNickname()).append("]请悉知!");
  373. sendEmailAndNoticeAndSoucket(u.getAid(), 3, str2.toString());
  374. }else {
  375. str2.append(my.getName()).append("(需审核),准备公出您的企业")
  376. .append("[").append(u.getNickname()).append("]。");
  377. addPublicExamine(in.getId(), admin);
  378. if (in.getPublicType() == null || in.getPublicType() == 0) in.setPublicType(1);
  379. //审核通知
  380. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  381. status.set(0);
  382. }
  383. //行政公出通知
  384. }else if (in.getType()==2){
  385. str2.append(my.getName()).append(",准备[行政公出]您的企业")
  386. .append("[").append(u.getNickname()).append("]。");
  387. addPublicExamine(in.getId(), admin);
  388. //审核通知
  389. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  390. }
  391. }
  392. }
  393. }else {
  394. users.forEach(u->{
  395. if (!u.getAid().equals(my.getId())){
  396. addNoticeAndSoucket(my, u, formatDate);
  397. }
  398. });
  399. }
  400. } else if (in.getType()==1) {
  401. users.forEach(u->{
  402. if (!u.getAid().equals(my.getId())){
  403. addNoticeAndSoucket(my, u, formatDate);
  404. }
  405. });
  406. }
  407. if (status.get()==1){
  408. for (AdminPublicReviewerBo adminPublicReviewerBo : adminPublicReviewerBos) {
  409. Admin admin = adminMapper.selectById(adminPublicReviewerBo.getReviewerId());
  410. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  411. }
  412. }
  413. publicReleaseMapper.update(in);
  414. }else {
  415. TOrderNew tOrderNew = tOrderNewMapper.queryById(in.getOrderNo());
  416. String salesmanId = tOrderNew.getSalesmanId();
  417. Admin a = adminMapper.selectById(salesmanId);
  418. addPublicExamine(in.getId(),a);
  419. CheckOrderNoOut data = (CheckOrderNoOut) checkOrderNo.get("data");
  420. String format = getString(my, data,tOrderNew);
  421. pushNoticeAndSoucketAndEmail(my, in, date, a, format, map);
  422. }
  423. map.put("data", publicReleaseMapper.selectDtails(in.getId()));
  424. return map;
  425. }
  426. private void addNoticeAndSoucket(AdminListBo my, User u, String formatDate) {
  427. StringBuffer str2=new StringBuffer();
  428. str2=str2.append(my.getName()).append("计划公出您的企业").append(u.getNickname())
  429. .append(",").append(formatDate).append("【小程序端广播提示】");
  430. sendNoticeAndSoucket(u.getAid(),3,str2.toString());
  431. }
  432. private String getString(AdminListBo my, CheckOrderNoOut data,TOrderNew tOrderNew) {
  433. String amountName=data.getAmountName();
  434. String amountType=data.getAmountType();
  435. String format = String.format("%s准备公出%s(%s)," +
  436. "总计公出:%s人,%s次,%s时。%s,本次申请,%s。请确认是否同意本次公出?", my.getName(), data.getUserName(), data.getContractNo(),
  437. data.getPeopleCount(), data.getTimesCount(), data.getDurationCount().stripTrailingZeros().toPlainString(), amountName,
  438. amountType);
  439. return format;
  440. }
  441. /**
  442. *
  443. * @param my 发送人信息
  444. * @param in 公出信息
  445. * @param date 时间
  446. * @param a 接受者信息
  447. * @param str 站内信内容
  448. * @param map 返回实体
  449. */
  450. private void pushNoticeAndSoucketAndEmail(AdminListBo my, PublicRelease in, Date date, Admin a, String str, Map<String, Object> map) {
  451. System.out.println("================================="+1);
  452. sendNoticeAndSoucket(a.getId(),1, str);
  453. if (a.getOpenId() !=null) {
  454. //间隔一秒发送
  455. try {
  456. Thread.sleep(1000);
  457. } catch (InterruptedException e) {
  458. Thread.currentThread().interrupt();
  459. }
  460. Integer res= weChatUtils.addNotice(a.getOpenId(), in.getStatus(), in.getId(), date, my.getName(),"["+ my.getName()+"]发起外出申请");
  461. if (res!=0) {
  462. sendEmail(my, a,1);
  463. }
  464. map.put("code", res);
  465. }else {
  466. sendEmail(my, a,1);
  467. map.put("code", 2);
  468. }
  469. }
  470. private String getAssistAidName(String assistAid) {
  471. String [] ss=assistAid.split(",");
  472. StringBuffer sb=new StringBuffer();
  473. for (String s : ss) {
  474. Admin a=adminMapper.selectById(s);
  475. if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
  476. }
  477. if (sb.length()<1)return "";
  478. return sb.deleteCharAt(sb.length() - 1).toString();
  479. }
  480. private void sendEmailAndNoticeAndSoucket(String id,Integer type,String content){
  481. sendNoticeAndSoucket(id,type,content);
  482. Admin admin = adminMapper.selectById(id);
  483. String title="暂无标题";
  484. if (type==3)title=NoticeStatus.PUBLIC_OTHERS_USER.getDesc();
  485. EmailBo emailBo=new EmailBo(title,admin.getEmail(),content);
  486. asyncUtils.send(emailBo);
  487. }
  488. /**
  489. *
  490. * @param id 接受者编号
  491. * @param type 状态 0驳回 1发起 2同意 3 公出他人企业
  492. * @param content 内容
  493. */
  494. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  495. Integer noticeType=NoticeStatus.PUBLIC_RELEASE_START.getCode();
  496. if(type==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  497. else if (type==2)noticeType=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  498. else if (type==3)noticeType=NoticeStatus.PUBLIC_OTHERS_USER.getCode();
  499. //触发通知有未读消息
  500. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  501. Notice n =new Notice();
  502. n.setId(UUID.randomUUID().toString());
  503. n.setAid(id);
  504. n.setNoticeType(noticeType);
  505. n.setContent(content);
  506. n.setReaded(0);//未读
  507. asyncUtils.addNotice(n);
  508. }
  509. /**
  510. *
  511. * @param my 发送人
  512. * @param a 接受者
  513. * @param type 类型
  514. */
  515. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  516. StringBuffer title=new StringBuffer();
  517. if (type==0) title=title.append("外出申请驳回提醒");
  518. else if (type==1) title=title.append("外出申请提醒");
  519. else if (type==2) title=title.append("外出申请同意提醒");
  520. if (SendEmailUtil.isEmail(a.getEmail())) {
  521. EmailBo email=new EmailBo(title.toString(),a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  522. asyncUtils.send(email);
  523. }
  524. }
  525. @Override
  526. public int updatePublicRelease(InputPublicRelease in) {
  527. Date date = new Date();
  528. try {
  529. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  530. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  531. } catch (ParseException e) {
  532. e.printStackTrace();
  533. throw new BusinessException("转换异常");
  534. }
  535. Map checkOrderNo =null;
  536. List<User> uses=null;
  537. PublicRelease use = publicReleaseMapper.selectById(in.getId());
  538. in.setCreateTime(use.getCreateTime());
  539. String userNames=publicReleaseDetailsMapper.getNamesByPrid(in.getId());
  540. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
  541. in.setUserNames(userNames);
  542. if(in.getStatus()==null||in.getStatus()!=3) {
  543. if (in.getType() == 1) {
  544. checkOrderNo = checkOrderNoDuration(in,null,2);
  545. boolean isValid = (boolean) checkOrderNo.get("code");
  546. if (isValid){
  547. in.setTechStartProcess(0);
  548. }else {
  549. in.setTechStartProcess(1);
  550. }
  551. }else {
  552. in.setTechStartProcess(0);
  553. }
  554. if (in.getAssist()==1){
  555. in.setAssistProcess(1);
  556. //在有协单的情况下,新增是审核完成才新增,修改是审核完成才修改。
  557. //如果是删除,则需要判定
  558. String[] assistAid = in.getAssistAid().split(",");
  559. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(in.getId(), null, null);
  560. for (PublicRelease e : publicReleases) {
  561. boolean flag = false;
  562. for (String aid : assistAid) {
  563. if (e.getAid().equals(aid)){
  564. flag = true;
  565. break;
  566. }
  567. }
  568. if (!flag&&e.getClockIn()==1){
  569. throw new BusinessException("该公出已签到,无法取消");
  570. }
  571. }
  572. }else if (in.getAssist()==0){
  573. publicReleaseMapper.updateAssist(in);
  574. in.setAssistProcess(0);
  575. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(in.getId(), null, null);
  576. for (PublicRelease e : publicReleases) {
  577. if (e.getClockIn()==1){
  578. throw new BusinessException("该协单公出已打卡,无法取消");
  579. }
  580. }
  581. }
  582. //处理修改公出
  583. pushUpdatePublic(in, uses, use, log, userNames, date, checkOrderNo);
  584. //处理修改发起,将面谈信息与项目恢复
  585. pushUpdatePublicInterviewAndProject( use);
  586. }else {
  587. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
  588. List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
  589. log.setStatus(PublicReleaseLog.states.cx.getCode());
  590. for (PublicRelease out : list) {
  591. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
  592. out.setStatus(3);
  593. publicReleaseMapper.update(out);
  594. }
  595. for (PublicRelease out : list2) {
  596. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单助手");
  597. out.setStatus(3);
  598. publicReleaseMapper.update(out);
  599. }
  600. pushPublicInterview(use);
  601. }
  602. addPublicReleaseDateClock(in);
  603. publicReleaseLogMapper.insertSelective(log);
  604. publicReleaseMapper.update(in);
  605. if (in.getOrderNo()!=null){
  606. TOrderNew tOrderNew = tOrderNewMapper.queryById(in.getOrderNo());
  607. orderNewService.pushOrderPublicReleaseCount(tOrderNew);
  608. }
  609. return 1;
  610. }
  611. private void pushUpdatePublicInterviewAndProject(PublicRelease use) {
  612. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(use.getId());
  613. for (OutPublicReleaseDetails e : outPublicReleaseDetails) {
  614. //撤销后取消面谈项目,如果项目已存在则不恢复,不存在则恢复
  615. List<UserInterviewProjectBo> prdList = userInterviewProjectMapper.selectByPrdId(e.getId());
  616. List<UserInterviewProjectBo> userList = userInterviewProjectMapper.selectByAid(use.getAid(), e.getUid());
  617. if (!userList.isEmpty() && !prdList.isEmpty()) {
  618. prdList.forEach(e1 -> {
  619. boolean flag = false;
  620. userList.forEach(e2 -> {
  621. //如果不是同一个面谈项目
  622. if (e1.getPid().equals(e2.getPid())) {
  623. PublicReleaseDetails prdUpdate = new PublicReleaseDetails();
  624. prdUpdate.setId(e.getId());
  625. //是一个公出则恢复,不是则不恢复并且去掉有效
  626. if (e1.getPrdid()!=null&&(e1.getPrdid().equals(e2.getPrdid()))) {
  627. UserInterviewProject update = new UserInterviewProject();
  628. update.setId(e1.getId());
  629. update.setStatus(0);
  630. userInterviewProjectMapper.update(update);
  631. prdUpdate.setInterviewStatus(1);
  632. publicReleaseDetailsMapper.update(prdUpdate);
  633. }
  634. }
  635. });
  636. });
  637. }
  638. }
  639. }
  640. private void pushUpdatePublic(InputPublicRelease in, List<User> uses, PublicRelease use, PublicReleaseLog log, String userNames, Date date, Map checkOrderNo) {
  641. if (in.getUids()!=null){
  642. List<String> split = Arrays.asList(in.getUids().split(","));
  643. List<OutPublicReleaseDetails> prList = publicReleaseDetailsMapper.selectByPrid(in.getId());
  644. uses =pushPublicReleaseDetails(split,prList, use, in);
  645. }
  646. in.setStatus(1);
  647. log.setStatus(PublicReleaseLog.states.xg.getCode());
  648. in.setUpdateStatus(1);
  649. //如果是业务切公出则撤销营销审核与审核人
  650. pushUpdateType(in, use);
  651. //如果是业务公出,切审核状态为其他,则重置审核
  652. if(in.getType()==0&&(use.getPublicType()==2|| use.getPublicType()==3)){
  653. in.setPublicType(1);
  654. PublicExamine pe=new PublicExamine();
  655. pe.setPrid(in.getId());
  656. pe.setStatus(0);
  657. publicExamineMapper.updateByPridSelective(pe);
  658. }
  659. //处理协单,修改,正常不存在协单,反想操作有协单需要单独处理
  660. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
  661. String[] split = in.getAssistAid().split(",");
  662. if (split.length==0){
  663. for (PublicRelease e : list) {
  664. if (e.getClockIn()==1){
  665. throw new BusinessException("协单打卡不能删除");
  666. }
  667. }
  668. for (PublicRelease e : list) {
  669. publicReleaseMapper.deleteById(e.getId());
  670. }
  671. }
  672. // List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
  673. // for (PublicRelease out : list) {
  674. // addpublicLog(out.getId(), PublicReleaseLog.states.xg.getCode(), "修改公出信息,协单自动更改状态");
  675. // out.setStatus(1);
  676. // publicReleaseMapper.updateByPrimaryKeySelective(out);
  677. // }
  678. // for (PublicRelease out : list2) {
  679. // addpublicLog(out.getId(), PublicReleaseLog.states.xg.getCode(), "修改公出信息,协单助手自动更改状态");
  680. // out.setStatus(1);
  681. // publicReleaseMapper.updateByPrimaryKeySelective(out);
  682. // }
  683. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  684. pushPublicCarbonCopy( in, my, userNames);
  685. if (in.getAssist()==1){
  686. String[] split2 = in.getAssistAid().split(",");
  687. for (String aid2 : split2) {
  688. AdminListBo my2 = adminMapper.getDeptNameByAid(aid2);
  689. PublicRelease p=new PublicRelease();
  690. p.setId(in.getId());
  691. p.setAid(aid2);
  692. p.setReleaseStart(in.getReleaseStart());
  693. p.setReleaseEnd(in.getReleaseEnd());
  694. p.setPlan(in.getPlan());
  695. p.setType(3);
  696. pushPublicCarbonCopy(p, my2, userNames);
  697. }
  698. }
  699. //重新发起
  700. addPublicReleaseLog(my, in, in.getUserNames(), date, uses, checkOrderNo);
  701. }
  702. private void pushUpdateType(InputPublicRelease in, PublicRelease use) {
  703. //营销切换成技术
  704. if(use.getType()==0&&in.getType()==1){
  705. in.setPublicType(0);
  706. }
  707. if(use.getType()==1&&in.getType()==0){
  708. in.setTechStartProcess(0);
  709. }
  710. publicExamineMapper.deletePrid(in.getId());
  711. }
  712. private List<User> pushPublicReleaseDetails(List<String> split, List<OutPublicReleaseDetails> prList, PublicRelease use, InputPublicRelease in) {
  713. //先删除,再修改个,再新增,有利于减少计算
  714. deletePRD(split,prList);
  715. publicReleaseDetailsMapper.updateDistrictByPrid(in);
  716. List<User> users = addPRD(split, prList, use,in);
  717. return users;
  718. }
  719. private void deletePRD(List<String> split, List<OutPublicReleaseDetails> prdList) {
  720. for (OutPublicReleaseDetails prd : prdList) {
  721. boolean flag=true;
  722. for (String s : split) {
  723. if (prd.getUid().equals(s)){
  724. flag=false;
  725. }
  726. }
  727. if (flag){
  728. publicReleaseDetailsMapper.deleteById(prd.getId());
  729. }
  730. }
  731. }
  732. /**
  733. * @param split 修改后客户集
  734. * @param prdList 修改前客户集
  735. * @param use 原订单信息
  736. */
  737. private List<User> addPRD(List<String> split, List<OutPublicReleaseDetails> prdList, PublicRelease use, InputPublicRelease in) {
  738. List<PublicReleaseDetails> addPrdList=new ArrayList<>();
  739. List<User> users=new ArrayList<>();
  740. Integer publicType = use.getPublicType();
  741. //计算平均
  742. Integer userCount=split.size();
  743. Integer index=0;
  744. Double duration= in.getDuration();
  745. double d = durationSum(duration,userCount );
  746. for (String s : split) {
  747. User u=userMapper.queryById(s);
  748. users.add(u);
  749. boolean flag=true;
  750. Integer id=null;
  751. String districtName=null,latitude=null,longitude=null;
  752. for (OutPublicReleaseDetails prd : prdList) {
  753. if (id==null)id=prd.getPrid();
  754. if (districtName==null)districtName=prd.getDistrictName();
  755. if (latitude==null)latitude=prd.getLatitude();
  756. if (longitude==null)longitude=prd.getLongitude();
  757. if (s.equals(prd.getUid())){
  758. flag=false;
  759. }
  760. }
  761. //计算下
  762. if (flag){
  763. PublicReleaseDetails prd=new PublicReleaseDetails();
  764. if (u!=null&&u.getShareType()==2){
  765. prd.setNewUser(1);
  766. }else {
  767. prd.setNewUser(0);
  768. }
  769. if (u.getAid().equals(use.getAid())){
  770. prd.setMainStatus(1);
  771. }else {
  772. prd.setMainStatus(0);
  773. }
  774. prd.setPrid(id);
  775. prd.setUid(s);
  776. prd.setSignSum(0);
  777. prd.setDistrictName(districtName);
  778. prd.setAddressName(in.getAddressName());
  779. prd.setLatitude(latitude);
  780. prd.setLongitude(longitude);
  781. prd.setClockIn(0);
  782. addPrdList.add(prd);
  783. //设置时长
  784. if (index<userCount){
  785. if (in.getDuration()==0){
  786. prd.setDuration(in.getDuration());
  787. } else {
  788. prd.setDuration(d);
  789. duration=duration-d;
  790. }
  791. }else {
  792. prd.setDuration(duration);
  793. }
  794. index++;
  795. //修改公出判定是否需要他人审核
  796. //先只有业务公出才有,再看是否是业务员,再看是否是限定客户
  797. if (in.getType()==null)in.setType(use.getType());
  798. if (in.getType()==0){
  799. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  800. if (my.getPublicPurview()==0){
  801. int countRestrictProject = userMapper.getCountRestrictProject(u.getId(), my.getId());
  802. if (countRestrictProject==0){
  803. if (!use.getAid().equals(u.getAid())){
  804. addPublicExamine(use.getId(), u.getAid());
  805. if (publicType==1)publicType=1;
  806. }
  807. }
  808. }
  809. }
  810. }else {
  811. InputPublicRelease inp=new InputPublicRelease();
  812. inp.setId(in.getId());
  813. inp.setUid(s);
  814. PublicReleaseDetails publicReleaseDetails = publicReleaseDetailsMapper.selectBypridAndUid(inp);
  815. PublicReleaseDetails newprd =new PublicReleaseDetails();
  816. newprd.setId(publicReleaseDetails.getId());
  817. //设置时长
  818. if (index<userCount){
  819. if (in.getDuration()==0){
  820. newprd.setDuration(in.getDuration());
  821. } else {
  822. newprd.setDuration(d);
  823. duration=duration-d;
  824. }
  825. }else {
  826. newprd.setDuration(duration);
  827. }
  828. index++;
  829. publicReleaseDetailsMapper.update(newprd);
  830. }
  831. }
  832. StringBuffer str=new StringBuffer();
  833. for (User u : users) {
  834. str=str.append(use.getUserNames()).append(",");
  835. }
  836. if (publicType!=use.getPublicType()){
  837. PublicRelease newP=new PublicRelease();
  838. newP.setId(use.getId());
  839. if (str.length()>1)newP.setUserNames(str.substring(0,str.length()-1));
  840. newP.setPublicType(publicType);
  841. publicReleaseMapper.update(newP);
  842. }
  843. if (!addPrdList.isEmpty())publicReleaseDetailsMapper.insertBatch(addPrdList);
  844. return users;
  845. }
  846. /**
  847. * @param in.type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部) 4 公出企业负责人审核 5 技术公出审核 6=协单审核
  848. * @return
  849. */
  850. @Override
  851. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  852. Map<String,Object> map =new HashMap<String, Object>();
  853. map.put("type", in.getType()==null?0:in.getType());
  854. OutPublicConfig config=null;
  855. if (in.getType()==7){
  856. config=publicConfigMapper.selectDetails();
  857. String aid=TokenManager.getAdminId();
  858. int configType=9;
  859. if (aid.equals(config.getTechAuditor())){
  860. configType=1;
  861. }else if (aid.equals(config.getFinanceAuditor())){
  862. configType=2;
  863. }else if (aid.equals(config.getOtherAuditor())){
  864. configType=3;
  865. }
  866. map.put("configType", configType);
  867. if (in.getMaxProcessStatus()!=null)map.put("maxProcessStatus", in.getMaxProcessStatus());
  868. }
  869. // if(in.getType()==4)map.put("type", 5);
  870. if (in.getType()==3) {
  871. in.setAssist(2);
  872. if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
  873. }else{
  874. map.put("aid",TokenManager.getAdminId());
  875. }
  876. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  877. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  878. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  879. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  880. if(in.getStatus()!=null) map.put("status", in.getStatus());
  881. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  882. map.put("assist",in.getAssist()==null?0:in.getAssist());
  883. Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  884. //处理审核人
  885. if (in.getType()==7){
  886. pushMaxExamines(p,config);
  887. }else {
  888. pushExamines(p);
  889. }
  890. return p;
  891. }
  892. private void pushMaxExamines(Pagination<OutPublicReleaseList> p,OutPublicConfig config) {
  893. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
  894. if (config==null)config=config=publicConfigMapper.selectDetails();
  895. for (OutPublicReleaseList e : list) {
  896. if (e.getOrderNo()!=null){
  897. if (e.getMaxProcess()==1){
  898. e.setAdminExamine(config.getTechAuditorName());
  899. }else if (e.getMaxProcess()==2){
  900. e.setAdminExamine(config.getFinanceAuditorName());
  901. }else if (e.getMaxProcess()==3){
  902. e.setAdminExamine(config.getOtherAuditorName());
  903. }
  904. }
  905. }
  906. }
  907. private void pushExamines(Pagination<OutPublicReleaseList> p) {
  908. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
  909. if (!list.isEmpty()){
  910. List<Integer> ids=new ArrayList<>();
  911. list.forEach(e ->{ ids.add(e.getId()); });
  912. List<PublicExamine> publicExamines = publicExamineMapper.selectByIds(ids);
  913. for (OutPublicReleaseList e : list) {
  914. if (e.getStatus()==1){
  915. List<AdminPublicReviewerBo> adminPublicReviewerBos=null;
  916. if (e.getType()==3){
  917. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e.getAid());
  918. StringBuffer str =new StringBuffer();
  919. for (AdminPublicReviewerBo ap : adminPublicReviewerBos) {
  920. if(ap.getType()==1)str=str.append(ap.getReviewerName()+",");
  921. }
  922. if(str.length()>1)e.setAdminExamine(str.substring(0,str.length()-1)+" 未审核");
  923. }else {
  924. if (((e.getPublicType()==0||e.getPublicType()==2)
  925. &&(e.getTechStartProcess()==0||e.getTechStartProcess()==2))
  926. &&(e.getAssistProcess()==0||e.getAssistProcess()==1)
  927. ){
  928. StringBuffer str =new StringBuffer();
  929. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e.getAid());
  930. if (e.getProcessStatus()==0||e.getProcessStatus()==1){
  931. for (AdminPublicReviewerBo ap : adminPublicReviewerBos) {
  932. if(ap.getType()==0)str=str.append(ap.getReviewerName()+",");
  933. }
  934. }else if (e.getProcessStatus()==2){
  935. for (AdminPublicReviewerBo ap : adminPublicReviewerBos) {
  936. if(ap.getType()==4)str=str.append(ap.getReviewerName()+",");
  937. }
  938. }
  939. e.setAdminExamine(str.substring(0,str.length()-1)+" 未审核");
  940. }else if (e.getType()==0&&e.getAssistProcess()==2){
  941. //获取技术协单
  942. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(e.getId(), null, null);
  943. StringBuffer str =new StringBuffer();
  944. for (PublicRelease e2 : publicReleases) {
  945. if (e2.getStatus()==1){
  946. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e2.getAid());
  947. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e1 -> e1.getType() == 1).collect(Collectors.toList());
  948. for (AdminPublicReviewerBo e1 : collect) {
  949. str.append(e1.getReviewerName()+",");
  950. }
  951. }
  952. }
  953. if (str.length()>1)e.setAdminExamine(str.substring(0,str.length()-1)+" 未审核");
  954. } else {
  955. String s = publicReleaseDetailsMapper.selectUserAdminByPrid(e.getId());
  956. e.setAdminExamine(s+" 未审核");
  957. }
  958. }
  959. }else if (e.getStatus()==0) {
  960. e.setAdminExamine("");
  961. }else {
  962. if (!publicExamines.isEmpty()){
  963. if (e.getStatus()==2){
  964. e.setAdminExamine("");
  965. }else{
  966. StringBuffer str =new StringBuffer();
  967. for (PublicExamine pe : publicExamines) {
  968. if (e.getId().equals(pe.getPrid())){
  969. str=str.append(pe.getAname());
  970. if (pe.getStatus()==0)str=str.append(" 未审核,");
  971. if (pe.getStatus()==1)str=str.append(" 已审核,");
  972. }
  973. if (str.length()>1) e.setAdminExamine(str.substring(0,str.length()-1));
  974. }
  975. }
  976. }
  977. }
  978. if(e.getType()==3){
  979. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(e.getId(), 0);
  980. if (publicAssistAdvices.isEmpty()){
  981. e.setPublicAssistAdvice(0);
  982. }else {
  983. e.setPublicAssistAdvice(publicAssistAdvices.size());
  984. }
  985. }else if(e.getType()==0){
  986. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(e.getId(), 1);
  987. if (publicAssistAdvices.isEmpty()){
  988. e.setPublicAssistAdvice(0);
  989. }else {
  990. e.setPublicAssistAdvice(publicAssistAdvices.size());
  991. }
  992. }
  993. }
  994. }
  995. }
  996. /**
  997. *
  998. * @param id
  999. * @param status 状态 0驳回 1发起 2同意 3 撤销 4技术驳回
  1000. * @param remarks
  1001. * @param examineType 0上级审核 1营销员审核 2技术审核 3二级审核
  1002. * @param evaluateType 0不存指导意见 1存指导意见
  1003. * @return
  1004. */
  1005. @Override
  1006. @Transactional
  1007. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Integer examineType,Integer evaluateType) {
  1008. PublicRelease p=new PublicRelease();
  1009. Date date =new Date();
  1010. String aid=TokenManager.getAdminId();
  1011. p.setId(id);
  1012. PublicRelease use=publicReleaseMapper.selectById(id);
  1013. if (use.getStatus()!=1) {
  1014. throw new BusinessException("只能修改发起的状态公出");
  1015. }
  1016. if((use.getTechStartProcess()==1||use.getTechStartProcess()==3)&&(examineType==0||examineType==1)){
  1017. if(use.getTechStartProcess()!=0) throw new BusinessException("技术公出先需营销审核。");
  1018. }
  1019. //当前审核人员
  1020. Admin ad=adminMapper.selectById(aid);
  1021. //公出负责人
  1022. Admin a;
  1023. Admin publicAdmin =adminMapper.selectById(use.getAid());
  1024. a=publicAdmin;
  1025. StringBuffer str=new StringBuffer();
  1026. str=str.append("(").append(ad.getName()).append(")");
  1027. StringBuffer content=new StringBuffer().append("[").append(use.getUserNames()).append("]公司的外出申请,");
  1028. //上级审核
  1029. if(examineType==0){
  1030. p.setStatus(status);
  1031. if (status==0){
  1032. addpublicLog(id, status, remarks);
  1033. str=str.append("驳回,");
  1034. if (use.getAssist()==2){
  1035. content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
  1036. }else {
  1037. content=content.append("未通过公出审核!");
  1038. }
  1039. if(use.getPublicType()>1){
  1040. p.setPublicType(1);
  1041. PublicExamine inpe=new PublicExamine();
  1042. inpe.setStatus(0);
  1043. inpe.setPrid(use.getId());
  1044. publicExamineMapper.updateStatusByPrid(inpe);
  1045. }
  1046. }else if(status==2){
  1047. str=str.append("同意,");
  1048. addpublicLog(id, status, remarks);
  1049. content=content.append("已通过审核!");
  1050. //新增二级审核
  1051. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(use.getAid());
  1052. adminPublicReviewerBos=adminPublicReviewerBos.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  1053. if (adminPublicReviewerBos.isEmpty()){
  1054. p.setStatus(2);
  1055. p.setProcessStatus(3);
  1056. //如果是协单公出主公出,在审核通过
  1057. if (use.getAssist()==1){
  1058. pushPublicReleaseAssist(use, p, date, a);
  1059. }else if (use.getAssist()==0){
  1060. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  1061. }
  1062. addpublicLog(id, status, "无需二级审核直接通过");
  1063. }else {
  1064. p.setStatus(1);
  1065. p.setProcessStatus(2);
  1066. }
  1067. }
  1068. str=str.append(remarks);
  1069. p.setAuditInfo(str.toString());
  1070. p.setAuditTime(date);
  1071. p.setRejectName(ad.getName());
  1072. sendNoticeAndSoucket(a.getId(),status,content.toString());
  1073. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(id);
  1074. //添加上级评价
  1075. if (evaluateType==1){
  1076. addUserSuperEvaluate(remarks, outPublicReleaseDetails, date);
  1077. }
  1078. //营销员审核
  1079. }else if (examineType==1){
  1080. //通知公出人切换成公出人审核人
  1081. if (status==2){
  1082. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(a.getId());
  1083. adminPublicReviewerBos=adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  1084. //审核通过
  1085. str=str.append("同意公出我的企业,").append(remarks);
  1086. content=content.append("已通过审核,请尽快审核。");
  1087. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  1088. int x=0;
  1089. for (PublicExamine pe : publicExamines) {
  1090. if (pe.getAid().equals(aid)){
  1091. pe.setStatus(1);
  1092. PublicExamine newp=new PublicExamine();
  1093. newp.setId(pe.getId());
  1094. newp.setStatus(1);
  1095. publicExamineMapper.updateByPrimaryKeySelective(newp);
  1096. x++;
  1097. }else {
  1098. if (pe.getStatus()==1){
  1099. x++;
  1100. }
  1101. }
  1102. }
  1103. if (x==publicExamines.size()){
  1104. p.setPublicType(2);
  1105. }
  1106. addpublicLog(id, status, str.toString());
  1107. //将信息发送给审核人
  1108. for (AdminPublicReviewerBo adminPublicReviewerBo : adminPublicReviewerBos) {
  1109. sendNoticeAndSoucket(adminPublicReviewerBo.getReviewerId(),status,content.toString());
  1110. }
  1111. }else if (status==0){//审核驳回
  1112. //切换通知人公出负责人
  1113. a=publicAdmin;
  1114. str=str.append("不同意公出我的企业,").append(remarks);;
  1115. content=content.append("未通过审核,请修改后重新发起。");
  1116. p.setPublicType(3);
  1117. p.setStatus(0);
  1118. p.setAuditInfo(str.toString());
  1119. p.setRejectName(ad.getName());
  1120. addpublicLog(id, 0, str.toString());
  1121. sendNoticeAndSoucket(a.getId(),status,content.toString());
  1122. }
  1123. }else if (examineType==2){
  1124. //技术审核
  1125. if (status==2){//审核通过
  1126. str=str.append("同意公出我的企业,").append(remarks);
  1127. content=content.append("已通过审核,请尽快审核。");
  1128. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  1129. int x=0;
  1130. for (PublicExamine pe : publicExamines) {
  1131. if (pe.getAid().equals(aid)){
  1132. pe.setStatus(1);
  1133. PublicExamine newp=new PublicExamine();
  1134. newp.setId(pe.getId());
  1135. newp.setStatus(1);
  1136. publicExamineMapper.updateByPrimaryKeySelective(newp);
  1137. x++;
  1138. }else {
  1139. if (pe.getStatus()==1){
  1140. x++;
  1141. }
  1142. }
  1143. }
  1144. if (x==publicExamines.size()){
  1145. p.setTechStartProcess(2);
  1146. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(a.getId());
  1147. adminPublicReviewerBos=adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  1148. for (AdminPublicReviewerBo adminPublicReviewerBo : adminPublicReviewerBos) {
  1149. sendNoticeAndSoucket(adminPublicReviewerBo.getReviewerId(),status,content.toString());
  1150. }
  1151. }
  1152. addpublicLog(id, status, str.toString());
  1153. }else if (status==0){
  1154. //审核驳回
  1155. //切换通知人公出负责人
  1156. a=publicAdmin;
  1157. str=str.append("不同意公出我的企业,").append(remarks);;
  1158. content=content.append("未通过审核,请修改后重新发起。");
  1159. p.setTechStartProcess(3);
  1160. p.setStatus(0);
  1161. p.setAuditInfo(str.toString());
  1162. p.setRejectName(ad.getName());
  1163. addpublicLog(id, 0, str.toString());
  1164. sendNoticeAndSoucket(a.getId(),status,content.toString());
  1165. }
  1166. }else if (examineType==3){
  1167. p.setStatus(status);
  1168. if (status==0){
  1169. addpublicLog(id, status, remarks);
  1170. str=str.append("驳回,");
  1171. if (use.getAssist()==2){
  1172. content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
  1173. }else {
  1174. content=content.append("未通过公出审核!");
  1175. }
  1176. if(use.getPublicType()>1){
  1177. p.setPublicType(1);
  1178. PublicExamine inpe=new PublicExamine();
  1179. inpe.setStatus(0);
  1180. inpe.setPrid(use.getId());
  1181. publicExamineMapper.updateStatusByPrid(inpe);
  1182. }
  1183. }else if(status==2){
  1184. str=str.append("同意,");
  1185. addpublicLog(id, status, remarks);
  1186. content=content.append("已通过审核!");
  1187. //新增二级审核
  1188. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(use.getAid());
  1189. adminPublicReviewerBos=adminPublicReviewerBos.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  1190. if (adminPublicReviewerBos.isEmpty()){
  1191. p.setStatus(2);
  1192. //如果是协单公出主公出,在审核通过
  1193. if (use.getAssist()==1){
  1194. pushPublicReleaseAssist(use, p, date, a);
  1195. }else if (use.getAssist()==0){
  1196. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  1197. }
  1198. }else {
  1199. //需要审核的情况下,看是否有审核通过
  1200. List<outPublicReleaseLog> outPublicReleaseLogs = publicReleaseLogMapper.listPublicReleaseLog(use.getId(), null);
  1201. //先看有没有驳回
  1202. int reject = 0;
  1203. //标记审核
  1204. AtomicInteger flag = new AtomicInteger();
  1205. List<outPublicReleaseLog> collect = outPublicReleaseLogs.stream().filter(e -> e.getStatus() == 0 || e.getStatus() == 4).collect(Collectors.toList());
  1206. //没有的的情况下看有没有审核 通过
  1207. long time;
  1208. if (collect.isEmpty()) {
  1209. time = 0;
  1210. } else {
  1211. time = collect.stream()
  1212. .mapToLong(e -> e.getCreateTime().getTime())
  1213. .max().orElse(0L);
  1214. }
  1215. //获取驳回或者撤销后的列表
  1216. Stream<outPublicReleaseLog> outPublicReleaseLogStream = outPublicReleaseLogs.stream().filter(e -> e.getCreateTime().getTime() > time);
  1217. outPublicReleaseLogStream.forEach(e -> {
  1218. outPublicReleaseLogs.stream().forEach(e1 -> {
  1219. if (e1.getAid().equals(e.getAid())) {
  1220. flag.set(1);
  1221. }
  1222. });
  1223. });
  1224. //有审核的情况下可以直接跳过
  1225. if (flag.get() == 1) {
  1226. p.setStatus(2);
  1227. p.setProcessStatus(3);
  1228. //如果是协单公出主公出,在审核通过
  1229. if (use.getAssist()==1){
  1230. pushPublicReleaseAssist(use, p, date, a);
  1231. }else if (use.getAssist()==0){
  1232. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  1233. }
  1234. addpublicLog(use.getId(), status, "审核人已审核,跳过二级审核");
  1235. }else {
  1236. adminPublicReviewerBos.forEach(e -> {
  1237. if(e.getAid()==aid){
  1238. p.setStatus(2);
  1239. p.setProcessStatus(3);
  1240. }
  1241. });
  1242. }
  1243. }
  1244. }
  1245. str=str.append(remarks);
  1246. p.setAuditInfo(str.toString());
  1247. p.setAuditTime(date);
  1248. p.setRejectName(ad.getName());
  1249. sendNoticeAndSoucket(a.getId(),status,content.toString());
  1250. }
  1251. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  1252. if (p.getStatus()!=null||p.getPublicType()!=null||p.getTechStartProcess()!=null){
  1253. publicReleaseMapper.update(p);
  1254. }
  1255. //驳回业务公出,需要取消标记首次面谈,取消本次面谈项目,取消标记有效面谈
  1256. if(status==0&&use.getType()==0){
  1257. pushPublicInterview(use);
  1258. }
  1259. if (a.getOpenId()!=null) {
  1260. if (remarks.length()>19) {
  1261. remarks=remarks.substring(0, 15)+"...";
  1262. }
  1263. Integer res=weChatUtils.addNotice(a.getOpenId(),status,p.getId(),date,my.getName(),remarks);
  1264. if (res!=0) {
  1265. sendEmail( my, a, status);
  1266. }
  1267. return res;
  1268. }
  1269. return 1;
  1270. }
  1271. /**
  1272. * 驳回的时候将首次面谈,本次面谈项目,有效面谈取消
  1273. * @param use
  1274. */
  1275. private void pushPublicInterview(PublicRelease use) {
  1276. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1277. for (OutPublicReleaseDetails e : outPublicReleaseDetails) {
  1278. //撤销后取消面谈项目
  1279. userInterviewProjectMapper.updateByPrdId(e.getId(),1);
  1280. //将有效面谈去掉
  1281. PublicReleaseDetails p=new PublicReleaseDetails();
  1282. p.setInterviewStatus(0);
  1283. p.setId(e.getId());
  1284. publicReleaseDetailsMapper.update(p);
  1285. //删除首次面谈数据
  1286. userFirstInterviewMapper.deleteByPrdId(e.getId());
  1287. }
  1288. }
  1289. /**
  1290. * 添加上级评价
  1291. * @param remarks
  1292. * @param outPublicReleaseDetails
  1293. * @param date
  1294. */
  1295. private void addUserSuperEvaluate(String remarks, List<OutPublicReleaseDetails> outPublicReleaseDetails, Date date) {
  1296. List<UserSuperEvaluate> addLsit=new ArrayList<>();
  1297. for (OutPublicReleaseDetails e : outPublicReleaseDetails) {
  1298. UserSuperEvaluate addUSE=new UserSuperEvaluate();
  1299. addUSE.setAid(TokenManager.getAdminId());
  1300. addUSE.setUid(e.getUid());
  1301. addUSE.setContent(remarks);
  1302. addUSE.setCreateTime(date);
  1303. addLsit.add(addUSE);
  1304. }
  1305. userSuperEvaluateMapper.insertBatch(addLsit);
  1306. }
  1307. @Override
  1308. public Object updateAssistExamine(Integer id, Integer status, String remarks,Integer evaluateType) {
  1309. PublicRelease use = publicReleaseMapper.selectById(id);
  1310. if (use.getAssistProcess()!=2){
  1311. throw new BusinessException("该公出不是待协单审核的公出。");
  1312. }
  1313. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainIdAndReviewer(id, TokenManager.getAdminId());
  1314. String content=use.getUserNames()+"公司的外出协单申请";
  1315. PublicRelease newPublic=new PublicRelease();
  1316. if (status==0){
  1317. content+="已被驳回。";
  1318. newPublic.setId(use.getId());
  1319. newPublic.setStatus(status);
  1320. publicReleaseMapper.update(newPublic);
  1321. addpublicLog(id, status, remarks);
  1322. for (PublicRelease e : publicReleases) {
  1323. PublicRelease newPublic2=new PublicRelease();
  1324. newPublic2.setId(e.getId());
  1325. newPublic2.setStatus(status);
  1326. publicReleaseMapper.update(newPublic2);
  1327. addpublicLog(e.getId(), status, remarks);
  1328. }
  1329. }else if(status==2){
  1330. content+="已通过审核。";
  1331. addpublicLog(id, status, remarks);
  1332. for (PublicRelease e : publicReleases) {
  1333. PublicRelease newPublic2=new PublicRelease();
  1334. newPublic2.setId(e.getId());
  1335. newPublic2.setStatus(status);
  1336. publicReleaseMapper.update(newPublic2);
  1337. addpublicLog(e.getId(), status, remarks);
  1338. }
  1339. //审核需看是否所有人审核
  1340. List<PublicRelease> newList = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  1341. int count = 0;
  1342. for (PublicRelease e : newList) {
  1343. if (e.getStatus()==2){
  1344. count++;
  1345. }
  1346. }
  1347. if(count==newList.size()){
  1348. PublicRelease newPublic2=new PublicRelease();
  1349. newPublic2.setId(use.getId());
  1350. newPublic2.setStatus(2);
  1351. publicReleaseMapper.update(newPublic2);
  1352. sendNoticeAndSoucket(use.getAid(),status,content.toString());
  1353. }else {
  1354. PublicRelease newPublic2=new PublicRelease();
  1355. newPublic2.setId(use.getId());
  1356. newPublic2.setStatus(1);
  1357. publicReleaseMapper.update(newPublic2);
  1358. }
  1359. if (evaluateType==1){
  1360. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(id);
  1361. addUserSuperEvaluate(remarks, outPublicReleaseDetails, new Date());
  1362. }
  1363. }
  1364. return 1;
  1365. }
  1366. @Override
  1367. public Object assistUnaudited() {
  1368. String aid=TokenManager.getAdminId();
  1369. int unaudited = publicReleaseMapper.selectCountByUnaudited(aid);
  1370. int assistUnaudited = publicReleaseMapper.selectCountByAssistUnaudited(aid);
  1371. int otherUnaudited = publicReleaseMapper.selectCountByOtherUnaudited(aid);
  1372. Map<String,Object> i=new HashMap<>();
  1373. i.put("unaudited",unaudited);
  1374. i.put("assistUnaudited",assistUnaudited);
  1375. i.put("otherUnaudited",otherUnaudited);
  1376. return i;
  1377. }
  1378. @Override
  1379. public boolean checkPublicReviewer(InputPublicRelease in) {
  1380. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(TokenManager.getAdminId());
  1381. if (adminPublicReviewerBos.isEmpty()){
  1382. return true;
  1383. }
  1384. return false;
  1385. }
  1386. @Override
  1387. public int pushLimitUser(String uid, Integer hours) {
  1388. User user = userMapper.queryById(uid);
  1389. if (!user.getAid().equals(TokenManager.getAdminId())){
  1390. return 0;
  1391. }
  1392. long l = System.currentTimeMillis();
  1393. if (hours==null)hours=2;
  1394. l=l+hours*60*60*1000;
  1395. UserLimitCheck userLimitCheck = userLimitCheckMapper.selectByUid(uid);
  1396. if (userLimitCheck==null){
  1397. UserLimitCheck ulc=new UserLimitCheck();
  1398. ulc.setUid(uid);
  1399. ulc.setCheckTime(new Date(l));
  1400. userLimitCheckMapper.insert(ulc);
  1401. }else {
  1402. userLimitCheck.setCheckTime(new Date(l));
  1403. userLimitCheckMapper.update(userLimitCheck);
  1404. }
  1405. return 1;
  1406. }
  1407. @Override
  1408. public boolean checkUserArchives(String uid) {
  1409. User user = userMapper.queryById(uid);
  1410. UserArchives userArchives = userArchivesMapper.queryByUid(uid);
  1411. if (user.getNewChannel()==0){
  1412. if (userArchives==null||
  1413. StringUtils.isBlank(userArchives.getFinancialData())||
  1414. StringUtils.isBlank(userArchives.getEarlyCommunication())||
  1415. StringUtils.isBlank(userArchives.getInterviewIdeas())){
  1416. return false;
  1417. }
  1418. }else {
  1419. OrganizationIdentity organizationIdentity = organizationIdentityMapper.selectOrgIdentityByUserId(uid);
  1420. Integer i = organizationContactBookMapper.checkContacts(uid, null, user.getAid());
  1421. if (i==null||i<1){
  1422. return false;
  1423. }
  1424. if (userArchives==null||
  1425. userArchives.getEnterpriseCount()==null||
  1426. StringUtils.isBlank(organizationIdentity.getIntendedProject())||
  1427. StringUtils.isBlank(userArchives.getChannelIndicators())||
  1428. StringUtils.isBlank(userArchives.getInterviewDistribution())||
  1429. StringUtils.isBlank(userArchives.getInterviewIdeas())){
  1430. return false;
  1431. }
  1432. }
  1433. return true;
  1434. }
  1435. @Override
  1436. public Object updateMaxDuration(String orderNo, Double maxDuration,String remarks) {
  1437. TOrderPublicReleaseCount in =new TOrderPublicReleaseCount();
  1438. TOrderPublicReleaseCount use = tOrderPublicReleaseCountMapper.selectByOrderNo(orderNo);
  1439. if (use.getMaxProcess()==1||use.getMaxProcess()==2||use.getMaxProcess()==3){
  1440. throw new BusinessException("该最大公出已经是待审核的状态。");
  1441. }
  1442. in.setOrderNo(orderNo);
  1443. in.setMaxDuration(maxDuration);
  1444. in.setMaxProcess(1);
  1445. in.setMaxStatus(1);
  1446. addOrderPublicReleaseLog(orderNo,0,0,remarks,use.getMaxDuration(),maxDuration);
  1447. PublicConfig publicConfig = publicConfigMapper.queryById(1);
  1448. TOrderNewBo order = tOrderNewMapper.getSaleIdByOno(orderNo);
  1449. StringBuilder str=new StringBuilder();
  1450. str.append("合同编号[").append(order.getContractNo()).append("]最大公出限制审核");
  1451. str.append("需要审核,请尽快审核。");
  1452. if (publicConfig.getTechAuditorStauts()==0){
  1453. if (publicConfig.getFinanceAuditorStauts()==0){
  1454. if (publicConfig.getOtherAuditorStauts()==0){
  1455. //当3个都未设置直接通过
  1456. in.setMaxProcess(5);
  1457. addOrderPublicReleaseLog(orderNo,1,5,"未设置审核人直接全部通过");
  1458. }else {
  1459. addNoticeAndEmail(publicConfig.getOtherAuditor(),NoticeStatus.PUBLIC_MAX_DURATION.getCode(), str.toString());
  1460. }
  1461. }else {
  1462. addNoticeAndEmail(publicConfig.getFinanceAuditor(),NoticeStatus.PUBLIC_MAX_DURATION.getCode(), str.toString());
  1463. }
  1464. }else {
  1465. addNoticeAndEmail(publicConfig.getTechAuditor(),NoticeStatus.PUBLIC_MAX_DURATION.getCode(), str.toString());
  1466. }
  1467. tOrderPublicReleaseCountMapper.updateByOrderNo(in);
  1468. return 1;
  1469. }
  1470. @Override
  1471. public Object pushExamineMaxDuration(String orderNo,Integer status, String remarks) {
  1472. TOrderPublicReleaseCount in =new TOrderPublicReleaseCount();
  1473. TOrderPublicReleaseCount use = tOrderPublicReleaseCountMapper.selectByOrderNo(orderNo);
  1474. in.setOrderNo(orderNo);
  1475. PublicConfig publicConfig = publicConfigMapper.queryById(1);
  1476. TOrderNewBo order = tOrderNewMapper.getSaleIdByOno(orderNo);
  1477. in.setMaxProcess(use.getMaxProcess());
  1478. String aid=TokenManager.getAdminId();
  1479. if (use.getMaxProcess()==1){
  1480. if (publicConfig.getTechAuditorStauts()==1&&TokenManager.getAdminId().equals(publicConfig.getTechAuditor())) {
  1481. addOrderPublicReleaseLog(orderNo,status,1,remarks);
  1482. }else {
  1483. throw new BusinessException("审核人错误,必须是设置的审核人员才能审核。");
  1484. }
  1485. }else if (use.getMaxProcess()==2){
  1486. if (publicConfig.getFinanceAuditorStauts()==1&&TokenManager.getAdminId().equals(publicConfig.getFinanceAuditor())) {
  1487. addOrderPublicReleaseLog(orderNo,status,2,remarks);
  1488. }else {
  1489. throw new BusinessException("审核人错误,必须是设置的审核人员才能审核。");
  1490. }
  1491. }else if (use.getMaxProcess()==3){
  1492. if (publicConfig.getOtherAuditorStauts()==1&&TokenManager.getAdminId().equals(publicConfig.getOtherAuditor())) {
  1493. addOrderPublicReleaseLog(orderNo,status,3,remarks);
  1494. }else {
  1495. throw new BusinessException("审核人错误,必须是设置的审核人员才能审核。");
  1496. }
  1497. }
  1498. pushPublicConfigSendNoticeAndEmail(publicConfig, in, aid, order, status);
  1499. return tOrderPublicReleaseCountMapper.updateByOrderNo(in);
  1500. }
  1501. private void pushPublicConfigSendNoticeAndEmail(PublicConfig publicConfig, TOrderPublicReleaseCount in, String aid, TOrderNewBo order,Integer status) {
  1502. StringBuilder str=new StringBuilder();
  1503. str.append("合同编号[").append(order.getContractNo()).append("]最大公出限制审核");
  1504. int noticeStatus=0;
  1505. if (status==1){
  1506. noticeStatus=NoticeStatus.PUBLIC_MAX_DURATION_YES.getCode();
  1507. }else if (status==2){
  1508. noticeStatus=NoticeStatus.PUBLIC_MAX_DURATION_NO.getCode();
  1509. }
  1510. //处理当前审核状态确定发送人
  1511. pushPublicConfig(publicConfig, in);
  1512. String str1="需要审核,请尽快审核。";
  1513. if (in.getMaxProcess()==2){
  1514. aid = publicConfig.getFinanceAuditor();
  1515. } else if (in.getMaxProcess()==3){
  1516. aid = publicConfig.getOtherAuditor();
  1517. }
  1518. else if (in.getMaxProcess()==5){
  1519. str1="审核通过。";
  1520. aid = order.getSalesmanId();
  1521. }
  1522. str.append(str1);
  1523. addNoticeAndEmail(aid, noticeStatus, str.toString());
  1524. if (in.getMaxProcess()==5){
  1525. pushCompleteMaxDuration( in.getOrderNo());
  1526. }
  1527. }
  1528. private void pushPublicConfig(PublicConfig config, TOrderPublicReleaseCount in) {
  1529. if (in.getMaxProcess()==1){
  1530. if (config.getFinanceAuditorStauts()==0){
  1531. if (config.getOtherAuditorStauts()==0){
  1532. in.setMaxProcess(5);
  1533. }else {
  1534. in.setMaxProcess(3);
  1535. }
  1536. }else {
  1537. in.setMaxProcess(2);
  1538. }
  1539. }else if (in.getMaxProcess()==2){
  1540. if (config.getOtherAuditorStauts()==0){
  1541. in.setMaxProcess(5);
  1542. }else {
  1543. in.setMaxProcess(3);
  1544. }
  1545. } else if (in.getMaxProcess()==3) {
  1546. in.setMaxProcess(5);
  1547. }
  1548. }
  1549. @Override
  1550. public Object maxDurationLog(String orderNo) {
  1551. return orderPublicReleaseLogMapper.queryByOrderNo(orderNo);
  1552. }
  1553. @Override
  1554. public Object updatePublicConfig(PublicConfig in) {
  1555. in.setId(1);
  1556. return publicConfigMapper.update(in);
  1557. }
  1558. @Override
  1559. public Object getPublicConfig() {
  1560. return publicConfigMapper.selectDetails();
  1561. }
  1562. private void pushCompleteMaxDuration(String orderNo) {
  1563. List<OrderPublicReleaseLog> orderPublicReleaseLogs = orderPublicReleaseLogMapper.queryByOrderNo(orderNo);
  1564. List<PublicRelease> publicReleases = publicReleaseMapper.selectByOrderNo(orderNo);
  1565. for (PublicRelease e : publicReleases) {
  1566. //只比对审核中的
  1567. if (e.getStatus()==1){
  1568. boolean flag = false;
  1569. //审核中的公出审核人,是公出审核人
  1570. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(e.getAid());
  1571. for (OrderPublicReleaseLog log : orderPublicReleaseLogs) {
  1572. for (AdminPublicReviewerBo e2 : adminPublicReviewerBos) {
  1573. if (log.getAuditor().equals(e2.getReviewerId())){
  1574. flag = true;
  1575. break;
  1576. }
  1577. }
  1578. }
  1579. if (flag){
  1580. //有审核人,需要审核
  1581. PublicRelease newP=new PublicRelease();
  1582. newP.setId(e.getId());
  1583. newP.setStatus(2);
  1584. addpublicLog(e.getId(),2,"公出审核人已经审核最大公出小时,跳过审核");
  1585. addNoticeAndEmail(e.getAid(), NoticeStatus.PUBLIC_RELEASE_YES.getCode(), "公出审核人已经审核最大公出小时,跳过审核");
  1586. publicReleaseMapper.update(e);
  1587. }
  1588. }
  1589. }
  1590. }
  1591. private void addNoticeAndEmail(String aid, Integer noticeStatus, String remarks) {
  1592. asyncUtils.addNoticAndEmail(noticeStatus,aid,remarks);
  1593. }
  1594. private void addNotice(String aid, Integer noticeType, String content) {
  1595. Notice n =new Notice();
  1596. n.setId(UUID.randomUUID().toString());
  1597. n.setAid(aid);
  1598. n.setNoticeType(noticeType);
  1599. n.setContent(content);
  1600. n.setReaded(0);//未读
  1601. asyncUtils.addNotice(n);
  1602. }
  1603. private void addOrderPublicReleaseLog(String orderNo, Integer status, Integer process, String remarks) {
  1604. addOrderPublicReleaseLog(orderNo,status,process,remarks,null,null);
  1605. }
  1606. private void addOrderPublicReleaseLog(String orderNo, Integer status, Integer process, String remarks,Double useDuration,Double newDuration) {
  1607. Admin admin = adminMapper.selectById(TokenManager.getAdminId());
  1608. OrderPublicReleaseLog log = new OrderPublicReleaseLog();
  1609. log.setOrderNo(orderNo);
  1610. log.setProcessStatus(process);
  1611. log.setStatus(status);
  1612. log.setAuditor(admin.getId());
  1613. log.setAuditorName(admin.getName());
  1614. log.setRemarks(remarks);
  1615. log.setNewDuration(newDuration);
  1616. log.setUseDuration(useDuration);
  1617. log.setCreateTime(new Date());
  1618. orderPublicReleaseLogMapper.insert(log);
  1619. }
  1620. private void addpublicLog(Integer id, Integer status, String remarks) {
  1621. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  1622. publicReleaseLogMapper.insertSelective(log);
  1623. }
  1624. @Override
  1625. public int pushTechReject(Integer id, String remarks) {
  1626. Integer status=0;
  1627. PublicRelease use=publicReleaseMapper.selectById(id);
  1628. PublicRelease mainPublic= publicReleaseMapper.selectById(use.getMainId());
  1629. Admin ad=adminMapper.selectById(TokenManager.getAdminId());
  1630. StringBuffer str=new StringBuffer();
  1631. if (use.getAssist()!=2){
  1632. throw new BusinessException("只有技术公出能发起技术驳回");
  1633. }
  1634. str=str.append("拒绝技术协单,").append(remarks);
  1635. PublicRelease newMain=new PublicRelease();
  1636. newMain.setId(mainPublic.getId());
  1637. newMain.setStatus(4);
  1638. newMain.setRejectName(ad.getName());
  1639. newMain.setAuditInfo(str.toString());
  1640. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  1641. publicReleaseMapper.update(newMain);
  1642. PublicRelease up=new PublicRelease();
  1643. up.setId(id);
  1644. up.setAuditInfo(str.toString());
  1645. up.setStatus(3);
  1646. addpublicLog(id, status, remarks);
  1647. publicReleaseMapper.update(up);
  1648. deleteAssistantPulicRelease(use,null);
  1649. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  1650. }
  1651. /**
  1652. * 新增日志、站内信、微信提醒
  1653. * @param id 日志公出编号
  1654. * @param aid 接受者
  1655. * @param remarks 日志内容
  1656. * @param status 0驳回
  1657. * @return
  1658. */
  1659. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  1660. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  1661. Admin a = adminMapper.selectById(TokenManager.getAdminId());
  1662. if (my.getOpenId()!=null) {
  1663. if (remarks.length()>19) {
  1664. remarks=remarks.substring(0, 15)+"...";
  1665. }
  1666. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  1667. }else {
  1668. sendEmail( my, a, status);
  1669. return 1;
  1670. }
  1671. }
  1672. /**
  1673. *
  1674. * @param use 原始公出信息
  1675. * @param status 状态
  1676. * @param date 时间
  1677. * @param a
  1678. */
  1679. private void pushPublicReleaseAssist(PublicRelease use,PublicRelease update,Date date,Admin a) {
  1680. if (use.getAssistAid()!=null){
  1681. updatePushassist(use, update, date,a);
  1682. if(use.getAssistantAid()!=null){
  1683. updatepushAssistant(use,a);
  1684. }
  1685. }
  1686. }
  1687. /**
  1688. * 处理技术协单
  1689. * @param use
  1690. * @param status
  1691. * @param date
  1692. */
  1693. private void updatePushassist(PublicRelease use, PublicRelease updatePR, Date date, Admin a) {
  1694. //协单
  1695. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  1696. String []ss= use.getAssistAid().split(",");
  1697. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  1698. for (PublicRelease out : list) {
  1699. boolean flag=false;
  1700. for (String s : ss) {
  1701. if (out.getAid().equals(s)){
  1702. flag=true;
  1703. break;
  1704. }
  1705. }
  1706. //不存在则取消公出
  1707. if (!flag){
  1708. PublicRelease in = new PublicRelease();
  1709. in.setId(out.getId());
  1710. in.setStatus(3);
  1711. publicReleaseMapper.update(in);
  1712. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  1713. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  1714. publicReleaseLogMapper.insertSelective(log);
  1715. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  1716. }else {
  1717. //存在则修改公出
  1718. PublicRelease np = new PublicRelease();
  1719. BeanUtils.copyProperties(use,np);
  1720. np.setId(out.getId());
  1721. np.setMainId(null);
  1722. np.setType(null);
  1723. np.setAssist(2);
  1724. pushAssist(use, date, a, out, np);
  1725. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  1726. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  1727. publicReleaseLogMapper.insertSelective(log);
  1728. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  1729. }
  1730. }
  1731. //有新增则新增公出
  1732. for (String s : ss) {
  1733. boolean flag2 = false;
  1734. for (PublicRelease o : list) {
  1735. if (s.equals(o.getAid())) {
  1736. flag2 = true;
  1737. }
  1738. }
  1739. if (!flag2) {
  1740. PublicRelease np = new PublicRelease();
  1741. BeanUtils.copyProperties(use,np);
  1742. np.setAssist(2);
  1743. np.setAid(s);
  1744. //协单审核,判定是否跳过的逻辑
  1745. np.setType(3);
  1746. np.setMainId(use.getId());
  1747. np.setId(null);
  1748. pushAssist(use, date, a, np, np);
  1749. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  1750. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  1751. sendNoticeAndSoucket(s,np.getStatus(),str.toString());
  1752. publicReleaseLogMapper.insertSelective(log);
  1753. }
  1754. }
  1755. //判定是审核还是完成,取决于协单是否通过
  1756. List<PublicRelease> newList = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  1757. int count = 0;
  1758. for (PublicRelease e : newList) {
  1759. //如果是完成或者拒绝则标记,全中断则修改状态
  1760. if (e.getStatus()==2||e.getStatus()==3){
  1761. count++;
  1762. }
  1763. }
  1764. if(count==newList.size()){
  1765. updatePR.setStatus(2);
  1766. updatePR.setAssistProcess(4);
  1767. }else {
  1768. updatePR.setStatus(1);
  1769. updatePR.setAssistProcess(2);
  1770. }
  1771. }
  1772. private void pushAssist(PublicRelease use, Date date, Admin a, PublicRelease out, PublicRelease np) {
  1773. //协单审核,判定是否跳过的逻辑
  1774. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  1775. adminPublicReviewerBos = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  1776. //协单人
  1777. Admin admin = adminMapper.selectById(out.getAid());
  1778. int x=pushAssist(np, use,adminPublicReviewerBos);
  1779. if (np.getId() == null){
  1780. publicReleaseMapper.insertSelective(np);
  1781. }else {
  1782. np.setAid(null);
  1783. publicReleaseMapper.update(np);
  1784. }
  1785. updatePublicReleaseDtails(use, np);
  1786. if (x==2||x==3){
  1787. String remarks="";
  1788. if (x==2){
  1789. remarks="协单未设置审核人,自动通过";
  1790. }else if (x==3){
  1791. remarks="协单审核人重复,自动通过";
  1792. }
  1793. PublicReleaseLog log2 = new PublicReleaseLog(np.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1794. publicReleaseLogMapper.insertSelective(log2);
  1795. PublicReleaseLog log3 = new PublicReleaseLog(use.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1796. publicReleaseLogMapper.insertSelective(log3);
  1797. }
  1798. // 通知协单上级审核
  1799. if(x==1){
  1800. for (AdminPublicReviewerBo e : adminPublicReviewerBos) {
  1801. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]发起了协单审核,协单人:").append(admin.getName()).append("。");
  1802. sendNoticeAndSoucket(e.getAid(), np.getStatus(),str.toString());
  1803. //协单通知人
  1804. Admin ad = adminMapper.selectById(e.getAid());
  1805. weChatUtils.addNotice(ad.getOpenId(),1, use.getId(), date, a.getName(),str.toString());
  1806. }
  1807. }
  1808. }
  1809. /**
  1810. * 协单审核判定是否跳过的逻辑
  1811. * 如果未设置跳过审核,如果已审核跳过
  1812. *
  1813. * @param s 协单人编号
  1814. * @param np 新协单公出信息
  1815. * @param use 原公出信息
  1816. */
  1817. private int pushAssist( PublicRelease np, PublicRelease use,List<AdminPublicReviewerBo> collect) {
  1818. int res=0;
  1819. if (!collect.isEmpty()){
  1820. //公出发起人
  1821. List<outPublicReleaseLog> outPublicReleaseLogs = publicReleaseLogMapper.listPublicReleaseLog(use.getId(), null);
  1822. List<outPublicReleaseLog> collect1 = outPublicReleaseLogs.stream().filter(e -> e.getStatus() == 2).collect(Collectors.toList());
  1823. boolean flag = false;
  1824. for (AdminPublicReviewerBo e : collect) {
  1825. for (outPublicReleaseLog log : collect1) {
  1826. if (log.getAid().equals(e.getReviewerId())){
  1827. flag=true;
  1828. break;
  1829. }
  1830. }
  1831. if(flag){
  1832. break;
  1833. }
  1834. }
  1835. if (flag){
  1836. np.setStatus(2);
  1837. res=3;
  1838. }else {
  1839. np.setStatus(1);
  1840. res=1;
  1841. }
  1842. }else {
  1843. np.setStatus(2);
  1844. res=2;
  1845. }
  1846. //res 1=未完成全部审核,2=未设置跳过审核,3=已审核全部跳过
  1847. return res;
  1848. }
  1849. private void updatePublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1850. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1851. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPrid(in.getId());
  1852. //打卡信息重新梳理
  1853. //查找新增的
  1854. for (OutPublicReleaseDetails out : list) {
  1855. boolean flag=true;
  1856. for (OutPublicReleaseDetails out2 : list2) {
  1857. if (out.getUid().equals(out2.getUid())){
  1858. flag=false;
  1859. }
  1860. }
  1861. if (flag){
  1862. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1863. BeanUtils.copyProperties(out,prd);
  1864. prd.setId(null);
  1865. prd.setPrid(in.getId());
  1866. prd.setClockIn(0);
  1867. prd.setClockInTime(null);
  1868. prd.setClockInRemarks(null);
  1869. prd.setUfid(null);
  1870. publicReleaseDetailsMapper.insertSelective(prd);
  1871. }
  1872. }
  1873. for (OutPublicReleaseDetails out2 : list2) {
  1874. boolean flag=true;
  1875. for (OutPublicReleaseDetails out : list) {
  1876. if (out2.getUid().equals(out.getUid())){
  1877. flag=false;
  1878. }
  1879. }
  1880. if (flag){
  1881. publicReleaseDetailsMapper.deleteById(out2.getId());
  1882. }
  1883. }
  1884. //信息补充,修改时没有打卡信息
  1885. if(in.getValidDate()==null)in.setValidDate(use.getValidDate());
  1886. //最后再来处理打卡信息
  1887. addPublicReleaseDateClock(in);
  1888. }
  1889. private void addpublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1890. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1891. for (OutPublicReleaseDetails out : list) {
  1892. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1893. BeanUtils.copyProperties(out,prd);
  1894. prd.setId(null);
  1895. prd.setPrid(in.getId());
  1896. prd.setClockIn(0);
  1897. prd.setClockInTime(null);
  1898. prd.setMainStatus(0);
  1899. publicReleaseDetailsMapper.insertSelective(prd);
  1900. }
  1901. addPublicReleaseDateClock(in);
  1902. }
  1903. /**
  1904. * 处理技术助手
  1905. * @param use
  1906. */
  1907. private void updatepushAssistant(PublicRelease use,Admin a) {
  1908. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  1909. for (PublicRelease p : uselist) {
  1910. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  1911. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  1912. p.setStatus(2);
  1913. p.setAssistantAid(use.getAssistantAid());
  1914. p.setAssistantName(use.getAssistantName());
  1915. p.setUserNames(use.getUserNames());
  1916. publicReleaseMapper.update(p);
  1917. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  1918. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  1919. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  1920. publicReleaseLogMapper.insertSelective(log);
  1921. }
  1922. }
  1923. @Override
  1924. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  1925. List<outPublicReleaseLog> list=new ArrayList<>();
  1926. List<outPublicReleaseLog> log=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  1927. PublicRelease e = publicReleaseMapper.selectById(id);
  1928. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
  1929. if (e.getStatus()==1){
  1930. outPublicReleaseLog outPublicReleaseLog = new outPublicReleaseLog();
  1931. outPublicReleaseLog.setStatus(6);
  1932. List<AdminPublicReviewerBo> adminPublicReviewerBos=null;
  1933. if (e.getType()==3){
  1934. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e.getAid());
  1935. StringBuffer str =new StringBuffer();
  1936. for (AdminPublicReviewerBo ap : adminPublicReviewerBos) {
  1937. if(ap.getType()==1)str=str.append(ap.getReviewerName()+",");
  1938. }
  1939. if(str.length()>1){
  1940. outPublicReleaseLog.setAname(str.substring(0,str.length()-1));
  1941. list.add(outPublicReleaseLog);
  1942. }
  1943. }else {
  1944. if (((e.getPublicType()==0||e.getPublicType()==2)
  1945. &&(e.getTechStartProcess()==0||e.getTechStartProcess()==2))
  1946. &&(e.getAssistProcess()==0||e.getAssistProcess()==1)
  1947. ){
  1948. StringBuffer str =new StringBuffer();
  1949. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e.getAid());
  1950. for (AdminPublicReviewerBo ap : adminPublicReviewerBos) {
  1951. if(ap.getType()==0)str=str.append(ap.getReviewerName()+",");
  1952. }
  1953. if(str.length()>1){
  1954. outPublicReleaseLog.setAname(str.substring(0,str.length()-1));
  1955. list.add(outPublicReleaseLog);
  1956. }
  1957. }else if (e.getType()==0&&e.getAssistProcess()==2){
  1958. //获取技术协单
  1959. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(e.getId(), null, null);
  1960. StringBuffer str =new StringBuffer();
  1961. for (PublicRelease e2 : publicReleases) {
  1962. if (e2.getStatus()==1){
  1963. adminPublicReviewerBos= adminPublicReviewerMapper.selectByAid(e2.getAid());
  1964. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e1 -> e1.getType() == 1).collect(Collectors.toList());
  1965. for (AdminPublicReviewerBo e1 : collect) {
  1966. str.append(e1.getReviewerName()+",");
  1967. }
  1968. }
  1969. }
  1970. if(str.length()>1){
  1971. outPublicReleaseLog.setAname(str.substring(0,str.length()-1));
  1972. list.add(outPublicReleaseLog);
  1973. }
  1974. } else {
  1975. String s = publicReleaseDetailsMapper.selectUserAdminByPrid(e.getId());
  1976. outPublicReleaseLog.setAname(s);
  1977. list.add(outPublicReleaseLog);
  1978. }
  1979. }
  1980. }
  1981. list.addAll(log);
  1982. return list;
  1983. }
  1984. @Override
  1985. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  1986. if (clockIn == null) clockIn = 1;
  1987. PublicRelease use = publicReleaseMapper.selectById(id);
  1988. if (use.getPublicType()==1||use.getPublicType()==3) {
  1989. return -1;
  1990. }
  1991. if (use.getStatus()!=2){
  1992. return -2;
  1993. }
  1994. if(use.getType()==3){
  1995. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(id, 0);
  1996. if(publicAssistAdvices.isEmpty()){
  1997. return -3;
  1998. }
  1999. }
  2000. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  2001. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  2002. pushDateClockDetails(prdList,prdcList);
  2003. String str = "";
  2004. Date date = new Date();
  2005. boolean flag=false;
  2006. Integer clockCount=0;
  2007. PublicReleaseClock pc=new PublicReleaseClock();
  2008. pc.setPrid(id);
  2009. pc.setPhotoUrl(photoUrl);
  2010. pc.setClockInTime(date);
  2011. for (OutPublicReleaseDetails prd : prdList) {
  2012. if (prd.getUid().equals(uid)){
  2013. String aid = TokenManager.getAdminId();
  2014. pc.setPrdid(prd.getId());
  2015. pc.setLatitude(prd.getLatitude());
  2016. pc.setLongitude(prd.getLongitude());
  2017. pc.setDistrictName(prd.getDistrictName());
  2018. prd.setClockInRemarks(clockInRemarks);
  2019. prd.setPhotoUrl(photoUrl);
  2020. prd.setClockInTime(date);
  2021. int count=0;
  2022. for (PublicReleaseDateClock ep : prd.getPrdcList()) {
  2023. if (DateUtils.isSameDay(prd.getClockInTime(), ep.getClockInTime())){
  2024. if (ep.getStatus()==0){
  2025. ep.setStatus(1);
  2026. FollowBusinessBo fbb = new FollowBusinessBo();
  2027. fbb.setUid(prd.getUid());
  2028. fbb.setContactType("5");
  2029. fbb.setResult(use.getRemarks());
  2030. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  2031. if (ub != null) {
  2032. fbb.setOcbId(ub.getId());
  2033. }
  2034. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  2035. String ufid = UUID.randomUUID().toString();
  2036. prd.setUfid(ufid);
  2037. customerService.addFollow(fbb, ufid, prd.getMainStatus(),0,null);
  2038. if (clockIn==1){
  2039. str = "公出人员打卡";
  2040. }else if (clockIn==2) {
  2041. str = "公出人员异常打卡";
  2042. }
  2043. count++;
  2044. publicReleaseDateClockMapper.updateByPrimaryKeySelective(ep);
  2045. }else {
  2046. if (clockIn==1){
  2047. str = "刷新打卡";
  2048. }else if (clockIn==2) {
  2049. str = "刷新打卡,公出人员异常打卡";
  2050. }
  2051. count++;
  2052. }
  2053. }else {
  2054. if (ep.getStatus()==1){
  2055. count++;
  2056. }
  2057. }
  2058. }
  2059. if(prd.getPrdcList().size() == count){
  2060. prd.setClockIn(1);
  2061. }
  2062. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  2063. log.setPhotoUrl(photoUrl);
  2064. publicReleaseLogMapper.insertSelective(log);
  2065. publicReleaseDetailsMapper.update(prd);
  2066. flag=true;
  2067. clockCount++;
  2068. }else if (prd.getClockIn()==1){
  2069. clockCount++;
  2070. }
  2071. }
  2072. if (prdList.size()==clockCount){
  2073. PublicRelease newp=new PublicRelease();
  2074. newp.setId(id);
  2075. newp.setClockIn(1);
  2076. publicReleaseMapper.update(newp);
  2077. }
  2078. publicReleaseClockMapper.insertSelective(pc);
  2079. if (!flag){
  2080. return 0;
  2081. }
  2082. return 1;
  2083. }
  2084. @Override
  2085. public OutPublicRelease dtails(Integer id) {
  2086. String aid=TokenManager.getAdminId();
  2087. //如果不是本人和审核人员则不返回信息
  2088. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  2089. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  2090. out.setPeList(ps);
  2091. List<AdminPublicReviewerBo> adminPublicReviewerBos=null;
  2092. if(out!=null){
  2093. //详情查看权限
  2094. boolean flag=false;
  2095. //客户文档查看权限
  2096. boolean flag2=false;
  2097. //自己、审核人员与部门负责人可以查看
  2098. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  2099. //获取设置公出最大值的
  2100. if(out.getType()==1){
  2101. TOrderPublicReleaseCount tOrderPublicReleaseCount = tOrderPublicReleaseCountMapper.selectByOrderNo(out.getOrderNo());
  2102. if(tOrderPublicReleaseCount!=null){
  2103. out.setMaxDuration(BigDecimal.valueOf(tOrderPublicReleaseCount.getMaxDuration()));
  2104. out.setMaxProcess(tOrderPublicReleaseCount.getMaxProcess());
  2105. out.setMaxType(tOrderPublicReleaseCount.getMaxType());
  2106. }else {
  2107. out.setMaxDuration(BigDecimal.ZERO);
  2108. out.setMaxProcess(0);
  2109. out.setMaxType(0);
  2110. }
  2111. }
  2112. //自己、部门负责人与技术财税管理员可以查看
  2113. if (aid.equals( out.getAid())||
  2114. aid.equals(ab.getDepManager())||
  2115. TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  2116. flag=true;
  2117. }
  2118. //技术公出 财务与技术管理员可以查看
  2119. if(out.getType()==1&&
  2120. ( TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||
  2121. TokenManager.hasRole(AFTConstants.TECH_ADMIN))){
  2122. flag=true;
  2123. }
  2124. //自己可以查看文档
  2125. if (aid.equals(out.getAid())){
  2126. if (out.getType()==0||out.getType() == 1){
  2127. flag2=true;
  2128. }
  2129. }
  2130. out.setMyExamine(0);
  2131. if (out.getType()==0||out.getType()==1||out.getType()==2){
  2132. if (adminPublicReviewerBos==null)adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  2133. //判定是否是上级审核人
  2134. boolean myFlag = false;
  2135. List<AdminPublicReviewerBo> collect = new ArrayList<>();
  2136. if (out.getProcessStatus()==0||out.getProcessStatus()==1){
  2137. collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  2138. }else if (out.getProcessStatus()==2){
  2139. collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  2140. //逻辑未完成先搁置
  2141. }
  2142. //如果是审核人可以查看
  2143. for (AdminPublicReviewerBo e : collect) {
  2144. if (e.getReviewerId().equals(aid)){
  2145. flag=true;
  2146. if (out.getType()==0){
  2147. flag2=true;
  2148. }
  2149. myFlag=true;
  2150. break;
  2151. }
  2152. }
  2153. //判定是否是上级审核状态
  2154. if((out.getPublicType()==0|| out.getPublicType()==2)&&
  2155. (out.getTechStartProcess()==0|| out.getTechStartProcess()==2)&&
  2156. (out.getAssistProcess()==0|| out.getAssistProcess()==1)&&
  2157. (out.getAssist()==0|| out.getAssist()==1)&& out.getStatus()==1
  2158. ){
  2159. if (myFlag){
  2160. out.setMyExamine(1);
  2161. }
  2162. if(out.getPublicType()==2){
  2163. for (PublicExamine p : ps) {
  2164. if (p.getAid().equals(aid)){{
  2165. flag = true;
  2166. break;
  2167. }
  2168. }
  2169. }
  2170. }
  2171. } else if (out.getPublicType()==1) {
  2172. //他人公出审核
  2173. if (!ps.isEmpty()){
  2174. for (PublicExamine p : ps) {
  2175. if (p.getAid().equals(aid)){
  2176. flag=true;
  2177. if (out.getPublicType()==1&&out.getStatus()==1){
  2178. if (p.getStatus()==0)out.setMyExamine(1);
  2179. else out.setMyExamine(0);
  2180. break;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }else if ((out.getTechStartProcess()==1||out.getTechStartProcess()==2)&&out.getStatus()==1) {
  2186. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(out.getId());
  2187. boolean myExamine = false;
  2188. for (OutPublicReleaseDetails ord : outPublicReleaseDetails) {
  2189. User user = userMapper.queryById(ord.getUid());
  2190. if (user.getAid().equals(aid)){
  2191. flag=true;
  2192. if (out.getTechStartProcess()==1)myExamine=true;
  2193. }
  2194. }
  2195. if (myExamine)out.setMyExamine(1);
  2196. } else if (out.getAssistProcess()==2||out.getAssistProcess()==3||out.getAssistProcess()==4) {
  2197. //添加协单审核人可以查看
  2198. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(out.getId(), null, null);
  2199. for (PublicRelease e : publicReleases) {
  2200. List<AdminPublicReviewerBo> sonAPRList = adminPublicReviewerMapper.selectByAid(e.getAid());
  2201. List<AdminPublicReviewerBo> collect2 = sonAPRList.stream().filter(e2 -> e2.getType() == 1).collect(Collectors.toList());
  2202. for (AdminPublicReviewerBo e2 : collect2) {
  2203. if (e2.getReviewerId().equals(aid)){
  2204. flag=true;
  2205. if((out.getAssistProcess()==2||out.getAssistProcess()==3)&&
  2206. out.getStatus()==1
  2207. ){
  2208. out.setMyExamine(1);
  2209. break;
  2210. }
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }else if(out.getType()==3){
  2216. //如果是协单,如果是审核人则不可以查看
  2217. if (adminPublicReviewerBos==null)adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  2218. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  2219. for (AdminPublicReviewerBo e : collect) {
  2220. if (e.getReviewerId().equals(aid)){
  2221. flag=true;
  2222. break;
  2223. }
  2224. }
  2225. String[] split = out.getAssistAid().split(",");
  2226. for (String s : split) {
  2227. if (s.equals(aid)){
  2228. flag2=true;
  2229. break;
  2230. }
  2231. }
  2232. }
  2233. //客户档案设置查看权限
  2234. if (flag2){
  2235. out.setViewPermission(1);
  2236. }else {
  2237. out.setViewPermission(0);
  2238. }
  2239. //处理返回
  2240. if(flag){
  2241. if(aid.equals(out.getAid())) {
  2242. out.setPermission(0);
  2243. }else {
  2244. out.setPermission(1);
  2245. }
  2246. }else {
  2247. out=null;
  2248. return out;
  2249. }
  2250. }
  2251. //设置审核人
  2252. pushExamine(out, adminPublicReviewerBos, ps);
  2253. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  2254. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  2255. pushDateClockDetailsToday(prdList,prdcList);
  2256. out.setPrdList(prdList);
  2257. //判定公出协单意见有没有的权限
  2258. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(out.getId(), 0);
  2259. if (publicAssistAdvices.isEmpty()){
  2260. out.setPublicAssistAdvice(0);
  2261. }else {
  2262. out.setPublicAssistAdvice(publicAssistAdvices.size());
  2263. }
  2264. return out;
  2265. }
  2266. /**
  2267. * 设置审核人
  2268. * @param out
  2269. * @param adminPublicReviewerBos
  2270. * @param ps
  2271. */
  2272. private void pushExamine(OutPublicRelease out, List<AdminPublicReviewerBo> adminPublicReviewerBos, List<PublicExamine> ps) {
  2273. //设置审核人
  2274. if (out.getStatus()==1&&
  2275. ((out.getPublicType()==0|| out.getPublicType()==2)&&(out.getTechStartProcess()==0|| out.getTechStartProcess()==2)))
  2276. {
  2277. if (adminPublicReviewerBos ==null) adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  2278. StringBuffer str =new StringBuffer();
  2279. //技术协单,获取协单审核人
  2280. if(out.getType()==3){
  2281. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  2282. for (AdminPublicReviewerBo e : collect) {
  2283. str.append(e.getReviewerName()+",");
  2284. }
  2285. //业务公出且协单部分审核(看着流程有点问题)
  2286. }else if (out.getType()==0&& out.getAssistProcess()==2){
  2287. //获取技术协单
  2288. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(out.getId(), null, null);
  2289. List<String> names=new ArrayList<>();
  2290. List<String> ids=new ArrayList<>();
  2291. for (PublicRelease e : publicReleases) {
  2292. if (e.getStatus()==1){
  2293. adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(e.getAid());
  2294. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e1 -> e1.getType() == 1).collect(Collectors.toList());
  2295. for (AdminPublicReviewerBo e1 : collect) {
  2296. if (!names.contains(e1.getReviewerName())){
  2297. names.add(e1.getReviewerName());
  2298. ids.add(e1.getReviewerId());
  2299. }
  2300. }
  2301. }
  2302. }
  2303. for (String name : names) {
  2304. str.append(name+",");
  2305. }
  2306. // out.setMyExamine(1);
  2307. // for (String s : ids) {
  2308. // if (s.equals(TokenManager.getAdminId())){
  2309. // out.setMyExamine(0);
  2310. // }
  2311. // }
  2312. } else {
  2313. //业务公出,且协单审核完成?
  2314. List<AdminPublicReviewerBo> collect=new ArrayList<>();
  2315. if (out.getProcessStatus()==0||out.getProcessStatus()==1){
  2316. collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  2317. }else {
  2318. collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 4).collect(Collectors.toList());
  2319. }
  2320. for (AdminPublicReviewerBo e : collect) {
  2321. str.append(e.getReviewerName()+",");
  2322. }
  2323. }
  2324. if(str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1)+" 未审核");
  2325. }else if (out.getStatus()==0) {
  2326. out.setAdminExamine("");
  2327. }else {
  2328. if (!ps.isEmpty()){
  2329. StringBuffer str =new StringBuffer();
  2330. for (PublicExamine e : ps) {
  2331. if (out.getId().equals(e.getPrid())){
  2332. str.append(e.getAname());
  2333. if (e.getStatus()==0) str.append(" 未审核,");
  2334. if (e.getStatus()==1) str.append(" 已审核,");
  2335. }
  2336. if (str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1));
  2337. }
  2338. }
  2339. }
  2340. }
  2341. @Override
  2342. public OutPublicReleaseAndDetails followDtails(String id) {
  2343. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  2344. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(out.getId());
  2345. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(out.getId());
  2346. pushDateClockDetails(prdList,prdcList);
  2347. out.setPrdList(prdList);
  2348. return out;
  2349. }
  2350. @SuppressWarnings("unchecked")
  2351. @Override
  2352. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  2353. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  2354. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  2355. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  2356. public Object publicReleaseStatistics(InputPublicStatistics in) {
  2357. Map<String,Object> map =new HashMap<String, Object>();
  2358. if(in.getAid()!=null)map.put("aid", in.getAid());
  2359. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  2360. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  2361. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  2362. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  2363. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  2364. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  2365. }
  2366. @SuppressWarnings("unchecked")
  2367. @Override
  2368. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  2369. Map<String,Object> map =new HashMap<String, Object>();
  2370. if(in.getAid()!=null)map.put("aid", in.getAid());
  2371. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  2372. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  2373. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  2374. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  2375. }
  2376. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  2377. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  2378. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  2379. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  2380. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  2381. }
  2382. @SuppressWarnings("unchecked")
  2383. @Override
  2384. public Object publicReleaseListDtails(InputPublicDtails in) {
  2385. Map<String,Object> map =new HashMap<String, Object>();
  2386. addParams(in, map);
  2387. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  2388. List<OutPublicDtails> list = (List<OutPublicDtails>)page.getList();
  2389. List<Integer> collect = list.stream().map(OutPublicDtails::getId).collect(Collectors.toList());
  2390. if (!collect.isEmpty()){
  2391. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(collect);
  2392. pushiClockInTime(list, publicReleaseClocks);
  2393. }
  2394. return page;
  2395. }
  2396. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  2397. if(in.getAid()!=null) map.put("aid", in.getAid());
  2398. if(in.getSid()!=null) map.put("sid", in.getSid());
  2399. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  2400. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  2401. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  2402. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  2403. if(in.getUid()!=null) map.put("uid", in.getUid());
  2404. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  2405. if(in.getStatus()!=null) map.put("status", in.getStatus());
  2406. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  2407. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  2408. //type 0私有 1管理权限 2所有权限
  2409. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  2410. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  2411. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  2412. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  2413. //添加财务和财务经理。查看客户所有公出
  2414. in.setType(2);
  2415. if(in.getDeps()!=null){
  2416. map.put("deps", departmentService.parseArray(in.getDeps()));
  2417. }
  2418. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
  2419. ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  2420. in.setType(1);
  2421. if (in.getDeps()!=null){
  2422. List<String> list = departmentService.selectSubDeps(in.getDeps());
  2423. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  2424. map.put("deps", list);
  2425. }else {
  2426. map.put("deps",departmentService.selectMyDeps());
  2427. }
  2428. }else{
  2429. in.setType(0);
  2430. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  2431. if(in.getDeps()!=null){
  2432. map.put("deps", departmentService.parseArray(in.getDeps()));
  2433. }
  2434. }
  2435. map.put("type", in.getType());
  2436. if(in.getStatusType()!=null) map.put("statusType", in.getStatusType());
  2437. }
  2438. @SuppressWarnings("unchecked")
  2439. @Override
  2440. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  2441. Map<String,Object> map =new HashMap<String, Object>();
  2442. addParams(in, map);
  2443. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  2444. }
  2445. @Override
  2446. public int addSupplement(Integer id, String supplement, String nextPlan) {
  2447. PublicRelease pr=new PublicRelease();
  2448. pr.setId(id);
  2449. if (StringUtils.isNotEmpty(supplement)) pr.setSupplement(supplement);
  2450. if (StringUtils.isNotEmpty(nextPlan)) pr.setNextPlan(nextPlan);
  2451. return publicReleaseMapper.update(pr);
  2452. }
  2453. @Override
  2454. public int checkTime(InputPublicRelease in) {
  2455. try {
  2456. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  2457. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  2458. } catch (ParseException e) {
  2459. e.printStackTrace();
  2460. throw new BusinessException("转换异常");
  2461. }
  2462. //如果主协单且一起公出
  2463. if(in.getAssist()==1){
  2464. //如果一起公出先判定发起人,再判定协单人,如果只是协单公出则只需要判定协单
  2465. if (in.getAlone()==1){
  2466. if(checkPublicTime(TokenManager.getAdminId(), in)){
  2467. //第一种,发起人时间重复
  2468. return 1;
  2469. // return true;
  2470. }
  2471. }
  2472. //判定协单时间重复
  2473. Integer x = checkTech(in);
  2474. if (x != null) return x;
  2475. }else {
  2476. //判定当前发起人能发起不
  2477. if(checkPublicTime(TokenManager.getAdminId(), in)){
  2478. //第一种,发起人时间重复
  2479. return 1;
  2480. // return true;
  2481. }
  2482. }
  2483. return 0;
  2484. }
  2485. private Integer checkTech(InputPublicRelease in) {
  2486. String[] split = in.getAssistAid().split(",");
  2487. for (String s : split) {
  2488. //先查审核中和完成的时间有没有冲突的
  2489. if(checTechTime(s, in)){
  2490. //第二种,协单人时间重复
  2491. return 2;
  2492. // return true;
  2493. }
  2494. //再查发起前营销审核中时间有没有冲突的
  2495. Integer x = checkSalesmanExamine(in, s);
  2496. if (x != null) return x;
  2497. }
  2498. return 0;
  2499. }
  2500. private boolean checTechTime(String aid, InputPublicRelease in) {
  2501. List<PublicRelease> is=publicReleaseMapper.checkTime(aid,in.getReleaseStart(),in.getReleaseEnd());
  2502. if (is.size()>1) {
  2503. return true;
  2504. }else if(is.size()==1){
  2505. //如果id为新增那么直接不允许时间重复
  2506. if (in.getId()==null){
  2507. return true;
  2508. }else {
  2509. //如果有id,与获取id一直,则为当前修改可以
  2510. if (in.getId().equals(is.get(0).getMainId())){
  2511. return false;
  2512. }else {
  2513. return true;
  2514. }
  2515. }
  2516. }
  2517. return false;
  2518. }
  2519. private Integer checkSalesmanExamine(InputPublicRelease in, String s) {
  2520. List<PublicRelease> is = publicReleaseMapper.checkTech(s, in.getReleaseStart(), in.getReleaseEnd());
  2521. if (is.size()>1) {
  2522. return 2;
  2523. }else if(is.size()==1){
  2524. //如果id为新增那么直接不允许时间重复
  2525. if (in.getId()==null){
  2526. return 2;
  2527. }else {
  2528. //如果有id,与获取id一直,则为当前修改可以
  2529. if (in.getId().equals(is.get(0).getId())){
  2530. return 0;
  2531. }else {
  2532. return 2;
  2533. }
  2534. }
  2535. }
  2536. return null;
  2537. }
  2538. /**
  2539. *
  2540. * @param aid
  2541. * @param in
  2542. * @return true 已经发起 false 未发起
  2543. */
  2544. private boolean checkPublicTime(String aid, InputPublicRelease in) {
  2545. List<PublicRelease> is=publicReleaseMapper.checkTime(aid,in.getReleaseStart(),in.getReleaseEnd());
  2546. if (is.size()>1) {
  2547. return true;
  2548. }else if(is.size()==1){
  2549. //如果id为新增那么直接不允许时间重复
  2550. if (in.getId()==null){
  2551. return true;
  2552. }else {
  2553. //如果有id,与获取id一直,则为当前修改可以
  2554. if (in.getId().equals(is.get(0).getId())){
  2555. return false;
  2556. }else {
  2557. return true;
  2558. }
  2559. }
  2560. }
  2561. return false;
  2562. }
  2563. @Override
  2564. public List<Map<String, Object>> selectOrderByUid(String uid) {
  2565. return tOrderNewMapper.selectOrderByuid(uid);
  2566. }
  2567. @Override
  2568. public List<OutPublicRelease> publicByOrder(String orderNo) {
  2569. return publicReleaseMapper.publicByOrder(orderNo);
  2570. }
  2571. @Override
  2572. public Object getMyNewPublic() {
  2573. List<PublicRelease> myPublic=publicReleaseMapper.selectMyNewPublic(TokenManager.getAdminId());
  2574. if(myPublic.isEmpty())return null;
  2575. Integer id=null;
  2576. long count=999999;
  2577. for (PublicRelease e : myPublic) {
  2578. long nowTime=System.currentTimeMillis();
  2579. long time = Math.abs(nowTime-e.getReleaseStart().getTime())/(1000*60);
  2580. long time2 = Math.abs(e.getReleaseEnd().getTime()-nowTime)/(1000*60);
  2581. //距离当前时间近的开始时间,不大于当前时间
  2582. if (time<count&&e.getReleaseStart().getTime()<nowTime){
  2583. if (e.getAlone()!=1 && e.getAssist()!=1){
  2584. count=time;
  2585. id=e.getId();
  2586. }
  2587. }
  2588. //距离当前时间近的结束时间,不小于当前时间
  2589. if (time2<count&&e.getReleaseEnd().getTime()>nowTime){
  2590. if (e.getAlone()!=1 && e.getAssist()!=1){
  2591. count=time2;
  2592. id=e.getId();
  2593. }
  2594. }
  2595. }
  2596. if (id==null)id=myPublic.get(0).getId();
  2597. OutPublicReleaseList out = publicReleaseMapper.selectOutListBoById(id);
  2598. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  2599. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  2600. pushDateClockDetails(prdList,prdcList);
  2601. pushDateClockDetailsToday(prdList,prdcList);
  2602. out.setPrdList(prdList);
  2603. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(out.getId(), 0);
  2604. if (publicAssistAdvices.isEmpty()){
  2605. out.setPublicAssistAdvice(0);
  2606. }else {
  2607. out.setPublicAssistAdvice(publicAssistAdvices.size());
  2608. }
  2609. return out;
  2610. // List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  2611. // if (myPublic.isEmpty()){
  2612. // List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  2613. // if (!myPublic2.isEmpty()){
  2614. // return myPublic2.get(0);
  2615. // }
  2616. // }else {
  2617. // return myPublic.get(0);
  2618. // }
  2619. }
  2620. private void pushDateClockDetailsToday(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  2621. for (OutPublicReleaseDetails out : prdList) {
  2622. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  2623. for (PublicReleaseDateClock prdc : prdcList) {
  2624. if (prdc.getPrdid().equals(out.getId())&&DateUtils.isSameDay(new Date(), prdc.getClockInTime())){
  2625. elist.add(prdc);
  2626. }
  2627. }
  2628. out.setPrdcList(elist);
  2629. }
  2630. }
  2631. private void pushDateClockDetails(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  2632. for (OutPublicReleaseDetails out : prdList) {
  2633. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  2634. for (PublicReleaseDateClock prdc : prdcList) {
  2635. if (prdc.getPrdid().equals(out.getId())){
  2636. elist.add(prdc);
  2637. }
  2638. }
  2639. out.setPrdcList(elist);
  2640. }
  2641. }
  2642. /**
  2643. *
  2644. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  2645. * @param dateType 是否含打卡时间 0否 1是
  2646. * @return
  2647. */
  2648. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  2649. Map<String, Object> map = new HashMap<>();
  2650. if (type==null)type=0;
  2651. map.put("type",type);
  2652. //statusType=1情况下
  2653. map.put("statusType",1);
  2654. if (dateType==1){
  2655. Date date = new Date();
  2656. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  2657. map.put("clockTime",clockTime);
  2658. }
  2659. map.put("aid",TokenManager.getAdminId());
  2660. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  2661. for (OutPublicReleaseList out : list) {
  2662. out.setPrdList(publicReleaseDetailsMapper.selectByPrid(out.getId()));
  2663. }
  2664. return list;
  2665. }
  2666. @Override
  2667. public int addAssistant(Integer id,String aid) {
  2668. PublicRelease p = publicReleaseMapper.selectById(id);
  2669. List<String> list=new ArrayList<>();
  2670. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  2671. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  2672. }
  2673. String sname = pushAssistant(aid, list,0);
  2674. String said =String.join(",",list);
  2675. p.setAssistantAid(said);
  2676. p.setAssistantName(sname);
  2677. addAssistantPublicRelease(p,aid);
  2678. return updateAssistant(p, said, sname);
  2679. }
  2680. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  2681. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  2682. PublicRelease newP= new PublicRelease();
  2683. if(list.isEmpty()){
  2684. BeanUtils.copyProperties(p,newP);
  2685. newP.setId(null);
  2686. newP.setAid(aid);
  2687. newP.setAssist(3);
  2688. newP.setType(4);
  2689. publicReleaseMapper.insertSelective(newP);
  2690. addpublicReleaseDtails(p,newP);
  2691. StringBuffer str=new StringBuffer();
  2692. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  2693. addWeChatNotice( aid,1,str.toString(),newP.getId());
  2694. }else {
  2695. for (PublicRelease pr : list) {
  2696. newP.setId(pr.getId());
  2697. newP.setAssistantAid(p.getAssistantAid());
  2698. newP.setAssistantName(p.getAssistantName());
  2699. publicReleaseMapper.update(newP);
  2700. updatePublicReleaseDtails(p,newP);
  2701. }
  2702. }
  2703. }
  2704. /**
  2705. * 添加微信提示和站内消息
  2706. * @param aid 接受者
  2707. * @param type 状态 0驳回 1发起 2同意 3撤销
  2708. * @param str 备注
  2709. * @param prid 公出编号
  2710. */
  2711. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  2712. Admin recipient = adminMapper.selectById(aid);
  2713. addWeChatNotice( recipient, type, str, prid);
  2714. }
  2715. /**
  2716. * 添加微信提示和站内消息
  2717. * @param recipient 接受者
  2718. * @param type 状态 0驳回 1发起 2同意 3撤销
  2719. * @param str
  2720. */
  2721. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  2722. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  2723. String openid=recipient.getOpenId();
  2724. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  2725. if(type==3){
  2726. addpublicLog(prid,4,str);
  2727. }else {
  2728. addpublicLog(prid,type,str);
  2729. }
  2730. sendNoticeAndSoucket(recipient.getId(),type,str);
  2731. if (type==0||type==2){
  2732. if (openid!=null) {
  2733. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  2734. return res;
  2735. }else {
  2736. sendEmail(my, recipient,type);
  2737. }
  2738. }
  2739. return 0;
  2740. }
  2741. private int updateAssistant(PublicRelease p, String said, String sname) {
  2742. PublicRelease newPr=new PublicRelease();
  2743. newPr.setId(p.getId());
  2744. newPr.setAssistantAid(said);
  2745. newPr.setAssistantName(sname);
  2746. if (p.getMainId()!=null){
  2747. PublicRelease mianPr=new PublicRelease();
  2748. mianPr.setId(p.getMainId());
  2749. // mianPr.setAid(said);
  2750. mianPr.setAssistantAid(said);
  2751. mianPr.setAssistantName(sname);
  2752. publicReleaseMapper.update(mianPr);
  2753. }
  2754. return publicReleaseMapper.update(newPr);
  2755. }
  2756. /**
  2757. *
  2758. * @param aid 元素
  2759. * @param list 集合
  2760. * @param type 0新增 1删除
  2761. * @return
  2762. */
  2763. private String pushAssistant(String aid, List<String> list,Integer type) {
  2764. StringBuffer sb=new StringBuffer();
  2765. if(type==0){
  2766. list.add(aid);
  2767. }else if (type==1){
  2768. Iterator<String > it =list.iterator();
  2769. while (it.hasNext()){
  2770. if (it.next().equals(aid))
  2771. it.remove();
  2772. }
  2773. }
  2774. for (String s : list) {
  2775. sb.append(adminMapper.selectById(s).getName()).append(",");
  2776. }
  2777. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  2778. }
  2779. @Override
  2780. public int deleteAssistant(Integer id, String aid) {
  2781. PublicRelease p = publicReleaseMapper.selectById(id);
  2782. if (p.getAssistantAid()==null){
  2783. throw new BusinessException("人员不存在");
  2784. }
  2785. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  2786. if (!list.contains(aid)){
  2787. throw new BusinessException("人员不存在");
  2788. }
  2789. String sname = pushAssistant(aid, list,1);
  2790. String said =String.join(",",list);
  2791. p.setAssistantAid(said);
  2792. p.setAssistantName(sname);
  2793. deleteAssistantPulicRelease(p,aid);
  2794. return updateAssistant(p, said, sname);
  2795. }
  2796. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  2797. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  2798. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  2799. StringBuffer str=new StringBuffer();
  2800. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  2801. for (PublicRelease pr : list) {
  2802. if (pr.getAid().equals(aid)){
  2803. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  2804. }else {
  2805. PublicRelease newPr=new PublicRelease();
  2806. newPr.setId(pr.getId());
  2807. newPr.setAssistantAid(p.getAssistantAid());
  2808. newPr.setAssistantName(p.getAssistantName());
  2809. publicReleaseMapper.update(newPr);
  2810. }
  2811. }
  2812. }
  2813. @Override
  2814. public boolean checkdeleteAssistant(Integer id, String aid) {
  2815. PublicRelease p = publicReleaseMapper.selectById(id);
  2816. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  2817. for (PublicRelease use : list) {
  2818. // if (use.getClockIn()==1){
  2819. // return true;
  2820. // }
  2821. }
  2822. return false;
  2823. }
  2824. @Override
  2825. public boolean checkaddAssistant(Integer id, String aid) {
  2826. PublicRelease p = publicReleaseMapper.selectById(id);
  2827. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  2828. for (PublicRelease use : list) {
  2829. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  2830. return true;
  2831. }
  2832. }
  2833. return false;
  2834. }
  2835. @Override
  2836. public int updateLocation(InputPublicRelease in) {
  2837. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  2838. if (prd==null){
  2839. throw new BusinessException("公出企业不存在");
  2840. }
  2841. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  2842. updateprd.setId(prd.getId());
  2843. updateprd.setLatitude(in.getLatitude());
  2844. updateprd.setLongitude(in.getLongitude());
  2845. updateprd.setDistrictName(in.getDistrictName());
  2846. updateprd.setClockIn(0);
  2847. addpublicLog(in.getId(),5,"发起公出地点修改");
  2848. return publicReleaseDetailsMapper.update(updateprd);
  2849. }
  2850. @Override
  2851. public Object publicReleaseAndCount(InputPublicDtails in) {
  2852. List<OutPublicDtails> list = publicReleaseListDtailsList(in);
  2853. Map<String,Object> map=new HashMap<String, Object>();
  2854. if (list.isEmpty()){
  2855. map.put("list",list);
  2856. map.put("count",0);
  2857. map.put("durationCount",0);
  2858. map.put("peopleCount",0);
  2859. }else {
  2860. //公出次数
  2861. int count=0;
  2862. BigDecimal durationCount=BigDecimal.ZERO;
  2863. List<String> aList =new ArrayList<>();
  2864. for (OutPublicDtails e : list) {
  2865. if (e.getType()==0||e.getType()==1||e.getType()==2){
  2866. count++;
  2867. if (e.getDuration()!=null){
  2868. durationCount=durationCount.add(new BigDecimal(e.getDuration()));
  2869. }
  2870. if (!aList.contains(e.getAname())){
  2871. aList.add(e.getAname());
  2872. }
  2873. if (StringUtils.isNotEmpty(e.getAssistAidName())){
  2874. String[] split = e.getAssistAidName().split(",");
  2875. for (String s : split) {
  2876. if (!aList.contains(s)){
  2877. aList.add(s);
  2878. }
  2879. }
  2880. }
  2881. if (StringUtils.isNotEmpty(e.getAssistantName())){
  2882. String[] split = e.getAssistantName().split(",");
  2883. for (String s : split) {
  2884. if (!aList.contains(s)){
  2885. aList.add(s);
  2886. }
  2887. }
  2888. }
  2889. }
  2890. }
  2891. map.put("list",list);
  2892. map.put("count",count);
  2893. map.put("durationCount",durationCount);
  2894. map.put("peopleCount",aList.size());
  2895. }
  2896. return map;
  2897. }
  2898. /**
  2899. *
  2900. * @param in 公出参数
  2901. * @param a 新增时需哟额外知道当前任务
  2902. * @param type 0查询 1新增 2修改
  2903. * @return
  2904. */
  2905. public Map checkOrderNoDuration( InputPublicRelease in,AdminListBo a,int type) {
  2906. List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
  2907. TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
  2908. OutPublicRelease outPublicRelease=null;
  2909. //实际公出
  2910. BigDecimal actualDuration = BigDecimal.ZERO;
  2911. //公出次数
  2912. int frequency=0;
  2913. List<String> peopleList = new ArrayList<>();
  2914. //判定是不是新增获取原数据,是新增数量加1
  2915. if (in.getId()!=null){
  2916. outPublicRelease= publicReleaseMapper.selectDtails(in.getId());
  2917. }else {
  2918. peopleList.add(TokenManager.getAdminId());
  2919. actualDuration=actualDuration.add(BigDecimal.valueOf(in.getDuration()));
  2920. frequency++;
  2921. }
  2922. for (PublicRelease e : list) {
  2923. //新增直接计算
  2924. if (in.getId()==null){
  2925. if (e.getDuration()!=null){
  2926. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  2927. if (!peopleList.contains(e.getAid())){
  2928. peopleList.add(e.getAid());
  2929. }
  2930. frequency++;
  2931. }
  2932. }else {
  2933. //修改当前数据要从修改后获取
  2934. if (!e.getId().equals(in.getId())){
  2935. if (e.getDuration()!=null){
  2936. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  2937. if (!peopleList.contains(e.getAid())){
  2938. peopleList.add(e.getAid());
  2939. }
  2940. frequency++;
  2941. }
  2942. }else {
  2943. if (outPublicRelease != null && outPublicRelease.getDuration() != null) {
  2944. actualDuration = actualDuration.add(BigDecimal.valueOf(outPublicRelease.getDuration()));
  2945. if (!peopleList.contains(outPublicRelease.getAid())) {
  2946. peopleList.add(outPublicRelease.getAid());
  2947. }
  2948. frequency++;
  2949. }
  2950. }
  2951. }
  2952. }
  2953. Map map=new HashMap();
  2954. CheckOrderNoOut data= new CheckOrderNoOut();
  2955. if (outPublicRelease!=null){
  2956. data.setPublicReleaseName(outPublicRelease.getAname());
  2957. }
  2958. //新增与修改,需要重新获取实际公出与人数与次数
  2959. if (type==1||type==2){
  2960. TOrderPublicReleaseCount update=new TOrderPublicReleaseCount();
  2961. update.setOrderNo(in.getOrderNo());
  2962. update.setFrequency(frequency);
  2963. update.setActualDuration(actualDuration.doubleValue());
  2964. update.setPeopleCount(peopleList.size());
  2965. tOrderPublicReleaseCountMapper.updateByOrderNo(update);
  2966. }
  2967. List<OrderYearMaxDuration> orderYearMaxDurations = orderYearMaxDurationMapper.selectByOrderNo(in.getOrderNo());
  2968. data.setTimesCount(frequency);
  2969. data.setPeopleCount(peopleList.size());
  2970. data.setUserName(t.getUserName());
  2971. data.setContractNo(t.getContractNo());
  2972. data.setAdminName(t.getSalesmanName());
  2973. data.setDurationCount(actualDuration);
  2974. TOrderPublicReleaseCount releaseCount = tOrderPublicReleaseCountMapper.selectByOrderNo(in.getOrderNo());
  2975. data.setDurationMax(BigDecimal.valueOf(releaseCount.getMaxDuration()));
  2976. TOrderNew tOrderNew = tOrderNewMapper.queryById(in.getOrderNo());
  2977. List<TTaskMember> tTaskMembers = tTaskMemberMapper.selectByOrderNo(tOrderNew.getOrderNo());
  2978. String amountName=null;
  2979. String amountType=null;
  2980. if (releaseCount.getMaxType()==2){
  2981. map.put("code",true);
  2982. map.put("data",null);
  2983. }else {
  2984. if (tTaskMembers.size()<1){
  2985. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(1))<0){
  2986. amountName="本合同低于1万";
  2987. amountType="原则上技术人员不可下户";
  2988. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0){
  2989. amountName="本合同在1~3万";
  2990. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2991. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0){
  2992. amountName="本合同在3~5万";
  2993. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2994. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0){
  2995. amountName="本合同在5~10万";
  2996. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2997. }
  2998. }else {
  2999. int yearSum=1;
  3000. for (TTaskMember tTaskMember : tTaskMembers) {
  3001. if (tTaskMember.getYearSum()!=null&&tTaskMember.getYearSum()>yearSum){
  3002. yearSum=tTaskMember.getYearSum();
  3003. }
  3004. }
  3005. BigDecimal divide =BigDecimal.ZERO;
  3006. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(0))>0&&yearSum>0){
  3007. divide=tOrderNew.getTotalAmount().divide(BigDecimal.valueOf(yearSum), BigDecimal.ROUND_HALF_UP);
  3008. }else {
  3009. divide=tOrderNew.getTotalAmount();
  3010. }
  3011. if (divide.compareTo(BigDecimal.valueOf(1))<0){
  3012. amountName="此会员订单,本年度金额低于1万";
  3013. amountType="原则上技术人员不可下户";
  3014. }else if (divide.compareTo(BigDecimal.valueOf(3))<0){
  3015. amountName="此会员订单,本年度金额1~3万";
  3016. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  3017. }else if (divide.compareTo(BigDecimal.valueOf(5))<0){
  3018. amountName="此会员订单,本年度金额3~5万";
  3019. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  3020. }else if (divide.compareTo(BigDecimal.valueOf(10))<0){
  3021. amountName="此会员订单,本年度金额5~10万";
  3022. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  3023. }
  3024. }
  3025. data.setAmountName(amountName);
  3026. data.setAmountType(amountType);
  3027. map.put("releaseCount",releaseCount);
  3028. //如果小于或者等于并且是未发起或者审核完成状态
  3029. if (actualDuration.compareTo(data.getDurationMax())<1&&
  3030. (releaseCount.getMaxProcess()==0||releaseCount.getMaxProcess()==4)
  3031. ){
  3032. map.put("code",true);
  3033. map.put("data",null);
  3034. }else {
  3035. map.put("code",false);
  3036. map.put("data",data);
  3037. }
  3038. }
  3039. return map;
  3040. }
  3041. @Override
  3042. public Map checkOrderNoDuration( InputPublicRelease in){
  3043. return checkOrderNoDuration(in,null,0);
  3044. }
  3045. @Override
  3046. public void pushOutPublicDtails(List<OutPublicDtails> list) {
  3047. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(list.stream().map(OutPublicDtails::getId).collect(Collectors.toList()));
  3048. pushiClockInTime(list, publicReleaseClocks);
  3049. }
  3050. private void pushiClockInTime(List<OutPublicDtails> list, List<PublicReleaseClock> publicReleaseClocks) {
  3051. for (OutPublicDtails outPublicDtails : list) {
  3052. if (outPublicDtails.getClockIn()!=null){
  3053. if (outPublicDtails.getAlone()==2&&outPublicDtails.getAssist()==1){
  3054. outPublicDtails.setClockInStr("无需打卡");
  3055. }else if (outPublicDtails.getClockIn()==0)outPublicDtails.setClockInStr("未打卡");
  3056. else if (outPublicDtails.getClockIn()==1)outPublicDtails.setClockInStr("已打卡");
  3057. else if (outPublicDtails.getClockIn()==2)outPublicDtails.setClockInStr("异常打卡");
  3058. }
  3059. List<PublicReleaseClock> colokList =new ArrayList<>();
  3060. StringBuilder sb = new StringBuilder();
  3061. for (PublicReleaseClock e : publicReleaseClocks) {
  3062. if (outPublicDtails.getPrdId().equals(e.getPrdid())){
  3063. sb.append(DateUtils.formatDateYYYYMMddHHmm(e.getClockInTime())).append("\n");
  3064. colokList.add(e);
  3065. }
  3066. colokList.sort(Comparator.comparing(PublicReleaseClock::getClockInTime));
  3067. Collections.reverse(colokList);
  3068. outPublicDtails.setList(colokList);
  3069. }
  3070. outPublicDtails.setClockInTimes(sb.toString());
  3071. List<UserInterviewProjectBo> userInterviewProjectBos = userInterviewProjectMapper.selectByPrdId(outPublicDtails.getPrdId());
  3072. if (userInterviewProjectBos.size()>0){
  3073. StringBuilder builder = new StringBuilder();
  3074. userInterviewProjectBos.forEach(e -> {
  3075. if (e.getName()!=null)builder.append(e.getName());
  3076. if (e.getExamineStatus()!=null){
  3077. if (e.getExamineStatus()==1){
  3078. builder.append("(初次审核)");
  3079. }else if (e.getExamineStatus()==2){
  3080. builder.append("(复审 ").append(e.getExamineStatusOther()).append(")");
  3081. }
  3082. }
  3083. if (e.getBuyStatus()!=null){
  3084. if (e.getBuyStatus()==1){
  3085. builder.append("(新购)");
  3086. }else if (e.getBuyStatus()==2){
  3087. builder.append("(复购 ").append(e.getBuyStatusOther()).append(")");
  3088. }
  3089. }
  3090. builder.append(",");
  3091. });
  3092. outPublicDtails.setInterviewProject(builder.substring(0,builder.length()-1));
  3093. }
  3094. }
  3095. }
  3096. @Override
  3097. public Object pushDateClock() {
  3098. List<PublicRelease> publicReleases = publicReleaseMapper.selectAll();
  3099. for (PublicRelease e : publicReleases) {
  3100. addPublicReleaseDateClock(e);
  3101. }
  3102. return 1;
  3103. }
  3104. private void addPublicReleaseDateClock(PublicRelease e) {
  3105. publicReleaseDateClockMapper.deleteByPrid(e.getId());
  3106. List<PublicReleaseDateClock> list= new ArrayList<>();
  3107. if (e.getValidDate()!=null){
  3108. List<Map> maps = JSONArray.parseArray(e.getValidDate(), Map.class);
  3109. for (Map map : maps) {
  3110. String dates = (String) map.get("value");
  3111. if (dates!=null){
  3112. Date date = DateUtils.parseDate(dates);
  3113. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(e.getId());
  3114. for (OutPublicReleaseDetails det : outPublicReleaseDetails) {
  3115. PublicReleaseDateClock newPRDC = new PublicReleaseDateClock();
  3116. newPRDC.setClockInTime(date);
  3117. newPRDC.setPrid(e.getId());
  3118. newPRDC.setPrdid(det.getId());
  3119. newPRDC.setStatus(det.getClockIn());
  3120. list.add(newPRDC);
  3121. }
  3122. }
  3123. }
  3124. }
  3125. if(!list.isEmpty()){
  3126. publicReleaseDateClockMapper.insertBatch(list);
  3127. list.clear();
  3128. }
  3129. }
  3130. @Override
  3131. @Cacheable(value = "releaseAndExpenseCount#300", key = "'getCounts:key='+#in.buyerName+#in.contractNo+#in.aid+#in.depId+#in.allStatus+#in.startTime+#in.endTime")
  3132. public List<releaseAndExpenseCountOut> releaseAndExpenseCount(InputreleaseAndExpenseCount in) {
  3133. if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
  3134. List<releaseAndExpenseCountOut> expenseCountsOrders = publicReleaseMapper.releaseAndExpenseCount(in);
  3135. expenseCountsOrders.forEach(e->{
  3136. if (e.getExceedDuration()!=null){
  3137. double exceedDuration = Double.parseDouble(e.getExceedDuration());
  3138. if (exceedDuration>0){
  3139. e.setExceedType(1);
  3140. }
  3141. }
  3142. if (StringUtils.isNotEmpty(e.getOrderNo())){
  3143. BigDecimal maxDuration = new BigDecimal(e.getMaxDuration());
  3144. if (e.getMaxType()==2){
  3145. e.setMaxDuration("预"+e.getMaxDuration());
  3146. } else if (e.getMaxType()==0) {
  3147. e.setMaxDuration("0");
  3148. }
  3149. if(!e.getActualDuration().equals("0")){
  3150. if (maxDuration.compareTo(new BigDecimal(e.getActualDuration()))>=0){
  3151. e.setExceedDuration("0");
  3152. }else {
  3153. e.setExceedDuration(new BigDecimal(e.getActualDuration()).subtract(maxDuration).toString());
  3154. }
  3155. }
  3156. }
  3157. });
  3158. return expenseCountsOrders;
  3159. }
  3160. @Override
  3161. @CacheEvict(value = "releaseAndExpenseCount#300",allEntries = true)
  3162. public Object releaseAndExpenseCountClear() {
  3163. LoggerUtils.debug(getClass(),"公出&报销缓存清除。");
  3164. return 1;
  3165. }
  3166. }