|
@@ -1,17 +1,29 @@
|
|
|
package cn.rankin.productservice.controller;
|
|
|
|
|
|
+import cn.rankin.common.utils.api.model.APICode;
|
|
|
import cn.rankin.common.utils.api.model.APICodeManager;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
|
import cn.rankin.common.utils.dto.product.TagDTO;
|
|
|
-import cn.rankin.common.utils.dto.search.TagSearchDTO;
|
|
|
+import cn.rankin.common.utils.enums.*;
|
|
|
+import cn.rankin.productservice.entity.Item;
|
|
|
+import cn.rankin.productservice.entity.ItemTagRelation;
|
|
|
import cn.rankin.productservice.entity.Tag;
|
|
|
+import cn.rankin.productservice.service.ItemService;
|
|
|
+import cn.rankin.productservice.service.ItemTagRelationService;
|
|
|
import cn.rankin.productservice.service.TagService;
|
|
|
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.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping(value = "tag")
|
|
@@ -20,53 +32,133 @@ public class TagController {
|
|
|
@Autowired
|
|
|
private TagService tagService;
|
|
|
|
|
|
- @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
- public APIResult<Page<Tag>> search(TagSearchDTO searchDTO) {
|
|
|
- Tag tag = new Tag();
|
|
|
-
|
|
|
- String code = searchDTO.getCode();
|
|
|
- if (!StringUtils.isEmpty(code)) {
|
|
|
- tag.setCode("%" + code + "%");
|
|
|
- }
|
|
|
-
|
|
|
- String name = searchDTO.getName();
|
|
|
- if (!StringUtils.isEmpty(name)) {
|
|
|
- tag.setName("%" + name + "%");
|
|
|
- }
|
|
|
-
|
|
|
- String merchantId = searchDTO.getMerchantId();
|
|
|
- if (merchantId != null) {
|
|
|
- tag.setMerchantId(merchantId);
|
|
|
- }
|
|
|
-
|
|
|
- return tagService.search(tag, searchDTO.getPageNo(), searchDTO.getPageSize());
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(method = RequestMethod.POST)
|
|
|
- public APIResult<Tag> create(@RequestBody TagDTO tagDTO) {
|
|
|
- String code = tagDTO.getCode();
|
|
|
- if (StringUtils.isEmpty(code)) {
|
|
|
- return APIResult.error(APICodeManager.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- return tagService.create(tagDTO);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(method = RequestMethod.PUT)
|
|
|
- public APIResult<Tag> update(@RequestBody TagDTO tagDTO) {
|
|
|
- if (tagDTO.getId() == null) {
|
|
|
- return APIResult.error(APICodeManager.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- return tagService.update(tagDTO);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private ItemTagRelationService tagRelationService;
|
|
|
|
|
|
- @RequestMapping(value = "/{code}", method = RequestMethod.DELETE)
|
|
|
- public APIResult<Boolean> delete(@PathVariable String code) {
|
|
|
- if (StringUtils.isEmpty(code)) {
|
|
|
- return APIResult.error(APICodeManager.PARAMETER_ERROR);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private ItemService itemService;
|
|
|
|
|
|
- return tagService.delete(code);
|
|
|
- }
|
|
|
+// @RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
|
|
+// public APIResult<Tag> getTag(@PathVariable String id) {
|
|
|
+// APIResult<Tag> result = tagService.findById(id);
|
|
|
+// Tag tag = result.getData();
|
|
|
+// if (tag == null) {
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// APIResult<List<Item>> itemResult = getTagItem(tag.getId());
|
|
|
+// tag.setItemList(itemResult.getData());
|
|
|
+//
|
|
|
+// return result;
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Transactional
|
|
|
+// @RequestMapping(method = RequestMethod.POST)
|
|
|
+// public APIResult<Tag> create(@RequestBody TagDTO tagDTO) {
|
|
|
+//
|
|
|
+// APIResult<Tag> result = tagService.create(tagDTO);
|
|
|
+// Tag tag = result.getData();
|
|
|
+//
|
|
|
+// List<String> itemIdList = tagDTO.getItemList();
|
|
|
+// if (itemIdList == null || tag == null) {
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// APIResult<List<Item>> relationResult = updateTagRelation(tag, itemIdList);
|
|
|
+// if (!relationResult.getSuccess()) {
|
|
|
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+// return APIResult.error(new APICode(relationResult.getCode(), relationResult.getMessage()));
|
|
|
+// }
|
|
|
+// tag.setItemList(relationResult.getData());
|
|
|
+//
|
|
|
+// return result;
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Transactional
|
|
|
+// @RequestMapping(method = RequestMethod.PUT)
|
|
|
+// public APIResult<Tag> update(@RequestBody TagDTO tagDTO) {
|
|
|
+// if (tagDTO.getId() == null) {
|
|
|
+// return APIResult.error(APICodeManager.PARAMETER_ERROR);
|
|
|
+// }
|
|
|
+//
|
|
|
+// APIResult<Tag> result = tagService.update(tagDTO);
|
|
|
+// Tag tag = result.getData();
|
|
|
+//
|
|
|
+// List<String> itemIdList = tagDTO.getItemList();
|
|
|
+// if (itemIdList == null || tag == null) {
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// APIResult<List<Item>> relationResult = updateTagRelation(tag, itemIdList);
|
|
|
+// if (!relationResult.getSuccess()) {
|
|
|
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+// return APIResult.error(new APICode(relationResult.getCode(), relationResult.getMessage()));
|
|
|
+// }
|
|
|
+// tag.setItemList(relationResult.getData());
|
|
|
+//
|
|
|
+// return tagService.update(tagDTO);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @RequestMapping(value = "/id", method = RequestMethod.DELETE)
|
|
|
+// public APIResult delete(@PathVariable String id) {
|
|
|
+// if (StringUtils.isEmpty(id)) {
|
|
|
+// return APIResult.error(APICodeManager.PARAMETER_ERROR);
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<ItemTagRelation> relationList = tagRelationService.findAllByTagId(id);
|
|
|
+// if (CollectionUtils.isEmpty(relationList)) {
|
|
|
+// return tagService.delete(id);
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<String> itemIdList = new ArrayList<>();
|
|
|
+// relationList.forEach( relation -> {
|
|
|
+// String itemId = relation.getItemId();
|
|
|
+// if (itemId != null && !itemIdList.contains(itemId)) {
|
|
|
+// itemIdList.add(itemId);
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// List<Item> itemList = itemService.findAllByIds(itemIdList).getData();
|
|
|
+//
|
|
|
+// APIResult<List<Item>> result = APIResult.error(APICodeManager.CAN_NOT_DEL);
|
|
|
+// result.setData(itemList);
|
|
|
+//
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Transactional
|
|
|
+// public APIResult<List<Item>> updateTagRelation(Tag tag, List<String> itemIdList) {
|
|
|
+// List<Item> itemList = itemService.findAllByIds(itemIdList).getData();
|
|
|
+// if (itemList == null || itemList.size() != itemIdList.size()) {
|
|
|
+// return APIResult.error(APICodeManager.error("itemId不匹配"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// TagTypeEnum tagType = tag.getType();
|
|
|
+// String merchantId = tag.getMerchantId();
|
|
|
+// for (int i = 0; i < itemList.size(); i++) {
|
|
|
+// Item item = itemList.get(i);
|
|
|
+// if (!item.getMerchantId().equals(merchantId) || !EnumUtil.compare(item.getType(), tagType)) {
|
|
|
+// return APIResult.error(APICodeManager.error("类型或渠道商不匹配"));
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// tagRelationService.updateByTag(tag.getId(), itemIdList);
|
|
|
+// return APIResult.ok(itemList);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public APIResult<List<Item>> getTagItem(String tagId) {
|
|
|
+// List<ItemTagRelation> relationList = tagRelationService.findByTagId(tagId);
|
|
|
+// if (relationList == null || relationList.size() == 0) {
|
|
|
+// return APIResult.ok();
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<String> itemIdList = new ArrayList<>();
|
|
|
+// relationList.forEach( relation -> itemIdList.add(relation.getItemId()));
|
|
|
+//
|
|
|
+// // 返回上架的item
|
|
|
+// return itemService.findAllByIds(itemIdList, ItemStatusEnum.DEL);
|
|
|
+//
|
|
|
+// }
|
|
|
}
|