PublicReleaseServiceImpl.java 112 KB

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