PublicReleaseServiceImpl.java 126 KB

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