Merge branch 'feature/product' into develop
This commit is contained in:
commit
62ce622d9b
|
|
@ -34,7 +34,6 @@ 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;
|
||||||
|
|
@ -993,11 +992,11 @@ public class ProductModelController extends ControllerBase{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存资料排序
|
* 保存资料排序
|
||||||
* @param ids 排序后的id列表
|
* @param request 请求参数
|
||||||
*/
|
*/
|
||||||
@PostMapping("/saveFileSort")
|
@PostMapping("/saveFileSort")
|
||||||
public ApiResult<Void> saveFileSort(@Valid @RequestBody @NotEmpty List<Integer> ids) {
|
public ApiResult<Void> saveFileSort(@Valid @RequestBody SortSaveRequest request) {
|
||||||
productModelFileService.saveSort(ids);
|
productModelFileService.saveSort(request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public interface IProductModelFileService extends IService<ProductModelFile> {
|
||||||
|
|
||||||
List<ProductModelFile> getListForSort(Integer modelId);
|
List<ProductModelFile> getListForSort(Integer modelId);
|
||||||
|
|
||||||
void saveSort(List<Integer> ids);
|
void saveSort(SortSaveRequest request);
|
||||||
|
|
||||||
void copyItems(Integer oldId, Integer newId);
|
void copyItems(Integer oldId, Integer newId);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,10 +73,12 @@ public class ProductModelFileItemServiceImpl extends ServiceImpl<ProductModelFil
|
||||||
.eq(ProductModelFileItem::getModelId, request.getModelId())
|
.eq(ProductModelFileItem::getModelId, request.getModelId())
|
||||||
.update();
|
.update();
|
||||||
request.getItems().forEach(item -> {
|
request.getItems().forEach(item -> {
|
||||||
lambdaUpdate()
|
if (Objects.nonNull(item.getFileItemId())) {
|
||||||
.set(ProductModelFileItem::getShowInList, true)
|
lambdaUpdate()
|
||||||
.eq(ProductModelFileItem::getId, item.getFileItemId())
|
.set(ProductModelFileItem::getShowInList, true)
|
||||||
.update();
|
.eq(ProductModelFileItem::getId, item.getFileItemId())
|
||||||
|
.update();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ 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;
|
||||||
|
|
@ -27,7 +29,6 @@ import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -204,13 +205,22 @@ public class ProductModelFileServiceImpl extends ServiceImpl<ProductModelFileMap
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void saveSort(List<Integer> ids) {
|
public void saveSort(SortSaveRequest request) {
|
||||||
List<ProductModelFile> datas = new ArrayList<>();
|
List<ProductModelFile> datas = lambdaQuery()
|
||||||
for (int i = 0; i < ids.size(); i++) {
|
.select(ProductModelFile::getId, ProductModelFile::getSort)
|
||||||
datas.add(new ProductModelFile()
|
.in(ProductModelFile::getId, request.getId(), request.getPreviousId(), request.getNextId())
|
||||||
.setId(ids.get(i))
|
.list();
|
||||||
.setSort(i + 1)
|
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);
|
updateBatchById(datas);
|
||||||
}
|
}
|
||||||
|
|
@ -229,25 +239,20 @@ public class ProductModelFileServiceImpl extends ServiceImpl<ProductModelFileMap
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<FileDefaultConfigVO> getDefaultConfig(Integer modelId) {
|
public List<FileDefaultConfigVO> getDefaultConfig(Integer modelId) {
|
||||||
List<Language> languages = languageService.getAllLanguages();
|
|
||||||
// List<ProductModelFileItem> list = productModelFileItemService.lambdaQuery()
|
|
||||||
// .eq(ProductModelFileItem::getModelId, modelId)
|
|
||||||
// .orderByAsc(ProductModelFileItem::getLanguageCode)
|
|
||||||
// .orderByDesc(ProductModelFileItem::getShowInList)
|
|
||||||
// .list();
|
|
||||||
List<ProductModelFileItem> list =productModelFileItemService.getPublishedByLanguage(modelId);
|
|
||||||
List<FileDefaultConfigVO> vos=new ArrayList<>();
|
List<FileDefaultConfigVO> vos=new ArrayList<>();
|
||||||
Map<String, List<ProductModelFileItem>> maps=list.stream().collect(Collectors.groupingBy(ProductModelFileItem::getLanguageCode));
|
List<Language> languages = languageService.getLanguages();
|
||||||
maps.forEach((languageCode,data)->{
|
List<ProductModelFileItem> list = productModelFileItemService.getPublishedByLanguage(modelId);
|
||||||
FileDefaultConfigVO vo=new FileDefaultConfigVO()
|
languages.forEach(language -> {
|
||||||
.setLanguageCode(languageCode)
|
FileDefaultConfigVO vo = new FileDefaultConfigVO()
|
||||||
.setLanguageName(languages.stream().filter(lang->lang.getCode().equals(languageCode)).findFirst().get().getName())
|
.setLanguageCode(language.getCode())
|
||||||
.setItems(data.stream().map(item->new FileDefaultConfigItemVO()
|
.setLanguageName(language.getName())
|
||||||
.setId(item.getId())
|
.setItems(list.stream().filter(item -> StrUtil.equals(language.getCode(), item.getLanguageCode()))
|
||||||
.setName(item.getName())
|
.map(item -> {
|
||||||
.setSelected(item.getShowInList()))
|
return new FileDefaultConfigItemVO()
|
||||||
.collect(Collectors.toList())
|
.setId(item.getId())
|
||||||
);
|
.setName(item.getName())
|
||||||
|
.setSelected(item.getShowInList());
|
||||||
|
}).collect(Collectors.toList()));
|
||||||
vos.add(vo);
|
vos.add(vo);
|
||||||
});
|
});
|
||||||
return vos;
|
return vos;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue