|  |  |  | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.model.PageData; | 
|---|
|  |  |  | import com.doumee.core.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DESUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.CarUseBookMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.CarsMapper; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.PageData; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.*; | 
|---|
|  |  |  | import com.doumee.core.wx.wxPlat.WxPlatConstants; | 
|---|
|  |  |  | import com.doumee.core.wx.wxPlat.WxPlatNotice; | 
|---|
|  |  |  | import com.doumee.dao.business.*; | 
|---|
|  |  |  | import com.doumee.dao.business.dao.MemberMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.dao.SmsConfigMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.dao.SmsEmailMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.ApproveJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.CarUseBookJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.ApproveDataVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.DateIntervalVO; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.model.Member; | 
|---|
|  |  |  | import com.doumee.dao.system.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.join.NoticesJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.Notices; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.service.business.ApproveService; | 
|---|
|  |  |  | import com.doumee.service.business.CarUseBookService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.doumee.service.business.third.EmayService; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.ZoneId; | 
|---|
|  |  |  | import java.time.format.DateTimeFormatter; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 车辆_用车申请信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApproveJoinMapper approveJoinMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NoticesJoinMapper noticesJoinMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApproveService approveService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CarDriverMapper carDriverMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MemberMapper memberMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SmsConfigMapper smsConfigMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SmsEmailMapper smsEmailMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private EmayService emayService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxNoticeConfigMapper wxNoticeConfigMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserMapper systemUserMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(CarUseBook carUseBook) { | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public Integer create(CarUseBook carUseBook)  throws Exception { | 
|---|
|  |  |  | if(Objects.isNull(carUseBook) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getCarId()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getStartTime()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getEndTime()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getCreator()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getMemberId()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getPlanUseDate()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getType()) | 
|---|
|  |  |  | || StringUtils.isEmpty(carUseBook.getMemberIds()) | 
|---|
|  |  |  | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.nonNull(carUseBook.getCreator())&&Objects.isNull(carUseBook.getMemberId())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户无法进行该操作!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(carUseBook.getEndTime().getTime()<=System.currentTimeMillis()){ | 
|---|
|  |  |  | //            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"选择日期异常[结束时间小于当前时间],请刷新重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!(DateUtil.getDateFromString(carUseBook.getPlanUseDate()+":00").getTime()>=carUseBook.getStartTime().getTime() | 
|---|
|  |  |  | && DateUtil.getDateFromString(carUseBook.getPlanUseDate() +":00").getTime()<= carUseBook.getEndTime().getTime()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"出发时间错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | carUseBook.setStatus(Constants.ZERO); | 
|---|
|  |  |  | carUseBook.setCreateDate(new Date()); | 
|---|
|  |  |  | carUseBook.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | Cars cars = carsMapper.selectById(carUseBook.getCarId()); | 
|---|
|  |  |  | if(Objects.isNull(cars)||!cars.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | if(Objects.isNull(cars)||!cars.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"车辆信息异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //TODO 查询车辆提交时间是否存在冲突的预约记录 | 
|---|
|  |  |  | List<CarUseBook> carUseBookList = carUseBookJoinMapper.selectJoinList(CarUseBook.class, | 
|---|
|  |  |  | new MPJLambdaWrapper<CarUseBook>() | 
|---|
|  |  |  | .selectAll(CarUseBook.class) | 
|---|
|  |  |  | .selectAs(Member::getName,CarUseBook::getMemberName) | 
|---|
|  |  |  | .selectAs(Member::getPhone,CarUseBook::getMemberMobile) | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,CarUseBook::getMemberId) | 
|---|
|  |  |  | .eq(CarUseBook::getId,carUseBook.getCarId()) | 
|---|
|  |  |  | .in(CarUseBook::getStatus,0,1,2) | 
|---|
|  |  |  | //                        .in( " ( '"+carUseBook.getStartTime()+"' < t.start_time AND '"+ carUseBook.getEndTime()+"'> t.end_time ) " ) | 
|---|
|  |  |  | carUseBook.setCarCode(cars.getCode()); | 
|---|
|  |  |  | //根据车辆查询司机信息 | 
|---|
|  |  |  | CarDriver carDriver = carDriverMapper.selectOne(new QueryWrapper<CarDriver>().lambda() | 
|---|
|  |  |  | .eq(CarDriver::getCarId,cars.getId()) | 
|---|
|  |  |  | .eq(CarDriver::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | //                .eq(CarDriver::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .last( " limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(carUseBookList)){ | 
|---|
|  |  |  | if(Objects.nonNull(carDriver)&&Objects.nonNull(carDriver.getMemberId())){ | 
|---|
|  |  |  | carUseBook.setDriverId(carDriver.getMemberId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //查询车辆提交时间是否存在冲突的预约记录 | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(this.carUseBookList(carUseBook))){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在车辆预约时间与已预约时间冲突~"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | carUseBookMapper.insert(carUseBook); | 
|---|
|  |  |  | //用车申请 审批记录创建 | 
|---|
|  |  |  | approveService.createApproveFlow(carUseBook.getType()==0?3:4,carUseBook.getId(),carUseBook.getMemberId()); | 
|---|
|  |  |  | //发送微信公众号通知 | 
|---|
|  |  |  | //发送微信公众号通知 | 
|---|
|  |  |  | WxPlatNotice wxPlatNotice = new WxPlatNotice(); | 
|---|
|  |  |  | SystemUser systemUser = systemUserMapper.selectById(carUseBook.getCreator()); | 
|---|
|  |  |  | if(Objects.nonNull(systemUser) && StringUtils.isNotBlank(systemUser.getOpenid())){ | 
|---|
|  |  |  | carUseBook.setMemberName(systemUser.getRealname()); | 
|---|
|  |  |  | wxPlatNotice.sendCarUseBookTemplateNotice(systemDictDataBiz, | 
|---|
|  |  |  | wxNoticeConfigMapper,carUseBook, | 
|---|
|  |  |  | WxPlatConstants.carUseBookContent.carUseBookUpload, | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(), | 
|---|
|  |  |  | Arrays.asList(systemUser.getOpenid().split(",")),0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return carUseBook.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 主键 | 
|---|
|  |  |  | * @param memberId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public CarUseBook findById(Integer id) { | 
|---|
|  |  |  | public CarUseBook findById(Integer id,Integer memberId) { | 
|---|
|  |  |  | MPJLambdaWrapper<CarUseBook>  queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(CarUseBook.class); | 
|---|
|  |  |  | queryWrapper.select("t1.name",CarUseBook::getMemberName); | 
|---|
|  |  |  | queryWrapper.select("t1.phone",CarUseBook::getMemberPhone); | 
|---|
|  |  |  | queryWrapper.select("t2.name",CarUseBook::getDriverName); | 
|---|
|  |  |  | queryWrapper.select("t3.phone",CarUseBook::getDriverPhone); | 
|---|
|  |  |  | queryWrapper.select("t2.phone",CarUseBook::getDriverPhone); | 
|---|
|  |  |  | queryWrapper.select("t4.company_name_path",CarUseBook::getCompanyName); | 
|---|
|  |  |  | queryWrapper.leftJoin(Member.class,Member::getId,CarUseBook::getMemberId) | 
|---|
|  |  |  | .leftJoin("company t4 on t1.company_id=t4.id") | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,CarUseBook::getDriverId) | 
|---|
|  |  |  | .leftJoin("company t4 on t1.company_id=t4.id") | 
|---|
|  |  |  | .eq(CarUseBook::getId,id) | 
|---|
|  |  |  | .last("limit 1"  ); | 
|---|
|  |  |  | CarUseBook model = carUseBookMapper.selectJoinOne(CarUseBook.class,queryWrapper); | 
|---|
|  |  |  | if(Objects.isNull(model)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ApproveDataVO approveDataVO = approveService.arrangeApprovedData(id, | 
|---|
|  |  |  | Constants.equalsInteger(model.getType(),Constants.ZERO)?3:4, | 
|---|
|  |  |  | memberId); | 
|---|
|  |  |  | List<Approve> approveList = approveDataVO.getApproveList(); | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getStatus(),Constants.FOUR)){ | 
|---|
|  |  |  | String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() | 
|---|
|  |  |  | +systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode(); | 
|---|
|  |  |  | Member member1 = memberMapper.selectById(model.getCancelUser()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Approve approve = new Approve(); | 
|---|
|  |  |  | approve.setApproveType(Constants.ZERO); | 
|---|
|  |  |  | approve.setCreateDate(model.getCancelTime()); | 
|---|
|  |  |  | approve.setTitle("撤销人"); | 
|---|
|  |  |  | approve.setStatusInfo("已撤销"); | 
|---|
|  |  |  | approve.setStatus(Constants.FOUR); | 
|---|
|  |  |  | approve.setType(Constants.ZERO); | 
|---|
|  |  |  | if(member1!=null) { | 
|---|
|  |  |  | approve.setMemberName(member1.getName()); | 
|---|
|  |  |  | if (StringUtils.isNotBlank(member1.getFaceImg())) { | 
|---|
|  |  |  | approve.setFaceImg(path + member1.getFaceImg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | approve.setCheckInfo(model.getCancelInfo()); | 
|---|
|  |  |  | approve.setCheckDate(model.getCancelTime()); | 
|---|
|  |  |  | approveList.add(approve); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | model.setApproveDateVO(approveDataVO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Notices notices = noticesJoinMapper.selectOne(new QueryWrapper<Notices>().lambda() | 
|---|
|  |  |  | .eq(Notices::getObjId,id) | 
|---|
|  |  |  | .eq(Notices::getType,Constants.noticesObjectType.useCar) | 
|---|
|  |  |  | .eq(Notices::getUserId,memberId) | 
|---|
|  |  |  | .eq(Notices::getSendacopy,Constants.ZERO) | 
|---|
|  |  |  | .orderByDesc(Notices::getId).last(" limit 1 ")); | 
|---|
|  |  |  | if(Objects.nonNull(notices)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(notices.getStatus(),Constants.ZERO)){ | 
|---|
|  |  |  | model.setInfo("待我处理"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | model.setInfo(notices.getInfo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return  model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.select("t1.name",CarUseBook::getMemberName); | 
|---|
|  |  |  | queryWrapper.select("t1.phone",CarUseBook::getMemberPhone); | 
|---|
|  |  |  | queryWrapper.select("t2.name",CarUseBook::getDriverName); | 
|---|
|  |  |  | queryWrapper.select("t3.phone",CarUseBook::getDriverPhone); | 
|---|
|  |  |  | queryWrapper.select("t2.phone",CarUseBook::getDriverPhone); | 
|---|
|  |  |  | queryWrapper.select("t4.company_name_path",CarUseBook::getCompanyName); | 
|---|
|  |  |  | queryWrapper.leftJoin(Member.class,Member::getId,CarUseBook::getMemberId) | 
|---|
|  |  |  | .leftJoin("company t4 on t1.company_id=t4.id") | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,CarUseBook::getDriverId); | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,CarUseBook::getDriverId) | 
|---|
|  |  |  | .leftJoin("company t4 on t1.company_id=t4.id");   //数据权限开始--------------------start---------------- | 
|---|
|  |  |  | LoginUserInfo userInfo =pageWrap.getModel().getLoginUserInfo(); | 
|---|
|  |  |  | if(userInfo!=null && userInfo.getCompanyIdList()!=null){ | 
|---|
|  |  |  | if( userInfo.getCompanyIdList().size() ==0){ | 
|---|
|  |  |  | //只能看自己 | 
|---|
|  |  |  | queryWrapper.eq(CarUseBook::getCreator,userInfo.getId()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | queryWrapper.in("t1.company_id" ,userInfo.getCompanyIdList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //数据权限开始--------------------end---------------- | 
|---|
|  |  |  |  | 
|---|
|  |  |  | queryWrapper | 
|---|
|  |  |  | .eq(pageWrap.getModel().getId() != null, CarUseBook::getId, pageWrap.getModel().getId()) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCreator() != null, CarUseBook::getCreator, pageWrap.getModel().getCreator()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .le(pageWrap.getModel().getCheckDate() != null, CarUseBook::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate())) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCheckUserId() != null, CarUseBook::getCheckUserId, pageWrap.getModel().getCheckUserId()) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCheckInfo() != null, CarUseBook::getCheckInfo, pageWrap.getModel().getCheckInfo()) | 
|---|
|  |  |  | .ge(pageWrap.getModel().getCancelType() != null, CarUseBook::getCancelType, Utils.Date.getStart(pageWrap.getModel().getCancelType())) | 
|---|
|  |  |  | .le(pageWrap.getModel().getCancelType() != null, CarUseBook::getCancelType, Utils.Date.getEnd(pageWrap.getModel().getCancelType())) | 
|---|
|  |  |  | .ge(pageWrap.getModel().getCancelStatus() != null, CarUseBook::getCancelStatus, Utils.Date.getStart(pageWrap.getModel().getCancelStatus())) | 
|---|
|  |  |  | .le(pageWrap.getModel().getCancelStatus() != null, CarUseBook::getCancelStatus, Utils.Date.getEnd(pageWrap.getModel().getCancelStatus())) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCancelType() != null, CarUseBook::getCancelType,  pageWrap.getModel().getCancelType()) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCancelStatus() != null, CarUseBook::getCancelStatus, pageWrap.getModel().getCancelStatus()) | 
|---|
|  |  |  | .ge(pageWrap.getModel().getCancelTime() != null, CarUseBook::getCancelTime, Utils.Date.getStart(pageWrap.getModel().getCancelTime())) | 
|---|
|  |  |  | .le(pageWrap.getModel().getCancelTime() != null, CarUseBook::getCancelTime, Utils.Date.getEnd(pageWrap.getModel().getCancelTime())) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getCancelUser() != null, CarUseBook::getCancelUser, pageWrap.getModel().getCancelUser()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(pageWrap.getModel().getAddr() != null, CarUseBook::getAddr, pageWrap.getModel().getAddr()) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getMemberId() != null, CarUseBook::getMemberId, pageWrap.getModel().getMemberId()) | 
|---|
|  |  |  | .eq(pageWrap.getModel().getDriverId() != null, CarUseBook::getDriverId, pageWrap.getModel().getDriverId()) | 
|---|
|  |  |  | .apply(pageWrap.getModel().getCompanyName() != null, "t4.company_name_path like '%"+pageWrap.getModel().getCompanyName()+"%'") | 
|---|
|  |  |  |  | 
|---|
|  |  |  | .and(StringUtils.isNotBlank(pageWrap.getModel().getMemberName()), ms->ms.like(Member::getName,pageWrap.getModel().getMemberName()) | 
|---|
|  |  |  | .or().like(Member::getPhone,pageWrap.getModel().getMemberName())) | 
|---|
|  |  |  | .ge(Objects.nonNull(pageWrap.getModel().getQueryStartTime()), Empower::getCreateDate,pageWrap.getModel().getQueryStartTime()) | 
|---|
|  |  |  | .le(Objects.nonNull(pageWrap.getModel().getQueryEndTime()),Empower::getCreateDate,pageWrap.getModel().getQueryEndTime()) | 
|---|
|  |  |  | .ge(Objects.nonNull(pageWrap.getModel().getQueryStartTime()), CarUseBook::getPlanUseDate,pageWrap.getModel().getQueryStartTime()) | 
|---|
|  |  |  | .le(Objects.nonNull(pageWrap.getModel().getQueryEndTime()),CarUseBook::getPlanUseDate,pageWrap.getModel().getQueryEndTime()) | 
|---|
|  |  |  | .orderByDesc(Visits::getCreateDate) | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<CarUseBook> carUseBookList(CarUseBook carUseBook){ | 
|---|
|  |  |  | public List<CarUseBook> carUseBookList(CarUseBook carUseBook) throws Exception { | 
|---|
|  |  |  | if(Objects.isNull(carUseBook) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getCarId()) | 
|---|
|  |  |  | || Objects.isNull(carUseBook.getStartTime()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .selectAs(Member::getName,CarUseBook::getMemberName) | 
|---|
|  |  |  | .selectAs(Member::getPhone,CarUseBook::getMemberMobile) | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,CarUseBook::getMemberId) | 
|---|
|  |  |  | .eq(CarUseBook::getId,carUseBook.getCarId()) | 
|---|
|  |  |  | .eq(CarUseBook::getCarId,carUseBook.getCarId()) | 
|---|
|  |  |  | .in(CarUseBook::getStatus,0,1,2) | 
|---|
|  |  |  | //                        .in( " ( '"+carUseBook.getStartTime()+"' < t.start_time AND '"+ carUseBook.getEndTime()+"'> t.end_time ) " ) | 
|---|
|  |  |  | .apply(" ( " + | 
|---|
|  |  |  | " '"+DateUtil.getPlusTime(carUseBook.getStartTime())+"'  <= t.start_time AND t.start_time < '"+DateUtil.getPlusTime(carUseBook.getEndTime())+"' " + | 
|---|
|  |  |  | " or " + | 
|---|
|  |  |  | "  ( '"+DateUtil.getPlusTime(carUseBook.getStartTime())+"' < t.end_time AND t.end_time < '"+DateUtil.getPlusTime(carUseBook.getEndTime())+"' )  " + | 
|---|
|  |  |  | " or " + | 
|---|
|  |  |  | " ( '"+DateUtil.getPlusTime(carUseBook.getStartTime())+"' > t.start_time AND '"+DateUtil.getPlusTime(carUseBook.getEndTime())+"' < t.end_time )" + | 
|---|
|  |  |  | " ) " ) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return carUseBookList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public void checkDateUse(Integer cars,String dateDay){ | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        SystemDictData workStart = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WORK_START); | 
|---|
|  |  |  | //        SystemDictData workEnd = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WORK_END); | 
|---|
|  |  |  | //        SystemDictData interval = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.INTERVAL); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        Date start = DateUtil.StringToDate(dateDay + workStart.getCode(),"yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据日期查询车辆可预约情况 | 
|---|
|  |  |  | * @param cars | 
|---|
|  |  |  | * @param dateDay | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<DateIntervalVO> checkDateUse(Integer cars,String dateDay){ | 
|---|
|  |  |  | SystemDictData workStart = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WORK_START); | 
|---|
|  |  |  | SystemDictData workEnd = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WORK_END); | 
|---|
|  |  |  | SystemDictData interval = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.INTERVAL); | 
|---|
|  |  |  | if(Objects.isNull(workStart) | 
|---|
|  |  |  | ||Objects.isNull(workEnd) | 
|---|
|  |  |  | ||Objects.isNull(interval) | 
|---|
|  |  |  | ||Objects.isNull(workStart.getCode()) | 
|---|
|  |  |  | ||Objects.isNull(workEnd.getCode()) | 
|---|
|  |  |  | ||Objects.isNull(interval.getCode())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"配置错误,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date startTime = DateUtil.StringToDate((dateDay + " " +workStart.getCode()),"yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Date endTime = DateUtil.StringToDate(dateDay + " " + workEnd.getCode(),"yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Long intervalTime = Long.valueOf(interval.getCode()); | 
|---|
|  |  |  | LocalDateTime localStartTime = startTime.toInstant() | 
|---|
|  |  |  | .atZone(ZoneId.systemDefault()) | 
|---|
|  |  |  | .toLocalDateTime(); | 
|---|
|  |  |  | LocalDateTime localEndTime = endTime.toInstant() | 
|---|
|  |  |  | .atZone(ZoneId.systemDefault()) | 
|---|
|  |  |  | .toLocalDateTime(); | 
|---|
|  |  |  | List<DateIntervalVO> dateIntervalVOList = this.checkDate(localStartTime,localEndTime,intervalTime); | 
|---|
|  |  |  | //查询车辆市内 | 
|---|
|  |  |  | List<CarUseBook> carUseBookList = carUseBookMapper.selectList(new QueryWrapper<CarUseBook>().lambda() | 
|---|
|  |  |  | .eq(CarUseBook::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(CarUseBook::getCarId,cars) | 
|---|
|  |  |  | .in(CarUseBook::getStatus,0,1,2) | 
|---|
|  |  |  | .and(i->i.like(CarUseBook::getStartTime,dateDay) | 
|---|
|  |  |  | .or().like(CarUseBook::getEndTime,dateDay) | 
|---|
|  |  |  | .or().apply("  START_TIME < '"+dateDay+" 00:00:00' and END_TIME  > '"+dateDay+" 23:59:59'  ")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (DateIntervalVO dateIntervalVO:dateIntervalVOList) { | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(carUseBookList)){ | 
|---|
|  |  |  | for (CarUseBook i:carUseBookList  ) { | 
|---|
|  |  |  | if( | 
|---|
|  |  |  | (DateUtil.getDateFromString(dateIntervalVO.getStartTime()).getTime() <= i.getStartTime().getTime() && | 
|---|
|  |  |  | i.getStartTime().getTime() < DateUtil.getDateFromString(dateIntervalVO.getEndTime()).getTime()) | 
|---|
|  |  |  | || | 
|---|
|  |  |  | (DateUtil.getDateFromString(dateIntervalVO.getStartTime()).getTime() < i.getEndTime().getTime() && | 
|---|
|  |  |  | i.getEndTime().getTime() <= DateUtil.getDateFromString(dateIntervalVO.getEndTime()).getTime()) | 
|---|
|  |  |  | || | 
|---|
|  |  |  | (DateUtil.getDateFromString(dateIntervalVO.getStartTime()).getTime() >= i.getStartTime().getTime() && | 
|---|
|  |  |  | DateUtil.getDateFromString(dateIntervalVO.getEndTime()).getTime() <= i.getEndTime().getTime()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | dateIntervalVO.setCarUseBookId(i.getId()); | 
|---|
|  |  |  | dateIntervalVO.setIsUse(Constants.ONE); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //判断时间是否大于当前 | 
|---|
|  |  |  | if(Constants.equalsInteger(dateIntervalVO.getIsUse(),Constants.ZERO)  && DateUtil.getDateFromString(dateIntervalVO.getEndTime()).getTime()<=System.currentTimeMillis()){ | 
|---|
|  |  |  | //                dateIntervalVO.setIsUse(Constants.ONE); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return dateIntervalVOList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<DateIntervalVO> checkDate(LocalDateTime localStartTime , LocalDateTime localEndTime ,Long intervalTime ){ | 
|---|
|  |  |  | List<DateIntervalVO> dateIntervalVOList = new ArrayList<>(); | 
|---|
|  |  |  | List<LocalDateTime> segments = DateUtil.checkDateInterval(localStartTime,localEndTime,intervalTime); | 
|---|
|  |  |  | DateTimeFormatter dfTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | DateTimeFormatter dfHours = DateTimeFormatter.ofPattern("HH:mm"); | 
|---|
|  |  |  | for (int i = 0; i < segments.size(); i++) { | 
|---|
|  |  |  | String  startHours = segments.get(i).format(dfHours); | 
|---|
|  |  |  | String  endHours = localEndTime.format(dfHours); | 
|---|
|  |  |  | String  startTime = segments.get(i).format(dfTime); | 
|---|
|  |  |  | String  endTime = localEndTime.format(dfTime); | 
|---|
|  |  |  | if(i!=segments.size()-1){ | 
|---|
|  |  |  | endHours = segments.get(i+1).format(dfHours); | 
|---|
|  |  |  | endTime = segments.get(i+1).format(dfTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DateIntervalVO dateIntervalVO = new DateIntervalVO(); | 
|---|
|  |  |  | dateIntervalVO.setStartHours(startHours); | 
|---|
|  |  |  | dateIntervalVO.setEndHours(endHours); | 
|---|
|  |  |  | dateIntervalVO.setStartTime(startTime); | 
|---|
|  |  |  | dateIntervalVO.setEndTime(endTime); | 
|---|
|  |  |  | dateIntervalVO.setIsUse(Constants.ZERO); | 
|---|
|  |  |  | dateIntervalVOList.add(dateIntervalVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return dateIntervalVOList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void revoke(Integer id, String info, LoginUserInfo loginUserInfo){ | 
|---|
|  |  |  | CarUseBook carUseBook = carUseBookMapper.selectById(id); | 
|---|
|  |  |  | if(Objects.isNull(carUseBook)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到用车申请信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | carUseBook.setCancelInfo(info); | 
|---|
|  |  |  | carUseBook.setCancelTime(new Date()); | 
|---|
|  |  |  | carUseBook.setCancelStatus(Constants.ONE); | 
|---|
|  |  |  | carUseBook.setStatus(Constants.FOUR); | 
|---|
|  |  |  | carUseBook.setCancelUser(loginUserInfo.getMemberId()); | 
|---|
|  |  |  | carUseBook.setCancelType(Constants.ONE); | 
|---|
|  |  |  | if(loginUserInfo.getId().equals(carUseBook.getCreator())){ | 
|---|
|  |  |  | carUseBook.setCancelType(Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | carUseBookMapper.updateById(carUseBook); | 
|---|
|  |  |  | //处理审批记录 | 
|---|
|  |  |  | approveJoinMapper.update(null,new UpdateWrapper<Approve>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | .set(Approve::getIsdeleted,Constants.ONE) | 
|---|
|  |  |  | .set(Approve::getStatus,Constants.FOUR) | 
|---|
|  |  |  | .set(Approve::getCheckInfo,"用车申请取消") | 
|---|
|  |  |  | .in(Approve::getStatus,Constants.ZERO,Constants.ONE) | 
|---|
|  |  |  | .in(Approve::getObjType,Constants.approveObjectType.cityUseCar,Constants.approveObjectType.unCityUseCar) | 
|---|
|  |  |  | .eq(Approve::getObjId,id) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //处理待办信息 | 
|---|
|  |  |  | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() | 
|---|
|  |  |  | .set(Notices::getStatus,Constants.ONE) | 
|---|
|  |  |  | .set(Notices::getInfo,"已取消") | 
|---|
|  |  |  | .eq(Notices::getType,Constants.TWO) | 
|---|
|  |  |  | .eq(Notices::getObjId,carUseBook.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SystemUser systemUser = systemUserMapper.selectById(carUseBook.getCreator()); | 
|---|
|  |  |  | if(Objects.nonNull(systemUser)&&StringUtils.isNotBlank(systemUser.getMobile())){ | 
|---|
|  |  |  | //用车申请取消 | 
|---|
|  |  |  | SmsEmailServiceImpl.sendCarUseSms(systemDictDataBiz, | 
|---|
|  |  |  | emayService,smsEmailMapper,smsConfigMapper,carUseBookMapper,carUseBook.getId(), | 
|---|
|  |  |  | SmsConstants.carUseBookContent.carUseBookCancel, | 
|---|
|  |  |  | info, Arrays.asList(systemUser.getMobile().split(",")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(StringUtils.isNotBlank(systemUser.getOpenid())){ | 
|---|
|  |  |  | carUseBook.setMemberName(systemUser.getRealname()); | 
|---|
|  |  |  | WxPlatNotice wxPlatNotice = new WxPlatNotice(); | 
|---|
|  |  |  | wxPlatNotice.sendCarUseBookTemplateNotice(systemDictDataBiz, | 
|---|
|  |  |  | wxNoticeConfigMapper, | 
|---|
|  |  |  | carUseBook, | 
|---|
|  |  |  | WxPlatConstants.carUseBookContent.carUseBookCancel, | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(), | 
|---|
|  |  |  | Arrays.asList(systemUser.getOpenid().split(",")), | 
|---|
|  |  |  | Constants.TWO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|