PublicReleaseServiceImpl.java 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803
  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,Integer evaluateType) {
  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. if (evaluateType==1){
  1046. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(id);
  1047. addUserSuperEvaluate(remarks, outPublicReleaseDetails, new Date());
  1048. }
  1049. }
  1050. return 1;
  1051. }
  1052. @Override
  1053. public Object assistUnaudited() {
  1054. String aid=TokenManager.getAdminId();
  1055. int unaudited = publicReleaseMapper.selectCountByUnaudited(aid);
  1056. int assistUnaudited = publicReleaseMapper.selectCountByAssistUnaudited(aid);
  1057. int otherUnaudited = publicReleaseMapper.selectCountByOtherUnaudited(aid);
  1058. Map<String,Object> i=new HashMap<>();
  1059. i.put("unaudited",unaudited);
  1060. i.put("assistUnaudited",assistUnaudited);
  1061. i.put("otherUnaudited",otherUnaudited);
  1062. return i;
  1063. }
  1064. @Override
  1065. public boolean checkPublicReviewer(InputPublicRelease in) {
  1066. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(TokenManager.getAdminId());
  1067. if (adminPublicReviewerBos.isEmpty()){
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. @Override
  1073. public int pushLimitUser(String uid, Integer hours) {
  1074. User user = userMapper.selectByPrimaryKey(uid);
  1075. if (!user.getAid().equals(TokenManager.getAdminId())){
  1076. return 0;
  1077. }
  1078. long l = System.currentTimeMillis();
  1079. if (hours==null)hours=2;
  1080. l=l+hours*60*60*1000;
  1081. UserLimitCheck userLimitCheck = userLimitCheckMapper.selectByUid(uid);
  1082. if (userLimitCheck==null){
  1083. UserLimitCheck ulc=new UserLimitCheck();
  1084. ulc.setUid(uid);
  1085. ulc.setCheckTime(new Date(l));
  1086. userLimitCheckMapper.insert(ulc);
  1087. }else {
  1088. userLimitCheck.setCheckTime(new Date(l));
  1089. userLimitCheckMapper.update(userLimitCheck);
  1090. }
  1091. return 1;
  1092. }
  1093. @Override
  1094. public boolean checkUserArchives(String uid) {
  1095. User user = userMapper.selectByPrimaryKey(uid);
  1096. UserArchives userArchives = userArchivesMapper.queryByUid(uid);
  1097. if (user.getNewChannel()==0){
  1098. if (userArchives==null||
  1099. StringUtils.isBlank(userArchives.getFinancialData())||
  1100. StringUtils.isBlank(userArchives.getEarlyCommunication())||
  1101. StringUtils.isBlank(userArchives.getInterviewIdeas())){
  1102. return false;
  1103. }
  1104. }else {
  1105. OrganizationIdentity organizationIdentity = organizationIdentityMapper.selectOrgIdentityByUserId(uid);
  1106. Integer i = organizationContactBookMapper.checkContacts(uid, null, user.getAid());
  1107. if (i==null||i<1){
  1108. return false;
  1109. }
  1110. if (userArchives==null||
  1111. userArchives.getEnterpriseCount()==null||
  1112. StringUtils.isBlank(organizationIdentity.getIntendedProject())||
  1113. StringUtils.isBlank(userArchives.getChannelIndicators())||
  1114. StringUtils.isBlank(userArchives.getInterviewDistribution())||
  1115. StringUtils.isBlank(userArchives.getInterviewIdeas())){
  1116. return false;
  1117. }
  1118. }
  1119. return true;
  1120. }
  1121. private void updateAdminUserCountPublicRelease(String aid, Date transferTime) {
  1122. String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
  1123. String endTime=startTime+" 23:59:59";
  1124. AdminUserCount adminUserCount = customerService.getAdminUserCount(aid,startTime);
  1125. Integer count = publicReleaseMapper.selectCountByaidAndDate(aid, startTime, endTime);
  1126. if (count==null){
  1127. count=0;
  1128. }
  1129. if (adminUserCount==null){
  1130. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  1131. if (selectAUC==null)selectAUC=new AdminUserCount();
  1132. selectAUC.setPublicReleaseCount(count);
  1133. selectAUC.setAid(aid);
  1134. selectAUC.setDateTime(transferTime);
  1135. adminUserCountMapper.insertSelective(selectAUC);
  1136. }else {
  1137. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  1138. AdminUserCount newAUC=new AdminUserCount();
  1139. newAUC.setId(adminUserCount.getId());
  1140. newAUC.setPublicReleaseCount(count);
  1141. if (selectAUC==null){
  1142. newAUC.setPrivateCount(0);
  1143. newAUC.setChannelCount(0);
  1144. newAUC.setSignCount(0);
  1145. }else {
  1146. if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
  1147. if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
  1148. if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
  1149. newAUC.setPrivateCount(selectAUC.getPrivateCount());
  1150. newAUC.setChannelCount(selectAUC.getChannelCount());
  1151. newAUC.setSignCount(selectAUC.getSignCount());
  1152. }
  1153. adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
  1154. }
  1155. }
  1156. private void addpublicLog(Integer id, Integer status, String remarks) {
  1157. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  1158. publicReleaseLogMapper.insertSelective(log);
  1159. }
  1160. @Override
  1161. public int pushTechReject(Integer id, String remarks) {
  1162. Integer status=0;
  1163. PublicRelease use=publicReleaseMapper.queryById(id);
  1164. PublicRelease mainPublic= publicReleaseMapper.queryById(use.getMainId());
  1165. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  1166. StringBuffer str=new StringBuffer();
  1167. if (use.getAssist()!=2){
  1168. throw new BusinessException("只有技术公出能发起技术驳回");
  1169. }
  1170. str=str.append("拒绝技术协单,").append(remarks);
  1171. PublicRelease newMain=new PublicRelease();
  1172. newMain.setId(mainPublic.getId());
  1173. newMain.setStatus(4);
  1174. newMain.setRejectName(ad.getName());
  1175. newMain.setAuditInfo(str.toString());
  1176. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  1177. publicReleaseMapper.update(newMain);
  1178. PublicRelease up=new PublicRelease();
  1179. up.setId(id);
  1180. up.setAuditInfo(str.toString());
  1181. up.setStatus(3);
  1182. addpublicLog(id, status, remarks);
  1183. publicReleaseMapper.update(up);
  1184. deleteAssistantPulicRelease(use,null);
  1185. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  1186. }
  1187. /**
  1188. * 新增日志、站内信、微信提醒
  1189. * @param id 日志公出编号
  1190. * @param aid 接受者
  1191. * @param remarks 日志内容
  1192. * @param status 0驳回
  1193. * @return
  1194. */
  1195. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  1196. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  1197. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  1198. if (my.getOpenId()!=null) {
  1199. if (remarks.length()>19) {
  1200. remarks=remarks.substring(0, 15)+"...";
  1201. }
  1202. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  1203. }else {
  1204. sendEmail( my, a, status);
  1205. return 1;
  1206. }
  1207. }
  1208. /**
  1209. *
  1210. * @param use 原始公出信息
  1211. * @param status 状态
  1212. * @param date 时间
  1213. * @param a
  1214. */
  1215. private void pushPublicReleaseAssist(PublicRelease use,PublicRelease update,Date date,Admin a) {
  1216. if (use.getAssistAid()!=null){
  1217. updatePushassist(use, update, date,a);
  1218. if(use.getAssistantAid()!=null){
  1219. updatepushAssistant(use,a);
  1220. }
  1221. }
  1222. }
  1223. /**
  1224. * 处理技术协单
  1225. * @param use
  1226. * @param status
  1227. * @param date
  1228. */
  1229. private void updatePushassist(PublicRelease use, PublicRelease updatePR, Date date, Admin a) {
  1230. //协单
  1231. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  1232. String []ss= use.getAssistAid().split(",");
  1233. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  1234. for (PublicRelease out : list) {
  1235. boolean flag=false;
  1236. for (String s : ss) {
  1237. if (out.getAid().equals(s)){
  1238. flag=true;
  1239. break;
  1240. }
  1241. }
  1242. //不存在则取消公出
  1243. if (!flag){
  1244. PublicRelease in = new PublicRelease();
  1245. in.setId(out.getId());
  1246. in.setStatus(3);
  1247. publicReleaseMapper.update(in);
  1248. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  1249. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  1250. publicReleaseLogMapper.insertSelective(log);
  1251. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  1252. }else {
  1253. //存在则修改公出
  1254. PublicRelease np = new PublicRelease();
  1255. BeanUtils.copyProperties(use,np);
  1256. np.setId(out.getId());
  1257. np.setMainId(null);
  1258. np.setType(null);
  1259. np.setAssist(2);
  1260. //协单审核,判定是否跳过的逻辑
  1261. int x=pushAssist(out.getAid(), np,use);
  1262. np.setAid(null);
  1263. publicReleaseMapper.update(np);
  1264. updatePublicReleaseDtails(use,np);
  1265. if (x==2||x==3){
  1266. String remarks="";
  1267. if (x==2){
  1268. remarks="协单未设置审核人,自动通过";
  1269. }else if (x==3){
  1270. remarks="协单审核人重复,自动通过";
  1271. }
  1272. PublicReleaseLog log2 = new PublicReleaseLog(np.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1273. publicReleaseLogMapper.insertSelective(log2);
  1274. PublicReleaseLog log3 = new PublicReleaseLog(use.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1275. publicReleaseLogMapper.insertSelective(log3);
  1276. }
  1277. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  1278. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  1279. publicReleaseLogMapper.insertSelective(log);
  1280. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  1281. }
  1282. }
  1283. //有新增则新增公出
  1284. for (String s : ss) {
  1285. boolean flag2 = false;
  1286. for (PublicRelease o : list) {
  1287. if (s.equals(o.getAid())) {
  1288. flag2 = true;
  1289. }
  1290. }
  1291. if (!flag2) {
  1292. PublicRelease np = new PublicRelease();
  1293. BeanUtils.copyProperties(use,np);
  1294. np.setAssist(2);
  1295. np.setAid(s);
  1296. //协单审核,判定是否跳过的逻辑
  1297. np.setType(3);
  1298. np.setMainId(use.getId());
  1299. np.setId(null);
  1300. int x=pushAssist(s, np,use);
  1301. publicReleaseMapper.insertSelective(np);
  1302. //补充客户表
  1303. addpublicReleaseDtails(use,np);
  1304. if (x==2||x==3){
  1305. String remarks="";
  1306. if (x==2){
  1307. remarks="协单未设置审核人,自动通过";
  1308. }else if (x==3){
  1309. remarks="协单审核人重复,自动通过";
  1310. }
  1311. PublicReleaseLog log2 = new PublicReleaseLog(np.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1312. publicReleaseLogMapper.insertSelective(log2);
  1313. PublicReleaseLog log3 = new PublicReleaseLog(use.getId(), "1", PublicReleaseLog.states.ty.getCode(), remarks, new Date());
  1314. publicReleaseLogMapper.insertSelective(log3);
  1315. }
  1316. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  1317. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  1318. sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
  1319. publicReleaseLogMapper.insertSelective(log);
  1320. }
  1321. }
  1322. //判定是审核还是完成,取决于协单是否通过
  1323. List<PublicRelease> newList = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  1324. int count = 0;
  1325. for (PublicRelease e : newList) {
  1326. if (e.getStatus()==2){
  1327. count++;
  1328. }
  1329. }
  1330. if(count==newList.size()){
  1331. updatePR.setStatus(2);
  1332. updatePR.setAssistProcess(4);
  1333. }else {
  1334. updatePR.setStatus(1);
  1335. updatePR.setAssistProcess(2);
  1336. }
  1337. }
  1338. /**
  1339. * 协单审核判定是否跳过的逻辑
  1340. * 如果未设置跳过审核,如果已审核跳过
  1341. *
  1342. * @param s 协单人编号
  1343. * @param np 新协单公出信息
  1344. * @param use 原公出信息
  1345. */
  1346. private int pushAssist(String s, PublicRelease np, PublicRelease use) {
  1347. List<AdminPublicReviewerBo> adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(s);
  1348. int res=0;
  1349. //协单人
  1350. Admin admin = adminMapper.selectByPrimaryKey(s);
  1351. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  1352. if (!collect.isEmpty()){
  1353. //公出发起人
  1354. List<outPublicReleaseLog> outPublicReleaseLogs = publicReleaseLogMapper.listPublicReleaseLog(use.getId(), null);
  1355. List<outPublicReleaseLog> collect1 = outPublicReleaseLogs.stream().filter(e -> e.getStatus() == 2).collect(Collectors.toList());
  1356. boolean flag = false;
  1357. for (AdminPublicReviewerBo e : collect) {
  1358. for (outPublicReleaseLog log : collect1) {
  1359. if (log.getAid().equals(e.getReviewerId())){
  1360. flag=true;
  1361. break;
  1362. }
  1363. }
  1364. if(flag){
  1365. break;
  1366. }
  1367. }
  1368. if (flag){
  1369. np.setStatus(2);
  1370. res=3;
  1371. }else {
  1372. np.setStatus(1);
  1373. res=1;
  1374. }
  1375. }else {
  1376. np.setStatus(2);
  1377. res=2;
  1378. }
  1379. //res 1=未完成全部审核,2=未设置跳过审核,3=已审核全部跳过
  1380. return res;
  1381. }
  1382. private void updatePublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1383. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1384. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPrid(in.getId());
  1385. //打卡信息重新梳理
  1386. //查找新增的
  1387. for (OutPublicReleaseDetails out : list) {
  1388. boolean flag=true;
  1389. for (OutPublicReleaseDetails out2 : list2) {
  1390. if (out.getUid().equals(out2.getUid())){
  1391. flag=false;
  1392. }
  1393. }
  1394. if (flag){
  1395. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1396. BeanUtils.copyProperties(out,prd);
  1397. prd.setId(null);
  1398. prd.setPrid(in.getId());
  1399. prd.setClockIn(0);
  1400. prd.setClockInTime(null);
  1401. prd.setClockInRemarks(null);
  1402. prd.setUfid(null);
  1403. publicReleaseDetailsMapper.insertSelective(prd);
  1404. }
  1405. }
  1406. for (OutPublicReleaseDetails out2 : list2) {
  1407. boolean flag=true;
  1408. for (OutPublicReleaseDetails out : list) {
  1409. if (out2.getUid().equals(out.getUid())){
  1410. flag=false;
  1411. }
  1412. }
  1413. if (flag){
  1414. publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
  1415. }
  1416. }
  1417. //信息补充,修改时没有打卡信息
  1418. if(in.getValidDate()==null)in.setValidDate(use.getValidDate());
  1419. //最后再来处理打卡信息
  1420. addPublicReleaseDateClock(in);
  1421. }
  1422. private void addpublicReleaseDtails(PublicRelease use, PublicRelease in) {
  1423. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
  1424. for (OutPublicReleaseDetails out : list) {
  1425. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  1426. BeanUtils.copyProperties(out,prd);
  1427. prd.setId(null);
  1428. prd.setPrid(in.getId());
  1429. prd.setClockIn(0);
  1430. prd.setClockInTime(null);
  1431. prd.setMainStatus(0);
  1432. publicReleaseDetailsMapper.insertSelective(prd);
  1433. }
  1434. addPublicReleaseDateClock(in);
  1435. }
  1436. /**
  1437. * 处理技术助手
  1438. * @param use
  1439. */
  1440. private void updatepushAssistant(PublicRelease use,Admin a) {
  1441. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  1442. for (PublicRelease p : uselist) {
  1443. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  1444. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  1445. p.setStatus(2);
  1446. p.setAssistantAid(use.getAssistantAid());
  1447. p.setAssistantName(use.getAssistantName());
  1448. p.setUserNames(use.getUserNames());
  1449. publicReleaseMapper.update(p);
  1450. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  1451. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  1452. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  1453. publicReleaseLogMapper.insertSelective(log);
  1454. }
  1455. }
  1456. @Override
  1457. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  1458. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  1459. return list;
  1460. }
  1461. @Override
  1462. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  1463. if (clockIn == null) clockIn = 1;
  1464. PublicRelease use = publicReleaseMapper.queryById(id);
  1465. if (use.getPublicType()==1||use.getPublicType()==3) {
  1466. return -1;
  1467. }
  1468. if (use.getStatus()!=2){
  1469. return -2;
  1470. }
  1471. if(use.getType()==3){
  1472. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(id, 0);
  1473. if(publicAssistAdvices.isEmpty()){
  1474. return -3;
  1475. }
  1476. }
  1477. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  1478. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  1479. pushDateClockDetails(prdList,prdcList);
  1480. String str = "";
  1481. Date date = new Date();
  1482. boolean flag=false;
  1483. Integer clockCount=0;
  1484. PublicReleaseClock pc=new PublicReleaseClock();
  1485. pc.setPrid(id);
  1486. pc.setPhotoUrl(photoUrl);
  1487. pc.setClockInTime(date);
  1488. for (OutPublicReleaseDetails prd : prdList) {
  1489. if (prd.getUid().equals(uid)){
  1490. String aid = TokenManager.getAdminId();
  1491. pc.setPrdid(prd.getId());
  1492. prd.setClockInRemarks(clockInRemarks);
  1493. prd.setPhotoUrl(photoUrl);
  1494. prd.setClockInTime(date);
  1495. int count=0;
  1496. for (PublicReleaseDateClock ep : prd.getPrdcList()) {
  1497. if (DateUtils.isSameDay(prd.getClockInTime(), ep.getClockInTime())){
  1498. if (ep.getStatus()==0){
  1499. ep.setStatus(1);
  1500. FollowBusinessBo fbb = new FollowBusinessBo();
  1501. fbb.setUid(prd.getUid());
  1502. fbb.setContactType("5");
  1503. fbb.setResult(use.getRemarks());
  1504. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  1505. if (ub != null) {
  1506. fbb.setOcbId(ub.getId());
  1507. }
  1508. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  1509. String ufid = UUID.randomUUID().toString();
  1510. prd.setUfid(ufid);
  1511. customerService.addFollow(fbb, ufid, prd.getMainStatus(),0,null);
  1512. if (clockIn==1){
  1513. str = "公出人员打卡";
  1514. }else if (clockIn==2) {
  1515. str = "公出人员异常打卡";
  1516. }
  1517. count++;
  1518. publicReleaseDateClockMapper.updateByPrimaryKeySelective(ep);
  1519. }else {
  1520. if (clockIn==1){
  1521. str = "刷新打卡";
  1522. }else if (clockIn==2) {
  1523. str = "刷新打卡,公出人员异常打卡";
  1524. }
  1525. count++;
  1526. }
  1527. }else {
  1528. if (ep.getStatus()==1){
  1529. count++;
  1530. }
  1531. }
  1532. }
  1533. if(prd.getPrdcList().size() == count){
  1534. prd.setClockIn(1);
  1535. }
  1536. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  1537. log.setPhotoUrl(photoUrl);
  1538. publicReleaseLogMapper.insertSelective(log);
  1539. publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
  1540. flag=true;
  1541. clockCount++;
  1542. }else if (prd.getClockIn()==1){
  1543. clockCount++;
  1544. }
  1545. }
  1546. if (prdList.size()==clockCount){
  1547. PublicRelease newp=new PublicRelease();
  1548. newp.setId(id);
  1549. newp.setClockIn(1);
  1550. publicReleaseMapper.update(newp);
  1551. }
  1552. publicReleaseClockMapper.insertSelective(pc);
  1553. if (!flag){
  1554. return 0;
  1555. }
  1556. return 1;
  1557. }
  1558. @Override
  1559. public OutPublicRelease dtails(Integer id) {
  1560. String aid=TokenManager.getAdminId();
  1561. //如果不是本人和审核人员则不返回信息
  1562. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  1563. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  1564. out.setPeList(ps);
  1565. List<AdminPublicReviewerBo> adminPublicReviewerBos=null;
  1566. if(out!=null){
  1567. //详情查看权限
  1568. boolean flag=false;
  1569. //客户文档查看权限
  1570. boolean flag2=false;
  1571. //自己、审核人员与部门负责人可以查看
  1572. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  1573. if (!aid.equals( out.getAid())&&
  1574. !aid.equals(ab.getDepManager())&&
  1575. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  1576. flag=true;
  1577. }
  1578. //自己可以查看
  1579. if (aid.equals(out.getAid())){
  1580. if (out.getType()==0||out.getType() == 1){
  1581. flag2=true;
  1582. }
  1583. }
  1584. out.setMyExamine(0);
  1585. if (out.getType()==0||out.getType()==1||out.getType()==2){
  1586. if (adminPublicReviewerBos==null)adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  1587. //判定是否是上级审核人
  1588. boolean myFlag = false;
  1589. //如果是审核人可以查看
  1590. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  1591. for (AdminPublicReviewerBo e : collect) {
  1592. if (e.getReviewerId().equals(aid)){
  1593. flag=false;
  1594. if (out.getType()==0){
  1595. flag2=true;
  1596. }
  1597. myFlag=true;
  1598. break;
  1599. }
  1600. }
  1601. //判定是否是上级审核状态
  1602. if((out.getPublicType()==0|| out.getPublicType()==2)&&
  1603. (out.getTechStartProcess()==0|| out.getTechStartProcess()==2)&&
  1604. (out.getAssistProcess()==0|| out.getAssistProcess()==1)&&
  1605. (out.getAssist()==0|| out.getAssist()==1)&& out.getStatus()==1
  1606. ){
  1607. if (myFlag){
  1608. out.setMyExamine(1);
  1609. }
  1610. if(out.getPublicType()==2){
  1611. for (PublicExamine p : ps) {
  1612. if (p.getAid().equals(aid)){{
  1613. flag = false;
  1614. break;
  1615. }
  1616. }
  1617. }
  1618. } else if (out.getPublicType()==1) {
  1619. //他人公出审核
  1620. if (!ps.isEmpty()){
  1621. for (PublicExamine p : ps) {
  1622. if (p.getAid().equals(aid)){
  1623. flag=false;
  1624. if (out.getPublicType()==1&&out.getStatus()==1){
  1625. if (p.getStatus()==0)out.setMyExamine(1);
  1626. else out.setMyExamine(0);
  1627. break;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. } else if ((out.getTechStartProcess()==1&&out.getTechStartProcess()==2)&&out.getStatus()==1) {
  1634. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(out.getId());
  1635. boolean myExamine = false;
  1636. for (OutPublicReleaseDetails ord : outPublicReleaseDetails) {
  1637. User user = userMapper.selectByPrimaryKey(ord.getUid());
  1638. if (user.getAid().equals(aid)){
  1639. flag=false;
  1640. if (out.getTechStartProcess()==1)myExamine=true;
  1641. }
  1642. }
  1643. if (myExamine)out.setMyExamine(1);
  1644. } else if (out.getAssistProcess()==2||out.getAssistProcess()==3||out.getAssistProcess()==4) {
  1645. //添加协单审核人可以查看
  1646. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(out.getId(), null, null);
  1647. for (PublicRelease e : publicReleases) {
  1648. List<AdminPublicReviewerBo> sonAPRList = adminPublicReviewerMapper.selectByAid(e.getAid());
  1649. List<AdminPublicReviewerBo> collect2 = sonAPRList.stream().filter(e2 -> e2.getType() == 1).collect(Collectors.toList());
  1650. for (AdminPublicReviewerBo e2 : collect2) {
  1651. if (e2.getReviewerId().equals(aid)){
  1652. flag=false;
  1653. if((out.getAssistProcess()==2||out.getAssistProcess()==3)&&
  1654. out.getStatus()==1
  1655. ){
  1656. out.setMyExamine(1);
  1657. break;
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }else if(out.getType()==3){
  1664. //如果是协单,如果是审核人则不可以查看
  1665. if (adminPublicReviewerBos==null)adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  1666. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  1667. for (AdminPublicReviewerBo e : collect) {
  1668. if (e.getReviewerId().equals(aid)){
  1669. flag=false;
  1670. break;
  1671. }
  1672. }
  1673. String[] split = out.getAssistAid().split(",");
  1674. for (String s : split) {
  1675. if (s.equals(aid)){
  1676. flag2=true;
  1677. break;
  1678. }
  1679. }
  1680. }
  1681. //客户档案设置查看权限
  1682. if (flag2){
  1683. out.setViewPermission(1);
  1684. }else {
  1685. out.setViewPermission(0);
  1686. }
  1687. //处理返回
  1688. if(flag){
  1689. out=null;
  1690. return out;
  1691. }else {
  1692. if(aid.equals(out.getAid())) {
  1693. out.setPermission(0);
  1694. }else {
  1695. out.setPermission(1);
  1696. }
  1697. }
  1698. }
  1699. //设置审核人
  1700. pushExamine(out, adminPublicReviewerBos, ps);
  1701. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  1702. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  1703. pushDateClockDetailsToday(prdList,prdcList);
  1704. out.setPrdList(prdList);
  1705. //判定公出协单意见有没有的权限
  1706. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(out.getId(), 0);
  1707. if (publicAssistAdvices.isEmpty()){
  1708. out.setPublicAssistAdvice(0);
  1709. }else {
  1710. out.setPublicAssistAdvice(publicAssistAdvices.size());
  1711. }
  1712. return out;
  1713. }
  1714. /**
  1715. * 设置审核人
  1716. * @param out
  1717. * @param adminPublicReviewerBos
  1718. * @param ps
  1719. */
  1720. private void pushExamine(OutPublicRelease out, List<AdminPublicReviewerBo> adminPublicReviewerBos, List<PublicExamine> ps) {
  1721. //设置审核人
  1722. if (out.getStatus()==1&&
  1723. ((out.getPublicType()==0|| out.getPublicType()==2)&&(out.getTechStartProcess()==0|| out.getTechStartProcess()==2)))
  1724. {
  1725. if (adminPublicReviewerBos ==null) adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(out.getAid());
  1726. StringBuffer str =new StringBuffer();
  1727. if(out.getType()==3){
  1728. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
  1729. for (AdminPublicReviewerBo e : collect) {
  1730. str.append(e.getReviewerName()+",");
  1731. }
  1732. }else if (out.getType()==0&& out.getAssistProcess()==2){
  1733. //获取技术协单
  1734. List<PublicRelease> publicReleases = publicReleaseMapper.selectByMainId(out.getId(), null, null);
  1735. List<String> names=new ArrayList<>();
  1736. List<String> ids=new ArrayList<>();
  1737. for (PublicRelease e : publicReleases) {
  1738. if (e.getStatus()==1){
  1739. adminPublicReviewerBos = adminPublicReviewerMapper.selectByAid(e.getAid());
  1740. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e1 -> e1.getType() == 1).collect(Collectors.toList());
  1741. for (AdminPublicReviewerBo e1 : collect) {
  1742. if (!names.contains(e1.getReviewerName())){
  1743. names.add(e1.getReviewerName());
  1744. ids.add(e1.getReviewerId());
  1745. }
  1746. }
  1747. }
  1748. }
  1749. for (String name : names) {
  1750. str.append(name+",");
  1751. }
  1752. // out.setMyExamine(1);
  1753. // for (String s : ids) {
  1754. // if (s.equals(TokenManager.getAdminId())){
  1755. // out.setMyExamine(0);
  1756. // }
  1757. // }
  1758. } else {
  1759. List<AdminPublicReviewerBo> collect = adminPublicReviewerBos.stream().filter(e -> e.getType() == 0).collect(Collectors.toList());
  1760. for (AdminPublicReviewerBo e : collect) {
  1761. str.append(e.getReviewerName()+",");
  1762. }
  1763. }
  1764. if(str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1)+" 未审核");
  1765. }else if (out.getStatus()==0) {
  1766. out.setAdminExamine("");
  1767. }else {
  1768. if (!ps.isEmpty()){
  1769. StringBuffer str =new StringBuffer();
  1770. for (PublicExamine e : ps) {
  1771. if (out.getId().equals(e.getPrid())){
  1772. str.append(e.getAname());
  1773. if (e.getStatus()==0) str.append(" 未审核,");
  1774. if (e.getStatus()==1) str.append(" 已审核,");
  1775. }
  1776. if (str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1));
  1777. }
  1778. }
  1779. }
  1780. }
  1781. @Override
  1782. public OutPublicReleaseAndDetails followDtails(String id) {
  1783. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  1784. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(out.getId());
  1785. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(out.getId());
  1786. pushDateClockDetails(prdList,prdcList);
  1787. out.setPrdList(prdList);
  1788. return out;
  1789. }
  1790. @SuppressWarnings("unchecked")
  1791. @Override
  1792. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  1793. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  1794. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  1795. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  1796. public Object publicReleaseStatistics(InputPublicStatistics in) {
  1797. Map<String,Object> map =new HashMap<String, Object>();
  1798. if(in.getAid()!=null)map.put("aid", in.getAid());
  1799. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1800. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1801. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1802. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1803. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1804. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  1805. }
  1806. @SuppressWarnings("unchecked")
  1807. @Override
  1808. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  1809. Map<String,Object> map =new HashMap<String, Object>();
  1810. if(in.getAid()!=null)map.put("aid", in.getAid());
  1811. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  1812. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  1813. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1814. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  1815. }
  1816. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1817. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1818. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1819. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1820. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  1821. }
  1822. @SuppressWarnings("unchecked")
  1823. @Override
  1824. public Object publicReleaseListDtails(InputPublicDtails in) {
  1825. Map<String,Object> map =new HashMap<String, Object>();
  1826. addParams(in, map);
  1827. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  1828. List<OutPublicDtails> list = (List<OutPublicDtails>)page.getList();
  1829. List<Integer> collect = list.stream().map(OutPublicDtails::getId).collect(Collectors.toList());
  1830. if (!collect.isEmpty()){
  1831. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(collect);
  1832. pushiClockInTime(list, publicReleaseClocks);
  1833. }
  1834. return page;
  1835. }
  1836. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  1837. if(in.getAid()!=null) map.put("aid", in.getAid());
  1838. if(in.getSid()!=null) map.put("sid", in.getSid());
  1839. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  1840. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  1841. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  1842. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1843. if(in.getUid()!=null) map.put("uid", in.getUid());
  1844. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  1845. if(in.getStatus()!=null) map.put("status", in.getStatus());
  1846. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  1847. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  1848. //type 0私有 1管理权限 2所有权限
  1849. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  1850. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  1851. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  1852. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1853. //添加财务和财务经理。查看客户所有公出
  1854. in.setType(2);
  1855. if(in.getDeps()!=null){
  1856. map.put("deps", departmentService.parseArray(in.getDeps()));
  1857. }
  1858. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
  1859. ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  1860. in.setType(1);
  1861. if (in.getDeps()!=null){
  1862. List<String> list = departmentService.selectSubDeps(in.getDeps());
  1863. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  1864. map.put("deps", list);
  1865. }else {
  1866. map.put("deps",departmentService.selectMyDeps());
  1867. }
  1868. }else{
  1869. in.setType(0);
  1870. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  1871. if(in.getDeps()!=null){
  1872. map.put("deps", departmentService.parseArray(in.getDeps()));
  1873. }
  1874. }
  1875. map.put("type", in.getType());
  1876. if(in.getStatusType()!=null) map.put("statusType", in.getStatusType());
  1877. }
  1878. @SuppressWarnings("unchecked")
  1879. @Override
  1880. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  1881. Map<String,Object> map =new HashMap<String, Object>();
  1882. addParams(in, map);
  1883. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  1884. }
  1885. @Override
  1886. public int addSupplement(Integer id, String supplement, String nextPlan) {
  1887. PublicRelease pr=new PublicRelease();
  1888. pr.setId(id);
  1889. if (StringUtils.isNotEmpty(supplement)) pr.setSupplement(supplement);
  1890. if (StringUtils.isNotEmpty(nextPlan)) pr.setNextPlan(nextPlan);
  1891. return publicReleaseMapper.update(pr);
  1892. }
  1893. @Override
  1894. public int checkTime(InputPublicRelease in) {
  1895. try {
  1896. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  1897. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  1898. } catch (ParseException e) {
  1899. e.printStackTrace();
  1900. throw new BusinessException("转换异常");
  1901. }
  1902. //如果主协单且一起公出
  1903. if(in.getAssist()==1&&in.getAlone()==1){
  1904. //判定当前发起人能发起不
  1905. if(checkPublicTime(TokenManager.getAdminId(), in)){
  1906. //第一种,发起人时间重复
  1907. return 1;
  1908. // return true;
  1909. }
  1910. //判定协单时间重复
  1911. Integer x = checkTech(in);
  1912. if (x != null) return x;
  1913. }else if(in.getAssist()==1&&in.getAlone()==2){
  1914. //判定协单时间重复
  1915. Integer x = checkTech(in);
  1916. if (x != null) return x;
  1917. }else {
  1918. //判定当前发起人能发起不
  1919. if(checkPublicTime(TokenManager.getAdminId(), in)){
  1920. //第一种,发起人时间重复
  1921. return 1;
  1922. // return true;
  1923. }
  1924. }
  1925. return 0;
  1926. }
  1927. private Integer checkTech(InputPublicRelease in) {
  1928. String[] split = in.getAssistAid().split(",");
  1929. for (String s : split) {
  1930. //先查审核中和完成的时间有没有冲突的
  1931. if(checTechTime(s, in)){
  1932. //第二种,协单人时间重复
  1933. return 2;
  1934. // return true;
  1935. }
  1936. //再查发起前营销审核中时间有没有冲突的
  1937. Integer x = checkSalesmanExamine(in, s);
  1938. if (x != null) return x;
  1939. }
  1940. return 0;
  1941. }
  1942. private boolean checTechTime(String aid, InputPublicRelease in) {
  1943. List<PublicRelease> is=publicReleaseMapper.checkTime(aid,in.getReleaseStart(),in.getReleaseEnd());
  1944. if (is.size()>1) {
  1945. return true;
  1946. }else if(is.size()==1){
  1947. //如果id为新增那么直接不允许时间重复
  1948. if (in.getId()==null){
  1949. return true;
  1950. }else {
  1951. //如果有id,与获取id一直,则为当前修改可以
  1952. if (in.getId().equals(is.get(0).getMainId())){
  1953. return false;
  1954. }else {
  1955. return true;
  1956. }
  1957. }
  1958. }
  1959. return false;
  1960. }
  1961. private Integer checkSalesmanExamine(InputPublicRelease in, String s) {
  1962. List<PublicRelease> is = publicReleaseMapper.checkTech(s, in.getReleaseStart(), in.getReleaseEnd());
  1963. if (is.size()>1) {
  1964. return 2;
  1965. }else if(is.size()==1){
  1966. //如果id为新增那么直接不允许时间重复
  1967. if (in.getId()==null){
  1968. return 2;
  1969. }else {
  1970. //如果有id,与获取id一直,则为当前修改可以
  1971. if (in.getId().equals(is.get(0).getId())){
  1972. return 0;
  1973. }else {
  1974. return 2;
  1975. }
  1976. }
  1977. }
  1978. return null;
  1979. }
  1980. /**
  1981. *
  1982. * @param aid
  1983. * @param in
  1984. * @return true 已经发起 false 未发起
  1985. */
  1986. private boolean checkPublicTime(String aid, InputPublicRelease in) {
  1987. List<PublicRelease> is=publicReleaseMapper.checkTime(aid,in.getReleaseStart(),in.getReleaseEnd());
  1988. if (is.size()>1) {
  1989. return true;
  1990. }else if(is.size()==1){
  1991. //如果id为新增那么直接不允许时间重复
  1992. if (in.getId()==null){
  1993. return true;
  1994. }else {
  1995. //如果有id,与获取id一直,则为当前修改可以
  1996. if (in.getId().equals(is.get(0))){
  1997. return false;
  1998. }else {
  1999. return true;
  2000. }
  2001. }
  2002. }
  2003. return false;
  2004. }
  2005. @Override
  2006. public List<Map<String, Object>> selectOrderByUid(String uid) {
  2007. return tOrderNewMapper.selectOrderByuid(uid);
  2008. }
  2009. @Override
  2010. public List<OutPublicRelease> publicByOrder(String orderNo) {
  2011. return publicReleaseMapper.publicByOrder(orderNo);
  2012. }
  2013. @Override
  2014. public Object getMyNewPublic() {
  2015. List<PublicRelease> myPublic=publicReleaseMapper.selectMyNewPublic(TokenManager.getAdminId());
  2016. if(myPublic.isEmpty())return null;
  2017. Integer id=null;
  2018. long count=999999;
  2019. for (PublicRelease e : myPublic) {
  2020. long nowTime=System.currentTimeMillis();
  2021. long time = Math.abs(nowTime-e.getReleaseStart().getTime())/(1000*60);
  2022. long time2 = Math.abs(e.getReleaseEnd().getTime()-nowTime)/(1000*60);
  2023. //距离当前时间近的开始时间,不大于当前时间
  2024. if (time<count&&e.getReleaseStart().getTime()<nowTime){
  2025. if (e.getAlone()!=1 && e.getAssist()!=1){
  2026. count=time;
  2027. id=e.getId();
  2028. }
  2029. }
  2030. //距离当前时间近的结束时间,不小于当前时间
  2031. if (time2<count&&e.getReleaseEnd().getTime()>nowTime){
  2032. if (e.getAlone()!=1 && e.getAssist()!=1){
  2033. count=time2;
  2034. id=e.getId();
  2035. }
  2036. }
  2037. }
  2038. if (id==null)id=myPublic.get(0).getId();
  2039. OutPublicReleaseList out = publicReleaseMapper.selectOutListBoById(id);
  2040. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
  2041. List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
  2042. pushDateClockDetails(prdList,prdcList);
  2043. pushDateClockDetailsToday(prdList,prdcList);
  2044. out.setPrdList(prdList);
  2045. List<PublicAssistAdvice> publicAssistAdvices = publicAssistAdviceMapper.selectList(out.getId(), 0);
  2046. if (publicAssistAdvices.isEmpty()){
  2047. out.setPublicAssistAdvice(0);
  2048. }else {
  2049. out.setPublicAssistAdvice(publicAssistAdvices.size());
  2050. }
  2051. return out;
  2052. // List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  2053. // if (myPublic.isEmpty()){
  2054. // List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  2055. // if (!myPublic2.isEmpty()){
  2056. // return myPublic2.get(0);
  2057. // }
  2058. // }else {
  2059. // return myPublic.get(0);
  2060. // }
  2061. }
  2062. private void pushDateClockDetailsToday(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  2063. for (OutPublicReleaseDetails out : prdList) {
  2064. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  2065. for (PublicReleaseDateClock prdc : prdcList) {
  2066. if (prdc.getPrdid().equals(out.getId())&&DateUtils.isSameDay(new Date(), prdc.getClockInTime())){
  2067. elist.add(prdc);
  2068. }
  2069. }
  2070. out.setPrdcList(elist);
  2071. }
  2072. }
  2073. private void pushDateClockDetails(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
  2074. for (OutPublicReleaseDetails out : prdList) {
  2075. List<PublicReleaseDateClock> elist=new ArrayList<>();;
  2076. for (PublicReleaseDateClock prdc : prdcList) {
  2077. if (prdc.getPrdid().equals(out.getId())){
  2078. elist.add(prdc);
  2079. }
  2080. }
  2081. out.setPrdcList(elist);
  2082. }
  2083. }
  2084. /**
  2085. *
  2086. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  2087. * @param dateType 是否含打卡时间 0否 1是
  2088. * @return
  2089. */
  2090. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  2091. Map<String, Object> map = new HashMap<>();
  2092. if (type==null)type=0;
  2093. map.put("type",type);
  2094. //statusType=1情况下
  2095. map.put("statusType",1);
  2096. if (dateType==1){
  2097. Date date = new Date();
  2098. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  2099. map.put("clockTime",clockTime);
  2100. }
  2101. map.put("aid",TokenManager.getAdminId());
  2102. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  2103. for (OutPublicReleaseList out : list) {
  2104. out.setPrdList(publicReleaseDetailsMapper.selectByPrid(out.getId()));
  2105. }
  2106. return list;
  2107. }
  2108. @Override
  2109. public int addAssistant(Integer id,String aid) {
  2110. PublicRelease p = publicReleaseMapper.queryById(id);
  2111. List<String> list=new ArrayList<>();
  2112. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  2113. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  2114. }
  2115. String sname = pushAssistant(aid, list,0);
  2116. String said =String.join(",",list);
  2117. p.setAssistantAid(said);
  2118. p.setAssistantName(sname);
  2119. addAssistantPublicRelease(p,aid);
  2120. return updateAssistant(p, said, sname);
  2121. }
  2122. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  2123. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  2124. PublicRelease newP= new PublicRelease();
  2125. if(list.isEmpty()){
  2126. BeanUtils.copyProperties(p,newP);
  2127. newP.setId(null);
  2128. newP.setAid(aid);
  2129. newP.setAssist(3);
  2130. newP.setType(4);
  2131. publicReleaseMapper.insertSelective(newP);
  2132. addpublicReleaseDtails(p,newP);
  2133. StringBuffer str=new StringBuffer();
  2134. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  2135. addWeChatNotice( aid,1,str.toString(),newP.getId());
  2136. }else {
  2137. for (PublicRelease pr : list) {
  2138. newP.setId(pr.getId());
  2139. newP.setAssistantAid(p.getAssistantAid());
  2140. newP.setAssistantName(p.getAssistantName());
  2141. publicReleaseMapper.update(newP);
  2142. updatePublicReleaseDtails(p,newP);
  2143. }
  2144. }
  2145. }
  2146. /**
  2147. * 添加微信提示和站内消息
  2148. * @param aid 接受者
  2149. * @param type 状态 0驳回 1发起 2同意 3撤销
  2150. * @param str 备注
  2151. * @param prid 公出编号
  2152. */
  2153. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  2154. Admin recipient = adminMapper.selectByPrimaryKey(aid);
  2155. addWeChatNotice( recipient, type, str, prid);
  2156. }
  2157. /**
  2158. * 添加微信提示和站内消息
  2159. * @param recipient 接受者
  2160. * @param type 状态 0驳回 1发起 2同意 3撤销
  2161. * @param str
  2162. */
  2163. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  2164. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  2165. String openid=recipient.getOpenId();
  2166. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  2167. if(type==3){
  2168. addpublicLog(prid,4,str);
  2169. }else {
  2170. addpublicLog(prid,type,str);
  2171. }
  2172. sendNoticeAndSoucket(recipient.getId(),type,str);
  2173. if (type==0||type==2){
  2174. if (openid!=null) {
  2175. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  2176. return res;
  2177. }else {
  2178. sendEmail(my, recipient,type);
  2179. }
  2180. }
  2181. return 0;
  2182. }
  2183. private int updateAssistant(PublicRelease p, String said, String sname) {
  2184. PublicRelease newPr=new PublicRelease();
  2185. newPr.setId(p.getId());
  2186. newPr.setAssistantAid(said);
  2187. newPr.setAssistantName(sname);
  2188. if (p.getMainId()!=null){
  2189. PublicRelease mianPr=new PublicRelease();
  2190. mianPr.setId(p.getMainId());
  2191. // mianPr.setAid(said);
  2192. mianPr.setAssistantAid(said);
  2193. mianPr.setAssistantName(sname);
  2194. publicReleaseMapper.update(mianPr);
  2195. }
  2196. return publicReleaseMapper.update(newPr);
  2197. }
  2198. /**
  2199. *
  2200. * @param aid 元素
  2201. * @param list 集合
  2202. * @param type 0新增 1删除
  2203. * @return
  2204. */
  2205. private String pushAssistant(String aid, List<String> list,Integer type) {
  2206. StringBuffer sb=new StringBuffer();
  2207. if(type==0){
  2208. list.add(aid);
  2209. }else if (type==1){
  2210. Iterator<String > it =list.iterator();
  2211. while (it.hasNext()){
  2212. if (it.next().equals(aid))
  2213. it.remove();
  2214. }
  2215. }
  2216. for (String s : list) {
  2217. sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
  2218. }
  2219. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  2220. }
  2221. @Override
  2222. public int deleteAssistant(Integer id, String aid) {
  2223. PublicRelease p = publicReleaseMapper.queryById(id);
  2224. if (p.getAssistantAid()==null){
  2225. throw new BusinessException("人员不存在");
  2226. }
  2227. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  2228. if (!list.contains(aid)){
  2229. throw new BusinessException("人员不存在");
  2230. }
  2231. String sname = pushAssistant(aid, list,1);
  2232. String said =String.join(",",list);
  2233. p.setAssistantAid(said);
  2234. p.setAssistantName(sname);
  2235. deleteAssistantPulicRelease(p,aid);
  2236. return updateAssistant(p, said, sname);
  2237. }
  2238. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  2239. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  2240. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  2241. StringBuffer str=new StringBuffer();
  2242. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  2243. for (PublicRelease pr : list) {
  2244. if (pr.getAid().equals(aid)){
  2245. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  2246. }else {
  2247. PublicRelease newPr=new PublicRelease();
  2248. newPr.setId(pr.getId());
  2249. newPr.setAssistantAid(p.getAssistantAid());
  2250. newPr.setAssistantName(p.getAssistantName());
  2251. publicReleaseMapper.update(newPr);
  2252. }
  2253. }
  2254. }
  2255. @Override
  2256. public boolean checkdeleteAssistant(Integer id, String aid) {
  2257. PublicRelease p = publicReleaseMapper.queryById(id);
  2258. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  2259. for (PublicRelease use : list) {
  2260. // if (use.getClockIn()==1){
  2261. // return true;
  2262. // }
  2263. }
  2264. return false;
  2265. }
  2266. @Override
  2267. public boolean checkaddAssistant(Integer id, String aid) {
  2268. PublicRelease p = publicReleaseMapper.queryById(id);
  2269. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  2270. for (PublicRelease use : list) {
  2271. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  2272. return true;
  2273. }
  2274. }
  2275. return false;
  2276. }
  2277. @Override
  2278. public int updateLocation(InputPublicRelease in) {
  2279. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  2280. if (prd==null){
  2281. throw new BusinessException("公出企业不存在");
  2282. }
  2283. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  2284. updateprd.setId(prd.getId());
  2285. updateprd.setLatitude(in.getLatitude());
  2286. updateprd.setLongitude(in.getLongitude());
  2287. updateprd.setDistrictName(in.getDistrictName());
  2288. updateprd.setClockIn(0);
  2289. addpublicLog(in.getId(),5,"发起公出地点修改");
  2290. return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
  2291. }
  2292. @Override
  2293. public Object publicReleaseAndCount(InputPublicDtails in) {
  2294. List<OutPublicDtails> list = publicReleaseListDtailsList(in);
  2295. Map<String,Object> map=new HashMap<String, Object>();
  2296. if (list.isEmpty()){
  2297. map.put("list",list);
  2298. map.put("count",0);
  2299. map.put("durationCount",0);
  2300. map.put("peopleCount",0);
  2301. }else {
  2302. //公出次数
  2303. int count=0;
  2304. BigDecimal durationCount=BigDecimal.ZERO;
  2305. List<String> aList =new ArrayList<>();
  2306. for (OutPublicDtails e : list) {
  2307. if (e.getType()==0||e.getType()==1||e.getType()==2){
  2308. count++;
  2309. if (e.getDuration()!=null){
  2310. durationCount=durationCount.add(new BigDecimal(e.getDuration()));
  2311. }
  2312. if (!aList.contains(e.getAname())){
  2313. aList.add(e.getAname());
  2314. }
  2315. if (StringUtils.isNotEmpty(e.getAssistAidName())){
  2316. String[] split = e.getAssistAidName().split(",");
  2317. for (String s : split) {
  2318. if (!aList.contains(s)){
  2319. aList.add(s);
  2320. }
  2321. }
  2322. }
  2323. if (StringUtils.isNotEmpty(e.getAssistantName())){
  2324. String[] split = e.getAssistantName().split(",");
  2325. for (String s : split) {
  2326. if (!aList.contains(s)){
  2327. aList.add(s);
  2328. }
  2329. }
  2330. }
  2331. }
  2332. }
  2333. map.put("list",list);
  2334. map.put("count",count);
  2335. map.put("durationCount",durationCount);
  2336. map.put("peopleCount",aList.size());
  2337. }
  2338. return map;
  2339. }
  2340. /**
  2341. *
  2342. * @param in 公出参数
  2343. * @param a 新增时需哟额外知道当前任务
  2344. * @param type 0查询 1新增 2修改
  2345. * @return
  2346. */
  2347. public Map checkOrderNoDuration( InputPublicRelease in,AdminListBo a,int type) {
  2348. List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
  2349. TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
  2350. OutPublicRelease outPublicRelease=null;
  2351. //实际公出
  2352. BigDecimal actualDuration = BigDecimal.ZERO;
  2353. //公出次数
  2354. int frequency=0;
  2355. List<String> peopleList = new ArrayList<>();
  2356. //判定是不是新增获取原数据,是新增数量加1
  2357. if (in.getId()!=null){
  2358. outPublicRelease= publicReleaseMapper.selectDtails(in.getId());
  2359. }else {
  2360. peopleList.add(TokenManager.getAdminId());
  2361. actualDuration=actualDuration.add(BigDecimal.valueOf(in.getDuration()));
  2362. frequency++;
  2363. }
  2364. for (PublicRelease e : list) {
  2365. //新增直接计算
  2366. if (in.getId()==null){
  2367. if (e.getDuration()!=null){
  2368. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  2369. if (!peopleList.contains(e.getAid())){
  2370. peopleList.add(e.getAid());
  2371. }
  2372. frequency++;
  2373. }
  2374. }else {
  2375. //修改当前数据要从修改后获取
  2376. if (!e.getId().equals(in.getId())){
  2377. if (e.getDuration()!=null){
  2378. actualDuration=actualDuration.add(BigDecimal.valueOf(e.getDuration()));
  2379. if (!peopleList.contains(e.getAid())){
  2380. peopleList.add(e.getAid());
  2381. }
  2382. frequency++;
  2383. }
  2384. }else {
  2385. if (outPublicRelease != null && outPublicRelease.getDuration() != null) {
  2386. actualDuration = actualDuration.add(BigDecimal.valueOf(outPublicRelease.getDuration()));
  2387. if (!peopleList.contains(outPublicRelease.getAid())) {
  2388. peopleList.add(outPublicRelease.getAid());
  2389. }
  2390. frequency++;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. Map map=new HashMap();
  2396. CheckOrderNoOut data= new CheckOrderNoOut();
  2397. if (outPublicRelease!=null){
  2398. data.setPublicReleaseName(outPublicRelease.getAname());
  2399. }
  2400. //新增与修改,需要重新获取实际公出与人数与次数
  2401. if (type==1||type==2){
  2402. TOrderPublicReleaseCount update=new TOrderPublicReleaseCount();
  2403. update.setOrderNo(in.getOrderNo());
  2404. update.setFrequency(frequency);
  2405. update.setActualDuration(actualDuration.doubleValue());
  2406. update.setPeopleCount(peopleList.size());
  2407. tOrderPublicReleaseCountMapper.updateByOrderNo(update);
  2408. }
  2409. data.setTimesCount(frequency);
  2410. data.setPeopleCount(peopleList.size());
  2411. data.setUserName(t.getUserName());
  2412. data.setContractNo(t.getContractNo());
  2413. data.setAdminName(t.getSalesmanName());
  2414. data.setDurationCount(actualDuration);
  2415. //获取年份
  2416. List<OrderYearMaxDuration> yearMaxDurationList = orderYearMaxDurationMapper.selectByOrderNo(in.getOrderNo());
  2417. int year = LocalDate.now().getYear();
  2418. OrderYearMaxDuration useOyd = null;
  2419. for (int i = 0; i < yearMaxDurationList.size(); i++) {
  2420. OrderYearMaxDuration oyd = yearMaxDurationList.get(i);
  2421. //年份为0不是会员直接获取跳出循环,否则获取当前年份,获取不到获取最后一年
  2422. if (oyd.getYear()==0){
  2423. useOyd=oyd;
  2424. break;
  2425. }else {
  2426. if (oyd.getYear().equals(year)){
  2427. useOyd = oyd;
  2428. break;
  2429. }
  2430. if(i==yearMaxDurationList.size()-1&&useOyd==null){
  2431. useOyd = yearMaxDurationList.get(i);
  2432. }
  2433. }
  2434. }
  2435. data.setDurationMax(useOyd.getMaxDuration());
  2436. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(in.getOrderNo());
  2437. List<TTaskMember> tTaskMembers = tTaskMemberMapper.selectByOrderNo(tOrderNew.getOrderNo());
  2438. String amountName=null;
  2439. String amountType=null;
  2440. if (tTaskMembers.size()<1){
  2441. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(1))<0){
  2442. amountName="本合同低于1万";
  2443. amountType="原则上技术人员不可下户";
  2444. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0){
  2445. amountName="本合同在1~3万";
  2446. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2447. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0){
  2448. amountName="本合同在3~5万";
  2449. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2450. }else if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0){
  2451. amountName="本合同在5~10万";
  2452. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2453. }
  2454. }else {
  2455. int yearSum=1;
  2456. for (TTaskMember tTaskMember : tTaskMembers) {
  2457. if (tTaskMember.getYearSum()!=null&&tTaskMember.getYearSum()>yearSum){
  2458. yearSum=tTaskMember.getYearSum();
  2459. }
  2460. }
  2461. BigDecimal divide =BigDecimal.ZERO;
  2462. if (tOrderNew.getTotalAmount().compareTo(BigDecimal.valueOf(0))>0&&yearSum>0){
  2463. divide=tOrderNew.getTotalAmount().divide(BigDecimal.valueOf(yearSum), BigDecimal.ROUND_HALF_UP);
  2464. }else {
  2465. divide=tOrderNew.getTotalAmount();
  2466. }
  2467. if (divide.compareTo(BigDecimal.valueOf(1))<0){
  2468. amountName="此会员订单,本年度金额低于1万";
  2469. amountType="原则上技术人员不可下户";
  2470. }else if (divide.compareTo(BigDecimal.valueOf(3))<0){
  2471. amountName="此会员订单,本年度金额1~3万";
  2472. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2473. }else if (divide.compareTo(BigDecimal.valueOf(5))<0){
  2474. amountName="此会员订单,本年度金额3~5万";
  2475. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2476. }else if (divide.compareTo(BigDecimal.valueOf(10))<0){
  2477. amountName="此会员订单,本年度金额5~10万";
  2478. amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
  2479. }
  2480. }
  2481. data.setAmountName(amountName);
  2482. data.setAmountType(amountType);
  2483. //不需要限制
  2484. if(useOyd.getStatus()==1){
  2485. map.put("code",true);
  2486. map.put("data",null);
  2487. }else {
  2488. //需要限制判定小时
  2489. if (actualDuration.compareTo(data.getDurationMax())<1){
  2490. map.put("code",true);
  2491. map.put("data",null);
  2492. }else {
  2493. map.put("code",false);
  2494. map.put("data",data);
  2495. }
  2496. }
  2497. return map;
  2498. }
  2499. @Override
  2500. public Map checkOrderNoDuration( InputPublicRelease in){
  2501. return checkOrderNoDuration(in,null,0);
  2502. }
  2503. @Override
  2504. public void pushOutPublicDtails(List<OutPublicDtails> list) {
  2505. List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(list.stream().map(OutPublicDtails::getId).collect(Collectors.toList()));
  2506. pushiClockInTime(list, publicReleaseClocks);
  2507. }
  2508. private void pushiClockInTime(List<OutPublicDtails> list, List<PublicReleaseClock> publicReleaseClocks) {
  2509. for (OutPublicDtails outPublicDtails : list) {
  2510. if (outPublicDtails.getClockIn()!=null){
  2511. if (outPublicDtails.getAlone()==2&&outPublicDtails.getAssist()==1){
  2512. outPublicDtails.setClockInStr("无需打卡");
  2513. }else if (outPublicDtails.getClockIn()==0)outPublicDtails.setClockInStr("未打卡");
  2514. else if (outPublicDtails.getClockIn()==1)outPublicDtails.setClockInStr("已打卡");
  2515. else if (outPublicDtails.getClockIn()==2)outPublicDtails.setClockInStr("异常打卡");
  2516. }
  2517. List<PublicReleaseClock> colokList =new ArrayList<>();
  2518. StringBuilder sb = new StringBuilder();
  2519. for (PublicReleaseClock e : publicReleaseClocks) {
  2520. if (outPublicDtails.getPrdId().equals(e.getPrdid())){
  2521. sb.append(DateUtils.formatDateYYYYMMddHHmm(e.getClockInTime())).append("\n");
  2522. colokList.add(e);
  2523. }
  2524. colokList.sort(Comparator.comparing(PublicReleaseClock::getClockInTime));
  2525. Collections.reverse(colokList);
  2526. outPublicDtails.setList(colokList);
  2527. }
  2528. outPublicDtails.setClockInTimes(sb.toString());
  2529. }
  2530. }
  2531. @Override
  2532. public Object pushDateClock() {
  2533. List<PublicRelease> publicReleases = publicReleaseMapper.selectAll();
  2534. for (PublicRelease e : publicReleases) {
  2535. addPublicReleaseDateClock(e);
  2536. }
  2537. return 1;
  2538. }
  2539. private void addPublicReleaseDateClock(PublicRelease e) {
  2540. publicReleaseDateClockMapper.deleteByPrid(e.getId());
  2541. List<PublicReleaseDateClock> list= new ArrayList<>();
  2542. if (e.getValidDate()!=null){
  2543. List<Map> maps = JSONArray.parseArray(e.getValidDate(), Map.class);
  2544. for (Map map : maps) {
  2545. String dates = (String) map.get("value");
  2546. if (dates!=null){
  2547. Date date = DateUtils.parseDate(dates);
  2548. List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(e.getId());
  2549. for (OutPublicReleaseDetails det : outPublicReleaseDetails) {
  2550. PublicReleaseDateClock newPRDC = new PublicReleaseDateClock();
  2551. newPRDC.setClockInTime(date);
  2552. newPRDC.setPrid(e.getId());
  2553. newPRDC.setPrdid(det.getId());
  2554. newPRDC.setStatus(det.getClockIn());
  2555. list.add(newPRDC);
  2556. }
  2557. }
  2558. }
  2559. }
  2560. if(!list.isEmpty()){
  2561. publicReleaseDateClockMapper.insertBatch(list);
  2562. list.clear();
  2563. }
  2564. }
  2565. @Override
  2566. @Cacheable(value = "releaseAndExpenseCount#300", key = "'getCounts:key='+#in.buyerName+#in.contractNo+#in.aid+#in.depId+#in.allStatus+#in.startTime+#in.endTime")
  2567. public List<releaseAndExpenseCountOut> releaseAndExpenseCount(InputreleaseAndExpenseCount in) {
  2568. if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
  2569. List<releaseAndExpenseCountOut> expenseCountsOrders = publicReleaseMapper.releaseAndExpenseCount(in);
  2570. expenseCountsOrders.forEach(e->{
  2571. if (e.getExceedDuration()!=null){
  2572. double exceedDuration = Double.parseDouble(e.getExceedDuration());
  2573. if (exceedDuration>0){
  2574. e.setExceedType(1);
  2575. }
  2576. }
  2577. //获取年份
  2578. if (StringUtils.isNotEmpty(e.getOrderNo())){
  2579. List<OrderYearMaxDuration> yearMaxDurationList = orderYearMaxDurationMapper.selectByOrderNo(e.getOrderNo());
  2580. int year = LocalDate.now().getYear();
  2581. OrderYearMaxDuration useOyd = null;
  2582. for (int i = 0; i < yearMaxDurationList.size(); i++) {
  2583. OrderYearMaxDuration oyd = yearMaxDurationList.get(i);
  2584. //年份为0不是会员直接获取跳出循环,否则获取当前年份,获取不到获取最后一年
  2585. if (oyd.getYear()==0){
  2586. useOyd=oyd;
  2587. break;
  2588. }else {
  2589. if (oyd.getYear().equals(year)){
  2590. useOyd = oyd;
  2591. break;
  2592. }
  2593. if(i==yearMaxDurationList.size()-1&&useOyd==null){
  2594. useOyd = yearMaxDurationList.get(i);
  2595. }
  2596. }
  2597. }
  2598. if(useOyd.getStatus()==1){
  2599. e.setMaxDuration("不限制");
  2600. e.setExceedDuration("0");
  2601. }else {
  2602. e.setMaxDuration(useOyd.getMaxDuration().toString());
  2603. if (useOyd.getMaxDuration().compareTo(new BigDecimal(e.getActualDuration()))>=0){
  2604. e.setExceedDuration("0");
  2605. }else {
  2606. e.setExceedDuration(new BigDecimal(e.getActualDuration()).subtract(useOyd.getMaxDuration()).toString());
  2607. }
  2608. }
  2609. }
  2610. });
  2611. return expenseCountsOrders;
  2612. }
  2613. @Override
  2614. @CacheEvict(value = "releaseAndExpenseCount#300",allEntries = true)
  2615. public Object releaseAndExpenseCountClear() {
  2616. LoggerUtils.debug(getClass(),"公出&报销缓存清除。");
  2617. return 1;
  2618. }
  2619. }