PublicReleaseServiceImpl.java 109 KB

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