PublicReleaseServiceImpl.java 96 KB

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