| | |
| | | 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 |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | } |