jiaosong
2023-08-25 2916c4c250268482d8dd31aa9cc00b950f6b7cc9
server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
@@ -1,6 +1,7 @@
package doumeemes.service.business.impl;
import com.baomidou.mybatisplus.extension.api.R;
import doumeemes.biz.system.SystemDictBiz;
import doumeemes.core.constants.ResponseStatus;
import doumeemes.core.exception.BusinessException;
import doumeemes.core.model.ApiResponse;
@@ -17,6 +18,8 @@
import doumeemes.dao.ext.dto.DeviceImportDTO;
import doumeemes.dao.ext.dto.QueryDeviceExtDTO;
import doumeemes.dao.ext.vo.DeviceExtListVO;
import doumeemes.dao.system.SystemDictDataMapper;
import doumeemes.dao.system.model.SystemDictData;
import doumeemes.service.business.DeviceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -62,6 +65,13 @@
    @Autowired
    private WarehouseLocationMapper  warehouseLocationMapper;
    @Autowired
    private WarehouseMapper  warehouseMapper;
    @Autowired
    private SystemDictDataMapper systemDictDataMapper;
    @Override
    public Integer create(Device device) {
@@ -304,7 +314,7 @@
            QueryWrapper<Department> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(Department::getRootId,user.getRootDepartment().getId())
                    .eq(Department::getName,departName)
                    .eq(Department::getName,s.getDepartName())
                    .last("limit 1");
            Department department = departmentMapper.selectOne(wrapper);
            if(Objects.isNull(department)){
@@ -314,11 +324,11 @@
            QueryWrapper<Procedures> proceduresQuery = new QueryWrapper<>();
            proceduresQuery.lambda()
                    .eq(Procedures::getRootDepartId,user.getRootDepartment().getId())
                    .eq(Procedures::getDepartId,department.getId())
                    .eq(Procedures::getOrgId,department.getId())
                    .eq(Procedures::getName,s.getProcedureName());
            Procedures procedures = proceduresMapper.selectOne(proceduresQuery);
            if(Objects.isNull(procedures)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"工序名称已存在");
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"工序名称不存在");
            }
            QueryDeviceExtDTO queryDeviceExtDTO=new QueryDeviceExtDTO();
            queryDeviceExtDTO.setDeleted(Constants.ZERO);
@@ -329,17 +339,41 @@
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"设备编码不存在");
            }
            QueryWrapper<WarehouseLocation> warehouseLocationQuery = new QueryWrapper<>();
            warehouseLocationQuery.lambda()
                                    .eq(WarehouseLocation::getRootDepartId,department.getRootId())
                                    .eq(WarehouseLocation::getUnionName
                                            ,Arrays.asList(s.getFinishWarehouseLocationName(),s.getProduceWarehouseLocationName()));
            if(Objects.equals(list.size(),2)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"库位信息已存在");
            }
            List<WarehouseLocation> warehouseLocations = warehouseLocationMapper.selectList(warehouseLocationQuery);
                                            ,s.getProduceWarehouseLocationName()).last("limit 1");
            Map<String, WarehouseLocation> collect = warehouseLocations.stream().collect(Collectors.toMap(w -> w.getUnionName(), w -> w));
            WarehouseLocation warehouseLocation = warehouseLocationMapper.selectOne(warehouseLocationQuery);
            if (Objects.isNull(warehouseLocation)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"待生产货位不存在");
            }
            QueryWrapper<SystemDictData> systemDictDataQuery = new QueryWrapper<>();
            systemDictDataQuery.lambda()
                    .eq(SystemDictData::getDictId,3)
                    .eq(SystemDictData::getCode,"混合");
            SystemDictData systemDictData = systemDictDataMapper.selectOne(systemDictDataQuery);
            warehouseLocationQuery.clear();
            warehouseLocationQuery.lambda()
                                    .eq(WarehouseLocation::getRootDepartId,department.getRootId())
                                    .eq(WarehouseLocation::getSystemDicDataId,systemDictData.getId())
                                    .eq(WarehouseLocation::getUnionName,s.getFinishWarehouseLocationName()).last("limit 1");
            WarehouseLocation finishWarehouseLocations = warehouseLocationMapper.selectOne(warehouseLocationQuery);
            if (Objects.isNull(finishWarehouseLocations)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"已完工货位不存在");
            }
            Map<String, WarehouseLocation> collect =new HashMap<>();
            collect.put(warehouseLocation.getUnionName(),warehouseLocation);
            collect.put(finishWarehouseLocations.getUnionName(),finishWarehouseLocations);
            Device device = new Device();
            device.setDeleted(Constants.ZERO);
@@ -348,8 +382,8 @@
            device.setUpdateUser(user.getId());
            device.setUpdateTime(new Date());
//            device.setRemark();
            device.setRootDepartId(department.getRootId());
            device.setDepartId(procedures.getId());
            device.setRootDepartId(user.getRootDepartment().getId());
            device.setDepartId(user.getCurComDepartment().getId());
            device.setProcedureId(procedures.getId());
            device.setCode(StringUtils.isNotBlank(device.getCode()) ? device.getCode() : this.getNextCode(user.getCompany().getId()));
@@ -357,15 +391,23 @@
            device.setName(s.getDeviceName());
            device.setModel(s.getModel());
            device.setStatus(Constants.ZERO);
//            device.setSupplier();
            device.setStationCode(s.getStationCode());
//            device.setGroupId();
//            device.setSerialNum();
            device.setProduceWarehouseLocationId(collect.get(s.getProduceWarehouseLocationName()).getId());
            device.setFinishWarehouseLocationId(collect.get(s.getFinishWarehouseLocationName()).getId());
            device.setProduceWarehouseLocationId(Optional.ofNullable(collect.get(s.getProduceWarehouseLocationName())).map(m->m.getId()).orElseThrow(null));
            device.setFinishWarehouseLocationId(Optional.ofNullable(collect.get(s.getFinishWarehouseLocationName())).map(m->m.getId()).orElseThrow(null));
            deviceMapper.insert(device);
            if(StringUtils.isNotBlank(s.getUserIds())){
                this.dealDeviceUserId(Constants.ZERO,device.getUserIds().trim(),device.getId(),user);
                QueryWrapper<CompanyUser>  companyUserQuery = new QueryWrapper<>();
                companyUserQuery.lambda()
                                .eq(CompanyUser::getComDepartId,user.getComDepartment().getId())
                                .in(CompanyUser::getPhone,Arrays.asList(s.getUserIds().split("[.,;,]")));
                List<CompanyUser> list1 = companyUserService.findList(companyUserQuery);
                if (!CollectionUtils.isEmpty(list1)){
                    List<String> collect1 = list1.stream().map(c -> c.getId().toString()).collect(Collectors.toList());
                    this.dealDeviceUserId(Constants.ZERO,StringUtils.join(collect1,","),device.getId(),user);
                }
            }
        });