| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.pojo.Customer; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.production.dto.ProductProcessDto; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | @Autowired |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) { |
| | |
| | | productProcessMapper.deleteBatchIds(ids); |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult bindDevices(Long processId, List<Long> deviceIds) { |
| | | ProductProcess productProcess = productProcessMapper.selectById(processId); |
| | | if (productProcess == null) { |
| | | return AjaxResult.error("工序不存在"); |
| | | } |
| | | String deviceIdsJson = productProcess.getDeviceIds(); |
| | | // 获取已有的设备ID列表 |
| | | List<Long> existingDeviceIds = Collections.emptyList(); |
| | | if (StringUtils.isNotEmpty(deviceIdsJson)) { |
| | | existingDeviceIds = JSON.parseArray(deviceIdsJson, Long.class); |
| | | } |
| | | // 合并设备ID(去重) |
| | | List<Long> mergedDeviceIds = new ArrayList<>(existingDeviceIds); |
| | | for (Long deviceId : deviceIds) { |
| | | if (!mergedDeviceIds.contains(deviceId)) { |
| | | mergedDeviceIds.add(deviceId); |
| | | } |
| | | } |
| | | deviceIdsJson = JSON.toJSONString(mergedDeviceIds); |
| | | productProcess.setDeviceIds(deviceIdsJson); |
| | | productProcessMapper.updateById(productProcess); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult unbindDevice(Long processId, Long deviceId) { |
| | | ProductProcess productProcess = productProcessMapper.selectById(processId); |
| | | if (productProcess == null) { |
| | | return AjaxResult.error("工序不存在"); |
| | | } |
| | | if (productProcess.getDeviceIds() == null || productProcess.getDeviceIds().isEmpty()) { |
| | | return AjaxResult.success(); |
| | | } |
| | | List<Long> existingDeviceIds = JSON.parseArray(productProcess.getDeviceIds(), Long.class); |
| | | existingDeviceIds.remove(deviceId); |
| | | String deviceIdsJson = JSON.toJSONString(existingDeviceIds); |
| | | productProcess.setDeviceIds(deviceIdsJson); |
| | | productProcessMapper.updateById(productProcess); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceLedger> getBindDevices(Long processId) { |
| | | ProductProcess productProcess = productProcessMapper.selectById(processId); |
| | | if (productProcess == null || productProcess.getDeviceIds() == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | List<Long> deviceIdList = JSON.parseArray(productProcess.getDeviceIds(), Long.class); |
| | | if (CollectionUtils.isEmpty(deviceIdList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return deviceLedgerMapper.selectBatchIds(deviceIdList); |
| | | } |
| | | } |