|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.bean.BeanUtil; | 
|---|
|  |  |  | import com.doumee.core.annotation.excel.ExcelImporter; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DateUtil; | 
|---|
|  |  |  | import com.doumee.dao.admin.request.JkLineImport; | 
|---|
|  |  |  | import com.doumee.dao.business.CarsMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.CategoryMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.JkCustomerMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.TelecomLineInfoDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.TelecomCategoryDataVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.TelecomJkLineListVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.TelecomLineCountVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.TelecomLineDataVO; | 
|---|
|  |  |  | 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.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.JkLineMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.JkLine; | 
|---|
|  |  |  | import com.doumee.service.business.JkLineService; | 
|---|
|  |  |  | 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.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | 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.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 交控-线路信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | public class JkLineServiceImpl implements JkLineService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate<String, Object> redisTemplate; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JkLineMapper jkLineMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CategoryMapper categoryMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JkCustomerMapper jkCustomerMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CarsMapper carsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(JkLine jkLine) { | 
|---|
|  |  |  | if(jkLineMapper.selectCount(new QueryWrapper<JkLine>().lambda() | 
|---|
|  |  |  | .eq(JkLine::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkLine::getName,jkLine.getName()) )>0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,线路名称已存在,请返回刷新页面查看!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(categoryMapper.selectOne(new QueryWrapper<Category>().lambda() | 
|---|
|  |  |  | .eq(Category::getId,jkLine.getCategoryId()) | 
|---|
|  |  |  | .eq(Category::getType,Constants.FOUR) | 
|---|
|  |  |  | .eq(Category::getIsdeleted,Constants.ZERO)) ==null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,所属主线路不存在,请返回刷新页面查看!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkLine.setStatus(Constants.formatIntegerNum(jkLine.getStatus())); | 
|---|
|  |  |  | jkLine.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | jkLine.setCreator(jkLine.getLoginUserInfo().getId()); | 
|---|
|  |  |  | jkLine.setCreateDate(new Date()); | 
|---|
|  |  |  | jkLine.setEditDate(jkLine.getCreateDate()); | 
|---|
|  |  |  | jkLine.setEditor(jkLine.getCreator()); | 
|---|
|  |  |  | jkLineMapper.insert(jkLine); | 
|---|
|  |  |  | return jkLine.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteById(Integer id) { | 
|---|
|  |  |  | jkLineMapper.deleteById(id); | 
|---|
|  |  |  | public void deleteById(Integer id, LoginUserInfo user) { | 
|---|
|  |  |  | JkLine c = jkLineMapper.selectById(id); | 
|---|
|  |  |  | if(c == null||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果是新线路,检查是否有子线路,有则不允许删除 | 
|---|
|  |  |  | if(jkCustomerMapper.selectCount(new MPJLambdaWrapper<JkCustomer>().eq(JkCustomer::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCustomer::getLineId,id)) >0){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+c.getName()+"】下已存在客户信息,不允许删除!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkLineMapper.update(null,new UpdateWrapper<JkLine>().lambda() | 
|---|
|  |  |  | .set(JkLine::getIsdeleted,Constants.ONE) | 
|---|
|  |  |  | .set(JkLine::getEditor,user.getId()) | 
|---|
|  |  |  | .set(JkLine::getEditDate,new Date()) | 
|---|
|  |  |  | .eq(JkLine::getId,id) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteByIdInBatch(List<Integer> ids) { | 
|---|
|  |  |  | public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(ids)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkLineMapper.deleteBatchIds(ids); | 
|---|
|  |  |  | for(Integer id :ids){ | 
|---|
|  |  |  | JkLine c = jkLineMapper.selectById(id); | 
|---|
|  |  |  | if(c == null||Constants.equalsInteger(c.getIsdeleted(),Constants.ONE)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果是新线路,检查是否有子线路,有则不允许删除 | 
|---|
|  |  |  | if(jkCustomerMapper.selectCount(new MPJLambdaWrapper<JkCustomer>().eq(JkCustomer::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCustomer::getLineId,id)) >0){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"线路【"+c.getName()+"】下已存在客户信息,不允许删除!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkLineMapper.update(null,new UpdateWrapper<JkLine>().lambda() | 
|---|
|  |  |  | .set(JkLine::getIsdeleted,Constants.ONE) | 
|---|
|  |  |  | .set(JkLine::getEditor,user.getId()) | 
|---|
|  |  |  | .set(JkLine::getEditDate,new Date()) | 
|---|
|  |  |  | .in(JkLine::getId,ids) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateById(JkLine jkLine) { | 
|---|
|  |  |  | if(jkLineMapper.selectCount(new QueryWrapper<JkLine>().lambda() | 
|---|
|  |  |  | .ne(JkLine::getId,jkLine.getId()) | 
|---|
|  |  |  | .eq(JkLine::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkLine::getName,jkLine.getName()) )>0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,线路名称已存在,请返回刷新页面查看!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(categoryMapper.selectOne(new QueryWrapper<Category>().lambda() | 
|---|
|  |  |  | .eq(Category::getId,jkLine.getCategoryId()) | 
|---|
|  |  |  | .eq(Category::getType,Constants.FOUR) | 
|---|
|  |  |  | .eq(Category::getIsdeleted,Constants.ZERO)) ==null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,所属主线路不存在,请返回刷新页面查看!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkLine.setEditor(jkLine.getLoginUserInfo().getId()); | 
|---|
|  |  |  | jkLine.setEditDate(new Date()); | 
|---|
|  |  |  | jkLineMapper.updateById(jkLine); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<JkLine> findList(JkLine jkLine) { | 
|---|
|  |  |  | QueryWrapper<JkLine> wrapper = new QueryWrapper<>(jkLine); | 
|---|
|  |  |  | return jkLineMapper.selectList(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MPJLambdaWrapper<JkLine> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | jkLine.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | queryWrapper.selectAll(JkLine.class ) | 
|---|
|  |  |  | .selectAs(Member::getName,JkLine::getMemberName) | 
|---|
|  |  |  | .selectAs(Cars::getCode,JkLine::getCarCode) | 
|---|
|  |  |  | .leftJoin(Cars.class,Cars::getId,JkLine::getCarId ) | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,Cars::getMemberId ); | 
|---|
|  |  |  | jkLine.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | if (jkLine.getIsdeleted() != null) { | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getIsdeleted, jkLine.getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (jkLine.getCategoryId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getCategoryId, jkLine.getCategoryId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (jkLine.getCarId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getCarId, jkLine.getCarId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (jkLine.getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getStatus, jkLine.getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (jkLine.getSortnum() != null) { | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getSortnum, jkLine.getSortnum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.orderByAsc(JkLine::getCode); | 
|---|
|  |  |  | return jkLineMapper.selectJoinList(JkLine.class,queryWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<JkLine> findPage(PageWrap<JkLine> pageWrap) { | 
|---|
|  |  |  | IPage<JkLine> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<JkLine> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | MPJLambdaWrapper<JkLine> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | pageWrap.getModel().setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | queryWrapper.selectAll(JkLine.class ) | 
|---|
|  |  |  | .selectAs(Cars::getCode,JkLine::getCarCode) | 
|---|
|  |  |  | .selectAs(Category::getName,JkLine::getCategoryName) | 
|---|
|  |  |  | .leftJoin(Category.class,Category::getId,JkLine::getCategoryId ) | 
|---|
|  |  |  | .leftJoin(Cars.class,Cars::getId,JkLine::getCarId ); | 
|---|
|  |  |  | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCarCode()),Cars::getCode, pageWrap.getModel().getCarCode()); | 
|---|
|  |  |  | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCategoryName()),Category::getName, pageWrap.getModel().getCategoryName()); | 
|---|
|  |  |  | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCode()),JkLine::getCode, pageWrap.getModel().getCode()); | 
|---|
|  |  |  | queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getWeeks()),JkLine::getWeeks, pageWrap.getModel().getWeeks()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreateDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(JkLine::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(JkLine::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.ge(JkLine::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.le(JkLine::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditor() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getEditor, pageWrap.getModel().getEditor()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getEditor, pageWrap.getModel().getEditor()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(JkLine::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(JkLine::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.ge(JkLine::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.le(JkLine::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getIsdeleted() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getInfo() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getInfo, pageWrap.getModel().getInfo()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getInfo, pageWrap.getModel().getInfo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getName() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getName, pageWrap.getModel().getName()); | 
|---|
|  |  |  | queryWrapper.like(JkLine::getName, pageWrap.getModel().getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCategoryId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getCategoryId, pageWrap.getModel().getCategoryId()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getCategoryId, pageWrap.getModel().getCategoryId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCarId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getCarId, pageWrap.getModel().getCarId()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getCarId, pageWrap.getModel().getCarId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getMaxCustomer() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getMaxCustomer, pageWrap.getModel().getMaxCustomer()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getMaxCustomer, pageWrap.getModel().getMaxCustomer()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getMaxOrder() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getMaxOrder, pageWrap.getModel().getMaxOrder()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getMaxOrder, pageWrap.getModel().getMaxOrder()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSortnum() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(JkLine::getSortnum, pageWrap.getModel().getSortnum()); | 
|---|
|  |  |  | queryWrapper.eq(JkLine::getSortnum, pageWrap.getModel().getSortnum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(sortData.getProperty()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(jkLineMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | queryWrapper.orderByAsc(JkLine::getCode); | 
|---|
|  |  |  | IPage<JkLine> result = jkLineMapper.selectJoinPage(page, JkLine.class,queryWrapper); | 
|---|
|  |  |  | return PageData.from(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<JkLine> wrapper = new QueryWrapper<>(jkLine); | 
|---|
|  |  |  | return jkLineMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public List<JkLine> importBatch(MultipartFile file, LoginUserInfo loginUserInfo){ | 
|---|
|  |  |  | Boolean importing = (Boolean) redisTemplate.opsForValue().get(Constants.RedisKeys.IMPORTING_JKLINE); | 
|---|
|  |  |  | if(importing!=null && importing){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,已存在导入任务正在执行中,请稍后再试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_JKLINE,true,30, TimeUnit.MINUTES); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ExcelImporter ie = null; | 
|---|
|  |  |  | List<JkLineImport> dataList =null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ie = new ExcelImporter(file,1,0); | 
|---|
|  |  |  | dataList = ie.getDataList(JkLineImport.class,null); | 
|---|
|  |  |  | }  catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(dataList == null || dataList.size() ==0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //当前所有线路 | 
|---|
|  |  |  | List<JkLine> allList =  jkLineMapper.selectJoinList(JkLine.class,new MPJLambdaWrapper<JkLine>() | 
|---|
|  |  |  | .selectAll(JkLine.class) | 
|---|
|  |  |  | .eq(JkLine::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //所有主线路 | 
|---|
|  |  |  | List<Category> categoryList =  categoryMapper.selectJoinList(Category.class,new MPJLambdaWrapper<Category>() | 
|---|
|  |  |  | .selectAll(Category.class) | 
|---|
|  |  |  | .eq(Category::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Category::getType,Constants.FOUR) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //所有物流车车辆 | 
|---|
|  |  |  | List<Cars> cars =  carsMapper.selectJoinList(Cars.class,new MPJLambdaWrapper<Cars>() | 
|---|
|  |  |  | .selectAll(Cars.class) | 
|---|
|  |  |  | .eq(Cars::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | //                    .eq(Cars::getType,Constants.ONE) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<JkLine> newList = new ArrayList<>(); | 
|---|
|  |  |  | List<JkLine> updateList = new ArrayList<>(); | 
|---|
|  |  |  | for(int i=0;i<dataList.size();i++){ | 
|---|
|  |  |  | JkLineImport model = dataList.get(i); | 
|---|
|  |  |  | if(StringUtils.isBlank(model.getName()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getCategoryName()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getCarCode()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getWeeks()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getCode()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getMaxCustomer()) | 
|---|
|  |  |  | &&StringUtils.isBlank(model.getMaxOrder()) ){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | checkModelParam(model,newList,updateList,i,loginUserInfo,allList,categoryList,cars); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if((newList == null || newList.size() ==0) && updateList.size() == 0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入有效数据为空!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(newList.size()>0){ | 
|---|
|  |  |  | jkLineMapper.insert(newList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(updateList.size()>0){ | 
|---|
|  |  |  | for (JkLine c : updateList){ | 
|---|
|  |  |  | jkLineMapper.updateById(c); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | newList.addAll(updateList); | 
|---|
|  |  |  | return newList; | 
|---|
|  |  |  | }catch (BusinessException e){ | 
|---|
|  |  |  | throw e; | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"信息导入失败,请稍后重试"); | 
|---|
|  |  |  | }finally { | 
|---|
|  |  |  | redisTemplate.delete(Constants.RedisKeys.IMPORTING_JKLINE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private JkLine checkModelParam(JkLineImport model, List<JkLine> newList | 
|---|
|  |  |  | , List<JkLine> updateList | 
|---|
|  |  |  | ,int index | 
|---|
|  |  |  | ,LoginUserInfo loginUserInfo | 
|---|
|  |  |  | ,List<JkLine> allList | 
|---|
|  |  |  | ,List<Category> categoryList | 
|---|
|  |  |  | , List<Cars> carsList) { | 
|---|
|  |  |  | if(StringUtils.isBlank(model.getName()) | 
|---|
|  |  |  | ||StringUtils.isBlank(model.getCategoryName()) ){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行线路信息不完整,请检查表格内容!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(JkLine param: newList){ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(model.getName())&&StringUtils.isNotBlank(param.getName())) { | 
|---|
|  |  |  | if (StringUtils.equals(model.getName(), param.getName())) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + (index + 3) + "行线路名称【" + model.getName() + "】重复出现,请检查表格内容!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Category cate = findCategoryFromListByName(model.getCategoryName(),categoryList); | 
|---|
|  |  |  | if(cate == null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + (index + 3) + "行所属主线路【" + model.getCategoryName() + "】不存在,请检查表格内容!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Cars car = findCarFromListByName(model.getCarCode(),carsList); | 
|---|
|  |  |  | if(car == null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + (index + 3) + "行送车车辆【" + model.getCarCode() + "】不存在,请检查表格内容!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JkLine line = findModelFromList(model.getName(),allList); | 
|---|
|  |  |  | if(line == null){ | 
|---|
|  |  |  | line = new JkLine(); | 
|---|
|  |  |  | line.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | line.setCreateDate(new Date()); | 
|---|
|  |  |  | line.setIsnew(Constants.ONE); | 
|---|
|  |  |  | newList.add(line); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | line.setIsnew(Constants.ZERO); | 
|---|
|  |  |  | updateList.add(line); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | line.setName(model.getName()); | 
|---|
|  |  |  | line.setCode(model.getCode()); | 
|---|
|  |  |  | line.setCategoryId(cate.getId()); | 
|---|
|  |  |  | line.setCarId(car.getId()); | 
|---|
|  |  |  | line.setWeeks(model.getWeeks()); | 
|---|
|  |  |  | line.setMaxCustomer(getIntegerByVal(model.getMaxCustomer())); | 
|---|
|  |  |  | line.setMaxOrder(getIntegerByVal(model.getMaxOrder())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | line.setEditDate(new Date()); | 
|---|
|  |  |  | line.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | line.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | return line; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Integer getIntegerByVal(String maxCustomer) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return Integer.parseInt(maxCustomer); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Company findCompanyFromList(String companyName, List<Company> companyList) { | 
|---|
|  |  |  | if(companyList !=null){ | 
|---|
|  |  |  | for(Company company : companyList){ | 
|---|
|  |  |  | if(StringUtils.equals(companyName,company.getCompanyNamePath())){ | 
|---|
|  |  |  | return  company; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private JkLine findModelFromList(String name, List<JkLine> list) { | 
|---|
|  |  |  | if(list !=null){ | 
|---|
|  |  |  | for(JkLine model : list){ | 
|---|
|  |  |  | if(StringUtils.equals(name,model.getName())){ | 
|---|
|  |  |  | return  model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private Category findCategoryFromListByName(String name, List<Category> list) { | 
|---|
|  |  |  | if(list !=null){ | 
|---|
|  |  |  | for(Category model : list){ | 
|---|
|  |  |  | if(StringUtils.equals(name,model.getName())){ | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private Cars findCarFromListByName(String name, List<Cars> list) { | 
|---|
|  |  |  | if(list !=null){ | 
|---|
|  |  |  | for(Cars model : list){ | 
|---|
|  |  |  | if(StringUtils.equals(name,model.getCode())){ | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|