|
@@ -1,134 +0,0 @@
|
|
|
-package cn.rankin.productservice.controller.cms;
|
|
|
-
|
|
|
-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.dto.search.TagTypeSearchDTO;
|
|
|
-import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
|
-import cn.rankin.data.api.product.dto.TagTypeDTO;
|
|
|
-import cn.rankin.data.api.product.entity.Tag;
|
|
|
-import cn.rankin.data.api.product.entity.TagType;
|
|
|
-import cn.rankin.productservice.code.ProductServiceAPICode;
|
|
|
-import cn.rankin.productservice.service.TagService;
|
|
|
-import cn.rankin.productservice.service.TagTypeService;
|
|
|
-import org.apache.commons.lang3.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.List;
|
|
|
-
|
|
|
-@RestController
|
|
|
-@RequestMapping(value = "tagType")
|
|
|
-public class TagTypeController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private TagTypeService tagTypeService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private TagService tagService;
|
|
|
-
|
|
|
- @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
- public APIResult<Page<TagType>> search(TagTypeSearchDTO searchDTO) {
|
|
|
- TagType tagType = new TagType();
|
|
|
-
|
|
|
- String code = searchDTO.getCode();
|
|
|
- if (!StringUtils.isEmpty(code)) {
|
|
|
- tagType.setCode("%" + code + "%");
|
|
|
- }
|
|
|
-
|
|
|
- String name = searchDTO.getName();
|
|
|
- if (!StringUtils.isEmpty(name)) {
|
|
|
- tagType.setName("%" + name + "%");
|
|
|
- }
|
|
|
-
|
|
|
-// // others
|
|
|
-// tagType.setMerchantId(searchDTO.getMerchantId());
|
|
|
-
|
|
|
- // sort
|
|
|
- LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
|
|
|
- sort.put("gmtModified", BaseOrderEnum.DESC);
|
|
|
-
|
|
|
- Page<TagType> pageResult = tagTypeService.search(tagType, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
|
|
|
-
|
|
|
-
|
|
|
- return APIResult.ok(pageResult);
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @RequestMapping(method = RequestMethod.POST)
|
|
|
- public APIResult<TagType> create(@Valid @RequestBody TagTypeDTO tagTypeDTO) {
|
|
|
- TagType tagType = tagTypeService.create(tagTypeDTO);
|
|
|
- if(tagType == null){
|
|
|
- return APIResult.error(APICode.ALREADY_EXISTS);
|
|
|
- }else{
|
|
|
- return APIResult.ok(tagType);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(method = RequestMethod.PUT)
|
|
|
- public APIResult<TagType> update(@RequestBody TagTypeDTO tagTypeDTO) {
|
|
|
-
|
|
|
- TagType tagType = tagTypeService.update(tagTypeDTO);
|
|
|
- return APIResult.ok(tagType);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "/{tagTypeId}", method = RequestMethod.DELETE)
|
|
|
- public APIResult<Boolean> delete(@PathVariable("tagTypeId") String tagTypeId) {
|
|
|
-
|
|
|
- Boolean flag = tagTypeService.delete(tagTypeId);
|
|
|
- if(flag){
|
|
|
- return APIResult.ok();
|
|
|
- }else{
|
|
|
- return APIResult.error(ProductServiceAPICode.error("删除失败"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "/{tagTypeId}", method = RequestMethod.GET)
|
|
|
- public APIResult<TagType> getTagType(@PathVariable("tagTypeId") String tagTypeId, @RequestParam("merchantId") String merchantId) {
|
|
|
- TagType tagType = tagTypeService.getTagType(tagTypeId);
|
|
|
-
|
|
|
- if (tagType == null) {
|
|
|
- return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
|
|
|
- }else{
|
|
|
-
|
|
|
- //开始组装数据
|
|
|
- List<Tag> tagList = tagService.findByTypeCode(tagType.getCode(),merchantId);
|
|
|
- tagType.setTagList(tagList);
|
|
|
-
|
|
|
-
|
|
|
- return APIResult.ok(tagType);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-/* @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
|
|
|
- public APIResult<List<Tag>> getTagTypeByCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
|
|
|
- TagType tagType = tagTypeService.getTagTypeByCode(typeCode);
|
|
|
- if (tagType == null) {
|
|
|
- return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
|
|
|
- }else{
|
|
|
-
|
|
|
- //开始组装数据
|
|
|
-
|
|
|
- //标签列表数据
|
|
|
- List<Tag> tagList = tagService.findByTypeCode(typeCode,merchantId);
|
|
|
-
|
|
|
- //标签下 课程数据
|
|
|
- tagList.forEach(tag -> {
|
|
|
- String tagId = tag.getId();
|
|
|
- List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
|
|
|
- tag.setRecs(itemVoList);
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- return APIResult.ok(tagList);
|
|
|
- }
|
|
|
-
|
|
|
- }*/
|
|
|
-}
|