feat: bug-565 产品机型详情页面,产品资料这里展示是有顺序的,需要在后台增加排序功能
This commit is contained in:
parent
b40ceda0eb
commit
7fd5bbb19e
|
|
@ -34,7 +34,6 @@ 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;
|
||||
|
|
@ -993,11 +992,11 @@ public class ProductModelController extends ControllerBase{
|
|||
|
||||
/**
|
||||
* 保存资料排序
|
||||
* @param ids 排序后的id列表
|
||||
* @param request 请求参数
|
||||
*/
|
||||
@PostMapping("/saveFileSort")
|
||||
public ApiResult<Void> saveFileSort(@Valid @RequestBody @NotEmpty List<Integer> ids) {
|
||||
productModelFileService.saveSort(ids);
|
||||
public ApiResult<Void> saveFileSort(@Valid @RequestBody SortSaveRequest request) {
|
||||
productModelFileService.saveSort(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public interface IProductModelFileService extends IService<ProductModelFile> {
|
|||
|
||||
List<ProductModelFile> getListForSort(Integer modelId);
|
||||
|
||||
void saveSort(List<Integer> ids);
|
||||
void saveSort(SortSaveRequest request);
|
||||
|
||||
void copyItems(Integer oldId, Integer newId);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ 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;
|
||||
|
|
@ -203,13 +205,22 @@ public class ProductModelFileServiceImpl extends ServiceImpl<ProductModelFileMap
|
|||
|
||||
@Transactional
|
||||
@Override
|
||||
public void saveSort(List<Integer> ids) {
|
||||
List<ProductModelFile> datas = new ArrayList<>();
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
datas.add(new ProductModelFile()
|
||||
.setId(ids.get(i))
|
||||
.setSort(i + 1)
|
||||
);
|
||||
public void saveSort(SortSaveRequest request) {
|
||||
List<ProductModelFile> 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);
|
||||
}
|
||||
updateBatchById(datas);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue