PublicReleaseServiceImpl.java 76 KB

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