| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985 |
- package com.goafanti.weChat.service.impl;
- import cn.jiguang.common.utils.StringUtils;
- import com.alibaba.fastjson.JSONArray;
- import com.goafanti.admin.bo.AdminListBo;
- import com.goafanti.admin.service.DepartmentService;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.*;
- import com.goafanti.common.enums.NoticeStatus;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.*;
- import com.goafanti.common.utils.*;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.core.websocket.SystemWebSocketHandler;
- import com.goafanti.customer.bo.FollowBusinessBo;
- import com.goafanti.customer.service.CustomerService;
- import com.goafanti.order.bo.TOrderNewBo;
- import com.goafanti.weChat.bo.*;
- import com.goafanti.weChat.service.PublicReleaseService;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.socket.TextMessage;
- import java.math.BigDecimal;
- import java.text.ParseException;
- import java.util.*;
- import java.util.concurrent.atomic.AtomicReference;
- import java.util.stream.Collectors;
- @Service
- public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
- @Autowired
- private PublicReleaseMapper publicReleaseMapper;
- @Autowired
- private PublicReleaseLogMapper publicReleaseLogMapper;
- @Autowired
- private CustomerService customerService;
- @Autowired
- private PublicReleaseDetailsMapper publicReleaseDetailsMapper;
- @Autowired
- private WeChatUtils weChatUtils;
- @Autowired
- private AdminMapper adminMapper;
- @Autowired
- private AsyncUtils asyncUtils;
- @Autowired
- private UserMapper userMapper;
- @Autowired
- private OrganizationContactBookMapper organizationContactBookMapper;
- @Autowired
- private SystemWebSocketHandler systemWebSocketHandler;
- @Autowired
- private TOrderNewMapper tOrderNewMapper;
- @Autowired
- private DepartmentService departmentService;
- @Autowired
- private PublicExamineMapper publicExamineMapper;
- @Autowired
- private AdminUserCountMapper adminUserCountMapper;
- @Autowired
- private PublicReleaseClockMapper publicReleaseClockMapper;
- @Autowired
- private PublicReleaseDateClockMapper publicReleaseDateClockMapper;
- @Autowired
- private TOrderPublicReleaseCountMapper tOrderPublicReleaseCountMapper;
- @Override
- @Transactional
- public Map<String, Object> addPublicRelease(InputPublicRelease in) {
- Date date =new Date();
- if (in.getPublicAgain()==null)in.setPublicAgain(0);
- in.setCreateTime(date);
- in.setPublicType(0);
- in.setTechStartProcess(0);
- in.setStatus(1);
- in.setAid(TokenManager.getAdminId());
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- if (in.getAssist()==1){
- // in.setAssistAidName(getAssistAidName(in.getAssistAid()));
- in.setMainName(my.getName());
- }
- Map checkOrderNo =null;
- if (in.getType() == 1) {
- checkOrderNo = checkOrderNoDuration(in,my,1);
- boolean isValid = (boolean) checkOrderNo.get("code");
- if (isValid){
- in.setTechStartProcess(0);
- }else {
- in.setTechStartProcess(1);
- }
- }
- if (in.getValidDate()!=null){
- String validDate = in.getValidDate();
- List<Map> maps = JSONArray.parseArray(validDate, Map.class);
- }
- publicReleaseMapper.insertSelective(in);
- List<PublicReleaseDetails> prdList=new ArrayList<>();
- List<User> users=new ArrayList<>();
- StringBuilder str =new StringBuilder();
- if (in.getUids()!=null){
- List<String> split = Arrays.asList(in.getUids().split(","));
- int userCount=split.size();
- Double duration = in.getDuration();
- //计算平均
- double d = durationSum(duration, userCount);
- int index=1;
- //获取非已企业公出需要的审核人员
- for (String s : split) {
- PublicReleaseDetails prd=new PublicReleaseDetails();
- User u=userMapper.selectByPrimaryKey(s);
- users.add(u);
- str.append(u.getNickname()).append(",");
- if (u!=null&&u.getShareType()==2){
- prd.setNewUser(1);
- }else {
- prd.setNewUser(0);
- }
- if (u.getAid().equals(in.getAid())){
- prd.setMainStatus(1);
- }else {
- prd.setMainStatus(0);
- }
- prd.setPrid(in.getId());
- prd.setUid(s);
- prd.setSignSum(0);
- prd.setClockIn(0);
- prd.setDistrictName(in.getDistrictName());
- prd.setLatitude(in.getLatitude());
- prd.setLongitude(in.getLongitude());
- if (index<userCount){
- if (duration==0){
- prd.setDuration(duration);
- } else {
- prd.setDuration(d);
- duration=duration-d;
- }
- index++;
- }else {
- prd.setDuration(duration);
- }
- prdList.add(prd);
- }
- publicReleaseDetailsMapper.insertBatch(prdList);
- }
- addPublicReleaseDateClock(in);
- String userNames=str.substring(0,str.length()-1);
- in.setUserNames(userNames);
- PublicRelease updateName=new PublicRelease();
- updateName.setId(in.getId());
- updateName.setUserNames(userNames);
- publicReleaseMapper.updateByPrimaryKeySelective(updateName);
- addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
- return (Map<String, Object>) addPublicReleaseLog(my, in,userNames,date,users,checkOrderNo);
- }
- private void addPublicExamine(Integer id, String aid) {
- Admin admin = adminMapper.selectByPrimaryKey(aid);
- addPublicExamine(id,admin);
- }
- private void addPublicExamine(Integer id, Admin a) {
- List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(id);
- boolean flag=false;
- for (PublicExamine pe : publicExamines) {
- if (pe.getAid().equals(a.getId())){
- flag=true;
- }
- }
- if (!flag){
- PublicExamine pe=new PublicExamine();
- pe.setPrid(id);
- pe.setAid(a.getId());
- pe.setAname(a.getName());
- pe.setStatus(0);
- publicExamineMapper.insertSelective(pe);
- }
- }
- private double durationSum(Double duration, Integer sum) {
- Double counts= Math.floor(duration/0.5);
- //计算当前时间
- Double my=Math.floor(counts/sum)*0.5;
- if (my<0.5)return 0.5;
- return my;
- }
- /**
- *
- * @param my 我的相关人员
- * @param in 公出信息
- * @param nickname 客户名称
- * @param date 时间
- */
- private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users,
- Map<String,Object> checkOrderNo) {
- Map<String, Object>map=new HashMap<String, Object>();
- //无需订单负责人审核
- if (in.getTechStartProcess()==0){
- //获取公出审核人
- Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
- String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
- //默认上级审核
- AtomicReference<Integer> status= new AtomicReference<>(1);
- String formatDate = DateUtils.formatDate(in.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS);
- //不是业务员
- if (in.getType()==0){
- if (my.getPublicPurview()==0){
- users.forEach(u->{
- if (!u.getAid().equals(my.getId())){
- StringBuffer str2=new StringBuffer();
- str2=str2.append(my.getName()).append("(需审核),准备公出您的企业");
- str2=str2.append("[").append(u.getNickname()).append("]!!!。");
- sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
- Admin admin = adminMapper.selectByPrimaryKey(u.getAid());
- if (in.getType()==0){
- //不是自己的企业则需要审核并设置非自己客户待审核
- addPublicExamine(in.getId(), admin);
- if(in.getPublicType()==null|| in.getPublicType()==0)in.setPublicType(1);
- }
- pushNoticeAndSoucketAndEmail(my, in, date, admin, str, map);
- status.set(0);
- }
- });
- }else {
- users.forEach(u->{
- if (!u.getAid().equals(my.getId())){
- StringBuffer str2=new StringBuffer();
- str2=str2.append(my.getName()).append("计划公出您的企业").append(u.getNickname())
- .append(",").append(formatDate).append("【小程序端广播提示】");
- sendNoticeAndSoucket(u.getAid(),3,str2.toString());
- }
- });
- }
- }
- if (status.get()==1){
- pushNoticeAndSoucketAndEmail(my, in, date, a, str, map);
- }
- publicReleaseMapper.updateByPrimaryKeySelective(in);
- }else {
- TOrderNew tOrderNew = tOrderNewMapper.selectByPrimaryKey(in.getOrderNo());
- String salesmanId = tOrderNew.getSalesmanId();
- Admin a = adminMapper.selectByPrimaryKey(salesmanId);
- addPublicExamine(in.getId(),a);
- CheckOrderNoOut data = (CheckOrderNoOut) checkOrderNo.get("data");
- String format = getString(my, data);
- pushNoticeAndSoucketAndEmail(my, in, date, a, format, map);
- }
- map.put("data", publicReleaseMapper.selectDtails(in.getId()));
- return map;
- }
- private String getString(AdminListBo my, CheckOrderNoOut data) {
- String amountName="";
- String amountType="";
- if (data.getAmountType()==0){
- amountName="低于1万";
- amountType="原则上技术人员不可下户";
- }else if (data.getAmountType()==1){
- amountName="在1~3万";
- amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
- }else if (data.getAmountType()==2){
- amountName="在3~5万";
- amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
- }else if (data.getAmountType()==3){
- amountName="在5~10万";
- amountType="已超出合同可公出标准"+data.getDurationMax()+"小时";
- }
- String format = String.format("%s准备公出%s(%s)," +
- "总计公出:%s人,%s次,%s时。本合同%s,本次申请,%s。请确认是否同意本次公出?", my.getName(), data.getUserName(), data.getContractNo(),
- data.getPeopleCount(), data.getTimesCount(), data.getDurationCount().stripTrailingZeros().toPlainString(), amountName,
- amountType);
- return format;
- }
- /**
- *
- * @param my 发送人信息
- * @param in 公出信息
- * @param date 时间
- * @param a 接受者信息
- * @param str 站内信内容
- * @param map 返回实体
- */
- private void pushNoticeAndSoucketAndEmail(AdminListBo my, PublicRelease in, Date date, Admin a, String str, Map<String, Object> map) {
- sendNoticeAndSoucket(a.getId(),1, str);
- if (a.getOpenId() !=null) {
- Integer res= weChatUtils.addNotice(a.getOpenId(), in.getStatus(), in.getId(), date, my.getName(),"["+ my.getName()+"]发起外出申请");
- if (res!=0) {
- sendEmail(my, a,1);
- }
- map.put("code", res);
- }else {
- sendEmail(my, a,1);
- map.put("code", 2);
- }
- }
- private String getAssistAidName(String assistAid) {
- String [] ss=assistAid.split(",");
- StringBuffer sb=new StringBuffer();
- for (String s : ss) {
- Admin a=adminMapper.selectByPrimaryKey(s);
- if (a!=null&&a.getName()!=null)sb=sb.append(a.getName()).append(",");
- }
- if (sb.length()<1)return "";
- return sb.deleteCharAt(sb.length() - 1).toString();
- }
- private void sendEmailAndNoticeAndSoucket(String id,Integer type,String content){
- sendNoticeAndSoucket(id,type,content);
- Admin admin = adminMapper.selectByPrimaryKey(id);
- String title="暂无标题";
- if (type==3)title=NoticeStatus.PUBLIC_OTHERS_USER.getDesc();
- EmailBo emailBo=new EmailBo(title,admin.getEmail(),content);
- asyncUtils.send(emailBo);
- }
- /**
- *
- * @param id 接受者编号
- * @param type 状态 0驳回 1发起 2同意 3 公出他人企业
- * @param content 内容
- */
- private void sendNoticeAndSoucket(String id,Integer type,String content) {
- Integer noticeType=NoticeStatus.PUBLIC_RELEASE_START.getCode();
- if(type==0)noticeType=NoticeStatus.PUBLIC_RELEASE_NO.getCode();
- else if (type==2)noticeType=NoticeStatus.PUBLIC_RELEASE_YES.getCode();
- else if (type==3)noticeType=NoticeStatus.PUBLIC_OTHERS_USER.getCode();
- //触发通知有未读消息
- systemWebSocketHandler.sendMessageToUser(id, new TextMessage("unread"));
- Notice n =new Notice();
- n.setId(UUID.randomUUID().toString());
- n.setAid(id);
- n.setNoticeType(noticeType);
- n.setContent(content);
- n.setReaded(0);//未读
- asyncUtils.addNotice(n);
- }
- /**
- *
- * @param my 发送人
- * @param a 接受者
- * @param type 类型
- */
- private void sendEmail(AdminListBo my, Admin a,Integer type) {
- StringBuffer title=new StringBuffer();
- if (type==0) title=title.append("外出申请驳回提醒");
- else if (type==1) title=title.append("外出申请提醒");
- else if (type==2) title=title.append("外出申请同意提醒");
- if (SendEmailUtil.isEmail(a.getEmail())) {
- EmailBo email=new EmailBo(title.toString(),a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
- asyncUtils.send(email);
- }
- }
- @Override
- public int updatePublicRelease(InputPublicRelease in) {
- Date date = new Date();
- try {
- if(in.getReleaseStarts()!=null)in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
- if(in.getReleaseEnds()!=null)in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- throw new BusinessException("转换异常");
- }
- Map checkOrderNo =null;
- List<User> uses=null;
- PublicRelease use = publicReleaseMapper.selectByPrimaryKey(in.getId());
- in.setCreateTime(use.getCreateTime());
- String userNames=publicReleaseDetailsMapper.getNamesByPrid(in.getId());
- PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),null,in.getReason(),date);
- in.setUserNames(userNames);
- if(in.getStatus()==null||in.getStatus()!=3) {
- if (in.getType() == 1) {
- checkOrderNo = checkOrderNoDuration(in,null,2);
- boolean isValid = (boolean) checkOrderNo.get("code");
- if (isValid){
- in.setTechStartProcess(0);
- }else {
- in.setTechStartProcess(1);
- }
- }else {
- in.setTechStartProcess(0);
- }
- if (in.getUids()!=null){
- List<String> split = Arrays.asList(in.getUids().split(","));
- List<OutPublicReleaseDetails> prList = publicReleaseDetailsMapper.selectByPrid(in.getId());
- uses=pushPublicReleaseDetails(split,prList,use,in);
- }
- in.setStatus(1);
- log.setStatus(PublicReleaseLog.states.xg.getCode());
- in.setUpdateStatus(1);
- //如果是业务切公出则撤销营销审核与审核人
- pushUpdateType(in,use);
- //如果是业务公出,切审核状态为其他,则重置审核
- if(in.getType()==0&&(use.getPublicType()==2||use.getPublicType()==3)){
- in.setPublicType(1);
- PublicExamine pe=new PublicExamine();
- pe.setPrid(in.getId());
- pe.setStatus(0);
- publicExamineMapper.updateByPridSelective(pe);
- }
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- //重新发起
- addPublicReleaseLog(my,in,in.getUserNames(),date,uses,checkOrderNo);
- }else {
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
- List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);
- log.setStatus(PublicReleaseLog.states.cx.getCode());
- for (PublicRelease out : list) {
- addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单");
- out.setStatus(3);
- publicReleaseMapper.updateByPrimaryKeySelective(out);
- }
- for (PublicRelease out : list2) {
- addpublicLog(out.getId(), PublicReleaseLog.states.sc.getCode(), "修改撤销协单助手");
- out.setStatus(3);
- publicReleaseMapper.updateByPrimaryKeySelective(out);
- }
- }
- addPublicReleaseDateClock(in);
- publicReleaseLogMapper.insertSelective(log);
- publicReleaseMapper.updateByPrimaryKeySelective(in);
- return 1;
- }
- private void pushUpdateType(InputPublicRelease in, PublicRelease use) {
- //营销切换成技术
- if(use.getType()==0&&in.getType()==1){
- in.setPublicType(0);
- }
- if(use.getType()==1&&in.getType()==0){
- in.setTechStartProcess(0);
- }
- publicExamineMapper.deletePrid(in.getId());
- }
- private List<User> pushPublicReleaseDetails(List<String> split, List<OutPublicReleaseDetails> prList, PublicRelease use, InputPublicRelease in) {
- //先删除,再修改个,再新增,有利于减少计算
- deletePRD(split,prList);
- publicReleaseDetailsMapper.updateDistrictByPrid(in);
- List<User> users = addPRD(split, prList, use,in);
- return users;
- }
- private void deletePRD(List<String> split, List<OutPublicReleaseDetails> prdList) {
- for (OutPublicReleaseDetails prd : prdList) {
- boolean flag=true;
- for (String s : split) {
- if (prd.getUid().equals(s)){
- flag=false;
- }
- }
- if (flag){
- publicReleaseDetailsMapper.deleteByPrimaryKey(prd.getId());
- }
- }
- }
- /**
- * @param split 修改后客户集
- * @param prdList 修改前客户集
- * @param use 原订单信息
- */
- private List<User> addPRD(List<String> split, List<OutPublicReleaseDetails> prdList, PublicRelease use, InputPublicRelease in) {
- List<PublicReleaseDetails> addPrdList=new ArrayList<>();
- List<User> users=new ArrayList<>();
- Integer publicType = use.getPublicType();
- //计算平均
- Integer userCount=split.size();
- Integer index=0;
- Double duration= in.getDuration();
- double d = durationSum(duration,userCount );
- for (String s : split) {
- User u=userMapper.selectByPrimaryKey(s);
- users.add(u);
- boolean flag=true;
- Integer id=null;
- String districtName=null,latitude=null,longitude=null;
- for (OutPublicReleaseDetails prd : prdList) {
- if (id==null)id=prd.getPrid();
- if (districtName==null)districtName=prd.getDistrictName();
- if (latitude==null)latitude=prd.getLatitude();
- if (longitude==null)longitude=prd.getLongitude();
- if (s.equals(prd.getUid())){
- flag=false;
- }
- }
- //计算下
- if (flag){
- PublicReleaseDetails prd=new PublicReleaseDetails();
- if (u!=null&&u.getShareType()==2){
- prd.setNewUser(1);
- }else {
- prd.setNewUser(0);
- }
- if (u.getAid().equals(use.getAid())){
- prd.setMainStatus(1);
- }else {
- prd.setMainStatus(0);
- }
- prd.setPrid(id);
- prd.setUid(s);
- prd.setSignSum(0);
- prd.setDistrictName(districtName);
- prd.setLatitude(latitude);
- prd.setLongitude(longitude);
- prd.setClockIn(0);
- addPrdList.add(prd);
- //设置时长
- if (index<userCount){
- if (in.getDuration()==0){
- prd.setDuration(in.getDuration());
- } else {
- prd.setDuration(d);
- duration=duration-d;
- }
- }else {
- prd.setDuration(duration);
- }
- index++;
- if (!use.getAid().equals(u.getAid())){
- addPublicExamine(use.getId(), u.getAid());
- if (publicType==1)publicType=1;
- }
- }else {
- InputPublicRelease inp=new InputPublicRelease();
- inp.setId(in.getId());
- inp.setUid(s);
- PublicReleaseDetails publicReleaseDetails = publicReleaseDetailsMapper.selectBypridAndUid(inp);
- PublicReleaseDetails newprd =new PublicReleaseDetails();
- newprd.setId(publicReleaseDetails.getId());
- //设置时长
- if (index<userCount){
- if (in.getDuration()==0){
- newprd.setDuration(in.getDuration());
- } else {
- newprd.setDuration(d);
- duration=duration-d;
- }
- }else {
- newprd.setDuration(duration);
- }
- index++;
- publicReleaseDetailsMapper.updateByPrimaryKeySelective(newprd);
- }
- }
- StringBuffer str=new StringBuffer();
- for (User u : users) {
- str=str.append(use.getUserNames()).append(",");
- }
- if (publicType!=use.getPublicType()){
- PublicRelease newP=new PublicRelease();
- newP.setId(use.getId());
- if (str.length()>1)newP.setUserNames(str.substring(0,str.length()-1));
- newP.setPublicType(publicType);
- publicReleaseMapper.updateByPrimaryKeySelective(newP);
- }
- if (!addPrdList.isEmpty())publicReleaseDetailsMapper.insertBatch(addPrdList);
- return users;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
- Map<String,Object> map =new HashMap<String, Object>();
- map.put("type", in.getType()==null?0:in.getType());
- //先修改他人公出做测试
- // if(in.getType()==4)map.put("type", 5);
- if (in.getType()==3) {
- in.setAssist(2);
- if (!TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR))map.put("aid",TokenManager.getAdminId());
- }else{
- map.put("aid",TokenManager.getAdminId());
- }
- if (StringUtils.isNotEmpty(in.getClockTime())) map.put("clockTime", in.getClockTime());
- if(StringUtils.isNotEmpty(in.getReleaseStarts())) map.put("releaseStarts", in.getReleaseStarts());
- if(StringUtils.isNotEmpty(in.getReleaseEnds())) map.put("publicEnd", in.getReleaseEnds()+" 23:59:59");
- if(StringUtils.isNotEmpty(in.getUserName())) map.put("userName", in.getUserName());
- if(in.getStatus()!=null) map.put("status", in.getStatus());
- if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
- map.put("assist",in.getAssist()==null?0:in.getAssist());
- Pagination<OutPublicReleaseList> p=(Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
- if(in.getType()==0||in.getType()==4){
- pushExamines(p);
- }
- return p;
- }
- private void pushExamines(Pagination<OutPublicReleaseList> p) {
- List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) p.getList();
- if (!list.isEmpty()){
- List<Integer> ids=new ArrayList<>();
- list.forEach(e ->{ ids.add(e.getId()); });
- List<PublicExamine> publicExamines = publicExamineMapper.selectByIds(ids);
- for (OutPublicReleaseList e : list) {
- if (e.getStatus()==1&&
- ((e.getPublicType()==0||e.getPublicType()==2)&&(e.getTechStartProcess()==0||e.getTechStartProcess()==2))
- ){
- e.setAdminExamine(e.getReviewerName()+" 未审核");
- }else if (e.getStatus()==0) {
- e.setAdminExamine("");
- }else {
- if (!publicExamines.isEmpty()){
- StringBuffer str =new StringBuffer();
- for (PublicExamine pe : publicExamines) {
- if (e.getId().equals(pe.getPrid())){
- str=str.append(pe.getAname());
- if (pe.getStatus()==0)str=str.append(" 未审核,");
- if (pe.getStatus()==1)str=str.append(" 已审核,");
- }
- if (str.length()>1) e.setAdminExamine(str.substring(0,str.length()-1));
- }
- }
- }
- }
- }
- }
- @Override
- @Transactional
- public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Integer examineType) {
- PublicRelease p=new PublicRelease();
- Date date =new Date();
- boolean flag=false;
- String aid=TokenManager.getAdminId();
- p.setId(id);
- PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
- if (use.getStatus()!=1) {
- throw new BusinessException("只能修改发起的状态公出");
- }
- if((use.getTechStartProcess()==1||use.getTechStartProcess()==3)&&(examineType==0||examineType==1)){
- if(use.getTechStartProcess()!=0) throw new BusinessException("技术公出先需营销审核。");
- }
- //当前审核人员
- Admin ad=adminMapper.selectByPrimaryKey(aid);
- //公出负责人
- Admin a;
- Admin publicAdmin =adminMapper.selectByPrimaryKey(use.getAid());
- a=publicAdmin;
- StringBuffer str=new StringBuffer();
- str=str.append("(").append(ad.getName()).append(")");
- StringBuffer content=new StringBuffer().append("[").append(use.getUserNames()).append("]公司的外出申请,");
- //上级审核
- if(examineType==0){
- p.setStatus(status);
- if (status==0){
- str=str.append("驳回,");
- if (use.getAssist()==2){
- content=content.append("技术协单被[").append(ad.getName()).append("]拒绝!");
- }else {
- content=content.append("未通过公出审核!");
- }
- if(use.getPublicType()>1){
- p.setPublicType(1);
- PublicExamine inpe=new PublicExamine();
- inpe.setStatus(0);
- inpe.setPrid(use.getId());
- publicExamineMapper.updateStatusByPrid(inpe);
- }
- }else if(status==2){
- str=str.append("同意,");
- //如果是协单公出主公出,在审核通过
- if (use.getAssist()==1){
- pushPublicReleaseAssist(use,status,date,a);
- }else if (use.getAssist()==0){
- publicReleaseMapper.updateStatusByMainId(3,use.getId(),null,null);
- }
- content=content.append("已通过审核!");
- }
- str=str.append(remarks);
- p.setAuditInfo(str.toString());
- p.setAuditTime(date);
- p.setRejectName(ad.getName());
- addpublicLog(id, status, remarks);
- flag=true;
- //营销员审核
- }else if (examineType==1){
- //通知公出人切换成公出人审核人
- a=adminMapper.selectByPrimaryKey(a.getReviewer());
- if (status==2){//审核通过
- str=str.append("同意公出我的企业,").append(remarks);
- content=content.append("已通过审核,请尽快审核。");
- List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
- int x=0;
- for (PublicExamine pe : publicExamines) {
- if (pe.getAid().equals(aid)){
- pe.setStatus(1);
- PublicExamine newp=new PublicExamine();
- newp.setId(pe.getId());
- newp.setStatus(1);
- publicExamineMapper.updateByPrimaryKeySelective(newp);
- x++;
- }else {
- if (pe.getStatus()==1){
- x++;
- }
- }
- }
- if (x==publicExamines.size()){
- p.setPublicType(2);
- flag=true;
- }
- addpublicLog(id, status, str.toString());
- }else if (status==0){//审核驳回
- //切换通知人公出负责人
- a=publicAdmin;
- str=str.append("不同意公出我的企业,").append(remarks);;
- content=content.append("未通过审核,请修改后重新发起。");
- p.setPublicType(3);
- p.setStatus(0);
- p.setAuditInfo(str.toString());
- p.setRejectName(ad.getName());
- addpublicLog(id, 0, str.toString());
- flag=true;
- }
- }else if (examineType==2){
- //通知公出人切换成公出人审核人
- a=adminMapper.selectByPrimaryKey(a.getReviewer());
- if (status==2){//审核通过
- str=str.append("同意公出我的企业,").append(remarks);
- content=content.append("已通过审核,请尽快审核。");
- List<PublicExamine> publicExamines = publicExamineMapper.selectByPrid(use.getId());
- int x=0;
- for (PublicExamine pe : publicExamines) {
- if (pe.getAid().equals(aid)){
- pe.setStatus(1);
- PublicExamine newp=new PublicExamine();
- newp.setId(pe.getId());
- newp.setStatus(1);
- publicExamineMapper.updateByPrimaryKeySelective(newp);
- x++;
- }else {
- if (pe.getStatus()==1){
- x++;
- }
- }
- }
- if (x==publicExamines.size()){
- p.setTechStartProcess(2);
- flag=true;
- }
- addpublicLog(id, status, str.toString());
- }else if (status==0){//审核驳回
- //切换通知人公出负责人
- a=publicAdmin;
- str=str.append("不同意公出我的企业,").append(remarks);;
- content=content.append("未通过审核,请修改后重新发起。");
- p.setTechStartProcess(3);
- p.setStatus(0);
- p.setAuditInfo(str.toString());
- p.setRejectName(ad.getName());
- addpublicLog(id, 0, str.toString());
- flag=true;
- }
- }
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- if (flag){
- sendNoticeAndSoucket(a.getId(),status,content.toString());
- }
- if (p.getStatus()!=null||p.getPublicType()!=null||p.getTechStartProcess()!=null){
- publicReleaseMapper.updateByPrimaryKeySelective(p);
- updateAdminUserCountPublicRelease(use.getAid(),use.getReleaseStart());
- }
- if (a.getOpenId()!=null) {
- if (remarks.length()>19) {
- remarks=remarks.substring(0, 15)+"...";
- }
- Integer res=weChatUtils.addNotice(a.getOpenId(),status,p.getId(),date,my.getName(),remarks);
- if (res!=0) {
- sendEmail( my, a, status);
- }
- return res;
- }
- return 1;
- }
- private void updateAdminUserCountPublicRelease(String aid, Date transferTime) {
- String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
- String endTime=startTime+" 23:59:59";
- AdminUserCount adminUserCount = customerService.getAdminUserCount(aid,startTime);
- Integer count = publicReleaseMapper.selectCountByaidAndDate(aid, startTime, endTime);
- if (count==null){
- count=0;
- }
- if (adminUserCount==null){
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- if (selectAUC==null)selectAUC=new AdminUserCount();
- selectAUC.setPublicReleaseCount(count);
- selectAUC.setAid(aid);
- selectAUC.setDateTime(transferTime);
- adminUserCountMapper.insertSelective(selectAUC);
- }else {
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- AdminUserCount newAUC=new AdminUserCount();
- newAUC.setId(adminUserCount.getId());
- newAUC.setPublicReleaseCount(count);
- if (selectAUC==null){
- newAUC.setPrivateCount(0);
- newAUC.setChannelCount(0);
- newAUC.setSignCount(0);
- }else {
- if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
- if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
- if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
- newAUC.setPrivateCount(selectAUC.getPrivateCount());
- newAUC.setChannelCount(selectAUC.getChannelCount());
- newAUC.setSignCount(selectAUC.getSignCount());
- }
- adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
- }
- }
- private void addpublicLog(Integer id, Integer status, String remarks) {
- PublicReleaseLog log = new PublicReleaseLog(id, TokenManager.getAdminId(), status, remarks, new Date());
- publicReleaseLogMapper.insertSelective(log);
- }
- @Override
- public int pushTechReject(Integer id, String remarks) {
- Integer status=0;
- PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
- PublicRelease mainPublic= publicReleaseMapper.selectByPrimaryKey(use.getMainId());
- Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
- StringBuffer str=new StringBuffer();
- if (use.getAssist()!=2){
- throw new BusinessException("只有技术公出能发起技术驳回");
- }
- str=str.append("拒绝技术协单,").append(remarks);
- PublicRelease newMain=new PublicRelease();
- newMain.setId(mainPublic.getId());
- newMain.setStatus(4);
- newMain.setRejectName(ad.getName());
- newMain.setAuditInfo(str.toString());
- addWeChatNotice(mainPublic.getAid(),0,str.toString(),mainPublic.getId());
- publicReleaseMapper.updateByPrimaryKeySelective(newMain);
- PublicRelease up=new PublicRelease();
- up.setId(id);
- up.setAuditInfo(str.toString());
- up.setStatus(3);
- addpublicLog(id, status, remarks);
- publicReleaseMapper.updateByPrimaryKeySelective(up);
- deleteAssistantPulicRelease(use,null);
- return addNoticeAndWeChat(mainPublic.getId(), mainPublic.getAid(), str.toString(), status);
- }
- /**
- * 新增日志、站内信、微信提醒
- * @param id 日志公出编号
- * @param aid 接受者
- * @param remarks 日志内容
- * @param status 0驳回
- * @return
- */
- private Integer addNoticeAndWeChat(Integer id,String aid, String remarks, Integer status) {
- AdminListBo my = adminMapper.getDeptNameByAid(aid);
- Admin a = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
- if (my.getOpenId()!=null) {
- if (remarks.length()>19) {
- remarks=remarks.substring(0, 15)+"...";
- }
- return weChatUtils.addNotice(my.getOpenId(),status,id,new Date(),my.getName(), remarks);
- }else {
- sendEmail( my, a, status);
- return 1;
- }
- }
- /**
- *
- * @param use 原始公出信息
- * @param status 状态
- * @param date 时间
- * @param a
- */
- private void pushPublicReleaseAssist(PublicRelease use,Integer status,Date date,Admin a) {
- if (use.getAssistAid()!=null){
- updatePushassist(use, status, date,a);
- if(use.getAssistantAid()!=null){
- updatepushAssistant(use,a);
- }
- }
- }
- /**
- * 处理技术协单
- * @param use
- * @param status
- * @param date
- */
- private void updatePushassist(PublicRelease use, Integer status, Date date, Admin a) {
- //协单
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(use.getId(),3,null);
- String []ss= use.getAssistAid().split(",");
- //数据库与传入比对,如果不存在就标记撤销 ,如果存在就修改成
- for (PublicRelease out : list) {
- boolean flag=false;
- for (String s : ss) {
- if (out.getAid().equals(s)){
- flag=true;
- break;
- }
- }
- if (!flag){
- PublicRelease in = new PublicRelease();
- in.setId(out.getId());
- in.setStatus(3);
- publicReleaseMapper.updateByPrimaryKeySelective(in);
- StringBuffer str = new StringBuffer("[").append(a.getName()).append("]取消公出").append("[").append(use.getUserNames()).append("]。");
- PublicReleaseLog log = new PublicReleaseLog(in.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.cx.getCode(), str.toString(), date);
- publicReleaseLogMapper.insertSelective(log);
- sendNoticeAndSoucket(out.getAid(),in.getStatus(),str.toString());
- }else {
- PublicRelease np = new PublicRelease();
- BeanUtils.copyProperties(use,np);
- np.setId(out.getId());
- np.setMainId(null);
- np.setType(null);
- np.setAssist(2);
- np.setStatus(status);
- np.setAid(null);
- publicReleaseMapper.updateByPrimaryKeySelective(np);
- updatePublicReleaseDtails(use,np);
- StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了公出").append("[").append(use.getUserNames()).append("]。");
- PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.xg.getCode(),str.toString(), date);
- publicReleaseLogMapper.insertSelective(log);
- sendNoticeAndSoucket(out.getAid(),np.getStatus(),str.toString());
- }
- }
- for (String s : ss) {
- boolean flag2 = false;
- for (PublicRelease o : list) {
- if (s.equals(o.getAid())) {
- flag2 = true;
- }
- }
- if (!flag2) {
- PublicRelease np = new PublicRelease();
- BeanUtils.copyProperties(use,np);
- np.setAssist(2);
- np.setAid(s);
- np.setStatus(2);
- np.setType(3);
- np.setMainId(use.getId());
- np.setId(null);
- publicReleaseMapper.insertSelective(np);
- //补充客户表
- addpublicReleaseDtails(use,np);
- StringBuffer str = new StringBuffer("[").append(a.getName()).append("]邀请你技术协单").append("[").append(use.getUserNames()).append("]。");
- PublicReleaseLog log = new PublicReleaseLog(np.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.fq.getCode(), str.toString(), date);
- sendNoticeAndSoucket(np.getAid(),np.getStatus(),str.toString());
- publicReleaseLogMapper.insertSelective(log);
- }
- }
- }
- private void updatePublicReleaseDtails(PublicRelease use, PublicRelease in) {
- List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
- List<OutPublicReleaseDetails> list2 = publicReleaseDetailsMapper.selectByPrid(in.getId());
- //打卡信息重新梳理
- //查找新增的
- for (OutPublicReleaseDetails out : list) {
- boolean flag=true;
- for (OutPublicReleaseDetails out2 : list2) {
- if (out.getUid().equals(out2.getUid())){
- flag=false;
- }
- }
- if (flag){
- OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
- BeanUtils.copyProperties(out,prd);
- prd.setPrid(in.getId());
- prd.setClockIn(0);
- prd.setClockInTime(null);
- prd.setClockInRemarks(null);
- prd.setUfid(null);
- publicReleaseDetailsMapper.insertSelective(prd);
- }
- }
- for (OutPublicReleaseDetails out2 : list2) {
- boolean flag=true;
- for (OutPublicReleaseDetails out : list) {
- if (out2.getUid().equals(out.getUid())){
- flag=false;
- }
- }
- if (flag){
- publicReleaseDetailsMapper.deleteByPrimaryKey(out2.getId());
- }
- }
- //信息补充,修改时没有打卡信息
- if(in.getValidDate()==null)in.setValidDate(use.getValidDate());
- //最后再来处理打卡信息
- addPublicReleaseDateClock(in);
- }
- private void addpublicReleaseDtails(PublicRelease use, PublicRelease in) {
- List<OutPublicReleaseDetails> list = publicReleaseDetailsMapper.selectByPrid(use.getId());
- for (OutPublicReleaseDetails out : list) {
- OutPublicReleaseDetails prd=new OutPublicReleaseDetails();
- BeanUtils.copyProperties(out,prd);
- prd.setPrid(in.getId());
- prd.setClockIn(0);
- prd.setClockInTime(null);
- prd.setMainStatus(0);
- publicReleaseDetailsMapper.insertSelective(prd);
- }
- addPublicReleaseDateClock(in);
- }
- /**
- * 处理技术助手
- * @param use
- */
- private void updatepushAssistant(PublicRelease use,Admin a) {
- List<PublicRelease> uselist = publicReleaseMapper.selectByMainId(use.getId(),4,null);
- for (PublicRelease p : uselist) {
- if(!use.getReleaseStart().equals(p.getReleaseStart()))p.setReleaseStart(use.getReleaseStart());
- if (!use.getReleaseEnd().equals(p.getReleaseEnd()))p.setReleaseEnd(use.getReleaseEnd());
- p.setStatus(2);
- p.setAssistantAid(use.getAssistantAid());
- p.setAssistantName(use.getAssistantName());
- p.setUserNames(use.getUserNames());
- publicReleaseMapper.updateByPrimaryKeySelective(p);
- StringBuffer str = new StringBuffer("[").append(a.getName()).append("]修改了").append("[").append(use.getUserNames()).append("]。");
- PublicReleaseLog log = new PublicReleaseLog(p.getId(), TokenManager.getAdminId(), PublicReleaseLog.states.ty.getCode(), str.toString(), new Date());
- sendNoticeAndSoucket(p.getAid(),p.getStatus(),str.toString());
- publicReleaseLogMapper.insertSelective(log);
- }
- }
- @Override
- public List<outPublicReleaseLog> listPublicReleaseLog(Integer id,String ufid) {
- List<outPublicReleaseLog> list=publicReleaseLogMapper.listPublicReleaseLog(id,ufid);
- return list;
- }
- @Override
- public int pushPublicReleaseClockIn(Integer id,String photoUrl,Integer clockIn ,String clockInRemarks ,String uid) {
- if (clockIn == null) clockIn = 1;
- PublicRelease use = publicReleaseMapper.selectByPrimaryKey(id);
- if (use.getPublicType()==1||use.getPublicType()==3) {
- return -1;
- }
- // 取消打卡限制
- // if (use.getTechStartProcess()==1||use.getTechStartProcess()==3){
- // return -2;
- // }
- List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
- List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
- pushDateClockDetails(prdList,prdcList);
- String str = "";
- Date date = new Date();
- boolean flag=false;
- Integer clockCount=0;
- PublicReleaseClock pc=new PublicReleaseClock();
- pc.setPrid(id);
- pc.setPhotoUrl(photoUrl);
- pc.setClockInTime(date);
- for (OutPublicReleaseDetails prd : prdList) {
- if (prd.getUid().equals(uid)){
- String aid = TokenManager.getAdminId();
- pc.setPrdid(prd.getId());
- prd.setClockInRemarks(clockInRemarks);
- prd.setPhotoUrl(photoUrl);
- prd.setClockInTime(date);
- int count=0;
- for (PublicReleaseDateClock ep : prd.getPrdcList()) {
- if (DateUtils.isSameDay(prd.getClockInTime(), ep.getClockInTime())){
- if (ep.getStatus()==0){
- ep.setStatus(1);
- FollowBusinessBo fbb = new FollowBusinessBo();
- fbb.setUid(prd.getUid());
- fbb.setContactType("5");
- fbb.setResult(use.getRemarks());
- OrganizationContactBook ub = organizationContactBookMapper.getMajor(prd.getUid(), aid);
- if (ub != null) {
- fbb.setOcbId(ub.getId());
- }
- fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
- String ufid = UUID.randomUUID().toString();
- prd.setUfid(ufid);
- customerService.addFollow(fbb, ufid, prd.getMainStatus());
- if (clockIn==1){
- str = "公出人员打卡";
- }else if (clockIn==2) {
- str = "公出人员异常打卡";
- }
- count++;
- publicReleaseDateClockMapper.updateByPrimaryKeySelective(ep);
- }else {
- if (clockIn==1){
- str = "刷新打卡";
- }else if (clockIn==2) {
- str = "刷新打卡,公出人员异常打卡";
- }
- count++;
- }
- }else {
- if (ep.getStatus()==1){
- count++;
- }
- }
- }
- if(prd.getPrdcList().size() == count){
- prd.setClockIn(1);
- }
- PublicReleaseLog log = new PublicReleaseLog(id, aid, PublicReleaseLog.states.dk.getCode(), str, new Date());
- log.setPhotoUrl(photoUrl);
- publicReleaseLogMapper.insertSelective(log);
- publicReleaseDetailsMapper.updateByPrimaryKeySelective(prd);
- flag=true;
- clockCount++;
- }else if (prd.getClockIn()==1){
- clockCount++;
- }
- }
- if (prdList.size()==clockCount){
- PublicRelease newp=new PublicRelease();
- newp.setId(id);
- newp.setClockIn(1);
- publicReleaseMapper.updateByPrimaryKeySelective(newp);
- }
- publicReleaseClockMapper.insertSelective(pc);
- if (!flag){
- return 0;
- }
- return 1;
- }
- @Override
- public OutPublicRelease dtails(Integer id) {
- String aid=TokenManager.getAdminId();
- //如果不是本人和审核人员则不返回信息
- OutPublicRelease out=publicReleaseMapper.selectDtails(id);
- List<PublicExamine> ps = publicExamineMapper.selectByPrid(out.getId());
- out.setPeList(ps);
- if(out!=null){
- boolean flag=false;
- //自己、审核人员与部门负责人可以查看
- AdminListBo ab=adminMapper.getDeptNameByAid(out.getAid());
- if (!aid.equals( out.getAid())&&
- !aid.equals(out.getReviewer())&&
- !aid.equals(ab.getDepManager())&&
- !TokenManager.hasRole(AFTConstants.TECH_FINANCE_DIRECTOR)){
- flag=true;
- }
- //是否可以审核
- if (!ps.isEmpty()){
- for (PublicExamine p : ps) {
- if (p.getAid().equals(aid)){
- if (p.getStatus()==1)out.setMyExamine(1);
- else out.setMyExamine(0);
- flag=false;
- break;
- }
- }
- }
- //处理返回
- if(flag){
- out=null;
- return out;
- }else {
- if (out.getPublicType()==1){
- if (aid.equals(out.getAid())){
- out.setPermission(0);
- }else {
- out.setPermission(1);
- }
- }else {
- if(aid.equals(out.getAid())) {
- out.setPermission(0);
- }else {
- out.setPermission(1);
- }
- }
- }
- }
- if (out.getStatus()==1&&
- ((out.getPublicType()==0||out.getPublicType()==2)&&(out.getTechStartProcess()==0||out.getTechStartProcess()==2))
- ){
- out.setAdminExamine(out.getReviewerName()+" 未审核");
- }else if (out.getStatus()==0) {
- out.setAdminExamine("");
- }else {
- if (!ps.isEmpty()){
- StringBuffer str =new StringBuffer();
- for (PublicExamine e : ps) {
- if (out.getId().equals(e.getPrid())){
- str.append(e.getAname());
- if (e.getStatus()==0) str.append(" 未审核,");
- if (e.getStatus()==1) str.append(" 已审核,");
- }
- if (str.length()>1) out.setAdminExamine(str.substring(0,str.length()-1));
- }
- }
- }
- List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
- List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
- pushDateClockDetailsToday(prdList,prdcList);
- out.setPrdList(prdList);
- return out;
- }
- @Override
- public OutPublicReleaseAndDetails followDtails(String id) {
- OutPublicReleaseAndDetails out = publicReleaseMapper.selectDtailsByFid( id);
- List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(out.getId());
- List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(out.getId());
- pushDateClockDetails(prdList,prdcList);
- out.setPrdList(prdList);
- return out;
- }
- @SuppressWarnings("unchecked")
- @Override
- // @Cacheable(value = "publicReleaseStatistics#300", key = "'publicReleaseStatistics:" +
- // "aid:'+#in.aid+'depId:'+#in.depId+'clockStart:'+#in.clockStart+" +
- // "'clockEnd:'+#in.clockEnd+'createStart:'+#in.createStart+'createEnd'+#in.createEnd+" +
- // "'pageNo:'+#in.pageNo+'pageSzie:'+#in.pageSize")
- public Object publicReleaseStatistics(InputPublicStatistics in) {
- Map<String,Object> map =new HashMap<String, Object>();
- if(in.getAid()!=null)map.put("aid", in.getAid());
- if(in.getDepId()!=null)map.put("depId", in.getDepId());
- if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
- if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
- if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
- if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
- return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
- }
- @SuppressWarnings("unchecked")
- @Override
- public List<OutPublicStatistics> publicReleaseStatisticsList(InputPublicStatistics in) {
- Map<String,Object> map =new HashMap<String, Object>();
- if(in.getAid()!=null)map.put("aid", in.getAid());
- if (TokenManager.hasRole(AFTConstants.SUPERADMIN)|| TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)||
- TokenManager.hasRole(AFTConstants.CED)|| TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
- if(in.getDepId()!=null)map.put("depId", in.getDepId());
- }else if (TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)){
- }
- if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
- if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
- if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
- if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
- return (List<OutPublicStatistics>) findList("listPublicStatistics",map, in.getPageNo(), 99999);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Object publicReleaseListDtails(InputPublicDtails in) {
- Map<String,Object> map =new HashMap<String, Object>();
- addParams(in, map);
- Pagination<OutPublicDtails> page = (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
- List<OutPublicDtails> list = (List<OutPublicDtails>)page.getList();
- List<Integer> collect = list.stream().map(OutPublicDtails::getId).collect(Collectors.toList());
- if (!collect.isEmpty()){
- List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(collect);
- pushiClockInTime(list, publicReleaseClocks);
- }
- return page;
- }
- private void addParams(InputPublicDtails in, Map<String, Object> map) {
- if(in.getAid()!=null) map.put("aid", in.getAid());
- if(in.getSid()!=null) map.put("sid", in.getSid());
- if(in.getReleaseStart()!=null) map.put("releaseStart", in.getReleaseStart());
- if(in.getReleaseEnd()!=null) map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
- if(in.getCreateStart()!=null) map.put("createStart", in.getCreateStart());
- if(in.getCreateEnd()!=null) map.put("createEnd", in.getCreateEnd()+" 23:59:59");
- if(in.getUid()!=null) map.put("uid", in.getUid());
- if(in.getContractNo()!=null) map.put("contractNo", in.getContractNo());
- if(in.getStatus()!=null) map.put("status", in.getStatus());
- if(in.getClockIn()!=null) map.put("clockIn", in.getClockIn());
- if(in.getPublicType()!=null)map.put("publicType",in.getPublicType());
- //type 0私有 1管理权限 2所有权限
- if(TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)
- ||TokenManager.hasRole(AFTConstants.CED_ASSISTANT )||TokenManager.hasRole(AFTConstants.PERSONNEL_AUDITOR)
- ||TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)
- ||TokenManager.hasRole(AFTConstants.FINANCE)||TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)){
- //添加财务和财务经理。查看客户所有公出
- in.setType(2);
- if(in.getDeps()!=null){
- map.put("deps", departmentService.parseArray(in.getDeps()));
- }
- }else if(TokenManager.hasRole(AFTConstants.COMPANY_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)
- ||TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
- in.setType(1);
- if (in.getDeps()!=null){
- List<String> list = departmentService.selectSubDeps(in.getDeps());
- if (list.isEmpty()) throw new BusinessException("无权查看此部门信息");
- map.put("deps", list);
- }else {
- map.put("deps",departmentService.selectMyDeps());
- }
- }else{
- in.setType(0);
- if (in.getAid()==null) map.put("aid",TokenManager.getAdminId());
- if(in.getDeps()!=null){
- map.put("deps", departmentService.parseArray(in.getDeps()));
- }
- }
- map.put("type", in.getType());
- if(in.getStatusType()!=null) map.put("statusType", in.getStatusType());
- }
- @SuppressWarnings("unchecked")
- @Override
- public List<OutPublicDtails> publicReleaseListDtailsList(InputPublicDtails in) {
- Map<String,Object> map =new HashMap<String, Object>();
- addParams(in, map);
- return (List<OutPublicDtails>) findList("listPublicDtails", map, in.getPageNo(), 99999);
- }
- @Override
- public int addSupplement(Integer id, String supplement, String nextPlan) {
- PublicRelease pr=new PublicRelease();
- pr.setId(id);
- pr.setSupplement(supplement);
- pr.setNextPlan(nextPlan);
- return publicReleaseMapper.updateByPrimaryKeySelective(pr);
- }
- @Override
- public boolean checkTime(InputPublicRelease in) {
- try {
- in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
- in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- throw new BusinessException("转换异常");
- }
- List<Integer> is=publicReleaseMapper.checkTime(TokenManager.getAdminId(),in.getReleaseStart(),in.getReleaseEnd());
- if (is.size()>1) {
- return true;
- }else if(is.size()==1){
- //如果id为新增那么直接不允许时间重复
- if (in.getId()==null){
- return true;
- }else {
- //如果有id,与获取id一直,则为当前修改可以
- if (in.getId().equals(is.get(0))){
- return false;
- }else {
- return true;
- }
- }
- }
- return false;
- }
- @Override
- public List<Map<String, Object>> selectOrderByUid(String uid) {
- return tOrderNewMapper.selectOrderByuid(uid);
- }
- @Override
- public List<OutPublicRelease> publicByOrder(String orderNo) {
- return publicReleaseMapper.publicByOrder(orderNo);
- }
- @Override
- public Object getMyNewPublic() {
- List<PublicRelease> myPublic=publicReleaseMapper.selectMyNewPublic(TokenManager.getAdminId());
- if(myPublic.isEmpty())return null;
- Integer id=null;
- long count=999999;
- for (PublicRelease e : myPublic) {
- long nowTime=System.currentTimeMillis();
- long time = Math.abs(nowTime-e.getReleaseStart().getTime())/(1000*60);
- long time2 = Math.abs(e.getReleaseEnd().getTime()-nowTime)/(1000*60);
- //距离当前时间近的开始时间,不大于当前时间
- if (time<count&&e.getReleaseStart().getTime()<nowTime){
- count=time;
- id=e.getId();
- }
- //距离当前时间近的结束时间,不小于当前时间
- if (time2<count&&e.getReleaseEnd().getTime()>nowTime){
- count=time2;
- id=e.getId();
- }
- }
- if (id==null)id=myPublic.get(0).getId();
- OutPublicReleaseList out = publicReleaseMapper.selectOutListBoById(id);
- List<OutPublicReleaseDetails> prdList = publicReleaseDetailsMapper.selectByPrid(id);
- List<PublicReleaseDateClock> prdcList = publicReleaseDateClockMapper.selectByPrid(id);
- pushDateClockDetails(prdList,prdcList);
- pushDateClockDetailsToday(prdList,prdcList);
- out.setPrdList(prdList);
- return out;
- // List<OutPublicReleaseList> myPublic = getMyPublic(0,1);
- // if (myPublic.isEmpty()){
- // List<OutPublicReleaseList> myPublic2 = getMyPublic(0,0);
- // if (!myPublic2.isEmpty()){
- // return myPublic2.get(0);
- // }
- // }else {
- // return myPublic.get(0);
- // }
- }
- private void pushDateClockDetailsToday(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
- for (OutPublicReleaseDetails out : prdList) {
- List<PublicReleaseDateClock> elist=new ArrayList<>();;
- for (PublicReleaseDateClock prdc : prdcList) {
- if (prdc.getPrdid().equals(out.getId())&&DateUtils.isSameDay(new Date(), prdc.getClockInTime())){
- elist.add(prdc);
- }
- }
- out.setPrdcList(elist);
- }
- }
- private void pushDateClockDetails(List<OutPublicReleaseDetails> prdList, List<PublicReleaseDateClock> prdcList) {
- for (OutPublicReleaseDetails out : prdList) {
- List<PublicReleaseDateClock> elist=new ArrayList<>();;
- for (PublicReleaseDateClock prdc : prdcList) {
- if (prdc.getPrdid().equals(out.getId())){
- elist.add(prdc);
- }
- }
- out.setPrdcList(elist);
- }
- }
- /**
- *
- * @param type 查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
- * @param dateType 是否含打卡时间 0否 1是
- * @return
- */
- public List<OutPublicReleaseList>getMyPublic(Integer type ,Integer dateType){
- Map<String, Object> map = new HashMap<>();
- if (type==null)type=0;
- map.put("type",type);
- //statusType=1情况下
- map.put("statusType",1);
- if (dateType==1){
- Date date = new Date();
- String clockTime=DateUtils.formatDate(date,AFTConstants.YYYYMMDDHHMMSS);
- map.put("clockTime",clockTime);
- }
- map.put("aid",TokenManager.getAdminId());
- List<OutPublicReleaseList> list = (List<OutPublicReleaseList>) findList("listPublicRelease",map,1,1);
- for (OutPublicReleaseList out : list) {
- out.setPrdList(publicReleaseDetailsMapper.selectByPrid(out.getId()));
- }
- return list;
- }
- @Override
- public int addAssistant(Integer id,String aid) {
- PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
- List<String> list=new ArrayList<>();
- if (StringUtils.isNotEmpty(p.getAssistantAid())){
- list =new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
- }
- String sname = pushAssistant(aid, list,0);
- String said =String.join(",",list);
- p.setAssistantAid(said);
- p.setAssistantName(sname);
- addAssistantPublicRelease(p,aid);
- return updateAssistant(p, said, sname);
- }
- private void addAssistantPublicRelease(PublicRelease p, String aid) {
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
- PublicRelease newP= new PublicRelease();
- if(list.isEmpty()){
- BeanUtils.copyProperties(p,newP);
- newP.setId(null);
- newP.setAid(aid);
- newP.setAssist(3);
- newP.setType(4);
- publicReleaseMapper.insertSelective(newP);
- addpublicReleaseDtails(p,newP);
- StringBuffer str=new StringBuffer();
- str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("邀请你协助!");
- addWeChatNotice( aid,1,str.toString(),newP.getId());
- }else {
- for (PublicRelease pr : list) {
- newP.setId(pr.getId());
- newP.setAssistantAid(p.getAssistantAid());
- newP.setAssistantName(p.getAssistantName());
- publicReleaseMapper.updateByPrimaryKeySelective(newP);
- updatePublicReleaseDtails(p,newP);
- }
- }
- }
- /**
- * 添加微信提示和站内消息
- * @param aid 接受者
- * @param type 状态 0驳回 1发起 2同意 3撤销
- * @param str 备注
- * @param prid 公出编号
- */
- private void addWeChatNotice(String aid,Integer type,String str,Integer prid){
- Admin recipient = adminMapper.selectByPrimaryKey(aid);
- addWeChatNotice( recipient, type, str, prid);
- }
- /**
- * 添加微信提示和站内消息
- * @param recipient 接受者
- * @param type 状态 0驳回 1发起 2同意 3撤销
- * @param str
- */
- private Integer addWeChatNotice(Admin recipient,Integer type,String str,Integer prid){
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- String openid=recipient.getOpenId();
- str=new StringBuffer("[").append(my.getName()).append("]").append(str).toString();
- if(type==3){
- addpublicLog(prid,4,str);
- }else {
- addpublicLog(prid,type,str);
- }
- sendNoticeAndSoucket(recipient.getId(),type,str);
- if (type==0||type==2){
- if (openid!=null) {
- Integer res= weChatUtils.addNotice(openid, type,prid,new Date(),my.getName(),str);
- return res;
- }else {
- sendEmail(my, recipient,type);
- }
- }
- return 0;
- }
- private int updateAssistant(PublicRelease p, String said, String sname) {
- PublicRelease newPr=new PublicRelease();
- newPr.setId(p.getId());
- newPr.setAssistantAid(said);
- newPr.setAssistantName(sname);
- if (p.getMainId()!=null){
- PublicRelease mianPr=new PublicRelease();
- mianPr.setId(p.getMainId());
- mianPr.setAid(said);
- mianPr.setAssistantAid(said);
- mianPr.setAssistantName(sname);
- publicReleaseMapper.updateByPrimaryKeySelective(mianPr);
- }
- return publicReleaseMapper.updateByPrimaryKeySelective(newPr);
- }
- /**
- *
- * @param aid 元素
- * @param list 集合
- * @param type 0新增 1删除
- * @return
- */
- private String pushAssistant(String aid, List<String> list,Integer type) {
- StringBuffer sb=new StringBuffer();
- if(type==0){
- list.add(aid);
- }else if (type==1){
- Iterator<String > it =list.iterator();
- while (it.hasNext()){
- if (it.next().equals(aid))
- it.remove();
- }
- }
- for (String s : list) {
- sb.append(adminMapper.selectByPrimaryKey(s).getName()).append(",");
- }
- return sb.length()>0?sb.substring(0,sb.length()-1):sb.toString();
- }
- @Override
- public int deleteAssistant(Integer id, String aid) {
- PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
- if (p.getAssistantAid()==null){
- throw new BusinessException("人员不存在");
- }
- List<String> list=new ArrayList<>(Arrays.asList(p.getAssistantAid().split(",")));
- if (!list.contains(aid)){
- throw new BusinessException("人员不存在");
- }
- String sname = pushAssistant(aid, list,1);
- String said =String.join(",",list);
- p.setAssistantAid(said);
- p.setAssistantName(sname);
- deleteAssistantPulicRelease(p,aid);
- return updateAssistant(p, said, sname);
- }
- private void deleteAssistantPulicRelease(PublicRelease p, String aid) {
- publicReleaseMapper.updateStatusByMainId(3,4,p.getMainId(),aid);
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, null);
- StringBuffer str=new StringBuffer();
- str=str.append("公出").append("[").append(p.getUserNames()).append("]").append("撤销了你的协助!");
- for (PublicRelease pr : list) {
- if (pr.getAid().equals(aid)){
- addWeChatNotice( pr.getAid(),3,str.toString(),pr.getId());
- }else {
- PublicRelease newPr=new PublicRelease();
- newPr.setId(pr.getId());
- newPr.setAssistantAid(p.getAssistantAid());
- newPr.setAssistantName(p.getAssistantName());
- publicReleaseMapper.updateByPrimaryKeySelective(newPr);
- }
- }
- }
- @Override
- public boolean checkdeleteAssistant(Integer id, String aid) {
- PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
- for (PublicRelease use : list) {
- // if (use.getClockIn()==1){
- // return true;
- // }
- }
- return false;
- }
- @Override
- public boolean checkaddAssistant(Integer id, String aid) {
- PublicRelease p = publicReleaseMapper.selectByPrimaryKey(id);
- List<PublicRelease> list = publicReleaseMapper.selectByMainId(p.getMainId(), 4, aid);
- for (PublicRelease use : list) {
- if (use.getAid().equals(aid)&&use.getStatus()!=3){
- return true;
- }
- }
- return false;
- }
- @Override
- public int updateLocation(InputPublicRelease in) {
- PublicReleaseDetails prd=publicReleaseDetailsMapper.selectBypridAndUid(in);
- if (prd==null){
- throw new BusinessException("公出企业不存在");
- }
- PublicReleaseDetails updateprd=new PublicReleaseDetails();
- updateprd.setId(prd.getId());
- updateprd.setLatitude(in.getLatitude());
- updateprd.setLongitude(in.getLongitude());
- updateprd.setDistrictName(in.getDistrictName());
- updateprd.setClockIn(0);
- addpublicLog(in.getId(),5,"发起公出地点修改");
- return publicReleaseDetailsMapper.updateByPrimaryKeySelective(updateprd);
- }
- @Override
- public Object publicReleaseAndCount(InputPublicDtails in) {
- List<OutPublicDtails> list = publicReleaseListDtailsList(in);
- Map<String,Object> map=new HashMap<String, Object>();
- if (list.isEmpty()){
- map.put("list",list);
- map.put("count",0);
- map.put("durationCount",0);
- map.put("peopleCount",0);
- }else {
- //公出次数
- int count=0;
- BigDecimal durationCount=BigDecimal.ZERO;
- List<String> aList =new ArrayList<>();
- for (OutPublicDtails e : list) {
- if (e.getType()==0||e.getType()==1||e.getType()==2){
- count++;
- if (e.getDuration()!=null){
- durationCount=durationCount.add(new BigDecimal(e.getDuration()));
- }
- if (!aList.contains(e.getAname())){
- aList.add(e.getAname());
- }
- if (StringUtils.isNotEmpty(e.getAssistAidName())){
- String[] split = e.getAssistAidName().split(",");
- for (String s : split) {
- if (!aList.contains(s)){
- aList.add(s);
- }
- }
- }
- if (StringUtils.isNotEmpty(e.getAssistantName())){
- String[] split = e.getAssistantName().split(",");
- for (String s : split) {
- if (!aList.contains(s)){
- aList.add(s);
- }
- }
- }
- }
- }
- map.put("list",list);
- map.put("count",count);
- map.put("durationCount",durationCount);
- map.put("peopleCount",aList.size());
- }
- return map;
- }
- /**
- *
- * @param in 公出参数
- * @param a 新增时需哟额外知道当前任务
- * @param type 0查询 1新增 2修改
- * @return
- */
- public Map checkOrderNoDuration( InputPublicRelease in,AdminListBo a,int type) {
- List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(in.getOrderNo());
- TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(in.getOrderNo());
- OutPublicRelease outPublicRelease=null;
- BigDecimal count = BigDecimal.ZERO;
- int timesCount=0;
- List<String> peopleList = new ArrayList<>();
- if (in.getId()!=null){
- outPublicRelease= publicReleaseMapper.selectDtails(in.getId());
- }else {
- peopleList.add(TokenManager.getAdminId());
- count=count.add(BigDecimal.valueOf(in.getDuration()));
- timesCount++;
- }
- for (PublicRelease e : list) {
- //新增直接计算
- if (in.getId()==null){
- if (e.getDuration()!=null){
- count=count.add(BigDecimal.valueOf(e.getDuration()));
- if (!peopleList.contains(e.getAid())){
- peopleList.add(e.getAid());
- }
- timesCount++;
- }
- }else {
- //修改当前数据要从修改后获取
- if (!e.getId().equals(in.getId())){
- if (e.getDuration()!=null){
- count=count.add(BigDecimal.valueOf(e.getDuration()));
- if (!peopleList.contains(e.getAid())){
- peopleList.add(e.getAid());
- }
- timesCount++;
- }
- }else {
- if (outPublicRelease != null && outPublicRelease.getDuration() != null) {
- count = count.add(BigDecimal.valueOf(outPublicRelease.getDuration()));
- if (!peopleList.contains(outPublicRelease.getAid())) {
- peopleList.add(outPublicRelease.getAid());
- }
- timesCount++;
- }
- }
- }
- }
- Map map=new HashMap();
- CheckOrderNoOut data= new CheckOrderNoOut();
- if (outPublicRelease!=null){
- data.setPublicReleaseName(outPublicRelease.getAname());
- }
- //新增与修改,需要重新获取实际公出与人数与次数
- if (type==1||type==2){
- TOrderPublicReleaseCount update=new TOrderPublicReleaseCount();
- update.setOrderNo(in.getOrderNo());
- update.setFrequency(timesCount);
- update.setActualDuration(count.doubleValue());
- update.setPeopleCount(peopleList.size());
- tOrderPublicReleaseCountMapper.updateByOrderNo(update);
- }
- data.setTimesCount(timesCount);
- data.setPeopleCount(peopleList.size());
- data.setUserName(t.getUserName());
- data.setContractNo(t.getContractNo());
- data.setAdminName(t.getSalesmanName());
- data.setDurationCount(count);
- // 0=0-1 1=1-3 2=3-5 3=5-10 4=10以上
- if (t.getTotalAmount().compareTo(BigDecimal.valueOf(1)) < 0) {
- data.setAmountType(0);
- data.setDurationMax(BigDecimal.ZERO);
- map.put("code",false);
- map.put("data",data);
- } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(3))<0) {
- data.setAmountType(1);
- data.setDurationMax(BigDecimal.valueOf(15));
- if (count.compareTo(data.getDurationMax())<1){
- map.put("code",true);
- map.put("data",null);
- }else {
- map.put("code",false);
- map.put("data",data);
- }
- } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(5))<0) {
- data.setAmountType(2);
- data.setDurationMax(BigDecimal.valueOf(45));
- if (count.compareTo(data.getDurationMax())<1){
- map.put("code",true);
- map.put("data",null);
- }else {
- map.put("code",false);
- map.put("data",data);
- }
- } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))<0) {
- data.setAmountType(3);
- data.setDurationMax(BigDecimal.valueOf(120));
- if (count.compareTo(data.getDurationMax())<1){
- map.put("code",true);
- map.put("data",null);
- }else {
- map.put("code",false);
- map.put("data",data);
- }
- } else if (t.getTotalAmount().compareTo(BigDecimal.valueOf(10))>=0) {
- data.setAmountType(4);
- map.put("code",true);
- map.put("data",null);
- }
- return map;
- }
- @Override
- public Map checkOrderNoDuration( InputPublicRelease in){
- return checkOrderNoDuration(in,null,0);
- }
- @Override
- public void pushOutPublicDtails(List<OutPublicDtails> list) {
- List<PublicReleaseClock> publicReleaseClocks = publicReleaseClockMapper.selectList(list.stream().map(OutPublicDtails::getId).collect(Collectors.toList()));
- pushiClockInTime(list, publicReleaseClocks);
- }
- private void pushiClockInTime(List<OutPublicDtails> list, List<PublicReleaseClock> publicReleaseClocks) {
- for (OutPublicDtails outPublicDtails : list) {
- List<PublicReleaseClock> colokList =new ArrayList<>();
- StringBuilder sb = new StringBuilder();
- for (PublicReleaseClock e : publicReleaseClocks) {
- if (outPublicDtails.getPrdId().equals(e.getPrdid())){
- sb.append(DateUtils.formatDateYYYYMMddHHmm(e.getClockInTime())).append("\n");
- colokList.add(e);
- }
- colokList.sort(Comparator.comparing(PublicReleaseClock::getClockInTime));
- Collections.reverse(colokList);
- outPublicDtails.setList(colokList);
- }
- outPublicDtails.setClockInTimes(sb.toString());
- }
- }
- @Override
- public Object pushDateClock() {
- List<PublicRelease> publicReleases = publicReleaseMapper.selectAll();
- for (PublicRelease e : publicReleases) {
- addPublicReleaseDateClock(e);
- }
- return 1;
- }
- private void addPublicReleaseDateClock(PublicRelease e) {
- publicReleaseDateClockMapper.deleteByPrid(e.getId());
- List<PublicReleaseDateClock> list= new ArrayList<>();
- if (e.getValidDate()!=null){
- List<Map> maps = JSONArray.parseArray(e.getValidDate(), Map.class);
- for (Map map : maps) {
- String dates = (String) map.get("value");
- if (dates!=null){
- Date date = DateUtils.parseDate(dates);
- List<OutPublicReleaseDetails> outPublicReleaseDetails = publicReleaseDetailsMapper.selectByPrid(e.getId());
- for (OutPublicReleaseDetails det : outPublicReleaseDetails) {
- PublicReleaseDateClock newPRDC = new PublicReleaseDateClock();
- newPRDC.setClockInTime(date);
- newPRDC.setPrid(e.getId());
- newPRDC.setPrdid(det.getId());
- newPRDC.setStatus(det.getClockIn());
- list.add(newPRDC);
- }
- }
- }
- }
- if(!list.isEmpty()){
- publicReleaseDateClockMapper.insertBatch(list);
- list.clear();
- }
- }
- @Override
- @Cacheable(value = "releaseAndExpenseCount#300", key = "'getCounts:key='+#in.buyerName+#in.contractNo+#in.aid+#in.depId+#in.allStatus")
- public List<releaseAndExpenseCountOut> releaseAndExpenseCount(InputreleaseAndExpenseCount in) {
- List<releaseAndExpenseCountOut> expenseCountsOrders = publicReleaseMapper.releaseAndExpenseCount(in);
- expenseCountsOrders.forEach(e->{
- if (e.getExceedDuration()!=null){
- double exceedDuration = Double.parseDouble(e.getExceedDuration());
- if (exceedDuration>0){
- e.setExceedType(1);
- }
- }
- if (e.getMaxDuration()!=null){
- if(e.getMaxDuration().equals("-1")){
- e.setMaxDuration("不限制");
- }
- }
- });
- return expenseCountsOrders;
- }
- @Override
- @CacheEvict(value = "releaseAndExpenseCount#300",allEntries = true)
- public Object releaseAndExpenseCountClear() {
- LoggerUtils.debug(getClass(),"公出&报销缓存清除。");
- return 1;
- }
- }
|