diff --git a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java index 12683ccc..1697f493 100644 --- a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java +++ b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java @@ -34,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.IOException; import java.io.InputStream; @@ -992,11 +993,11 @@ public class ProductModelController extends ControllerBase{ /** * 保存资料排序 - * @param request 请求参数 + * @param ids 排序后的id列表 */ @PostMapping("/saveFileSort") - public ApiResult saveFileSort(@Valid @RequestBody SortSaveRequest request){ - productModelFileService.saveSort(request); + public ApiResult saveFileSort(@Valid @RequestBody @NotEmpty List ids) { + productModelFileService.saveSort(ids); return ApiResult.success(); } diff --git a/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SortSaveNewRequest.java b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SortSaveNewRequest.java new file mode 100644 index 00000000..d1b52e47 --- /dev/null +++ b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/request/SortSaveNewRequest.java @@ -0,0 +1,23 @@ +package com.nflg.mobilebroken.common.pojo.request; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +public class SortSaveNewRequest { + + /** + * 机型id + */ + @NotNull + private Integer modelId; + + /** + * 调整后的顺序 + */ + @NotEmpty + private List ids; +} diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IProductModelFileService.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IProductModelFileService.java index e5307452..3f7108f2 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IProductModelFileService.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IProductModelFileService.java @@ -41,7 +41,7 @@ public interface IProductModelFileService extends IService { List getListForSort(Integer modelId); - void saveSort(SortSaveRequest request); + void saveSort(List ids); void copyItems(Integer oldId, Integer newId); diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelFileServiceImpl.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelFileServiceImpl.java index 835e5a2a..2b93511f 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelFileServiceImpl.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelFileServiceImpl.java @@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.nflg.mobilebroken.common.constant.PublishState; -import com.nflg.mobilebroken.common.constant.STATE; -import com.nflg.mobilebroken.common.exception.NflgException; import com.nflg.mobilebroken.common.pojo.request.*; import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigItemVO; import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigVO; @@ -206,22 +204,13 @@ public class ProductModelFileServiceImpl extends ServiceImpl datas = lambdaQuery() - .select(ProductModelFile::getId, ProductModelFile::getSort) - .in(ProductModelFile::getId, request.getId(), request.getPreviousId(), request.getNextId()) - .list(); - ProductModelFile current = datas.stream().filter(data -> data.getId().equals(request.getId())).findFirst().orElseThrow( - () -> new NflgException(STATE.BusinessError, "无效的数据") - ); - ProductModelFile previous = datas.stream().filter(data -> data.getId().equals(request.getPreviousId())).findFirst().orElse(null); - ProductModelFile next = datas.stream().filter(data -> data.getId().equals(request.getNextId())).findFirst().orElse(null); - if (Objects.isNull(previous)) { - current.setSort(next.getSort() / 2); - } else if (Objects.isNull(next)) { - current.setSort(previous.getSort() * 2); - } else { - current.setSort((previous.getSort() + next.getSort()) / 2); + public void saveSort(List ids) { + List datas = new ArrayList<>(); + for (int i = 0; i < ids.size(); i++) { + datas.add(new ProductModelFile() + .setId(ids.get(i)) + .setSort(i + 1) + ); } updateBatchById(datas); } diff --git a/nflg-mobilebroken-repository/src/main/resources/mapper/ProductModelFileMapper.xml b/nflg-mobilebroken-repository/src/main/resources/mapper/ProductModelFileMapper.xml index 78ecf0af..4dfe1a86 100644 --- a/nflg-mobilebroken-repository/src/main/resources/mapper/ProductModelFileMapper.xml +++ b/nflg-mobilebroken-repository/src/main/resources/mapper/ProductModelFileMapper.xml @@ -25,5 +25,6 @@ FROM product_model_file pmf INNER JOIN product_model_file_item pmfi ON pmf.id = pmfi.model_file_id WHERE pmf.`enable` = 1 AND pmf.state = 1 AND pmf.model_id = #{modelId} AND pmfi.language_code = #{language} + ORDER BY pmf.sort