|  |  | 
 |  |  | import com.doumee.core.model.LoginUserInfo; | 
 |  |  | 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.DateUtil; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.core.utils.*; | 
 |  |  | import com.doumee.dao.business.*; | 
 |  |  | 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.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 io.swagger.annotations.ApiModelProperty; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.ZoneId; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.time.temporal.ChronoUnit; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 车辆_用车申请信息表Service实现 | 
 |  |  | 
 |  |  |     private MemberMapper memberMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SmsConfigMapper smsConfigMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SmsEmailMapper smsEmailMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private EmayService emayService; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public Integer create(CarUseBook carUseBook)  throws Exception { | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户无法进行该操作!"); | 
 |  |  |         } | 
 |  |  |         if(carUseBook.getEndTime().getTime()<=System.currentTimeMillis()){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"选择日期异常[结束时间小于当前时间],请刷新重试"); | 
 |  |  | //            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()) | 
 |  |  | 
 |  |  |         CarDriver carDriver = carDriverMapper.selectOne(new QueryWrapper<CarDriver>().lambda() | 
 |  |  |                 .eq(CarDriver::getCarId,cars.getId()) | 
 |  |  |                 .eq(CarDriver::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(CarDriver::getStatus,Constants.ONE) | 
 |  |  | //                .eq(CarDriver::getStatus,Constants.ZERO) | 
 |  |  |                 .last( " limit 1 ") | 
 |  |  |         ); | 
 |  |  |         if(Objects.nonNull(carDriver)&&Objects.nonNull(carDriver.getMemberId())){ | 
 |  |  | 
 |  |  |         queryWrapper.select("t4.company_name_path",CarUseBook::getCompanyName); | 
 |  |  |         queryWrapper.leftJoin(Member.class,Member::getId,CarUseBook::getMemberId) | 
 |  |  |                     .leftJoin(Member.class,Member::getId,CarUseBook::getDriverId) | 
 |  |  |                     .leftJoin("company t4 on t1.company_id=t4.id"); | 
 |  |  |                     .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()) | 
 |  |  | 
 |  |  |             } | 
 |  |  |             //判断时间是否大于当前 | 
 |  |  |             if(Constants.equalsInteger(dateIntervalVO.getIsUse(),Constants.ZERO)  && DateUtil.getDateFromString(dateIntervalVO.getEndTime()).getTime()<=System.currentTimeMillis()){ | 
 |  |  |                 dateIntervalVO.setIsUse(Constants.ONE); | 
 |  |  | //                dateIntervalVO.setIsUse(Constants.ONE); | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |                .in(Approve::getObjType,Constants.approveObjectType.cityUseCar,Constants.approveObjectType.unCityUseCar) | 
 |  |  |                 .eq(Approve::getObjId,id) | 
 |  |  |         ); | 
 |  |  |         Member member = memberMapper.selectById(carUseBook.getMemberId()); | 
 |  |  |         if(Objects.nonNull(member)&&StringUtils.isNotBlank(member.getPhone())){ | 
 |  |  |             //用车申请取消 | 
 |  |  |             SmsEmailServiceImpl.sendCarUseSms(systemDictDataBiz, | 
 |  |  |                     emayService,smsEmailMapper,smsConfigMapper,carUseBookMapper,carUseBook.getId(), | 
 |  |  |                     SmsConstants.carUseBookContent.carUseBookCancel, | 
 |  |  |                     null, Arrays.asList(member.getPhone().split(",")) | 
 |  |  |             ); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  |