| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.production.dto.ProcessRouteItemDto; |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ProcessRouteItemServiceImpl extends ServiceImpl<ProcessRouteItemMapper, ProcessRouteItem> implements ProcessRouteItemService { |
| | | |
| | | @Autowired |
| | |
| | | public List<ProcessRouteItemDto> listProcessRouteItemDto(ProcessRouteItemDto processRouteItemDto) { |
| | | return processRouteItemMapper.listProcessRouteItemDto( processRouteItemDto); |
| | | } |
| | | |
| | | //排序 |
| | | @Override |
| | | public int sort(ProcessRouteItem processRouteItem) { |
| | | //查询被改动的这条数据 |
| | | ProcessRouteItem oldProcessRouteItem = processRouteItemMapper.selectById(processRouteItem.getId()); |
| | | //查询该工艺路线的所有工序并按照顺序排序 |
| | | List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(Wrappers.<ProcessRouteItem>lambdaQuery() |
| | | .eq(ProcessRouteItem::getRouteId, oldProcessRouteItem.getRouteId()) |
| | | .orderByAsc(ProcessRouteItem::getDragSort)); |
| | | // 获取目标位置(移动到第几个之后) |
| | | Integer targetPosition = processRouteItem.getDragSort(); |
| | | if (targetPosition != null && targetPosition >= 0) { |
| | | // 移动元素到新的位置 |
| | | processRouteItems.remove(oldProcessRouteItem); |
| | | processRouteItems.add(targetPosition-1, oldProcessRouteItem); |
| | | // 更新所有受影响的排序字段 |
| | | for (int i = 0; i < processRouteItems.size(); i++) { |
| | | ProcessRouteItem item = processRouteItems.get(i); |
| | | if (!item.getId().equals(oldProcessRouteItem.getId())) { |
| | | // 检查是否需要更新排序值 |
| | | if (item.getDragSort() != i+1) { |
| | | item.setDragSort(i+1); |
| | | processRouteItemMapper.updateById(item); |
| | | } |
| | | } else { |
| | | // 更新原记录的新排序位置 |
| | | oldProcessRouteItem.setDragSort(targetPosition); |
| | | processRouteItemMapper.updateById(oldProcessRouteItem); |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public String batchDelete(Long id) { |
| | | // 查询要删除的数据 |
| | | ProcessRouteItem deleteProcessRouteItem = processRouteItemMapper.selectById(id); |
| | | if (deleteProcessRouteItem == null) { |
| | | return "删除失败,未找到对应数据"; |
| | | } |
| | | Long routeId = deleteProcessRouteItem.getRouteId(); |
| | | // 删除指定数据 |
| | | processRouteItemMapper.deleteById(id); |
| | | // 查询该工艺路线的所有工序并按照顺序排序 |
| | | List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(Wrappers.<ProcessRouteItem>lambdaQuery() |
| | | .eq(ProcessRouteItem::getRouteId, routeId) |
| | | .orderByAsc(ProcessRouteItem::getDragSort)); |
| | | // 重新设置排序值,使序号连续 |
| | | for (int i = 0; i < processRouteItems.size(); i++) { |
| | | ProcessRouteItem item = processRouteItems.get(i); |
| | | if (!item.getDragSort().equals(i+1)) { |
| | | item.setDragSort(i+1); |
| | | processRouteItemMapper.updateById(item); |
| | | } |
| | | } |
| | | return "删除成功"; |
| | | } |
| | | } |