package doumeemes.service.business.impl; 
 | 
  
 | 
import com.sun.corba.se.spi.orbutil.threadpool.Work; 
 | 
import doumeemes.core.constants.ResponseStatus; 
 | 
import doumeemes.core.exception.BusinessException; 
 | 
import doumeemes.core.model.LoginUserInfo; 
 | 
import doumeemes.core.model.PageData; 
 | 
import doumeemes.core.model.PageWrap; 
 | 
import doumeemes.core.utils.Constants; 
 | 
import doumeemes.core.utils.DateUtil; 
 | 
import doumeemes.core.utils.Utils; 
 | 
import doumeemes.core.utils.excel.EasyExcelUtil; 
 | 
import doumeemes.dao.business.PlansMapper; 
 | 
import doumeemes.dao.business.WorkPlansMapper; 
 | 
import doumeemes.dao.business.model.*; 
 | 
import doumeemes.dao.business.vo.WorkPlansVO; 
 | 
import doumeemes.dao.ext.*; 
 | 
import doumeemes.dao.ext.dto.QueryMaterialDistributeExtDTO; 
 | 
import doumeemes.dao.ext.dto.QueryWorkPlansDTO; 
 | 
import doumeemes.dao.ext.dto.WorkPlansSaveDTO; 
 | 
import doumeemes.dao.ext.vo.DepartmentExtListVO; 
 | 
import doumeemes.dao.ext.vo.MaterialDistributeExtListVO; 
 | 
import doumeemes.service.business.WorkPlansService; 
 | 
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 doumeemes.service.ext.DepartmentExtService; 
 | 
import doumeemes.service.ext.PlansExtService; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.apache.poi.util.StringUtil; 
 | 
import org.apache.shiro.SecurityUtils; 
 | 
import org.springframework.beans.BeanUtils; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
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; 
 | 
  
 | 
/** 
 | 
 * 工单类-成品生产计划信息表Service实现 
 | 
 * @author 江蹄蹄 
 | 
 * @since 2023/07/24 15:33 
 | 
 */ 
 | 
@Service 
 | 
public class WorkPlansServiceImpl implements WorkPlansService { 
 | 
  
 | 
    @Autowired 
 | 
    private WorkPlansMapper workPlansMapper; 
 | 
  
 | 
//    @Autowired 
 | 
//    private PlansExtService plansExtService; 
 | 
// 
 | 
//    @Autowired 
 | 
//    private PlanImportExtMapper planImportExtMapper; 
 | 
// 
 | 
//    @Autowired 
 | 
//    private PlanHistoryExtMapper planHistoryExtMapper; 
 | 
// 
 | 
//    @Autowired 
 | 
//    private MaterialDistributeExtMapper materialDistributeExtMapper; 
 | 
// 
 | 
//    @Autowired 
 | 
//    private BomExtMapper bomExtMapper; 
 | 
// 
 | 
//    @Autowired 
 | 
//    private DepartmentExtService departmentExtService; 
 | 
  
 | 
//    @Override 
 | 
//    public Integer create(WorkPlans workPlans) { 
 | 
//        workPlansMapper.insert(workPlans); 
 | 
//        return workPlans.getId(); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void deleteById(Integer id) { 
 | 
//        workPlansMapper.deleteById(id); 
 | 
//    } 
 | 
  
 | 
//    @Override 
 | 
//    public void delete(WorkPlans workPlans) { 
 | 
//        UpdateWrapper<WorkPlans> deleteWrapper = new UpdateWrapper<>(workPlans); 
 | 
//        workPlansMapper.delete(deleteWrapper); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void deleteByIdInBatch(List<Integer> ids) { 
 | 
//        if (CollectionUtils.isEmpty(ids)) { 
 | 
//            return; 
 | 
//        } 
 | 
//        workPlansMapper.deleteBatchIds(ids); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void updateById(WorkPlans workPlans) { 
 | 
//        workPlansMapper.updateById(workPlans); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void updateByIdInBatch(List<WorkPlans> workPlanss) { 
 | 
//        if (CollectionUtils.isEmpty(workPlanss)) { 
 | 
//            return; 
 | 
//        } 
 | 
//        for (WorkPlans workPlans: workPlanss) { 
 | 
//            this.updateById(workPlans); 
 | 
//        } 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public WorkPlans findById(Integer id) { 
 | 
//        return workPlansMapper.selectById(id); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public WorkPlans findOne(WorkPlans workPlans) { 
 | 
//        QueryWrapper<WorkPlans> wrapper = new QueryWrapper<>(workPlans); 
 | 
//        return workPlansMapper.selectOne(wrapper); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public List<WorkPlans> findList(WorkPlans workPlans) { 
 | 
//        QueryWrapper<WorkPlans> wrapper = new QueryWrapper<>(workPlans); 
 | 
//        return workPlansMapper.selectList(wrapper); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public PageData<WorkPlans> findPage(PageWrap<WorkPlans> pageWrap) { 
 | 
//        IPage<WorkPlans> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); 
 | 
//        QueryWrapper<WorkPlans> queryWrapper = new QueryWrapper<>(); 
 | 
//        Utils.MP.blankToNull(pageWrap.getModel()); 
 | 
//        queryWrapper.lambda() 
 | 
//                .eq(pageWrap.getModel().getId() != null, WorkPlans::getId, pageWrap.getModel().getId()) 
 | 
//                .eq(pageWrap.getModel().getDeleted() != null, WorkPlans::getDeleted, pageWrap.getModel().getDeleted()) 
 | 
//                .eq(pageWrap.getModel().getCreateUser() != null, WorkPlans::getCreateUser, pageWrap.getModel().getCreateUser()) 
 | 
//                .ge(pageWrap.getModel().getCreateTime() != null, WorkPlans::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime())) 
 | 
//                .le(pageWrap.getModel().getCreateTime() != null, WorkPlans::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime())) 
 | 
//                .eq(pageWrap.getModel().getUpdateUser() != null, WorkPlans::getUpdateUser, pageWrap.getModel().getUpdateUser()) 
 | 
//                .ge(pageWrap.getModel().getUpdateTime() != null, WorkPlans::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime())) 
 | 
//                .le(pageWrap.getModel().getUpdateTime() != null, WorkPlans::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime())) 
 | 
//                .eq(pageWrap.getModel().getRemark() != null, WorkPlans::getRemark, pageWrap.getModel().getRemark()) 
 | 
//                .eq(pageWrap.getModel().getRootDepartId() != null, WorkPlans::getRootDepartId, pageWrap.getModel().getRootDepartId()) 
 | 
//                .eq(pageWrap.getModel().getDepartId() != null, WorkPlans::getDepartId, pageWrap.getModel().getDepartId()) 
 | 
//                .eq(pageWrap.getModel().getFactoryId() != null, WorkPlans::getFactoryId, pageWrap.getModel().getFactoryId()) 
 | 
//                .eq(pageWrap.getModel().getOrigin() != null, WorkPlans::getOrigin, pageWrap.getModel().getOrigin()) 
 | 
//                .eq(pageWrap.getModel().getPlanCode() != null, WorkPlans::getPlanCode, pageWrap.getModel().getPlanCode()) 
 | 
//                .ge(pageWrap.getModel().getPlanDate() != null, WorkPlans::getPlanDate, Utils.Date.getStart(pageWrap.getModel().getPlanDate())) 
 | 
//                .le(pageWrap.getModel().getPlanDate() != null, WorkPlans::getPlanDate, Utils.Date.getEnd(pageWrap.getModel().getPlanDate())) 
 | 
//                .eq(pageWrap.getModel().getMaterialId() != null, WorkPlans::getMaterialId, pageWrap.getModel().getMaterialId()) 
 | 
//                .eq(pageWrap.getModel().getUnitId() != null, WorkPlans::getUnitId, pageWrap.getModel().getUnitId()) 
 | 
//                .eq(pageWrap.getModel().getNum() != null, WorkPlans::getNum, pageWrap.getModel().getNum()) 
 | 
//                .eq(pageWrap.getModel().getBatch() != null, WorkPlans::getBatch, pageWrap.getModel().getBatch()) 
 | 
//                .eq(pageWrap.getModel().getStatus() != null, WorkPlans::getStatus, pageWrap.getModel().getStatus()) 
 | 
//                .eq(pageWrap.getModel().getImportId() != null, WorkPlans::getImportId, pageWrap.getModel().getImportId()) 
 | 
//                .eq(pageWrap.getModel().getPaused() != null, WorkPlans::getPaused, pageWrap.getModel().getPaused()) 
 | 
//                .eq(pageWrap.getModel().getUserId() != null, WorkPlans::getUserId, pageWrap.getModel().getUserId()) 
 | 
//                .ge(pageWrap.getModel().getPublishDate() != null, WorkPlans::getPublishDate, Utils.Date.getStart(pageWrap.getModel().getPublishDate())) 
 | 
//                .le(pageWrap.getModel().getPublishDate() != null, WorkPlans::getPublishDate, Utils.Date.getEnd(pageWrap.getModel().getPublishDate())) 
 | 
//        ; 
 | 
//        for(PageWrap.SortData sortData: pageWrap.getSorts()) { 
 | 
//            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { 
 | 
//                queryWrapper.orderByDesc(sortData.getProperty()); 
 | 
//            } else { 
 | 
//                queryWrapper.orderByAsc(sortData.getProperty()); 
 | 
//            } 
 | 
//        } 
 | 
//        return PageData.from(workPlansMapper.selectPage(page, queryWrapper)); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public long count(WorkPlans workPlans) { 
 | 
//        QueryWrapper<WorkPlans> wrapper = new QueryWrapper<>(workPlans); 
 | 
//        return workPlansMapper.selectCount(wrapper); 
 | 
//    } 
 | 
  
 | 
/****************************************************************************************************************************************************************************/ 
 | 
  
 | 
//    @Override 
 | 
//    public Integer saveOrUpdate(WorkPlansSaveDTO workPlansSaveDTO) { 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        if(Objects.isNull(workPlansSaveDTO) 
 | 
//            || StringUtils.isBlank(workPlansSaveDTO.getBatch()) 
 | 
//            || Objects.isNull(workPlansSaveDTO.getPlanDate()) 
 | 
//            || Objects.isNull(workPlansSaveDTO.getNum()) 
 | 
//            || Objects.isNull(workPlansSaveDTO.getFactoryId()) 
 | 
//            || Objects.isNull(workPlansSaveDTO.getMaterialId())){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST); 
 | 
//        } 
 | 
//        WorkPlans workPlans = new WorkPlans(); 
 | 
//        if(!Objects.isNull(workPlansSaveDTO.getWorkPlansId())){ 
 | 
//            workPlans = workPlansMapper.selectById(workPlansSaveDTO.getWorkPlansId()); 
 | 
//            if(Objects.isNull(workPlans)){ 
 | 
//                throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
//            } 
 | 
//            if (!workPlans.getStatus().equals(Constants.WORKORDER_HISTORY_STATUS.create)){ 
 | 
//                throw new BusinessException(ResponseStatus.ERR_STATUS); 
 | 
//            } 
 | 
//            BeanUtils.copyProperties(workPlansSaveDTO,workPlans); 
 | 
//            workPlans.setUpdateTime(DateUtil.getCurrentDate()); 
 | 
//            workPlans.setUpdateUser(user.getId()); 
 | 
//            workPlansMapper.updateById(workPlans); 
 | 
//        }else{ 
 | 
//            BeanUtils.copyProperties(workPlansSaveDTO,workPlans); 
 | 
//            workPlans.setCreateTime(DateUtil.getCurrentDate()); 
 | 
//            workPlans.setCreateUser(user.getId()); 
 | 
//            workPlans.setDeleted(Constants.ZERO); 
 | 
//            workPlans.setDepartId(user.getCurComDepartment().getId()); 
 | 
//            workPlans.setRootDepartId(user.getRootDepartment().getId()); 
 | 
//            workPlans.setUserId(user.getId()); 
 | 
//            workPlans.setOrigin(Constants.PLAS_ORIGIN.user); 
 | 
//            workPlans.setStatus(Constants.PLAN_STATUS.create); 
 | 
//            //TODO CODE 
 | 
//            workPlansMapper.insert(workPlans); 
 | 
//        } 
 | 
// 
 | 
//        return workPlans.getId(); 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    @Override 
 | 
//    public IPage<WorkPlansVO> getWorkPlansVOPage(PageWrap<QueryWorkPlansDTO> pageWrap) { 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        QueryWorkPlansDTO queryWorkPlansDTO = pageWrap.getModel(); 
 | 
//        QueryWrapper queryWrapper = new QueryWrapper<WorkPlansVO>() 
 | 
//                .eq("a.DELETED",Constants.ZERO) 
 | 
//                .eq("a.DEPART_ID",user.getCurComDepartment().getId()) 
 | 
//                .eq("a.ROOT_DEPART_ID",user.getRootDepartment().getId()) 
 | 
//                .orderByAsc("a.URGENT") 
 | 
//                .orderByDesc("a.CREATE_DATE"); 
 | 
//        if(!Objects.isNull(queryWorkPlansDTO)){ 
 | 
//            queryWrapper.eq(!Objects.isNull(queryWorkPlansDTO.getFactoryId()),"a.FACTORY_ID",queryWorkPlansDTO.getFactoryId()); 
 | 
//            queryWrapper.eq(!Objects.isNull(queryWorkPlansDTO.getPlanStatus()),"a.STATUS",queryWorkPlansDTO.getPlanStatus()); 
 | 
//            queryWrapper.like(StringUtils.isNotBlank(queryWorkPlansDTO.getMaterialCode()),"mmodel.CODE",queryWorkPlansDTO.getMaterialCode()); 
 | 
//            queryWrapper.like(StringUtils.isNotBlank(queryWorkPlansDTO.getMaterialName()),"mmodel.NAME",queryWorkPlansDTO.getMaterialName()); 
 | 
//            queryWrapper.like(StringUtils.isNotBlank(queryWorkPlansDTO.getBatch()),"a.BATCH",queryWorkPlansDTO.getBatch()); 
 | 
//            queryWrapper.apply(StringUtils.isNotBlank(queryWorkPlansDTO.getPlanDateStart()),"a.PLAN_DATE  > '"+ queryWorkPlansDTO.getPlanDateStart() +"'    "); 
 | 
//            queryWrapper.apply(StringUtils.isNotBlank(queryWorkPlansDTO.getPlanDateEnd()),"a.PLAN_DATE  < '"+ queryWorkPlansDTO.getPlanDateEnd() +"'    "); 
 | 
//        } 
 | 
//        IPage<WorkPlansVO> page = workPlansMapper.getWorkPlansVOPage(pageWrap.toPage(),queryWrapper); 
 | 
//        return page; 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    @Override 
 | 
//    public Integer deleteById(Integer id) { 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        WorkPlans workPlans = workPlansMapper.selectById(id); 
 | 
//        if(Objects.isNull(workPlans)){ 
 | 
//            throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
//        } 
 | 
//        workPlans.setDeleted(Constants.ONE); 
 | 
//        workPlans.setUpdateUser(user.getId()); 
 | 
//        workPlans.setUpdateTime(new Date()); 
 | 
//        return workPlansMapper.updateById(workPlans); 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    @Override 
 | 
//    public void paused(Integer id){ 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        WorkPlans workPlans = workPlansMapper.selectById(id); 
 | 
//        if(Objects.isNull(workPlans)){ 
 | 
//            throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
//        } 
 | 
//        //已暂停的计划不需重复操作 
 | 
//        if(Constants.equalsInteger(workPlans.getPaused(),Constants.ONE) ){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该计划已暂停,无需重复操作!"); 
 | 
//        } 
 | 
//        workPlans.setUpdateTime(DateUtil.getCurrentDate()); 
 | 
//        workPlans.setUpdateUser(user.getId()); 
 | 
//        workPlans.setPaused(Constants.ONE); 
 | 
//        workPlansMapper.updateById(workPlans); 
 | 
//        //历史数据,关闭 
 | 
//        planHistoryExtMapper.insert(initHistoryByModel(workPlans,user.getId(),Constants.PLANHISTORY_TYPE.pause)); 
 | 
//        List<Plans> plansList = plansExtService.getPlansList(new QueryWrapper<Plans>() 
 | 
//                .in("STATUS",0,1,4) 
 | 
//                .eq("PAUSED",Constants.ZERO) 
 | 
//                .eq("DELETED",Constants.ZERO) 
 | 
//                .eq("WORK_PLANS_ID",workPlans.getId())); 
 | 
// 
 | 
//        plansList.forEach(i->{ 
 | 
//            plansExtService.pauseByIdForStandard(i,user); 
 | 
//        }); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void regain(Integer id){ 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        WorkPlans workPlans = workPlansMapper.selectById(id); 
 | 
//        if(Objects.isNull(workPlans)){ 
 | 
//            throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
//        } 
 | 
//        //已暂停的计划不需重复操作 
 | 
//        if(Constants.equalsInteger(workPlans.getPaused(),Constants.ZERO) ){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该计划已恢复,无需重复操作!"); 
 | 
//        } 
 | 
//        workPlans.setUpdateTime(DateUtil.getCurrentDate()); 
 | 
//        workPlans.setUpdateUser(user.getId()); 
 | 
//        workPlans.setPaused(Constants.ZERO); 
 | 
//        workPlansMapper.updateById(workPlans); 
 | 
//        //历史数据,关闭 
 | 
//        planHistoryExtMapper.insert(initHistoryByModel(workPlans,user.getId(),Constants.PLANHISTORY_TYPE.pause)); 
 | 
//        List<Plans> plansList = plansExtService.getPlansList(new QueryWrapper<Plans>() 
 | 
//                .in("STATUS",0,1,4) 
 | 
//                .eq("PAUSED",Constants.ONE) 
 | 
//                .eq("DELETED",Constants.ZERO) 
 | 
//                .eq("WORK_PLANS_ID",workPlans.getId())); 
 | 
//        plansList.forEach(i->{ 
 | 
//            plansExtService.regainByIdForStandard(i,user); 
 | 
//        }); 
 | 
//    } 
 | 
// 
 | 
//    @Override 
 | 
//    public void close(Integer id){ 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        WorkPlans workPlans = workPlansMapper.selectById(id); 
 | 
//        if(Objects.isNull(workPlans)){ 
 | 
//            throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
//        } 
 | 
//        if(Constants.equalsInteger(workPlans.getStatus(),Constants.PLAN_STATUS.close) ){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该计划已关闭,无需重复操作!"); 
 | 
//        } 
 | 
//        workPlans.setUpdateTime(DateUtil.getCurrentDate()); 
 | 
//        workPlans.setUpdateUser(user.getId()); 
 | 
//        workPlans.setStatus(Constants.PLAN_STATUS.close); 
 | 
//        workPlansMapper.updateById(workPlans); 
 | 
//        List<Plans> plansList = plansExtService.getPlansList(new QueryWrapper<Plans>() 
 | 
//                .in("STATUS",0,1,4) 
 | 
//                .eq("DELETED",Constants.ZERO) 
 | 
//                .eq("WORK_PLANS_ID",workPlans.getId())); 
 | 
//        plansList.forEach(i->{ 
 | 
//            i.setUpdateTime(DateUtil.getCurrentDate()); 
 | 
//            i.setUpdateUser(user.getId()); 
 | 
//            i.setStatus(Constants.PLAN_STATUS.close); 
 | 
//            plansExtService.updateById(i); 
 | 
//        }); 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    public static PlanHistory initHistoryByModel(WorkPlans p, Integer userId, int status ) { 
 | 
//        PlanHistory h = new PlanHistory(); 
 | 
//        h.setDeleted(Constants.ZERO); 
 | 
//        h.setCreateTime(DateUtil.getCurrentDate()); 
 | 
//        h.setCreateUser(userId); 
 | 
//        h.setDepartId(p.getDepartId()); 
 | 
//        h.setRootDepartId(p.getRootDepartId()); 
 | 
//        h.setPlanId(p.getId()); 
 | 
//        h.setRootDepartId(p.getRootDepartId()); 
 | 
//        h.setDepartId(p.getDepartId()); 
 | 
//        h.setTitle(Constants.WORKPLANHISTORY_TYPE.getTitleByStatus(p,status)); 
 | 
//        h.setType(status); 
 | 
//        h.setInfo(Constants.WORKPLANHISTORY_TYPE.getInfoByStatus(p,status)); 
 | 
//        h.setType(status); 
 | 
// 
 | 
//        return h; 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    @Transactional(rollbackFor = {BusinessException.class,Exception.class}) 
 | 
//    @Override 
 | 
//    public void importPlans(MultipartFile file)  { 
 | 
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
//        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ 
 | 
//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); 
 | 
//        } 
 | 
//        //解析excel 
 | 
//        List<WorkPlans> plansList = EasyExcelUtil.importExcel(file, 1, 1, WorkPlans.class); 
 | 
//        if(plansList == null || plansList.size()==0){ 
 | 
//            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容有误!"); 
 | 
//        } 
 | 
//        PlanImport ip = new PlanImport(); 
 | 
//        ip.setDeleted(Constants.ZERO); 
 | 
//        ip.setCreateTime(DateUtil.getCurrentDate()); 
 | 
//        ip.setCreateUser(user.getId()); 
 | 
//        ip.setFileName(file.getOriginalFilename()); 
 | 
//        ip.setRootDepartId(user.getRootDepartment().getId()); 
 | 
//        ip.setDepartId(user.getComDepartment().getId()); 
 | 
//        //计划文件上传记录 
 | 
//        planImportExtMapper.insert(ip); 
 | 
//        int index = 1; 
 | 
//        List<PlanHistory> historyList = new ArrayList<>(); 
 | 
//        for(WorkPlans p : plansList){ 
 | 
//            p.setCreateTime(DateUtil.getCurrentDate()); 
 | 
//            p.setCreateUser(user.getId()); 
 | 
//            p.setDeleted(Constants.ZERO); 
 | 
//            p.setDepartId(user.getCurComDepartment().getId()); 
 | 
//            p.setRootDepartId(ip.getRootDepartId()); 
 | 
//            p.setImportId(ip.getId()); 
 | 
//            p.setStatus(Constants.PLAN_STATUS.create); 
 | 
//            p.setOrigin(Constants.PLAS_ORIGIN.imports); 
 | 
//            p.setUserId(user.getId()); 
 | 
////            p.setFactoryId(user.getDepartment().getId()); 
 | 
//            //检查数据有效性 
 | 
//            checkData(p,index,user); 
 | 
//            workPlansMapper.insert(p); 
 | 
//            historyList.add(initHistoryByModel(p,user.getId(),Constants.WORKPLANHISTORY_TYPE.create)); 
 | 
//            index++; 
 | 
//        } 
 | 
//        //批量导入计划数据 
 | 
//        planHistoryExtMapper.insertBatch(historyList); 
 | 
//    } 
 | 
// 
 | 
// 
 | 
//    /** 
 | 
//     * 数据有效性检查 
 | 
//     * @param p 
 | 
//     * @param index 
 | 
//     * @param user 
 | 
//     * @throws BusinessException 
 | 
//     */ 
 | 
//    private void checkData(WorkPlans p, int index,LoginUserInfo user) throws BusinessException{ 
 | 
//        if(Constants.formatIntegerNum(p.getNum())<=0){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【计划生产数量】数据错误!"); 
 | 
//        } 
 | 
//        if(p.getPlanDate() == null){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【计划日期】数据错误,正确格式为:yyyy-MM-dd(如2022-06-07)!"); 
 | 
//        } 
 | 
//        if(StringUtils.isBlank(p.getMaterialCode())){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品编码】数据错误!"); 
 | 
//        } 
 | 
//        if(p.getFactoryName() == null){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【生产工厂】数据错误!"); 
 | 
//        } 
 | 
//        if(p.getBatch() == null){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【生产批次】数据错误!"); 
 | 
//        } 
 | 
// 
 | 
//        Date pDate = DateUtil.getDateFromString(DateUtil.getShortTime(p.getPlanDate()) +" 00:00:00"); 
 | 
//        Date nDate =  DateUtil.getDateFromString(DateUtil.getShortTime(DateUtil.getCurrentDate()) +" 00:00:00"); 
 | 
//        if( nDate.getTime() > pDate.getTime()){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,计划生产日期必须为今天以后的日期!"); 
 | 
//        } 
 | 
//        p.setMaterialCode(p.getMaterialCode().trim()); 
 | 
//        p.setFactoryName(p.getFactoryName().trim()); 
 | 
//        p.setBatch(p.getBatch().trim()); 
 | 
//        QueryMaterialDistributeExtDTO d = new QueryMaterialDistributeExtDTO(); 
 | 
//        d.setDeleted(Constants.ZERO); 
 | 
//        d.setMmodelCode(p.getMaterialCode()); 
 | 
//        d.setRootDepartId(p.getRootDepartId()); 
 | 
//        d.setDepartId(p.getDepartId()); 
 | 
//        //查询产品信息 
 | 
//        MaterialDistributeExtListVO mm = materialDistributeExtMapper.selectByModel(d); 
 | 
//        if(mm == null){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品编码】数据不存在!"); 
 | 
//        } 
 | 
//        if(Constants.equalsInteger(mm.getStatus(),Constants.ZERO)){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品】已失效,无法进行生产!"); 
 | 
//        } 
 | 
//        //存储物料分配表主键 
 | 
//        p.setMaterialId(mm.getId()); 
 | 
//        //单位编码 
 | 
//        p.setUnitId(mm.getUnitId()); 
 | 
//        if(Constants.equalsInteger(mm.getStatus(),Constants.ZERO)){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品编码】不能安排生产计划!"); 
 | 
//        } 
 | 
//        Bom bom = new Bom(); 
 | 
//        bom.setDeleted(Constants.ZERO); 
 | 
//        bom.setMaterialId(mm.getId()); 
 | 
//        bom.setRootDepartId(mm.getRootDepartId()); 
 | 
//        bom = bomExtMapper.selectOne(new QueryWrapper<>(bom).last(" limit 1")); 
 | 
//        if(bom == null){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品】BOM未配置数据!"); 
 | 
//        } 
 | 
//        if(!Constants.equalsInteger(bom.getStatus(),Constants.ONE)){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【产品】BOM已失效,无法进行生产!"); 
 | 
//        } 
 | 
//        DepartmentExtListVO f = departmentExtService.getModelByName(user.getCompany().getId(),p.getFactoryName()); 
 | 
//        if(f==null || !Constants.equalsInteger(f.getType(),Constants.DEPART_TYPE.factory) ){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【生产工厂】数据非工厂组织,请检查!"); 
 | 
//        } 
 | 
//        if(Constants.equalsInteger(f.getStatus(),Constants.ONE) ){ 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【生产工厂】当前状态不正确!"); 
 | 
//        } 
 | 
//        if(!Constants.equalsInteger(p.getDepartId(),departmentExtService.getComDepartId(f))){ 
 | 
//            //如果工厂与公司级组织不对应 
 | 
//            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(index+2)+"】行【生产工厂】数据非当前公司组织,请检查!"); 
 | 
//        } 
 | 
//        p.setFactoryId(f.getId()); 
 | 
//    } 
 | 
  
 | 
} 
 |