feat: bug-565 产品机型详情页面,产品资料这里展示是有顺序的,需要在后台增加排序功能
This commit is contained in:
parent
0c7845bb62
commit
4a3d096ac2
|
|
@ -34,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -992,11 +993,11 @@ public class ProductModelController extends ControllerBase{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存资料排序
|
* 保存资料排序
|
||||||
* @param request 请求参数
|
* @param ids 排序后的id列表
|
||||||
*/
|
*/
|
||||||
@PostMapping("/saveFileSort")
|
@PostMapping("/saveFileSort")
|
||||||
public ApiResult<Void> saveFileSort(@Valid @RequestBody SortSaveRequest request){
|
public ApiResult<Void> saveFileSort(@Valid @RequestBody @NotEmpty List<Integer> ids) {
|
||||||
productModelFileService.saveSort(request);
|
productModelFileService.saveSort(ids);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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<Integer> ids;
|
||||||
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ public interface IProductModelFileService extends IService<ProductModelFile> {
|
||||||
|
|
||||||
List<ProductModelFile> getListForSort(Integer modelId);
|
List<ProductModelFile> getListForSort(Integer modelId);
|
||||||
|
|
||||||
void saveSort(SortSaveRequest request);
|
void saveSort(List<Integer> ids);
|
||||||
|
|
||||||
void copyItems(Integer oldId, Integer newId);
|
void copyItems(Integer oldId, Integer newId);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.nflg.mobilebroken.common.constant.PublishState;
|
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.request.*;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigItemVO;
|
import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigItemVO;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigVO;
|
import com.nflg.mobilebroken.common.pojo.vo.FileDefaultConfigVO;
|
||||||
|
|
@ -206,22 +204,13 @@ public class ProductModelFileServiceImpl extends ServiceImpl<ProductModelFileMap
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void saveSort(SortSaveRequest request) {
|
public void saveSort(List<Integer> ids) {
|
||||||
List<ProductModelFile> datas = lambdaQuery()
|
List<ProductModelFile> datas = new ArrayList<>();
|
||||||
.select(ProductModelFile::getId, ProductModelFile::getSort)
|
for (int i = 0; i < ids.size(); i++) {
|
||||||
.in(ProductModelFile::getId, request.getId(), request.getPreviousId(), request.getNextId())
|
datas.add(new ProductModelFile()
|
||||||
.list();
|
.setId(ids.get(i))
|
||||||
ProductModelFile current = datas.stream().filter(data -> data.getId().equals(request.getId())).findFirst().orElseThrow(
|
.setSort(i + 1)
|
||||||
() -> 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);
|
updateBatchById(datas);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,6 @@
|
||||||
FROM product_model_file pmf
|
FROM product_model_file pmf
|
||||||
INNER JOIN product_model_file_item pmfi ON pmf.id = pmfi.model_file_id
|
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}
|
WHERE pmf.`enable` = 1 AND pmf.state = 1 AND pmf.model_id = #{modelId} AND pmfi.language_code = #{language}
|
||||||
|
ORDER BY pmf.sort
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue