¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.dnc.entity.DeviceManagement; |
| | | import org.jeecg.modules.dnc.entity.DeviceType; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.DeviceManagementMapper; |
| | | import org.jeecg.modules.dnc.response.CommonCode; |
| | | import org.jeecg.modules.dnc.service.IDeviceManagementService; |
| | | import org.jeecg.modules.dnc.service.IDeviceTypeService; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.entity.MdcProductionEquipment; |
| | | import org.jeecg.modules.system.entity.MdcUserProduction; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.IMdcUserProductionService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DeviceManagementServiceImpl extends ServiceImpl<DeviceManagementMapper, DeviceManagement> implements IDeviceManagementService { |
| | | |
| | | @Autowired |
| | | private IMdcProductionService productionService; |
| | | @Autowired |
| | | private IMdcUserProductionService userProductionService; |
| | | @Autowired |
| | | private IMdcProductionEquipmentService productionEquipmentService; |
| | | @Autowired |
| | | private IMdcEquipmentService equipmentService; |
| | | @Autowired |
| | | private IDeviceTypeService deviceTypeService; |
| | | /** |
| | | * æ°å¢è®¾å¤ç±»ä¿¡æ¯ |
| | | * @param deviceManagement |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> add(DeviceManagement deviceManagement){ |
| | | if(deviceManagement == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(deviceManagement.getEquipmentIds())) |
| | | Result.error("æ æç设å¤ç±»"); |
| | | List<DeviceManagement> deviceManagementList =this.getDeviceManagementList(deviceManagement.getProductionId(),deviceManagement.getDeviceManagementName(),deviceManagement.getDeviceManagementCode()); |
| | | if (deviceManagementList != null && !deviceManagementList.isEmpty()) { |
| | | return Result.error("å·²åå¨ç¸åç设å¤ç±»"); |
| | | } |
| | | boolean save = this.save(deviceManagement); |
| | | if(save){ |
| | | return Result.OK("æ·»å 设å¤ç±»æå"); |
| | | } |
| | | return Result.error("æ°å¢è®¾å¤ç±»å¤±è´¥"); |
| | | } |
| | | /** |
| | | * ç¼è¾è®¾å¤ç±»ä¿¡æ¯ |
| | | * @param deviceManagement |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> edit(DeviceManagement deviceManagement){ |
| | | // æ£æ¥ä¼ å
¥ç设å¤ç±»å¯¹è±¡æ¯å¦ä¸ºç©º |
| | | if (deviceManagement == null) { |
| | | return Result.OK("设å¤ç±»å¯¹è±¡ä¸è½ä¸ºç©º"); |
| | | } |
| | | // æ£æ¥è®¾å¤ç±»åç§°æ¯å¦ææ |
| | | if (!ValidateUtil.validateString(deviceManagement.getDeviceManagementName())) { |
| | | return Result.OK("设å¤ç±»åç§°æ æ"); |
| | | } |
| | | // æ ¹æ®è®¾å¤ç±» ID è·å设å¤ç±»ä¿¡æ¯ |
| | | DeviceManagement existingCutter = super.getById(deviceManagement.getId()); |
| | | if (existingCutter == null) { |
| | | return Result.OK("设å¤ç±»ä¸åå¨"); |
| | | } |
| | | // è¿æ»¤æå½åè¦ç¼è¾ç设å¤ç±»ï¼æ£æ¥æ¯å¦æå
¶ä»è®¾å¤ç±»åå¨ç¸åç¼å· |
| | | List<DeviceManagement> otherCuttersWithSameNo =this.getDeviceManagementList(deviceManagement.getProductionId(),deviceManagement.getDeviceManagementName(),deviceManagement.getDeviceManagementCode()).stream() |
| | | .filter(cut -> !cut.getId().equals(deviceManagement.getId())) |
| | | .collect(Collectors.toList()); |
| | | if (!otherCuttersWithSameNo.isEmpty()) { |
| | | // 妿åå¨é¤å½å设å¤ç±»å¤çå
¶ä»è®¾å¤ç±»ç¼å·éå¤ |
| | | return Result.error("å·²åå¨ç¸åç设å¤ç±»ç¼å·"); |
| | | } |
| | | // å°è¯æ´æ°è®¾å¤ç±»ä¿¡æ¯ |
| | | boolean updated = this.updateById(deviceManagement); |
| | | if (updated) { |
| | | return Result.OK("设å¤ç±»ä¿¡æ¯ç¼è¾æå"); |
| | | } else { |
| | | return Result.error("设å¤ç±»ä¿¡æ¯ç¼è¾å¤±è´¥"); |
| | | } |
| | | } |
| | | /** |
| | | * æ ¹æ®idå é¤è®¾å¤ç±»ä¿¡æ¯ |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> delete(String id){ |
| | | if(!ValidateUtil.validateString(id)) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | DeviceManagement en = super.getById(id); |
| | | if(en == null) |
| | | return Result.error("æ æç设å¤ç±»"); |
| | | List<DeviceType> deviceTypes=deviceTypeService.list(new QueryWrapper<DeviceType>().eq("device_management_id",id)); |
| | | if(deviceTypes != null && !deviceTypes.isEmpty()){ |
| | | return Result.error("该设å¤ç±»å·²è¢«ä½¿ç¨ï¼ä¸è½å é¤"); |
| | | } |
| | | boolean b=super.removeById(id); |
| | | if(!b) { |
| | | return Result.error("å é¤è®¾å¤ç±»å¤±è´¥"); |
| | | } |
| | | return Result.OK("å é¤è®¾å¤ç±»æå"); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤è®¾å¤ç±» |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> deleteBatch(List<String> ids){ |
| | | if(ids == null || ids.isEmpty()) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | return super.removeByIds(ids) ? Result.OK("æ¹éå é¤è®¾å¤ç±»æå") : Result.error("æ¹éå é¤è®¾å¤ç±»å¤±è´¥"); |
| | | } |
| | | |
| | | /** |
| | | * 设å¤ç±»ä¿¡æ¯å页æ¥è¯¢ |
| | | * @param deviceManagement |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> query(DeviceManagement deviceManagement, Integer pageNo, Integer pageSize){ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | List<String> productIdList = Arrays.asList(user.getProductionIds().split(",")); |
| | | QueryWrapper<DeviceManagement> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq(StrUtil.isNotEmpty(deviceManagement.getProductionId()),"production_id",deviceManagement.getProductionId()); |
| | | queryWrapper.like(StrUtil.isNotEmpty(deviceManagement.getDeviceManagementName()),"device_management_name",deviceManagement.getDeviceManagementName()); |
| | | queryWrapper.like(StrUtil.isNotEmpty(deviceManagement.getDeviceManagementCode()),"device_management_code",deviceManagement.getDeviceManagementCode()); |
| | | queryWrapper.in("production_id",productIdList); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | Page<DeviceManagement> page = new Page<>(pageNo, pageSize); |
| | | IPage<DeviceManagement> pageList = super.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è½¦é´idå设å¤ç±»åç§°æ¥è¯¢è®¾å¤ç±»ä¿¡æ¯ |
| | | * @param productionId |
| | | * @parame deviceManagementName |
| | | * @return |
| | | */ |
| | | public List<DeviceManagement> getDeviceManagementList(String productionId,String deviceManagementName,String deviceManagementCode){ |
| | | return super.list(new QueryWrapper<DeviceManagement>() |
| | | .eq(StrUtil.isNotEmpty(productionId),"production_id", productionId) |
| | | .eq(StrUtil.isNotEmpty(deviceManagementName),"device_management_name", deviceManagementName) |
| | | .eq(StrUtil.isNotEmpty(deviceManagementCode),"device_management_code", deviceManagementCode)); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·æéæ¥æç车é´ä¿¡æ¯ |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MdcProduction> getProductionIdsByUserId(String userId){ |
| | | //æéä¿¡æ¯ï¼æ¹ä¸ºç»ææ æé |
| | | List<MdcUserProduction> productionList = userProductionService.list(new QueryWrapper<MdcUserProduction>().eq("user_id", userId)); |
| | | List<String> productionIds = productionList.stream().map(MdcUserProduction::getProId).collect(Collectors.toList()); |
| | | return productionService.list(new QueryWrapper<MdcProduction>().in("id", productionIds) |
| | | .eq("org_type","2")); |
| | | } |
| | | |
| | | /** |
| | | * éè¿è½¦é´idæ¥è¯¢è®¾å¤åè¡¨ä¿¡æ¯ |
| | | * @param productionId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<MdcEquipment> getEquipmentListByProductionId(String productionId,String equipmentId,String equipmentName,Integer pageNo,Integer pageSize){ |
| | | //æ¥è¯¢åèç¹ |
| | | List<String> productionIds = productionService.recursionChildren(productionId); |
| | | if (productionIds == null) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIds = productionEquipmentService.list(new QueryWrapper<MdcProductionEquipment>() |
| | | .in("production_id", productionIds)) |
| | | .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList()); |
| | | if (!equipmentIds.isEmpty()) { |
| | | QueryWrapper<MdcEquipment> queryWrapper = new QueryWrapper<MdcEquipment>() |
| | | .in("id", equipmentIds) |
| | | .like(StrUtil.isNotEmpty(equipmentName),"equipment_name", equipmentName) |
| | | .eq(StrUtil.isNotEmpty(equipmentId),"equipment_id", equipmentId); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | Page<MdcEquipment> page = new Page<>(pageNo, pageSize); |
| | | return equipmentService.page(page, queryWrapper); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * éè¿è½¦é´idæ¥è¯¢è®¾å¤ç±»ç®¡çåè¡¨ä¿¡æ¯ |
| | | * @param productionId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<DeviceManagement> getDeviceManagementListByProductionId(String productionId){ |
| | | QueryWrapper<DeviceManagement> queryWrapper = new QueryWrapper<DeviceManagement>() |
| | | .eq(StrUtil.isNotEmpty(productionId),"production_id", productionId); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | return super.list(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * éè¿idæ¥è¯¢è®¾å¤åè¡¨ä¿¡æ¯ |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MdcEquipment> getEquipmentListById(String id){ |
| | | DeviceManagement deviceManagement = super.getById(id); |
| | | if (deviceManagement == null) { |
| | | return null; |
| | | }else { |
| | | List<String> equipmentIds = Arrays.asList(deviceManagement.getEquipmentIds().split(",")); |
| | | return equipmentService.list(new QueryWrapper<MdcEquipment>() |
| | | .in("equipment_id", equipmentIds)); |
| | | } |
| | | } |
| | | } |