|
@@ -0,0 +1,138 @@
|
|
|
+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.*;
|
|
|
+import cn.rankin.productservice.code.ProductServiceAPICode;
|
|
|
+import cn.rankin.productservice.repository.ProductRepository;
|
|
|
+import cn.rankin.productservice.service.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "poster")
|
|
|
+public class PosterController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PosterService posterService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductRepository productRepository;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
+ public APIResult<Page<Poster>> search(@Valid @RequestBody 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());
|
|
|
+
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
|
|
+ public APIResult<Poster> getPoster(@PathVariable("id") String id) {
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ return APIResult.error(APICode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ Poster result = posterService.findById(id);
|
|
|
+ if(null == result){
|
|
|
+ return APIResult.error(APICode.NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// Product product = productService.find(result.getPid());
|
|
|
+ Product product = productRepository.findByPid(result.getPid());
|
|
|
+ result.setProduct(product);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return APIResult.ok(result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @RequestMapping(method = RequestMethod.POST)
|
|
|
+ public APIResult<Poster> create(@Valid @RequestBody PosterDTO posterDTO) {
|
|
|
+ try{
|
|
|
+ // 创建海报
|
|
|
+ Poster result = posterService.create(posterDTO);
|
|
|
+ if (null == result) {
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+ return APIResult.ok(result);
|
|
|
+ }catch(Exception e){
|
|
|
+ log.info("poster create error: message={}",e.getMessage());
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @RequestMapping(method = RequestMethod.PUT)
|
|
|
+ public APIResult<Poster> update(@Valid @RequestBody PosterDTO posterDTO) {
|
|
|
+ String Id = posterDTO.getId();
|
|
|
+ if (Id == null) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return APIResult.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
|
|
+ public APIResult delete(@PathVariable("id") String id) {
|
|
|
+ Boolean flag = posterService.delete(id);
|
|
|
+ if(flag){
|
|
|
+ return APIResult.ok();
|
|
|
+ }else{
|
|
|
+ return APIResult.error(ProductServiceAPICode.error("删除失败"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|