PublicReleaseServiceImpl.java 118 KB

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