Forráskód Böngészése

渠道指定登录设备型号

guozhaoshun 6 éve
szülő
commit
878c4f238d

+ 51 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/MerchantPermitDeviceController.java

@@ -0,0 +1,51 @@
+package cn.rankin.cmsweb.controller.user;
+
+import cn.rankin.cmsweb.service.user.MerchantPermitDeviceService;
+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.util.BeanUtil;
+import cn.rankin.data.api.user.dto.MerchantPermitDeviceDTO;
+import cn.rankin.data.api.user.vo.MerchantPermitDeviceVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@RestController
+@RequestMapping(value = "/merchantPermitDevice")
+public class MerchantPermitDeviceController
+{
+
+    @Autowired
+    private MerchantPermitDeviceService merchantPermitDeviceService;
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<MerchantPermitDeviceVo>> search(MerchantPermitDeviceDTO searchDTO) {
+        return merchantPermitDeviceService.search(BeanUtil.convertToMap(searchDTO));
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<MerchantPermitDeviceVo> create(@RequestBody MerchantPermitDeviceDTO dto){
+        return merchantPermitDeviceService.create(dto);
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<MerchantPermitDeviceVo> update(@Valid @RequestBody MerchantPermitDeviceDTO dto){
+        if (dto.getId() == null) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+        return merchantPermitDeviceService.update(dto);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public APIResult<Boolean> delete(@PathVariable String id) {
+        return merchantPermitDeviceService.delete(id);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public APIResult<MerchantPermitDeviceVo> getMerchantPermitDevice(@PathVariable String id) {
+        return merchantPermitDeviceService.getMerchantPermitDevice(id);
+    }
+
+}

+ 30 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/MerchantPermitDeviceService.java

@@ -0,0 +1,30 @@
+package cn.rankin.cmsweb.service.user;
+
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.user.dto.MerchantPermitDeviceDTO;
+import cn.rankin.data.api.user.vo.MerchantPermitDeviceVo;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@FeignClient(name = "${service.user.name}")
+public interface MerchantPermitDeviceService {
+
+    @RequestMapping(value = "/merchantPermitDevice/list", method = RequestMethod.GET)
+    APIResult<Page<MerchantPermitDeviceVo>> search(@RequestParam Map<String, Object> searchDTO);
+
+    @RequestMapping(value = "/merchantPermitDevice", method = RequestMethod.POST)
+    APIResult<MerchantPermitDeviceVo> create(@RequestBody MerchantPermitDeviceDTO dto);
+
+    @RequestMapping(value = "/merchantPermitDevice", method = RequestMethod.PUT)
+    APIResult<MerchantPermitDeviceVo> update(@RequestBody MerchantPermitDeviceDTO dto);
+
+    @RequestMapping(value = "/merchantPermitDevice/{id}", method = RequestMethod.DELETE)
+    APIResult<Boolean> delete(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/merchantPermitDevice/{id}", method = RequestMethod.GET)
+    APIResult<MerchantPermitDeviceVo> getMerchantPermitDevice(@PathVariable("id") String id);
+
+}

+ 37 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/dto/MerchantPermitDeviceDTO.java

@@ -0,0 +1,37 @@
+package cn.rankin.data.api.user.dto;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@ToString
+public class MerchantPermitDeviceDTO implements Serializable {
+
+    private String id;
+
+    private String merchantId;
+
+    private String deviceModel;
+
+    @NotNull
+    private String provinceCode;
+
+    private BaseStatusEnum status;
+
+    private Date gmtCreated;
+
+    private Date gmtModified;
+
+    private Integer pageNo = 1;
+
+    private Integer pageSize = 10;
+
+}
+
+
+

+ 49 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/MerchantPermitDevice.java

@@ -0,0 +1,49 @@
+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_merchant_permit_device")
+@DynamicInsert
+@DynamicUpdate
+public class MerchantPermitDevice implements Serializable {
+    @Id
+    @Column(name="id")
+    private String id;
+
+    @Column(name="merchant_id")
+    private String merchantId;
+
+    //设备型号
+    @Column(name="device_model")
+    private String deviceModel;
+
+    @Column(name = "province_code")
+    private String provinceCode;
+
+    @Enumerated(EnumType.ORDINAL)
+    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;
+
+}
+
+
+

+ 31 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/vo/MerchantPermitDeviceVo.java

@@ -0,0 +1,31 @@
+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 MerchantPermitDeviceVo implements Serializable {
+
+    private String id;
+
+    private String merchantId;
+
+    private String deviceModel;
+
+    private String provinceCode;
+
+    private BaseStatusEnum status;
+
+    private Date gmtCreated;
+
+    private Date gmtModified;
+
+}
+
+
+

+ 78 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/controller/MerchantPermitDeviceController.java

@@ -0,0 +1,78 @@
+package cn.rankin.userservice.controller;
+
+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.enums.BaseOrderEnum;
+import cn.rankin.data.api.user.dto.MerchantPermitDeviceDTO;
+import cn.rankin.data.api.user.dto.MerchantSearchDTO;
+import cn.rankin.data.api.user.dto.UserDeviceDTO;
+import cn.rankin.data.api.user.entity.Merchant;
+import cn.rankin.data.api.user.entity.MerchantPermitDevice;
+import cn.rankin.data.api.user.entity.UserDevice;
+import cn.rankin.data.api.user.vo.MerchantPermitDeviceVo;
+import cn.rankin.userservice.helper.RaStringHelper;
+import cn.rankin.userservice.service.MerchantPermitDeviceService;
+import cn.rankin.userservice.service.UserDeviceService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+
+@RestController
+@RequestMapping(value = "/merchantPermitDevice")
+public class MerchantPermitDeviceController
+{
+
+    @Autowired
+    private MerchantPermitDeviceService merchantPermitDeviceService;
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<MerchantPermitDevice>> search(MerchantPermitDeviceDTO searchDTO) {
+        MerchantPermitDevice simple = new MerchantPermitDevice();
+        String merchantId = searchDTO.getMerchantId();
+        if (StringUtils.isNotBlank(merchantId)) {
+            simple.setMerchantId(merchantId);
+        }
+
+        String provinceCode = searchDTO.getProvinceCode();
+        if (StringUtils.isNotBlank(provinceCode)) {
+            simple.setProvinceCode(provinceCode);
+        }
+
+        // sort
+        LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
+        sort.put("gmtModified", BaseOrderEnum.DESC);
+
+        return merchantPermitDeviceService.search(simple, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<MerchantPermitDevice> create(@Valid @RequestBody MerchantPermitDeviceDTO dto){
+        return merchantPermitDeviceService.create(dto);
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<MerchantPermitDevice> update(@Valid @RequestBody MerchantPermitDeviceDTO dto){
+        if (dto.getId() == null) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+        return merchantPermitDeviceService.update(dto);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public APIResult<Boolean> delete(@PathVariable String id) {
+        return merchantPermitDeviceService.delete(id);
+
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public APIResult<MerchantPermitDevice> getMerchantPermitDevice(@PathVariable String id) {
+        return merchantPermitDeviceService.getMerchantPermitDevice(id);
+    }
+
+}

+ 21 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/repository/MerchantPermitDeviceRepository.java

@@ -0,0 +1,21 @@
+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.MerchantPermitDevice;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+
+public interface MerchantPermitDeviceRepository extends BasicJpaRepository<MerchantPermitDevice, String> {
+
+    @Query(value = "select m from MerchantPermitDevice m where m.merchantId = :merchantId AND m.status = :status ")
+    List<MerchantPermitDevice> findByMerchantId(@Param("merchantId")String merchantId, @Param("status") BaseStatusEnum status);
+
+    @Modifying
+    @Query("update MerchantPermitDevice m set m.status = :status where m.id = :id ")
+    Integer updateStatusById(@Param("id") String id, @Param("status") BaseStatusEnum status);
+}

+ 88 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/MerchantPermitDeviceService.java

@@ -0,0 +1,88 @@
+package cn.rankin.userservice.service;
+
+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.enums.BaseOrderEnum;
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.common.utils.util.JpaSortUtil;
+import cn.rankin.data.api.user.dto.MerchantPermitDeviceDTO;
+import cn.rankin.data.api.user.entity.MerchantPermitDevice;
+import cn.rankin.userservice.repository.MerchantPermitDeviceRepository;
+import org.apache.commons.lang.StringUtils;
+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 MerchantPermitDeviceService
+{
+    @Autowired
+    private MerchantPermitDeviceRepository merchantPermitDeviceRepository;
+
+    public APIResult<MerchantPermitDevice> findByMerchantId(String merchantId){
+        List<MerchantPermitDevice> merchantPermitDevices = merchantPermitDeviceRepository.findByMerchantId(merchantId, BaseStatusEnum.NORMAL);
+        return APIResult.ok(merchantPermitDevices);
+    }
+
+    @Transactional
+    public APIResult<MerchantPermitDevice> create(MerchantPermitDeviceDTO dto) {
+        MerchantPermitDevice entity = convert(dto);
+        MerchantPermitDevice result = merchantPermitDeviceRepository.save(entity);
+
+        if(null == result ){
+            return APIResult.error(APICode.OPERATE_ERROR);
+        }
+
+        return APIResult.ok(result);
+    }
+
+    public APIResult<Page<MerchantPermitDevice>> search(MerchantPermitDevice simple, Integer pageNo, Integer pageSize, LinkedHashMap<String,BaseOrderEnum> sort) {
+        Long count = merchantPermitDeviceRepository.count(simple);
+        Page<MerchantPermitDevice> page = new Page<>(count, pageNo, pageSize);
+
+        if (count == 0) {
+            return APIResult.ok(page);
+        }
+
+        List<MerchantPermitDevice> list = merchantPermitDeviceRepository.find(simple, page.getStart(), page.getPageSize(), JpaSortUtil.sort(sort));
+        page.setList(list);
+
+        return APIResult.ok(page);
+    }
+
+    @Transactional
+    public APIResult<MerchantPermitDevice> update(MerchantPermitDeviceDTO dto) {
+        MerchantPermitDevice entity = convert(dto);
+        MerchantPermitDevice result = merchantPermitDeviceRepository.update(entity);
+
+        if(null == result ){
+            return APIResult.error(APICode.OPERATE_ERROR);
+        }
+
+        return APIResult.ok(result);
+    }
+
+    @Transactional
+    public APIResult<Boolean> delete(String id) {
+        Integer count = merchantPermitDeviceRepository.updateStatusById(id, BaseStatusEnum.DEL);
+
+        if (count == 0) {
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+        return APIResult.ok(true);
+    }
+
+    public APIResult<MerchantPermitDevice> getMerchantPermitDevice(String id) {
+        if(StringUtils.isBlank(id)){
+            return APIResult.error(APICode.OPERATE_ERROR);
+        }
+        MerchantPermitDevice result = merchantPermitDeviceRepository.find(id);
+        return APIResult.ok(result);
+    }
+}

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

@@ -82,4 +82,10 @@ public class DTOConverter {
         BeanUtils.copyProperties(dto, qrcode);
         return qrcode;
     }
+
+    public static MerchantPermitDevice convert(MerchantPermitDeviceDTO dto) {
+        MerchantPermitDevice entity = new MerchantPermitDevice();
+        BeanUtils.copyProperties(dto, entity);
+        return entity;
+    }
 }