|
@@ -5,6 +5,7 @@ import cn.rankin.common.utils.api.model.APICodeManager;
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
import cn.rankin.common.utils.dto.product.TagDTO;
|
|
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.common.utils.enums.*;
|
|
import cn.rankin.productservice.entity.Item;
|
|
import cn.rankin.productservice.entity.Item;
|
|
import cn.rankin.productservice.entity.ItemTagRelation;
|
|
import cn.rankin.productservice.entity.ItemTagRelation;
|
|
@@ -38,127 +39,142 @@ public class TagController {
|
|
@Autowired
|
|
@Autowired
|
|
private ItemService itemService;
|
|
private ItemService itemService;
|
|
|
|
|
|
-// @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);
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+ @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;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
+ public APIResult<Page<Tag>> search(TagSearchDTO searchDTO) {
|
|
|
|
+ Tag tag = new Tag();
|
|
|
|
+
|
|
|
|
+ String name = searchDTO.getName();
|
|
|
|
+ if (name != null) {
|
|
|
|
+ tag.setName("%" + name + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tag.setMerchantId(searchDTO.getMerchantId());
|
|
|
|
+ tag.setType(searchDTO.getType());
|
|
|
|
+
|
|
|
|
+ return tagService.search(tag, searchDTO.getPageNo(), searchDTO.getPageSize());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|