|
@@ -2,7 +2,6 @@ package cn.rankin.productservice.controller;
|
|
|
|
|
|
import cn.rankin.common.utils.api.model.APICode;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
-import cn.rankin.common.utils.api.page.Page;
|
|
|
import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
|
import cn.rankin.data.api.product.dto.PosterDTO;
|
|
|
import cn.rankin.data.api.product.entity.*;
|
|
@@ -17,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.LinkedHashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -28,42 +27,29 @@ public class PosterController {
|
|
|
private PosterService posterService;
|
|
|
|
|
|
@Autowired
|
|
|
- private ProductService productService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private ProductRepository productRepository;
|
|
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
- public APIResult<Page<Poster>> search(PosterDTO searchDTO) {
|
|
|
+ public APIResult<List<Poster>> search(PosterDTO searchDTO) {
|
|
|
Poster poster = new Poster();
|
|
|
|
|
|
-/* String code = searchDTO.getCode();
|
|
|
- if (!StringUtils.isEmpty(code)) {
|
|
|
- lesson.setCode("%" + code + "%");
|
|
|
- }
|
|
|
-
|
|
|
- String name = searchDTO.getName();
|
|
|
- if (!StringUtils.isEmpty(name)) {
|
|
|
- lesson.setTitle("%" + name + "%");
|
|
|
- }*/
|
|
|
-
|
|
|
poster.setStatus(searchDTO.getStatus());
|
|
|
poster.setMerchantId(searchDTO.getMerchantId());
|
|
|
poster.setPid(searchDTO.getPid());
|
|
|
- poster.setStatus(searchDTO.getStatus());
|
|
|
// sort
|
|
|
LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap() { {
|
|
|
this.put("gmtModified", BaseOrderEnum.DESC);
|
|
|
}};
|
|
|
|
|
|
- Page<Poster> posterPage = posterService.search(poster, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
|
|
|
-
|
|
|
- return APIResult.ok(posterPage);
|
|
|
+ List<Poster> posters = posterService.search(poster , sort);
|
|
|
+ posters.forEach(entity ->{
|
|
|
+ setProductInfo(entity);
|
|
|
+ } );
|
|
|
+ return APIResult.ok(posters);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
|
|
public APIResult<Poster> getPoster(@PathVariable("id") String id) {
|
|
|
-
|
|
|
if (StringUtils.isEmpty(id)) {
|
|
|
return APIResult.error(APICode.PARAMETER_ERROR);
|
|
|
}
|
|
@@ -73,15 +59,8 @@ public class PosterController {
|
|
|
return APIResult.error(APICode.NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// Product product = productService.find(result.getPid());
|
|
|
- Product product = productRepository.findByPid(result.getPid());
|
|
|
- result.setProduct(product);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ setProductInfo(result);
|
|
|
return APIResult.ok(result);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -93,6 +72,7 @@ public class PosterController {
|
|
|
if (null == result) {
|
|
|
return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
}
|
|
|
+ setProductInfo(result);
|
|
|
return APIResult.ok(result);
|
|
|
}catch(Exception e){
|
|
|
log.info("poster create error: message={}",e.getMessage());
|
|
@@ -109,22 +89,12 @@ public class PosterController {
|
|
|
return APIResult.error(APICode.error("参数错误: id不能为空"));
|
|
|
}
|
|
|
|
|
|
-/* List<String> wareIdList = lessonDTO.getWareList();
|
|
|
- List<CourseWare> courseWareList = new ArrayList<>();
|
|
|
- if (wareIdList != null) {
|
|
|
- APIResult<List<CourseWare>> wareResult = updateRelation(Id, wareIdList);
|
|
|
- if (!wareResult.getSuccess()) {
|
|
|
- return APIResult.error(new BaseCode(wareResult.getCode(), wareResult.getMessage()));
|
|
|
- }else {
|
|
|
- courseWareList = wareResult.getData();
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
Poster result = posterService.update(posterDTO);
|
|
|
if (null == result) {
|
|
|
return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
}
|
|
|
|
|
|
+ setProductInfo(result);
|
|
|
return APIResult.ok(result);
|
|
|
}
|
|
|
|
|
@@ -137,4 +107,39 @@ public class PosterController {
|
|
|
return APIResult.error(ProductServiceAPICode.error("删除失败"));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/updatePosters/{merchantId}", method = RequestMethod.PUT)
|
|
|
+ public APIResult<List<Poster>> updatePosters(@RequestParam("merchantId") String merchantId,
|
|
|
+ @RequestBody List<String> posterIdList){
|
|
|
+ List<Poster> posters = posterService.updatePosters(merchantId, posterIdList);
|
|
|
+
|
|
|
+ posters.forEach(poster ->{
|
|
|
+ setProductInfo(poster);
|
|
|
+ });
|
|
|
+ return APIResult.ok(posters);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/getPosters/{merchantId}", method = RequestMethod.GET)
|
|
|
+ public APIResult<List<Poster>> getPosters(@RequestParam("merchantId") String merchantId){
|
|
|
+ List<Poster> posters = posterService.getByMerchantId(merchantId);
|
|
|
+
|
|
|
+ posters.forEach(poster ->{
|
|
|
+ setProductInfo(poster);
|
|
|
+ });
|
|
|
+ return APIResult.ok(posters);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装产品信息
|
|
|
+ * @param poster
|
|
|
+ */
|
|
|
+ private void setProductInfo(Poster poster) {
|
|
|
+ if(null == poster){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ Product product = productRepository.findByPid(poster.getPid());
|
|
|
+ poster.setProduct(product);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|