PublicReleaseServiceImpl.java 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  1. package com.goafanti.weChat.service.impl;
  2. import cn.jiguang.common.utils.StringUtils;
  3. import com.goafanti.admin.bo.AdminListBo;
  4. import com.goafanti.admin.service.DepartmentService;
  5. import com.goafanti.common.bo.EmailBo;
  6. import com.goafanti.common.constant.AFTConstants;
  7. import com.goafanti.common.dao.*;
  8. import com.goafanti.common.enums.NoticeStatus;
  9. import com.goafanti.common.error.BusinessException;
  10. import com.goafanti.common.model.*;
  11. import com.goafanti.common.utils.AsyncUtils;
  12. import com.goafanti.common.utils.DateUtils;
  13. import com.goafanti.common.utils.SendEmailUtil;
  14. import com.goafanti.common.utils.WeChatUtils;
  15. import com.goafanti.core.mybatis.BaseMybatisDao;
  16. import com.goafanti.core.mybatis.page.Pagination;
  17. import com.goafanti.core.shiro.token.TokenManager;
  18. import com.goafanti.core.websocket.SystemWebSocketHandler;
  19. import com.goafanti.customer.bo.FollowBusinessBo;
  20. import com.goafanti.customer.service.CustomerService;
  21. import com.goafanti.order.bo.TOrderNewBo;
  22. import com.goafanti.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.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import org.springframework.web.socket.TextMessage;
  29. import java.math.BigDecimal;
  30. import java.text.ParseException;
  31. import java.util.*;
  32. import java.util.concurrent.atomic.AtomicReference;
  33. @Service
  34. public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
  35. @Autowired
  36. private PublicReleaseMapper publicReleaseMapper;
  37. @Autowired
  38. private PublicReleaseLogMapper publicReleaseLogMapper;
  39. @Autowired
  40. private CustomerService customerService;
  41. @Autowired
  42. private PublicReleaseDetailsMapper publicReleaseDetailsMapper;
  43. @Autowired
  44. private WeChatUtils weChatUtils;
  45. @Autowired
  46. private AdminMapper adminMapper;
  47. @Autowired
  48. private AsyncUtils asyncUtils;
  49. @Autowired
  50. private UserMapper userMapper;
  51. @Autowired
  52. private OrganizationContactBookMapper organizationContactBookMapper;
  53. @Autowired
  54. private SystemWebSocketHandler systemWebSocketHandler;
  55. @Autowired
  56. private TOrderNewMapper tOrderNewMapper;
  57. @Autowired
  58. private DepartmentService departmentService;
  59. @Autowired
  60. private PublicExamineMapper publicExamineMapper;
  61. @Autowired
  62. private AdminUserCountMapper adminUserCountMapper;
  63. @Override
  64. @Transactional
  65. public Map<String, Object> addPublicRelease(InputPublicRelease in) {
  66. Date date =new Date();
  67. if (in.getPublicAgain()==null)in.setPublicAgain(0);
  68. in.setCreateTime(date);
  69. in.setPublicType(0);
  70. in.setStatus(1);
  71. in.setAid(TokenManager.getAdminId());
  72. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  73. if (in.getAssist()==1){
  74. // in.setAssistAidName(getAssistAidName(in.getAssistAid()));
  75. in.setMainName(my.getName());
  76. }
  77. Map checkOrderNo =null;
  78. if (in.getType() == 1) {
  79. checkOrderNo = checkOrderNoDuration(in);
  80. boolean isValid = (boolean) checkOrderNo.get("code");
  81. if (isValid){
  82. in.setTechStartProcess(0);
  83. }else {
  84. in.setTechStartProcess(1);
  85. }
  86. }
  87. publicReleaseMapper.insertSelective(in);
  88. List<PublicReleaseDetails> prdList=new ArrayList<>();
  89. List<User> users=new ArrayList<>();
  90. StringBuilder str =new StringBuilder();
  91. if (in.getUids()!=null){
  92. List<String> split = Arrays.asList(in.getUids().split(","));
  93. int userCount=split.size();
  94. Double duration = in.getDuration();
  95. //计算平均
  96. double d = durationSum(duration, userCount);
  97. int index=1;
  98. //获取非已企业公出需要的审核人员
  99. for (String s : split) {
  100. PublicReleaseDetails prd=new PublicReleaseDetails();
  101. User u=userMapper.selectByPrimaryKey(s);
  102. users.add(u);
  103. str.append(u.getNickname()).append(",");
  104. if (u!=null&&u.getShareType()==2){
  105. prd.setNewUser(1);
  106. }else {
  107. prd.setNewUser(0);
  108. }
  109. if (u.getAid().equals(in.getAid())){
  110. prd.setMainStatus(1);
  111. }else {
  112. prd.setMainStatus(0);
  113. }
  114. prd.setPrid(in.getId());
  115. prd.setUid(s);
  116. prd.setSignSum(0);
  117. prd.setClockIn(0);
  118. prd.setDistrictName(in.getDistrictName());
  119. prd.setLatitude(in.getLatitude());
  120. prd.setLongitude(in.getLongitude());
  121. if (index<userCount){
  122. if (duration==0){
  123. prd.setDuration(duration);
  124. } else {
  125. prd.setDuration(d);
  126. duration=duration-d;
  127. }
  128. index++;
  129. }else {
  130. prd.setDuration(duration);
  131. }
  132. prdList.add(prd);
  133. }
  134. publicReleaseDetailsMapper.insertBatch(prdList);
  135. }
  136. String userNames=str.substring(0,str.length()-1);
  137. in.setUserNames(userNames);
  138. PublicRelease updateName=new PublicRelease();
  139. updateName.setId(in.getId());
  140. updateName.setUserNames(userNames);
  141. publicReleaseMapper.updateByPrimaryKeySelective(updateName);
  142. addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
  143. return (Map<String, Object>) addPublicReleaseLog(my, in,userNames,date,users,checkOrderNo);
  144. }
  145. private void addPublicExamine(Integer id, String aid) {
  146. Admin admin = adminMapper.selectByPrimaryKey(aid);
  147. addPublicExamine(id,admin);
  148. }
  149. private void addPublicExamine(Integer id, Admin a) {
  150. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
  151. boolean flag=false;
  152. for (PublicExamine pe : publicExamines) {
  153. if (pe.getAid().equals(a.getId())){
  154. flag=true;
  155. }
  156. }
  157. if (!flag){
  158. PublicExamine pe=new PublicExamine();
  159. pe.setPrid(id);
  160. pe.setAid(a.getId());
  161. pe.setAname(a.getName());
  162. pe.setStatus(0);
  163. publicExamineMapper.insertSelective(pe);
  164. }
  165. }
  166. private double durationSum(Double duration, Integer sum) {
  167. Double counts= Math.floor(duration/0.5);
  168. //计算当前时间
  169. Double my=Math.floor(counts/sum)*0.5;
  170. if (my<0.5)return 0.5;
  171. return my;
  172. }
  173. /**
  174. *
  175. * @param my 我的相关人员
  176. * @param in 公出信息
  177. * @param nickname 客户名称
  178. * @param date 时间
  179. */
  180. private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users,
  181. Map<String,Object> checkOrderNo) {
  182. Map<String, Object>map=new HashMap<String, Object>();
  183. //无需订单负责人审核
  184. if (in.getTechStartProcess()==0){
  185. //获取公出审核人
  186. Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
  187. String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
  188. //默认上级审核
  189. AtomicReference<Integer> status= new AtomicReference<>(1);
  190. String formatDate = DateUtils.formatDate(in.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS);
  191. //不是业务员
  192. if (in.getType()==0){
  193. if (my.getPublicPurview()==0){
  194. users.forEach(u->{
  195. if (!u.getAid().equals(my.getId())){
  196. StringBuffer str2=new StringBuffer();
  197. str2=str2.append(my.getName()).append("(需审核),准备公出您的企业");
  198. str2=str2.append("[").append(u.getNickname()).append("]!!!。");
  199. sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
  200. Admin admin = adminMapper.selectByPrimaryKey(u.getAid());
  201. if (in.getType()==0){
  202. //不是自己的企业则需要审核并设置非自己客户待审核
  203. addPublicExamine(in.getId(), admin);
  204. if(in.getPublicType()==null|| in.getPublicType()==0)in.setPublicType(1);
  205. }
  206. pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
  207. status.set(0);
  208. }
  209. });
  210. }else {
  211. users.forEach(u->{
  212. if (!u.getAid().equals(my.getId())){
  213. StringBuffer str2=new StringBuffer();
  214. str2=str2.append(my.getName()).append("计划公出您的企业").append(u.getNickname())
  215. .append(",").append(formatDate).append("【小程序端广播提示】");
  216. sendNoticeAndSoucket(u.getAid(),3,str2.toString());
  217. }
  218. });
  219. }
  220. }
  221. if (status.get()==1){
  222. pushNoticeAndSoucketAndEmail(my, in, date, a, str, map);
  223. }
  224. publicReleaseMapper.updateByPrimaryKeySelective(in);
  225. }else {
  226. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(in.getOrderNo());
  227. String salesmanId = tOrderNew.getSalesmanId();
  228. Admin a = adminMapper.selectByPrimaryKey(salesmanId);
  229. CheckOrderNoOut data = (CheckOrderNoOut) checkOrderNo.get("data");
  230. String format = getString(my, data);
  231. pushNoticeAndSoucketAndEmail(my, in, date, a, format, map);
  232. }
  233. map.put("data", publicReleaseMapper.selectDtails(in.getId()));
  234. return map;
  235. }
  236. private String getString(AdminListBo my, CheckOrderNoOut data) {
  237. String amountName="";
  238. if (data.getAmountType()==0)amountName="低于1万";
  239. if (data.getAmountType()==1)amountName="在1~3万";
  240. if (data.getAmountType()==2)amountName="在3~5万";
  241. if (data.getAmountType()==3)amountName="在5~10万";
  242. String format = String.format("%s准备公出%s(%s)," +
  243. "总计公出:%s人,%s次,%s时。本合同%s,本次公出申请,已超出%s小时。超出公出时长,将计入您的第三方成本," +
  244. "从奖金计算基数中扣除!请确认是否同意本次公出?", my.getName(), data.getUserName(), data.getContractNo(),
  245. data.getPeopleCount(), data.getTimesCount(), data.getDurationCount().stripTrailingZeros(), amountName,
  246. data.getDurationMax());
  247. return format;
  248. }
  249. /**
  250. *
  251. * @param my 发送人信息
  252. * @param in 公出信息
  253. * @param date 时间
  254. * @param a 接受者信息
  255. * @param str 站内信内容
  256. * @param map 返回实体
  257. */
  258. private void pushNoticeAndSoucketAndEmail(AdminListBo my, PublicRelease in, Date date, Admin a, String str, Map<String, Object> map) {
  259. sendNoticeAndSoucket(a.getId(),1, str);
  260. if (a.getOpenId() !=null) {
  261. Integer res= weChatUtils.addNotice(a.getOpenId(), in.getStatus(), in.getId(), date, my.getName(),"["+ my.getName()+"]发起外出申请");
  262. if (res!=0) {
  263. sendEmail(my, a,1);
  264. }
  265. map.put("code", res);
  266. }else {
  267. sendEmail(my, a,1);
  268. map.put("code", 2);
  269. }
  270. }
  271. private String getAssistAidName(String assistAid) {
  272. String [] ss=assistAid.split(",");
  273. StringBuffer sb=new StringBuffer();
  274. for (String s : ss) {
  275. Admin a=adminMapper.selectByPrimaryKey(s);
  276. if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
  277. }
  278. if (sb.length()<1)return "";
  279. return sb.deleteCharAt(sb.length() - 1).toString();
  280. }
  281. private void sendEmailAndNoticeAndSoucket(String id,Integer type,String content){
  282. sendNoticeAndSoucket(id,type,content);
  283. Admin admin = adminMapper.selectByPrimaryKey(id);
  284. String title="暂无标题";
  285. if (type==3)title=NoticeStatus.PUBLIC_OTHERS_USER.getDesc();
  286. EmailBo emailBo=new EmailBo(title,admin.getEmail(),content);
  287. asyncUtils.send(emailBo);
  288. }
  289. /**
  290. *
  291. * @param id 接受者编号
  292. * @param type 状态 0驳回 1发起 2同意 3 公出他人企业
  293. * @param content 内容
  294. */
  295. private void sendNoticeAndSoucket(String id,Integer type,String content) {
  296. Integer noticeType=NoticeStatus.PUBLIC_RELEASE_START.getCode();
  297. if(type==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
  298. else if (type==2)noticeType=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
  299. else if (type==3)noticeType=NoticeStatus.PUBLIC_OTHERS_USER.getCode();
  300. //触发通知有未读消息
  301. systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
  302. Notice n =new Notice();
  303. n.setId(UUID.randomUUID().toString());
  304. n.setAid(id);
  305. n.setNoticeType(noticeType);
  306. n.setContent(content);
  307. n.setReaded(0);//未读
  308. asyncUtils.addNotice(n);
  309. }
  310. /**
  311. *
  312. * @param my 发送人
  313. * @param a 接受者
  314. * @param type 类型
  315. */
  316. private void sendEmail(AdminListBo my, Admin a,Integer type) {
  317. StringBuffer title=new StringBuffer();
  318. if (type==0) title=title.append("外出申请驳回提醒");
  319. else if (type==1) title=title.append("外出申请提醒");
  320. else if (type==2) title=title.append("外出申请同意提醒");
  321. if (SendEmailUtil.isEmail(a.getEmail())) {
  322. EmailBo email=new EmailBo(title.toString(),a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
  323. asyncUtils.send(email);
  324. }
  325. }
  326. @Override
  327. public int updatePublicRelease(InputPublicRelease in) {
  328. Date date = new Date();
  329. try {
  330. if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  331. if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  332. } catch (ParseException e) {
  333. e.printStackTrace();
  334. throw new BusinessException("转换异常");
  335. }
  336. Map checkOrderNo =null;
  337. if (in.getType() == 1) {
  338. checkOrderNo = checkOrderNoDuration(in);
  339. boolean isValid = (boolean) checkOrderNo.get("code");
  340. if (isValid){
  341. in.setTechStartProcess(0);
  342. }else {
  343. in.setTechStartProcess(1);
  344. }
  345. }
  346. List<User> uses=null;
  347. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(in.getId());
  348. in.setCreateTime(use.getCreateTime());
  349. String userNames=publicReleaseDetailsMapper.getNamesByPrid(in.getId());
  350. PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
  351. in.setUserNames(userNames);
  352. if(in.getStatus()==null||in.getStatus()!=3) {
  353. if (in.getUids()!=null){
  354. List<String> split = Arrays.asList(in.getUids().split(","));
  355. List<OutPublicReleaseDetails> prList = publicReleaseDetailsMapper.selectByPCid(in.getId());
  356. uses=pushPublicReleaseDetails(split,prList,use,in);
  357. }
  358. in.setStatus(1);
  359. log.setStatus(PublicReleaseLog.states.xg.getCode());
  360. in.setUpdateStatus(1);
  361. //如果是业务切公出则撤销营销审核与审核人
  362. if(in.getType()==1&&use.getType()==0){
  363. in.setPublicType(0);
  364. publicExamineMapper.deletePrid(in.getId());
  365. }
  366. //如果是业务公出,切审核状态为其他,则重置审核
  367. if(in.getType()==0&&(use.getPublicType()==2||use.getPublicType()==3)){
  368. in.setPublicType(1);
  369. PublicExamine pe=new PublicExamine();
  370. pe.setPrid(in.getId());
  371. pe.setStatus(0);
  372. publicExamineMapper.updateByPridSelective(pe);
  373. }
  374. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  375. //重新发起
  376. addPublicReleaseLog(my,in,in.getUserNames(),date,uses,checkOrderNo);
  377. }else {
  378. List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
  379. List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
  380. log.setStatus(PublicReleaseLog.states.cx.getCode());
  381. for (PublicRelease out : list) {
  382. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
  383. out.setStatus(3);
  384. publicReleaseMapper.updateByPrimaryKeySelective(out);
  385. }
  386. for (PublicRelease out : list2) {
  387. addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单助手");
  388. out.setStatus(3);
  389. publicReleaseMapper.updateByPrimaryKeySelective(out);
  390. }
  391. }
  392. publicReleaseLogMapper.insertSelective(log);
  393. publicReleaseMapper.updateByPrimaryKeySelective(in);
  394. return 1;
  395. }
  396. private List<User> pushPublicReleaseDetails(List<String> split, List<OutPublicReleaseDetails> prList, PublicRelease use, InputPublicRelease in) {
  397. //先删除,再修改个,再新增,有利于减少计算
  398. deletePRD(split,prList);
  399. publicReleaseDetailsMapper.updateDistrictByPrid(in);
  400. List<User> users = addPRD(split, prList, use,in);
  401. return users;
  402. }
  403. private void deletePRD(List<String> split, List<OutPublicReleaseDetails> prdList) {
  404. for (OutPublicReleaseDetails prd : prdList) {
  405. boolean flag=true;
  406. for (String s : split) {
  407. if (prd.getUid().equals(s)){
  408. flag=false;
  409. }
  410. }
  411. if (flag){
  412. publicReleaseDetailsMapper.deleteByPrimaryKey(prd.getId());
  413. }
  414. }
  415. }
  416. /**
  417. * @param split 修改后客户集
  418. * @param prdList 修改前客户集
  419. * @param use 原订单信息
  420. */
  421. private List<User> addPRD(List<String> split, List<OutPublicReleaseDetails> prdList, PublicRelease use, InputPublicRelease in) {
  422. List<PublicReleaseDetails> addPrdList=new ArrayList<>();
  423. List<User> users=new ArrayList<>();
  424. Integer publicType = use.getPublicType();
  425. //计算平均
  426. Integer userCount=split.size();
  427. Integer index=0;
  428. Double duration= in.getDuration();
  429. double d = durationSum(duration,userCount );
  430. for (String s : split) {
  431. User u=userMapper.selectByPrimaryKey(s);
  432. users.add(u);
  433. boolean flag=true;
  434. Integer id=null;
  435. String districtName=null,latitude=null,longitude=null;
  436. for (OutPublicReleaseDetails prd : prdList) {
  437. if (id==null)id=prd.getPrid();
  438. if (districtName==null)districtName=prd.getDistrictName();
  439. if (latitude==null)latitude=prd.getLatitude();
  440. if (longitude==null)longitude=prd.getLongitude();
  441. if (s.equals(prd.getUid())){
  442. flag=false;
  443. }
  444. }
  445. //计算下
  446. if (flag){
  447. PublicReleaseDetails prd=new PublicReleaseDetails();
  448. if (u!=null&&u.getShareType()==2){
  449. prd.setNewUser(1);
  450. }else {
  451. prd.setNewUser(0);
  452. }
  453. if (u.getAid().equals(use.getAid())){
  454. prd.setMainStatus(1);
  455. }else {
  456. prd.setMainStatus(0);
  457. }
  458. prd.setPrid(id);
  459. prd.setUid(s);
  460. prd.setSignSum(0);
  461. prd.setDistrictName(districtName);
  462. prd.setLatitude(latitude);
  463. prd.setLongitude(longitude);
  464. prd.setClockIn(0);
  465. addPrdList.add(prd);
  466. //设置时长
  467. if (index<userCount){
  468. if (in.getDuration()==0){
  469. prd.setDuration(in.getDuration());
  470. } else {
  471. prd.setDuration(d);
  472. duration=duration-d;
  473. }
  474. }else {
  475. prd.setDuration(duration);
  476. }
  477. index++;
  478. if (!use.getAid().equals(u.getAid())){
  479. addPublicExamine(use.getId(), u.getAid());
  480. if (publicType==1)publicType=1;
  481. }
  482. }else {
  483. InputPublicRelease inp=new InputPublicRelease();
  484. inp.setId(in.getId());
  485. inp.setUid(s);
  486. PublicReleaseDetails publicReleaseDetails = publicReleaseDetailsMapper.selectBypridAndUid(inp);
  487. PublicReleaseDetails newprd =new PublicReleaseDetails();
  488. newprd.setId(publicReleaseDetails.getId());
  489. //设置时长
  490. if (index<userCount){
  491. if (in.getDuration()==0){
  492. newprd.setDuration(in.getDuration());
  493. } else {
  494. newprd.setDuration(d);
  495. duration=duration-d;
  496. }
  497. }else {
  498. newprd.setDuration(duration);
  499. }
  500. index++;
  501. publicReleaseDetailsMapper.updateByPrimaryKeySelective(newprd);
  502. }
  503. }
  504. StringBuffer str=new StringBuffer();
  505. for (User u : users) {
  506. str=str.append(use.getUserNames()).append(",");
  507. }
  508. if (publicType!=use.getPublicType()){
  509. PublicRelease newP=new PublicRelease();
  510. newP.setId(use.getId());
  511. if (str.length()>1)newP.setUserNames(str.substring(0,str.length()-1));
  512. newP.setPublicType(publicType);
  513. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  514. }
  515. if (!addPrdList.isEmpty())publicReleaseDetailsMapper.insertBatch(addPrdList);
  516. return users;
  517. }
  518. @SuppressWarnings("unchecked")
  519. @Override
  520. public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
  521. Map<String,Object> map =new HashMap<String, Object>();
  522. map.put("type", in.getType()==null?0:in.getType());
  523. // map.put("type", 5);
  524. if (in.getType()==3) {
  525. in.setAssist(2);
  526. if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
  527. }else{
  528. map.put("aid",TokenManager.getAdminId());
  529. }
  530. if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
  531. if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
  532. if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
  533. if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
  534. if(in.getStatus()!=null) map.put("status", in.getStatus());
  535. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  536. map.put("assist",in.getAssist()==null?0:in.getAssist());
  537. Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
  538. if(in.getType()==0||in.getType()==4){
  539. pushExamines(p);
  540. }
  541. return p;
  542. }
  543. private void pushExamines(Pagination<OutPublicReleaseList> p) {
  544. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
  545. if (!list.isEmpty()){
  546. List<Integer> ids=new ArrayList<>();
  547. list.forEach(e ->{ ids.add(e.getId()); });
  548. List<PublicExamine> publicExamines = publicExamineMapper.selectByIds(ids);
  549. for (OutPublicReleaseList e : list) {
  550. if (!publicExamines.isEmpty()){
  551. StringBuffer str =new StringBuffer();
  552. for (PublicExamine pe : publicExamines) {
  553. if (e.getId().equals(pe.getPrid())){
  554. str=str.append(pe.getAname());
  555. if (pe.getStatus()==0)str=str.append(" 未审核,");
  556. if (pe.getStatus()==1)str=str.append(" 已审核,");
  557. }
  558. if (str.length()>1) e.setAdminExamine(str.substring(0,str.length()-1));
  559. }
  560. }
  561. }
  562. }
  563. }
  564. @Override
  565. @Transactional
  566. public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Integer examineType) {
  567. PublicRelease p=new PublicRelease();
  568. Date date =new Date();
  569. boolean flag=false;
  570. String aid=TokenManager.getAdminId();
  571. p.setId(id);
  572. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  573. if (use.getStatus()!=1) {
  574. throw new BusinessException("只能修改发起的状态公出");
  575. }
  576. if(examineType==0||examineType==1){
  577. if(use.getTechStartProcess()!=0) throw new BusinessException("技术公出先需营销审核。");
  578. }
  579. //当前审核人员
  580. Admin ad=adminMapper.selectByPrimaryKey(aid);
  581. //公出负责人
  582. Admin a;
  583. Admin publicAdmin =adminMapper.selectByPrimaryKey(use.getAid());
  584. a=publicAdmin;
  585. StringBuffer str=new StringBuffer();
  586. str=str.append("(").append(ad.getName()).append(")");
  587. StringBuffer content=new StringBuffer().append("[").append(use.getUserNames()).append("]公司的外出申请,");
  588. //上级审核
  589. if(examineType==0){
  590. p.setStatus(status);
  591. if (status==0){
  592. str=str.append("驳回,");
  593. if (use.getAssist()==2){
  594. content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
  595. }else {
  596. content=content.append("未通过公出审核!");
  597. }
  598. if(use.getPublicType()>1){
  599. p.setPublicType(1);
  600. PublicExamine inpe=new PublicExamine();
  601. inpe.setStatus(0);
  602. inpe.setPrid(use.getId());
  603. publicExamineMapper.updateStatusByPrid(inpe);
  604. }
  605. }else if(status==2){
  606. str=str.append("同意,");
  607. //如果是协单公出主公出,在审核通过
  608. if (use.getAssist()==1){
  609. pushPublicReleaseAssist(use,status,date,a);
  610. }else if (use.getAssist()==0){
  611. publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
  612. }
  613. content=content.append("已通过审核!");
  614. }
  615. str=str.append(remarks);
  616. p.setAuditInfo(str.toString());
  617. p.setAuditTime(date);
  618. p.setRejectName(ad.getName());
  619. addpublicLog(id, status, remarks);
  620. flag=true;
  621. //营销员审核
  622. }else if (examineType==1){
  623. //通知公出人切换成公出人审核人
  624. a=adminMapper.selectByPrimaryKey(a.getReviewer());
  625. if (status==2){//审核通过
  626. str=str.append("同意公出我的企业,").append(remarks);
  627. content=content.append("已通过审核,请尽快审核。");
  628. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  629. int x=0;
  630. for (PublicExamine pe : publicExamines) {
  631. if (pe.getAid().equals(aid)){
  632. pe.setStatus(1);
  633. PublicExamine newp=new PublicExamine();
  634. newp.setId(pe.getId());
  635. newp.setStatus(1);
  636. publicExamineMapper.updateByPrimaryKeySelective(newp);
  637. x++;
  638. }else {
  639. if (pe.getStatus()==1){
  640. x++;
  641. }
  642. }
  643. }
  644. if (x==publicExamines.size()){
  645. p.setPublicType(2);
  646. flag=true;
  647. }
  648. addpublicLog(id, status, str.toString());
  649. }else if (status==0){//审核驳回
  650. //切换通知人公出负责人
  651. a=publicAdmin;
  652. str=str.append("不同意公出我的企业,").append(remarks);;
  653. content=content.append("未通过审核,请修改后重新发起。");
  654. p.setPublicType(3);
  655. p.setStatus(0);
  656. p.setAuditInfo(str.toString());
  657. p.setRejectName(ad.getName());
  658. addpublicLog(id, 0, str.toString());
  659. }
  660. }else if (examineType==2){
  661. //通知公出人切换成公出人审核人
  662. a=adminMapper.selectByPrimaryKey(a.getReviewer());
  663. if (status==2){//审核通过
  664. str=str.append("同意公出我的企业,").append(remarks);
  665. content=content.append("已通过审核,请尽快审核。");
  666. List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
  667. int x=0;
  668. for (PublicExamine pe : publicExamines) {
  669. if (pe.getAid().equals(aid)){
  670. pe.setStatus(1);
  671. PublicExamine newp=new PublicExamine();
  672. newp.setId(pe.getId());
  673. newp.setStatus(1);
  674. publicExamineMapper.updateByPrimaryKeySelective(newp);
  675. x++;
  676. }else {
  677. if (pe.getStatus()==1){
  678. x++;
  679. }
  680. }
  681. }
  682. if (x==publicExamines.size()){
  683. p.setPublicType(2);
  684. flag=true;
  685. }
  686. addpublicLog(id, status, str.toString());
  687. }else if (status==0){//审核驳回
  688. //切换通知人公出负责人
  689. a=publicAdmin;
  690. str=str.append("不同意公出我的企业,").append(remarks);;
  691. content=content.append("未通过审核,请修改后重新发起。");
  692. p.setPublicType(3);
  693. p.setStatus(0);
  694. p.setAuditInfo(str.toString());
  695. p.setRejectName(ad.getName());
  696. addpublicLog(id, 0, str.toString());
  697. }
  698. }
  699. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  700. if (flag){
  701. sendNoticeAndSoucket(a.getId(),status,content.toString());
  702. }
  703. if (p.getStatus()!=null||p.getPublicType()!=null){
  704. publicReleaseMapper.updateByPrimaryKeySelective(p);
  705. updateAdminUserCountPublicRelease(use.getAid(),use.getReleaseStart());
  706. }
  707. if (a.getOpenId()!=null) {
  708. if (remarks.length()>19) {
  709. remarks=remarks.substring(0, 15)+"...";
  710. }
  711. Integer res=weChatUtils.addNotice(a.getOpenId(),status,p.getId(),date,my.getName(),remarks);
  712. if (res!=0) {
  713. sendEmail( my, a, status);
  714. }
  715. return res;
  716. }else {
  717. }
  718. return 1;
  719. }
  720. private void updateAdminUserCountPublicRelease(String aid, Date transferTime) {
  721. String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
  722. String endTime=startTime+" 23:59:59";
  723. AdminUserCount adminUserCount = customerService.getAdminUserCount(aid,startTime);
  724. Integer count = publicReleaseMapper.selectCountByaidAndDate(aid, startTime, endTime);
  725. if (count==null){
  726. count=0;
  727. }
  728. if (adminUserCount==null){
  729. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  730. if (selectAUC==null)selectAUC=new AdminUserCount();
  731. selectAUC.setPublicReleaseCount(count);
  732. selectAUC.setAid(aid);
  733. selectAUC.setDateTime(transferTime);
  734. adminUserCountMapper.insertSelective(selectAUC);
  735. }else {
  736. AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
  737. AdminUserCount newAUC=new AdminUserCount();
  738. newAUC.setId(adminUserCount.getId());
  739. newAUC.setPublicReleaseCount(count);
  740. if (selectAUC==null){
  741. newAUC.setPrivateCount(0);
  742. newAUC.setChannelCount(0);
  743. newAUC.setSignCount(0);
  744. }else {
  745. if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
  746. if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
  747. if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
  748. newAUC.setPrivateCount(selectAUC.getPrivateCount());
  749. newAUC.setChannelCount(selectAUC.getChannelCount());
  750. newAUC.setSignCount(selectAUC.getSignCount());
  751. }
  752. adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
  753. }
  754. }
  755. private void addpublicLog(Integer id, Integer status, String remarks) {
  756. PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
  757. publicReleaseLogMapper.insertSelective(log);
  758. }
  759. @Override
  760. public int pushTechReject(Integer id, String remarks) {
  761. Integer status=0;
  762. PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
  763. PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
  764. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  765. StringBuffer str=new StringBuffer();
  766. if (use.getAssist()!=2){
  767. throw new BusinessException("只有技术公出能发起技术驳回");
  768. }
  769. str=str.append("拒绝技术协单,").append(remarks);
  770. PublicRelease newMain=new PublicRelease();
  771. newMain.setId(mainPublic.getId());
  772. newMain.setStatus(4);
  773. newMain.setRejectName(ad.getName());
  774. newMain.setAuditInfo(str.toString());
  775. addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
  776. publicReleaseMapper.updateByPrimaryKeySelective(newMain);
  777. PublicRelease up=new PublicRelease();
  778. up.setId(id);
  779. up.setAuditInfo(str.toString());
  780. up.setStatus(3);
  781. addpublicLog(id, status, remarks);
  782. publicReleaseMapper.updateByPrimaryKeySelective(up);
  783. deleteAssistantPulicRelease(use,null);
  784. return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
  785. }
  786. /**
  787. * 新增日志、站内信、微信提醒
  788. * @param id 日志公出编号
  789. * @param aid 接受者
  790. * @param remarks 日志内容
  791. * @param status 0驳回
  792. * @return
  793. */
  794. private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
  795. AdminListBo my = adminMapper.getDeptNameByAid(aid);
  796. Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  797. if (my.getOpenId()!=null) {
  798. if (remarks.length()>19) {
  799. remarks=remarks.substring(0, 15)+"...";
  800. }
  801. return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
  802. }else {
  803. sendEmail( my, a, status);
  804. return 1;
  805. }
  806. }
  807. /**
  808. *
  809. * @param use 原始公出信息
  810. * @param status 状态
  811. * @param date 时间
  812. * @param a
  813. */
  814. private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date,Admin a) {
  815. if (use.getAssistAid()!=null){
  816. updatePushassist(use, status, date,a);
  817. if(use.getAssistantAid()!=null){
  818. updatepushAssistant(use,a);
  819. }
  820. }
  821. }
  822. /**
  823. * 处理技术协单
  824. * @param use
  825. * @param status
  826. * @param date
  827. */
  828. private void updatePushassist(PublicRelease use, Integer status, Date date, Admin a) {
  829. //协单
  830. List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
  831. String []ss= use.getAssistAid().split(",");
  832. //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
  833. for (PublicRelease out : list) {
  834. boolean flag=false;
  835. for (String s : ss) {
  836. if (out.getAid().equals(s)){
  837. flag=true;
  838. break;
  839. }
  840. }
  841. if (!flag){
  842. PublicRelease in = new PublicRelease();
  843. in.setId(out.getId());
  844. in.setStatus(3);
  845. publicReleaseMapper.updateByPrimaryKeySelective(in);
  846. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
  847. PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
  848. publicReleaseLogMapper.insertSelective(log);
  849. sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
  850. }else {
  851. PublicRelease np = new PublicRelease();
  852. BeanUtils.copyProperties(use,np);
  853. np.setId(out.getId());
  854. np.setMainId(null);
  855. np.setType(null);
  856. np.setAssist(2);
  857. np.setStatus(status);
  858. np.setAid(null);
  859. publicReleaseMapper.updateByPrimaryKeySelective(np);
  860. updatePublicReleaseDtails(use,np.getId());
  861. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
  862. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
  863. publicReleaseLogMapper.insertSelective(log);
  864. sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
  865. }
  866. }
  867. for (String s : ss) {
  868. boolean flag2 = false;
  869. for (PublicRelease o : list) {
  870. if (s.equals(o.getAid())) {
  871. flag2 = true;
  872. }
  873. }
  874. if (!flag2) {
  875. PublicRelease np = new PublicRelease();
  876. BeanUtils.copyProperties(use,np);
  877. np.setAssist(2);
  878. np.setAid(s);
  879. np.setStatus(2);
  880. np.setType(3);
  881. np.setMainId(use.getId());
  882. np.setId(null);
  883. publicReleaseMapper.insertSelective(np);
  884. //补充客户表
  885. addpublicReleaseDtails(use,np.getId());
  886. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
  887. PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
  888. sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
  889. publicReleaseLogMapper.insertSelective(log);
  890. }
  891. }
  892. }
  893. private void updatePublicReleaseDtails(PublicRelease use, Integer id) {
  894. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  895. List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPCid(id);
  896. //查找新增的
  897. for (OutPublicReleaseDetails out : list) {
  898. boolean flag=true;
  899. for (OutPublicReleaseDetails out2 : list2) {
  900. if (out.getUid().equals(out2.getUid())){
  901. flag=false;
  902. }
  903. }
  904. if (flag){
  905. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  906. BeanUtils.copyProperties(out,prd);
  907. prd.setPrid(id);
  908. prd.setClockIn(0);
  909. prd.setClockInTime(null);
  910. prd.setClockInRemarks(null);
  911. prd.setUfid(null);
  912. publicReleaseDetailsMapper.insertSelective(prd);
  913. }
  914. }
  915. for (OutPublicReleaseDetails out2 : list2) {
  916. boolean flag=true;
  917. for (OutPublicReleaseDetails out : list) {
  918. if (out2.getUid().equals(out.getUid())){
  919. flag=false;
  920. }
  921. }
  922. if (flag){
  923. publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
  924. }
  925. }
  926. }
  927. private void addpublicReleaseDtails(PublicRelease use, Integer id) {
  928. List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPCid(use.getId());
  929. for (OutPublicReleaseDetails out : list) {
  930. OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
  931. BeanUtils.copyProperties(out,prd);
  932. prd.setPrid(id);
  933. prd.setClockIn(0);
  934. prd.setClockInTime(null);
  935. prd.setMainStatus(0);
  936. publicReleaseDetailsMapper.insertSelective(prd);
  937. }
  938. }
  939. /**
  940. * 处理技术助手
  941. * @param use
  942. */
  943. private void updatepushAssistant(PublicRelease use,Admin a) {
  944. List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
  945. for (PublicRelease p : uselist) {
  946. if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
  947. if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
  948. p.setStatus(2);
  949. p.setAssistantAid(use.getAssistantAid());
  950. p.setAssistantName(use.getAssistantName());
  951. p.setUserNames(use.getUserNames());
  952. publicReleaseMapper.updateByPrimaryKeySelective(p);
  953. StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
  954. PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
  955. sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
  956. publicReleaseLogMapper.insertSelective(log);
  957. }
  958. }
  959. @Override
  960. public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
  961. List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
  962. return list;
  963. }
  964. @Override
  965. public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
  966. if (clockIn == null) clockIn = 1;
  967. PublicRelease use = publicReleaseMapper.selectByPrimaryKey(id);
  968. if (use.getPublicType()==1||use.getPublicType()==3){
  969. return -1;
  970. }
  971. if (use.getTechStartProcess()==1||use.getTechStartProcess()==3){
  972. return -2;
  973. }
  974. List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPCid(id);
  975. String str = "";
  976. boolean flag=false;
  977. Integer clockCount=0;
  978. for (OutPublicReleaseDetails prd : prdList) {
  979. if (prd.getUid().equals(uid)){
  980. String aid = TokenManager.getAdminId();
  981. prd.setClockInRemarks(clockInRemarks);
  982. prd.setPhotoUrl(photoUrl);
  983. prd.setClockInTime(new Date());
  984. if (prd.getClockIn() == 0) {
  985. prd.setClockIn(clockIn);
  986. //获取列表
  987. FollowBusinessBo fbb = new FollowBusinessBo();
  988. fbb.setUid(prd.getUid());
  989. fbb.setContactType("5");
  990. fbb.setResult(use.getRemarks());
  991. OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
  992. if (ub != null) {
  993. fbb.setOcbId(ub.getId());
  994. }
  995. fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
  996. String ufid = UUID.randomUUID().toString();
  997. prd.setUfid(ufid);
  998. customerService.addFollow(fbb, ufid, prd.getMainStatus());
  999. str = "公出人员打卡";
  1000. }else if (clockIn == 2){
  1001. str = "公出人员异常打卡";
  1002. }else {
  1003. str = "刷新打卡";
  1004. }
  1005. PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
  1006. log.setPhotoUrl(photoUrl);
  1007. publicReleaseLogMapper.insertSelective(log);
  1008. publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
  1009. flag=true;
  1010. clockCount++;
  1011. }else if (prd.getClockIn()==1){
  1012. clockCount++;
  1013. }
  1014. }
  1015. if (prdList.size()==clockCount){
  1016. PublicRelease newp=new PublicRelease();
  1017. newp.setId(id);
  1018. newp.setClockIn(1);
  1019. publicReleaseMapper.updateByPrimaryKeySelective(newp);
  1020. }
  1021. if (!flag){
  1022. return 0;
  1023. }
  1024. return 1;
  1025. }
  1026. @Override
  1027. public OutPublicRelease dtails(Integer id) {
  1028. String aid=TokenManager.getAdminId();
  1029. //如果不是本人和审核人员则不返回信息
  1030. OutPublicRelease out=publicReleaseMapper.selectDtails(id);
  1031. List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
  1032. out.setPeList(ps);
  1033. if(out!=null){
  1034. boolean flag=false;
  1035. //自己、审核人员与部门负责人可以查看
  1036. AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
  1037. if (!aid.equals( out.getAid())&&
  1038. !aid.equals(out.getReviewer())&&
  1039. !aid.equals(ab.getDepManager())&&
  1040. !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
  1041. flag=true;
  1042. }
  1043. if(flag){
  1044. //技术发起审核可以看
  1045. if (out.getTechStartProcess()!=0){
  1046. TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(out.getOrderNo());
  1047. if (tOrderNew.getSalesmanId().equals(aid)){
  1048. flag=false;
  1049. out.setPermission(0);
  1050. }
  1051. }
  1052. }
  1053. if(flag){
  1054. //是否可以查看
  1055. if (!ps.isEmpty()){
  1056. for (PublicExamine p : ps) {
  1057. if (p.getAid().equals(aid)){
  1058. if (p.getStatus()==1)out.setMyExamine(1);
  1059. else out.setMyExamine(0);
  1060. flag=false;
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. //处理返回
  1067. if(flag){
  1068. out=null;
  1069. return out;
  1070. }else {
  1071. if (out.getPublicType()==1){
  1072. if (aid.equals(out.getAid())){
  1073. out.setPermission(0);
  1074. }else {
  1075. out.setPermission(1);
  1076. }
  1077. }else {
  1078. if(aid.equals(out.getAid())) {
  1079. out.setPermission(0);
  1080. }else {
  1081. out.setPermission(1);
  1082. }
  1083. }
  1084. }
  1085. }
  1086. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1087. return out;
  1088. }
  1089. @Override
  1090. public OutPublicReleaseAndDetails followDtails(String id) {
  1091. OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
  1092. return out;
  1093. }
  1094. @SuppressWarnings("unchecked")
  1095. @Override
  1096. // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
  1097. // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
  1098. // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
  1099. // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
  1100. public Object publicReleaseStatistics(InputPublicStatistics in) {
  1101. Map<String,Object> map =new HashMap<String, Object>();
  1102. if(in.getAid()!=null)map.put("aid", in.getAid());
  1103. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1104. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1105. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1106. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1107. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1108. return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
  1109. }
  1110. @SuppressWarnings("unchecked")
  1111. @Override
  1112. public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
  1113. Map<String,Object> map =new HashMap<String, Object>();
  1114. if(in.getAid()!=null)map.put("aid", in.getAid());
  1115. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
  1116. TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  1117. if(in.getDepId()!=null)map.put("depId", in.getDepId());
  1118. }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
  1119. }
  1120. if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
  1121. if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
  1122. if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
  1123. if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1124. return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
  1125. }
  1126. @SuppressWarnings("unchecked")
  1127. @Override
  1128. public Object publicReleaseListDtails(InputPublicDtails in) {
  1129. Map<String,Object> map =new HashMap<String, Object>();
  1130. addParams(in, map);
  1131. Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
  1132. return page;
  1133. }
  1134. private void addParams(InputPublicDtails in, Map<String, Object> map) {
  1135. if(in.getAid()!=null) map.put("aid", in.getAid());
  1136. if(in.getSid()!=null) map.put("sid", in.getSid());
  1137. if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
  1138. if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
  1139. if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
  1140. if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
  1141. if(in.getUid()!=null) map.put("uid", in.getUid());
  1142. if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
  1143. if(in.getStatus()!=null) map.put("status", in.getStatus());
  1144. if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
  1145. if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
  1146. //type 0私有 1管理权限 2所有权限
  1147. if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
  1148. ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
  1149. ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
  1150. ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
  1151. //添加财务和财务经理。查看客户所有公出
  1152. in.setType(2);
  1153. if(in.getDeps()!=null){
  1154. map.put("deps", departmentService.parseArray(in.getDeps()));
  1155. }
  1156. }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
  1157. ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  1158. in.setType(1);
  1159. if (in.getDeps()!=null){
  1160. List<String> list = departmentService.selectSubDeps(in.getDeps());
  1161. if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
  1162. map.put("deps", list);
  1163. }else {
  1164. map.put("deps",departmentService.selectMyDeps());
  1165. }
  1166. }else{
  1167. in.setType(0);
  1168. if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
  1169. if(in.getDeps()!=null){
  1170. map.put("deps", departmentService.parseArray(in.getDeps()));
  1171. }
  1172. }
  1173. map.put("type", in.getType());
  1174. }
  1175. @SuppressWarnings("unchecked")
  1176. @Override
  1177. public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
  1178. Map<String,Object> map =new HashMap<String, Object>();
  1179. addParams(in, map);
  1180. return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
  1181. }
  1182. @Override
  1183. public int addSupplement(Integer id, String supplement, String nextPlan) {
  1184. PublicRelease pr=new PublicRelease();
  1185. pr.setId(id);
  1186. pr.setSupplement(supplement);
  1187. pr.setNextPlan(nextPlan);
  1188. return publicReleaseMapper.updateByPrimaryKeySelective(pr);
  1189. }
  1190. @Override
  1191. public boolean checkTime(InputPublicRelease in) {
  1192. try {
  1193. in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
  1194. in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
  1195. } catch (ParseException e) {
  1196. e.printStackTrace();
  1197. throw new BusinessException("转换异常");
  1198. }
  1199. List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
  1200. if (is.size()>1) {
  1201. return true;
  1202. }else if(is.size()==1){
  1203. //如果id为新增那么直接不允许时间重复
  1204. if (in.getId()==null){
  1205. return true;
  1206. }else {
  1207. //如果有id,与获取id一直,则为当前修改可以
  1208. if (in.getId().equals(is.get(0))){
  1209. return false;
  1210. }else {
  1211. return true;
  1212. }
  1213. }
  1214. }
  1215. return false;
  1216. }
  1217. @Override
  1218. public List<Map<String, Object>> selectOrderByUid(String uid) {
  1219. return tOrderNewMapper.selectOrderByuid(uid);
  1220. }
  1221. @Override
  1222. public List<OutPublicRelease> publicByOrder(String orderNo) {
  1223. return publicReleaseMapper.publicByOrder(orderNo);
  1224. }
  1225. @Override
  1226. public Object getMyNewPublic() {
  1227. List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
  1228. if (myPublic.isEmpty()){
  1229. List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
  1230. if (!myPublic2.isEmpty()){
  1231. return myPublic2.get(0);
  1232. }
  1233. }else {
  1234. return myPublic.get(0);
  1235. }
  1236. return null;
  1237. }
  1238. /**
  1239. *
  1240. * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
  1241. * @param dateType 是否含打卡时间 0否 1是
  1242. * @return
  1243. */
  1244. public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
  1245. Map<String, Object> map = new HashMap<>();
  1246. if (type==null)type=0;
  1247. map.put("type",type);
  1248. //statusType=1情况下
  1249. map.put("statusType",1);
  1250. if (dateType==1){
  1251. Date date = new Date();
  1252. String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
  1253. map.put("clockTime",clockTime);
  1254. }
  1255. map.put("aid",TokenManager.getAdminId());
  1256. List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
  1257. for (OutPublicReleaseList out : list) {
  1258. out.setPrdList(publicReleaseDetailsMapper.selectByPCid(out.getId()));
  1259. }
  1260. return list;
  1261. }
  1262. @Override
  1263. public int addAssistant(Integer id,String aid) {
  1264. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1265. List<String> list=new ArrayList<>();
  1266. if (StringUtils.isNotEmpty(p.getAssistantAid())){
  1267. list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1268. }
  1269. String sname = pushAssistant(aid, list,0);
  1270. String said =String.join(",",list);
  1271. p.setAssistantAid(said);
  1272. p.setAssistantName(sname);
  1273. addAssistantPublicRelease(p,aid);
  1274. return updateAssistant(p, said, sname);
  1275. }
  1276. private void addAssistantPublicRelease(PublicRelease p, String aid) {
  1277. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1278. PublicRelease newP= new PublicRelease();
  1279. if(list.isEmpty()){
  1280. BeanUtils.copyProperties(p,newP);
  1281. newP.setId(null);
  1282. newP.setAid(aid);
  1283. newP.setAssist(3);
  1284. newP.setType(4);
  1285. publicReleaseMapper.insertSelective(newP);
  1286. addpublicReleaseDtails(p,newP.getId());
  1287. StringBuffer str=new StringBuffer();
  1288. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
  1289. addWeChatNotice( aid,1,str.toString(),newP.getId());
  1290. }else {
  1291. for (PublicRelease pr : list) {
  1292. newP.setId(pr.getId());
  1293. newP.setAssistantAid(p.getAssistantAid());
  1294. newP.setAssistantName(p.getAssistantName());
  1295. publicReleaseMapper.updateByPrimaryKeySelective(newP);
  1296. updatePublicReleaseDtails(p,newP.getId());
  1297. }
  1298. }
  1299. }
  1300. /**
  1301. * 添加微信提示和站内消息
  1302. * @param aid 接受者
  1303. * @param type 状态 0驳回 1发起 2同意 3撤销
  1304. * @param str 备注
  1305. * @param prid 公出编号
  1306. */
  1307. private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
  1308. Admin recipient = adminMapper.selectByPrimaryKey(aid);
  1309. addWeChatNotice( recipient, type, str, prid);
  1310. }
  1311. /**
  1312. * 添加微信提示和站内消息
  1313. * @param recipient 接受者
  1314. * @param type 状态 0驳回 1发起 2同意 3撤销
  1315. * @param str
  1316. */
  1317. private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
  1318. AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  1319. String openid=recipient.getOpenId();
  1320. str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
  1321. if(type==3){
  1322. addpublicLog(prid,4,str);
  1323. }else {
  1324. addpublicLog(prid,type,str);
  1325. }
  1326. sendNoticeAndSoucket(recipient.getId(),type,str);
  1327. if (type==0||type==2){
  1328. if (openid!=null) {
  1329. Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
  1330. return res;
  1331. }else {
  1332. sendEmail(my, recipient,type);
  1333. }
  1334. }
  1335. return 0;
  1336. }
  1337. private int updateAssistant(PublicRelease p, String said, String sname) {
  1338. PublicRelease newPr=new PublicRelease();
  1339. newPr.setId(p.getId());
  1340. newPr.setAssistantAid(said);
  1341. newPr.setAssistantName(sname);
  1342. if (p.getMainId()!=null){
  1343. PublicRelease mianPr=new PublicRelease();
  1344. mianPr.setId(p.getMainId());
  1345. mianPr.setAssistantAid(said);
  1346. mianPr.setAssistantName(sname);
  1347. publicReleaseMapper.updateByPrimaryKeySelective(mianPr);
  1348. }
  1349. return publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1350. }
  1351. /**
  1352. *
  1353. * @param aid 元素
  1354. * @param list 集合
  1355. * @param type 0新增 1删除
  1356. * @return
  1357. */
  1358. private String pushAssistant(String aid, List<String> list,Integer type) {
  1359. StringBuffer sb=new StringBuffer();
  1360. if(type==0){
  1361. list.add(aid);
  1362. }else if (type==1){
  1363. Iterator<String > it =list.iterator();
  1364. while (it.hasNext()){
  1365. if (it.next().equals(aid))
  1366. it.remove();
  1367. }
  1368. }
  1369. for (String s : list) {
  1370. sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
  1371. }
  1372. return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
  1373. }
  1374. @Override
  1375. public int deleteAssistant(Integer id, String aid) {
  1376. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1377. if (p.getAssistantAid()==null){
  1378. throw new BusinessException("人员不存在");
  1379. }
  1380. List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
  1381. if (!list.contains(aid)){
  1382. throw new BusinessException("人员不存在");
  1383. }
  1384. String sname = pushAssistant(aid, list,1);
  1385. String said =String.join(",",list);
  1386. p.setAssistantAid(said);
  1387. p.setAssistantName(sname);
  1388. deleteAssistantPulicRelease(p,aid);
  1389. return updateAssistant(p, said, sname);
  1390. }
  1391. private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
  1392. publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
  1393. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
  1394. StringBuffer str=new StringBuffer();
  1395. str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
  1396. for (PublicRelease pr : list) {
  1397. if (pr.getAid().equals(aid)){
  1398. addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
  1399. }else {
  1400. PublicRelease newPr=new PublicRelease();
  1401. newPr.setId(pr.getId());
  1402. newPr.setAssistantAid(p.getAssistantAid());
  1403. newPr.setAssistantName(p.getAssistantName());
  1404. publicReleaseMapper.updateByPrimaryKeySelective(newPr);
  1405. }
  1406. }
  1407. }
  1408. @Override
  1409. public boolean checkdeleteAssistant(Integer id, String aid) {
  1410. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1411. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1412. for (PublicRelease use : list) {
  1413. // if (use.getClockIn()==1){
  1414. // return true;
  1415. // }
  1416. }
  1417. return false;
  1418. }
  1419. @Override
  1420. public boolean checkaddAssistant(Integer id, String aid) {
  1421. PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
  1422. List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
  1423. for (PublicRelease use : list) {
  1424. if (use.getAid().equals(aid)&&use.getStatus()!=3){
  1425. return true;
  1426. }
  1427. }
  1428. return false;
  1429. }
  1430. @Override
  1431. public int updateLocation(InputPublicRelease in) {
  1432. PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
  1433. if (prd==null){
  1434. throw new BusinessException("公出企业不存在");
  1435. }
  1436. PublicReleaseDetails updateprd=new PublicReleaseDetails();
  1437. updateprd.setId(prd.getId());
  1438. updateprd.setLatitude(in.getLatitude());
  1439. updateprd.setLongitude(in.getLongitude());
  1440. updateprd.setDistrictName(in.getDistrictName());
  1441. updateprd.setClockIn(0);
  1442. addpublicLog(in.getId(),5,"发起公出地点修改");
  1443. return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
  1444. }
  1445. @Override
  1446. public Object publicReleaseAndCount(InputPublicDtails in) {
  1447. List<OutPublicDtails> list = publicReleaseListDtailsList(in);
  1448. Map<String,Object> map=new HashMap<String, Object>();
  1449. if (list.isEmpty()){
  1450. map.put("list",list);
  1451. map.put("count",0);
  1452. map.put("durationCount",0);
  1453. map.put("peopleCount",0);
  1454. }else {
  1455. //公出次数
  1456. int count=0;
  1457. BigDecimal durationCount=BigDecimal.ZERO;
  1458. List<String> aList =new ArrayList<>();
  1459. for (OutPublicDtails e : list) {
  1460. if (e.getType()==0||e.getType()==1||e.getType()==2){
  1461. count++;
  1462. if (e.getDuration()!=null){
  1463. durationCount=durationCount.add(new BigDecimal(e.getDuration()));
  1464. }
  1465. if (!aList.contains(e.getAname())){
  1466. aList.add(e.getAname());
  1467. }
  1468. if (StringUtils.isNotEmpty(e.getAssistAidName())){
  1469. String[] split = e.getAssistAidName().split(",");
  1470. for (String s : split) {
  1471. if (!aList.contains(s)){
  1472. aList.add(s);
  1473. }
  1474. }
  1475. }
  1476. if (StringUtils.isNotEmpty(e.getAssistantName())){
  1477. String[] split = e.getAssistantName().split(",");
  1478. for (String s : split) {
  1479. if (!aList.contains(s)){
  1480. aList.add(s);
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. map.put("list",list);
  1487. map.put("count",count);
  1488. map.put("durationCount",durationCount);
  1489. map.put("peopleCount",aList.size());
  1490. }
  1491. return map;
  1492. }
  1493. @Override
  1494. public Map checkOrderNoDuration( InputPublicRelease in) {
  1495. List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
  1496. TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
  1497. BigDecimal count = BigDecimal.ZERO;
  1498. count=count.add(BigDecimal.valueOf(in.getDuration()));
  1499. List<String> peopleList = new ArrayList<>();
  1500. peopleList.add(in.getAid());
  1501. int timesCount=1;
  1502. for (PublicRelease e : list) {
  1503. if (e.getDuration()!=null){
  1504. count=count.add(BigDecimal.valueOf(e.getDuration()));
  1505. if (!peopleList.contains(e.getAid())){
  1506. peopleList.add(e.getAid());
  1507. }
  1508. timesCount++;
  1509. }
  1510. }
  1511. Map map=new HashMap();
  1512. CheckOrderNoOut data= new CheckOrderNoOut();
  1513. data.setTimesCount(timesCount);
  1514. data.setPeopleCount(peopleList.size());
  1515. data.setUserName(t.getUserName());
  1516. data.setContractNo(t.getContractNo());
  1517. data.setAdminName(t.getSalesmanName());
  1518. data.setDurationCount(count);
  1519. // 0=0-1 1=1-3 2=3-5 3=5-10 4=10以上
  1520. if (t.getTotalAmount().compareTo(BigDecimal.valueOf(1)) < 0) {
  1521. data.setAmountType(0);
  1522. data.setDurationMax(BigDecimal.ZERO);
  1523. map.put("code",false);
  1524. map.put("data",data);
  1525. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0) {
  1526. data.setAmountType(1);
  1527. data.setDurationMax(BigDecimal.valueOf(15));
  1528. if (count.compareTo(data.getDurationMax())<1){
  1529. map.put("code",true);
  1530. map.put("data",null);
  1531. }else {
  1532. map.put("code",false);
  1533. map.put("data",data);
  1534. }
  1535. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0) {
  1536. data.setAmountType(2);
  1537. data.setDurationMax(BigDecimal.valueOf(45));
  1538. if (count.compareTo(data.getDurationMax())<1){
  1539. map.put("code",true);
  1540. map.put("data",null);
  1541. }else {
  1542. map.put("code",false);
  1543. map.put("data",data);
  1544. }
  1545. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0) {
  1546. data.setAmountType(3);
  1547. data.setDurationMax(BigDecimal.valueOf(120));
  1548. if (count.compareTo(data.getDurationMax())<1){
  1549. map.put("code",true);
  1550. map.put("data",null);
  1551. }else {
  1552. map.put("code",false);
  1553. map.put("data",data);
  1554. }
  1555. } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))>=0) {
  1556. data.setAmountType(4);
  1557. map.put("code",true);
  1558. map.put("data",null);
  1559. }
  1560. return map;
  1561. }
  1562. }