Merge branch 'feature/product' into develop

This commit is contained in:
曹鹏飞 2025-08-12 17:39:31 +08:00
commit fe6c3cc27a
5 changed files with 36 additions and 22 deletions

View File

@ -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<Void> saveFileSort(@Valid @RequestBody SortSaveRequest request){
productModelFileService.saveSort(request);
public ApiResult<Void> saveFileSort(@Valid @RequestBody @NotEmpty List<Integer> ids) {
productModelFileService.saveSort(ids);
return ApiResult.success();
}

View File

@ -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;
}

View File

@ -41,7 +41,7 @@ public interface IProductModelFileService extends IService<ProductModelFile> {
List<ProductModelFile> getListForSort(Integer modelId);
void saveSort(SortSaveRequest request);
void saveSort(List<Integer> ids);
void copyItems(Integer oldId, Integer newId);

View File

@ -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<ProductModelFileMap
@Transactional
@Override
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);
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)
);
}
updateBatchById(datas);
}

View File

@ -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
</select>
</mapper>