Browse Source

fix tag product sort bug

huodongdong 6 years ago
parent
commit
db8ea62107

+ 27 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/dto/WhiteUserDTO.java

@@ -0,0 +1,27 @@
+package cn.rankin.data.api.user.dto;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@ToString
+public class WhiteUserDTO implements Serializable{
+
+    private String id;
+
+    private String userId;
+
+    private Date startTime;
+
+    private Date endTime;
+
+    private BaseStatusEnum status;
+
+    private Date gmtCreated;
+
+    private Date gmtModified;
+}

+ 18 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/dto/WhiteUserSearchDTO.java

@@ -0,0 +1,18 @@
+package cn.rankin.data.api.user.dto;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+@Data
+@ToString
+public class WhiteUserSearchDTO implements Serializable {
+
+    private String code;
+
+    private Integer pageNo = 1;
+
+    private Integer pageSize = 10;
+}

+ 48 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/WhiteUser.java

@@ -0,0 +1,48 @@
+package cn.rankin.data.api.user.entity;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import lombok.Data;
+import lombok.ToString;
+import org.hibernate.annotations.DynamicInsert;
+import org.hibernate.annotations.DynamicUpdate;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@ToString
+@Entity
+@Table(name = "u_white_user")
+@DynamicInsert
+@DynamicUpdate
+public class WhiteUser implements Serializable {
+
+    @Id
+    private String id;
+
+    @Column(name = "user_id", nullable = false, unique = true)
+    private String userId;
+
+    @Column(name = "start_time", nullable = false, columnDefinition = "timestamp NULL DEFAULT CURRENT_TIMESTAMP")
+    private Date startTime;
+
+    @Column(name = "end_time")
+    private Date endTime;
+
+    @Enumerated(EnumType.ORDINAL)
+    @Column(name="status")
+    private BaseStatusEnum status;
+
+    @Column(name = "gmt_created", updatable = false, insertable = false, columnDefinition = "timestamp NULL DEFAULT CURRENT_TIMESTAMP")
+    @Temporal(TemporalType.TIMESTAMP)
+    private Date gmtCreated;
+
+    @Column(name = "gmt_modified", updatable = false, insertable = false, columnDefinition = "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
+    @Temporal(TemporalType.TIMESTAMP)
+    private Date gmtModified;
+
+    @Transient
+    private String code;
+
+}

+ 29 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/vo/WhiteUserVo.java

@@ -0,0 +1,29 @@
+package cn.rankin.data.api.user.vo;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@ToString
+public class WhiteUserVo implements Serializable {
+
+    private String id;
+
+    private String userId;
+
+    private Date startTime;
+
+    private Date endTime;
+
+    private BaseStatusEnum status;
+
+    private Date gmtCreated;
+
+    private Date gmtModified;
+
+    private String code;
+}

+ 7 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/service/app/ItemService.java

@@ -2,8 +2,10 @@ package cn.rankin.productservice.service.app;
 
 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.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.enums.ProductTypeEnum;
+import cn.rankin.common.utils.util.JpaSortUtil;
 import cn.rankin.common.utils.util.ListUtil;
 import cn.rankin.data.api.app.vo.ItemGoodsVo;
 import cn.rankin.data.api.app.vo.ItemVo;
@@ -250,7 +252,11 @@ public class ItemService {
         Long total = merchantProductTagRelationRepository.count(relation);
 
         Page<ItemVo> page = new Page(total, pageNo, pageSize);
-        List<MerchantProductTagRelation> relationList = merchantProductTagRelationRepository.find(relation, page.getStart(), pageSize);
+        // sort
+        LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap() { {
+            this.put("sort", BaseOrderEnum.ASC);
+        }};
+        List<MerchantProductTagRelation> relationList = merchantProductTagRelationRepository.find(relation, page.getStart(), pageSize, JpaSortUtil.sort(sort));
         if (CollectionUtils.isEmpty(relationList)) {
             return APIResult.ok(page);
         }

+ 49 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/controller/WhiteUserController.java

@@ -0,0 +1,49 @@
+package cn.rankin.userservice.controller;
+
+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.user.dto.WhiteUserSearchDTO;
+import cn.rankin.data.api.user.entity.WhiteUser;
+import cn.rankin.userservice.code.UserServiceAPICode;
+import cn.rankin.userservice.service.WhiteUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.LinkedHashMap;
+
+@RestController
+@RequestMapping(value = "/white/user")
+public class WhiteUserController {
+
+    @Autowired
+    private WhiteUserService whiteUserService;
+
+    @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
+    public APIResult<WhiteUser> getWhiteUser(@PathVariable String userId) {
+        WhiteUser whiteUser = whiteUserService.findUserByUserId(userId);
+        if (whiteUser == null) {
+            return APIResult.error(UserServiceAPICode.NOT_EXISTS);
+        }
+        return APIResult.ok(whiteUser);
+    }
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<WhiteUser>> search(WhiteUserSearchDTO searchDTO) {
+        WhiteUser sample = new WhiteUser();
+        String code = searchDTO.getCode();
+        if (!StringUtils.isEmpty(code)) {
+            sample.setCode("%" + code + "%");
+        }
+        Integer pageNo = searchDTO.getPageNo();
+        Integer pageSize = searchDTO.getPageSize();
+        LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
+        sort.put("gmtModified", BaseOrderEnum.DESC);
+//        return whiteUserService.search(sample, pageNo, pageSize, sort);
+        return null;
+    }
+}

+ 16 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/repository/WhiteUserRepository.java

@@ -0,0 +1,16 @@
+package cn.rankin.userservice.repository;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.common.utils.jpa.BasicJpaRepository;
+import cn.rankin.data.api.user.entity.WhiteUser;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+public interface WhiteUserRepository extends BasicJpaRepository<WhiteUser, String> {
+
+    WhiteUser findFirstByUserIdAndAndStatus(String userId, BaseStatusEnum status);
+
+    @Modifying
+    @Query(value = "update WhiteUser w set w.status = 1 where w.userId = ?1")
+    Integer deleteByUserId(String userId);
+}

+ 0 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/service/TerminalUserService.java

@@ -2,7 +2,6 @@ package cn.rankin.userservice.service;
 
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
-import cn.rankin.common.utils.util.SecurityUtil;
 import cn.rankin.data.api.user.dto.TerminalUserDTO;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.enums.BaseStatusEnum;

+ 58 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/WhiteUserService.java

@@ -0,0 +1,58 @@
+package cn.rankin.userservice.service;
+
+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.common.utils.enums.BaseStatusEnum;
+import cn.rankin.data.api.user.dto.WhiteUserDTO;
+import cn.rankin.data.api.user.entity.WhiteUser;
+import cn.rankin.userservice.repository.WhiteUserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.transaction.Transactional;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import static cn.rankin.userservice.utils.DTOConverter.convert;
+
+@Service
+public class WhiteUserService {
+
+    @Autowired
+    private WhiteUserRepository whiteUserRepository;
+
+    @Transactional
+    public WhiteUser addUser(WhiteUserDTO whiteUserDTO) {
+        WhiteUser whiteUser = convert(whiteUserDTO);
+        WhiteUser result = whiteUserRepository.save(whiteUser);
+        return null;
+    }
+
+    @Transactional
+    public WhiteUser updateUser(WhiteUserDTO whiteUserDTO) {
+        WhiteUser whiteUser = convert(whiteUserDTO);
+        return whiteUserRepository.update(whiteUser);
+    }
+
+    public WhiteUser findUserByUserId(String userId) {
+        return whiteUserRepository.findFirstByUserIdAndAndStatus(userId, BaseStatusEnum.NORMAL);
+    }
+
+    public Page<WhiteUser> searchPage(WhiteUser whiteUser, Integer pageNo, Integer pageSize, LinkedHashMap<String, BaseOrderEnum> sort) {
+        Long count = whiteUserRepository.count(whiteUser);
+        Page<WhiteUser> page = new Page(count, pageNo, pageSize);
+        if (count == 0) {
+            return page;
+        }
+        List<WhiteUser> whiteUserList = whiteUserRepository.find(whiteUser, page.getStart(), pageSize);
+        page.setList(whiteUserList);
+        return page;
+    }
+
+    @Transactional
+    public Boolean deleteUser(String userId) {
+        Integer count = whiteUserRepository.deleteByUserId(userId);
+        return count > 0;
+    }
+}

+ 7 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/utils/DTOConverter.java

@@ -5,6 +5,7 @@ import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.data.api.user.dto.*;
 import cn.rankin.data.api.user.entity.*;
 import cn.rankin.userservice.dto.UserRegistry;
+import org.bouncycastle.crypto.digests.WhirlpoolDigest;
 import org.springframework.beans.BeanUtils;
 
 import java.math.BigDecimal;
@@ -57,4 +58,10 @@ public class DTOConverter {
         eventLog.setStatus(BaseStatusEnum.NORMAL);
         return eventLog;
     }
+
+    public static WhiteUser convert(WhiteUserDTO whiteUserDTO) {
+        WhiteUser whiteUser = new WhiteUser();
+        BeanUtils.copyProperties(whiteUserDTO, whiteUser);
+        return whiteUser;
+    }
 }