|
@@ -0,0 +1,189 @@
|
|
|
|
+package cn.rankin.userservice.service;
|
|
|
|
+
|
|
|
|
+import cn.rankin.common.utils.api.page.Page;
|
|
|
|
+import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
|
|
+import cn.rankin.common.utils.enums.BaseStatusEnum;
|
|
|
|
+import cn.rankin.common.utils.util.JpaSortUtil;
|
|
|
|
+import cn.rankin.data.api.product.entity.Tag;
|
|
|
|
+import cn.rankin.data.api.user.dto.UserTagDTO;
|
|
|
|
+import cn.rankin.data.api.user.entity.UserTag;
|
|
|
|
+import cn.rankin.userservice.repository.UserTagRepository;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import static cn.rankin.userservice.utils.DTOConverter.convert;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class UserTagService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserTagRepository userTagRepository;
|
|
|
|
+
|
|
|
|
+/* @Autowired
|
|
|
|
+ private TagGroupRepository tagGroupRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MerchantProductRepository merchantProductRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MerchantProductTagRelationService merchantProductTagRelationService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private GoodsService goodsService;*/
|
|
|
|
+
|
|
|
|
+ public List<UserTag> findByTypeCode(String typeCode,String uid) {
|
|
|
|
+ List<UserTag> userTagList = userTagRepository.findByTypeCodeUid(typeCode,uid, BaseStatusEnum.NORMAL);
|
|
|
|
+ return userTagList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<UserTag> findByTypeCode(String typeCode) {
|
|
|
|
+ List<UserTag> userTagList = userTagRepository.findByTypeCode(typeCode);
|
|
|
|
+ return userTagList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+/* public List<MerchantProduct> getMerchantProductList(String tagId, String merchantId) {
|
|
|
|
+ List<MerchantProductTagRelation> relationList = merchantProductTagRelationService.findByTagId(tagId, BaseStatusEnum.NORMAL);
|
|
|
|
+ if (CollectionUtils.isEmpty(relationList)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> productIdList = new ArrayList<>();
|
|
|
|
+ relationList.forEach(relation -> productIdList.add(relation.getPid()));
|
|
|
|
+ List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidsAndMerchantId(productIdList, merchantId);
|
|
|
|
+ Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
|
|
|
|
+
|
|
|
|
+ List<MerchantProduct> sortMerchantProductList = new ArrayList<>();
|
|
|
|
+ for (String productId : productIdList) {
|
|
|
|
+ MerchantProduct merchantProduct = merchantProductMap.get(productId);
|
|
|
|
+ if (merchantProduct != null) {
|
|
|
|
+ sortMerchantProductList.add(merchantProduct);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sortMerchantProductList;
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ // 搜索用户标签
|
|
|
|
+ public Page<UserTag> search(UserTag userTag, Integer pageNo, Integer pageSize, LinkedHashMap<String, BaseOrderEnum> sort) {
|
|
|
|
+ Long count = userTagRepository.count(userTag);
|
|
|
|
+ Page<UserTag> page = new Page(count, pageNo, pageSize);
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<UserTag> userTagList = userTagRepository.find(userTag, page.getStart(), page.getPageSize(), JpaSortUtil.sort(sort));
|
|
|
|
+ page.setList(userTagList);
|
|
|
|
+
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 标签详情
|
|
|
|
+ public UserTag getUserTag(String id) {
|
|
|
|
+ UserTag userTag = userTagRepository.find(id);
|
|
|
|
+ String uid = userTag.getUid();
|
|
|
|
+
|
|
|
|
+ /*List<MerchantProduct> merchantProductList = getUserProductList(tagId, uid);
|
|
|
|
+ userTag.setProductList(merchantProductList);*/
|
|
|
|
+ return userTag;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 标签详情
|
|
|
|
+ public List<UserTag> findUserTagByCodeUid(String code,String uid) {
|
|
|
|
+ List<UserTag> userTagLIst = userTagRepository.findByTypeCodeUid(code,uid, BaseStatusEnum.NORMAL);
|
|
|
|
+// String uid = userTag.getUid();
|
|
|
|
+
|
|
|
|
+ /*List<MerchantProduct> merchantProductList = getUserProductList(tagId, uid);
|
|
|
|
+ userTag.setProductList(merchantProductList);*/
|
|
|
|
+ return userTagLIst;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public UserTag create(UserTagDTO userTagDTO) {
|
|
|
|
+ UserTag userTag = convert(userTagDTO);
|
|
|
|
+
|
|
|
|
+/* String merchantId = null;
|
|
|
|
+
|
|
|
|
+ String groupId = tagDTO.getGroupId();
|
|
|
|
+ if(StringUtils.isNotBlank(groupId)){
|
|
|
|
+ //兼容旧版本 tagGroup
|
|
|
|
+ TagGroup tagGroup = tagGroupRepository.find(groupId);
|
|
|
|
+ if (tagGroup == null) {
|
|
|
|
+ return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ merchantId = tagGroup.getMerchantId();
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ //新版本
|
|
|
|
+ merchantId = tagDTO.getMerchantId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tag.setMerchantId(merchantId);*/
|
|
|
|
+ UserTag result = userTagRepository.save(userTag);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public UserTag update(UserTagDTO userTagDTO) {
|
|
|
|
+ UserTag userTag = convert(userTagDTO);
|
|
|
|
+ UserTag result = userTagRepository.update(userTag);
|
|
|
|
+
|
|
|
|
+ /* String tagId = result.getId();
|
|
|
|
+ String uid = result.getUid();
|
|
|
|
+ List<String> productIdList = tagDTO.getProductList();
|
|
|
|
+ merchantProductTagRelationService.updateByTagId(tagId, merchantId, productIdList);
|
|
|
|
+
|
|
|
|
+ List<MerchantProduct> merchantProductList = getMerchantProductList(tagId, merchantId);
|
|
|
|
+ tag.setProductList(merchantProductList);*/
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public Boolean delete(String tagId) {
|
|
|
|
+ Integer count = userTagRepository.deleteById(tagId);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ return true;
|
|
|
|
+ }else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<UserTag> findUserTagByUid(String uid) {
|
|
|
|
+ return userTagRepository.findUserTagByUid(uid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+/* @Transactional
|
|
|
|
+ public void sortTag(String groupId, List<String> tagIdList) {
|
|
|
|
+ List<Tag> tagList = tagRepository.findByGroupId(groupId, BaseStatusEnum.NORMAL);
|
|
|
|
+ sortTag(tagIdList, tagList);
|
|
|
|
+ tagRepository.update(tagList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public void sortTagByTypeCode(String typeCode, List<String> tagIdList) {
|
|
|
|
+ List<Tag> tagList = tagRepository.findByTypeCode(typeCode);
|
|
|
|
+ sortTag(tagIdList, tagList);
|
|
|
|
+ tagRepository.update(tagList);
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+/* private void sortTag(List<String> tagIdList, List<Tag> tagList) {
|
|
|
|
+ for (Tag tag : tagList) {
|
|
|
|
+ String tagId = tag.getId();
|
|
|
|
+ if (!tagIdList.contains(tagId)) {
|
|
|
|
+ tag.setStatus(BaseStatusEnum.DEL);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Integer index = tagIdList.indexOf(tagId);
|
|
|
|
+ tag.setSort(index);
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+}
|