| | |
| | | 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.core.annotation.excel.ExcelImporter; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | 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.ScientificNotationTUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.admin.request.CarsImport; |
| | | import com.doumee.dao.admin.request.CarsQuery; |
| | | import com.doumee.dao.admin.request.MemberImport; |
| | | import com.doumee.dao.admin.response.CarsDTO; |
| | | import com.doumee.dao.business.CarsMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | @Autowired |
| | | private CarsMapper carsMapper; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | @Autowired |
| | | private CarJoinMapper carJoinMapper; |
| | | @Autowired |
| | |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | if(model.getMemberId()!=null){ |
| | | //检查车主信息 |
| | | Member member =memberMapper.selectOne(new QueryWrapper<Member>().lambda() |
| | |
| | | } |
| | | model.setMemberHkId(member.getHkId()); |
| | | } |
| | | if(!Constants.checkCarNo(model.getCode())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请输入正确的车牌!"); |
| | | }; |
| | | |
| | | //检查车牌号是否重复 |
| | | if(carsMapper.selectCount(new QueryWrapper<Cars>().lambda() |
| | | .eq(Cars::getCode,model.getCode() ) |
| | |
| | | Cars car = carJoinMapper.selectById(model.getId()); |
| | | if(car ==null ||Constants.equalsInteger(car.getIsdeleted(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,车辆信息不存在!"); |
| | | |
| | | } |
| | | if(!Constants.checkCarNo(model.getCode())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请输入正确的车牌!"); |
| | | }; |
| | | if(model.getMemberId()!=null){ |
| | | //检查车主信息 |
| | | Member member =memberMapper.selectOne(new QueryWrapper<Member>().lambda() |
| | |
| | | model.setHkStatus(Constants.ZERO); |
| | | model.setRemark(""); |
| | | model.setAuthStatus(Constants.ZERO); |
| | | dealCancelBookBiz(model.getCode(),model.getEditDate()); |
| | | dealCancelBookBiz(car.getCode(),model.getEditDate()); |
| | | carsMapper.update(null,new UpdateWrapper<Cars>().lambda() |
| | | .eq(Cars::getId,model.getId()) |
| | | .set(Cars::getAuthStatus,Constants.ZERO) |
| | |
| | | .or().like(Member::getPhone,pageWrap.getModel().getMemberName())); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),Company::getCompanyNamePath,pageWrap.getModel().getCompanyName()); |
| | | queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getMemberType()),Member::getType,pageWrap.getModel().getMemberType()); |
| | | queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getCatePId()),Category::getParentId,pageWrap.getModel().getCatePId()); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCode()),Cars::getCode,pageWrap.getModel().getCode()); |
| | | queryWrapper.eq(Cars::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.eq(pageWrap.getModel().getType()!=null,Cars::getType,pageWrap.getModel().getType()); |
| | |
| | | |
| | | return PageData.from(carsDTOIPage); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public String importBatch(MultipartFile file, LoginUserInfo loginUserInfo){ |
| | | Boolean importing = (Boolean) redisTemplate.opsForValue().get(Constants.RedisKeys.IMPORTING_CARS); |
| | | if(importing!=null && importing){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,已存在车辆导入任务正在执行中,请稍后再试!"); |
| | | } |
| | | redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_CARS,true); |
| | | try { |
| | | ExcelImporter ie = null; |
| | | List<CarsImport> dataList =null; |
| | | try { |
| | | ie = new ExcelImporter(file,1,0); |
| | | dataList = ie.getDataList(CarsImport.class,null); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(dataList == null || dataList.size() ==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!"); |
| | | } |
| | | List<Cars> list = carJoinMapper.selectJoinList(Cars.class,new MPJLambdaWrapper<Cars>() |
| | | .selectAll(Cars.class) |
| | | .eq(Cars::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getType,Constants.TWO) |
| | | .eq(Member::getIsdeleted,Constants.ZERO)); |
| | | List<Cars> newList = new ArrayList<>(); |
| | | for(int i=0;i<dataList.size();i++){ |
| | | CarsImport model = dataList.get(i); |
| | | model.setPhone(ScientificNotationTUtil.convertToString(model.getPhone())); |
| | | /* if(StringUtils.isBlank(model.getCode()) |
| | | &&StringUtils.isBlank(model.getIdcardNo()) |
| | | &&StringUtils.isBlank(model.getPhone()) |
| | | &&StringUtils.isBlank(model.getCompanyName())){ |
| | | continue; |
| | | } |
| | | Cars car = checkModelParam(model,newList,i,loginUserInfo,list,companyList,); |
| | | newList.add(car);*/ |
| | | } |
| | | if(newList == null || newList.size() ==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入有效数据为空!"); |
| | | } |
| | | // dealHkUserBizBatch(newList); |
| | | return "导入成功"; |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"车辆信息导入失败,请稍后重试"); |
| | | }finally { |
| | | redisTemplate.delete(Constants.RedisKeys.IMPORTING_CARS); |
| | | } |
| | | } |
| | | |
| | | } |