[feat] 增加绑定关系映射
Showing
19 changed files
with
396 additions
and
38 deletions
| ... | @@ -76,5 +76,11 @@ | ... | @@ -76,5 +76,11 @@ |
| 76 | <groupId>cn.hutool</groupId> | 76 | <groupId>cn.hutool</groupId> |
| 77 | <artifactId>hutool-all</artifactId> | 77 | <artifactId>hutool-all</artifactId> |
| 78 | </dependency> | 78 | </dependency> |
| 79 | |||
| 80 | <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> | ||
| 81 | <dependency> | ||
| 82 | <groupId>com.google.guava</groupId> | ||
| 83 | <artifactId>guava</artifactId> | ||
| 84 | </dependency> | ||
| 79 | </dependencies> | 85 | </dependencies> |
| 80 | </project> | 86 | </project> | ... | ... |
ql-backend-core/src/main/java/com/ql/backend/core/infrastructure/exception/CommonException.java
0 → 100644
| 1 | package com.ql.backend.core.infrastructure.exception; | ||
| 2 | |||
| 3 | /** | ||
| 4 | * @author lirenhao | ||
| 5 | * date: 2022/9/15 10:29 | ||
| 6 | */ | ||
| 7 | public class CommonException extends RuntimeException { | ||
| 8 | |||
| 9 | public CommonException(String errorMsg) { | ||
| 10 | super(errorMsg); | ||
| 11 | } | ||
| 12 | |||
| 13 | public static CommonException create(String errorMsg) { | ||
| 14 | return new CommonException(errorMsg); | ||
| 15 | } | ||
| 16 | } |
| ... | @@ -95,6 +95,12 @@ | ... | @@ -95,6 +95,12 @@ |
| 95 | <version>5.8.5</version> | 95 | <version>5.8.5</version> |
| 96 | </dependency> | 96 | </dependency> |
| 97 | 97 | ||
| 98 | <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> | ||
| 99 | <dependency> | ||
| 100 | <groupId>com.google.guava</groupId> | ||
| 101 | <artifactId>guava</artifactId> | ||
| 102 | <version>31.1-jre</version> | ||
| 103 | </dependency> | ||
| 98 | </dependencies> | 104 | </dependencies> |
| 99 | </dependencyManagement> | 105 | </dependencyManagement> |
| 100 | </project> | 106 | </project> | ... | ... |
| 1 | package com.ql.backend.ploycenter.application.impl; | 1 | package com.ql.backend.ploycenter.application.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.ql.backend.core.infrastructure.exception.CommonException; | ||
| 4 | import com.ql.backend.core.interfaces.vo.ApiResponse; | 5 | import com.ql.backend.core.interfaces.vo.ApiResponse; |
| 5 | import com.ql.backend.core.interfaces.vo.PageVO; | 6 | import com.ql.backend.core.interfaces.vo.PageVO; |
| 6 | import com.ql.backend.ploycenter.application.PloyService; | 7 | import com.ql.backend.ploycenter.application.PloyService; |
| 7 | import com.ql.backend.ploycenter.domain.condition.PloyCondition; | 8 | import com.ql.backend.ploycenter.domain.condition.PloyCondition; |
| 9 | import com.ql.backend.ploycenter.domain.po.BindPloyDevicePO; | ||
| 10 | import com.ql.backend.ploycenter.domain.po.BindShopPloyPO; | ||
| 8 | import com.ql.backend.ploycenter.domain.po.PloyPO; | 11 | import com.ql.backend.ploycenter.domain.po.PloyPO; |
| 9 | import com.ql.backend.ploycenter.infrastructure.adapter.ControlCenterAdapter; | 12 | import com.ql.backend.ploycenter.infrastructure.adapter.ControlCenterAdapter; |
| 10 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; | 13 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; |
| 14 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.BindPloyDeviceDao; | ||
| 15 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.BindShopPloyDao; | ||
| 11 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; | 16 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; |
| 12 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | 17 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; |
| 13 | import com.ql.backend.ploycenter.interfaces.request.PloyUpdateRequest; | 18 | import com.ql.backend.ploycenter.interfaces.request.PloyUpdateRequest; |
| ... | @@ -20,9 +25,8 @@ import org.springframework.util.CollectionUtils; | ... | @@ -20,9 +25,8 @@ import org.springframework.util.CollectionUtils; |
| 20 | import org.springframework.util.ObjectUtils; | 25 | import org.springframework.util.ObjectUtils; |
| 21 | 26 | ||
| 22 | import javax.annotation.Resource; | 27 | import javax.annotation.Resource; |
| 23 | import java.util.Date; | ||
| 24 | import java.util.List; | 28 | import java.util.List; |
| 25 | import java.util.UUID; | 29 | import java.util.Set; |
| 26 | 30 | ||
| 27 | /** | 31 | /** |
| 28 | * @author lirenhao | 32 | * @author lirenhao |
| ... | @@ -38,19 +42,23 @@ public class PloyServiceImpl implements PloyService { | ... | @@ -38,19 +42,23 @@ public class PloyServiceImpl implements PloyService { |
| 38 | @Resource | 42 | @Resource |
| 39 | private PloyDao ployDao; | 43 | private PloyDao ployDao; |
| 40 | 44 | ||
| 45 | @Resource | ||
| 46 | private BindPloyDeviceDao bindPloyDeviceDao; | ||
| 47 | |||
| 48 | @Resource | ||
| 49 | private BindShopPloyDao bindShopPloyDao; | ||
| 50 | |||
| 41 | @Override | 51 | @Override |
| 42 | @Transactional | 52 | @Transactional |
| 43 | public String createPloy(PloyCreateRequest request) { | 53 | public String createPloy(PloyCreateRequest request) { |
| 44 | PloyPO po = PloyConverter.INSTANCE.convertRequest2Po(request); | 54 | PloyPO po = PloyPO.create(request); |
| 45 | po.setPloyId(UUID.randomUUID().toString()); | ||
| 46 | po.setGmtCreated(new Date()); | ||
| 47 | po.setGmtModified(new Date()); | ||
| 48 | po.setIsDeleted(Boolean.FALSE); | ||
| 49 | ployDao.save(po); | 55 | ployDao.save(po); |
| 50 | 56 | ||
| 51 | if (!CollectionUtils.isEmpty(request.getBindShopIds())) { | 57 | /* 绑定店铺 */ |
| 52 | /* todo 绑定店铺 */ | 58 | reBindShops(po.getPloyId(), request.getBindShopIds()); |
| 53 | } | 59 | |
| 60 | /* 绑定设备 */ | ||
| 61 | reBindDevices(po.getPloyId(), request.getBindDeviceIds()); | ||
| 54 | 62 | ||
| 55 | return po.getPloyId(); | 63 | return po.getPloyId(); |
| 56 | } | 64 | } |
| ... | @@ -58,14 +66,14 @@ public class PloyServiceImpl implements PloyService { | ... | @@ -58,14 +66,14 @@ public class PloyServiceImpl implements PloyService { |
| 58 | @Override | 66 | @Override |
| 59 | @Transactional | 67 | @Transactional |
| 60 | public void updatePloy(String ployId, PloyUpdateRequest request) { | 68 | public void updatePloy(String ployId, PloyUpdateRequest request) { |
| 61 | PloyPO po = PloyConverter.INSTANCE.convertRequest2Po(request); | 69 | PloyPO po = PloyPO.update(ployId, request); |
| 62 | po.setPloyId(ployId); | ||
| 63 | po.setGmtModified(new Date()); | ||
| 64 | ployDao.updateById(po); | 70 | ployDao.updateById(po); |
| 65 | 71 | ||
| 66 | if (!CollectionUtils.isEmpty(request.getBindShopIds())) { | 72 | /* 绑定店铺 */ |
| 67 | /* todo 绑定店铺 */ | 73 | reBindShops(po.getPloyId(), request.getBindShopIds()); |
| 68 | } | 74 | |
| 75 | /* 绑定设备 */ | ||
| 76 | reBindDevices(po.getPloyId(), request.getBindDeviceIds()); | ||
| 69 | } | 77 | } |
| 70 | 78 | ||
| 71 | @Override | 79 | @Override |
| ... | @@ -105,4 +113,36 @@ public class PloyServiceImpl implements PloyService { | ... | @@ -105,4 +113,36 @@ public class PloyServiceImpl implements PloyService { |
| 105 | 113 | ||
| 106 | return ApiResponse.fail("未查询到策略", null); | 114 | return ApiResponse.fail("未查询到策略", null); |
| 107 | } | 115 | } |
| 116 | |||
| 117 | private void reBindShops(String ployId, Set<String> shopIds) { | ||
| 118 | if (CollectionUtils.isEmpty(shopIds)) { | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | |||
| 122 | /* 查询店铺是否绑定过策略 */ | ||
| 123 | if (bindShopPloyDao.existShopPloy(ployId, shopIds)) { | ||
| 124 | /* 店铺重复绑定 */ | ||
| 125 | throw CommonException.create("店铺重复绑定"); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* 解绑店铺 */ | ||
| 129 | bindShopPloyDao.deleteByPloyId(ployId); | ||
| 130 | |||
| 131 | /* 绑定店铺 */ | ||
| 132 | List<BindShopPloyPO> pos = BindShopPloyPO.createBinds(ployId, shopIds); | ||
| 133 | bindShopPloyDao.saveBatch(pos); | ||
| 134 | } | ||
| 135 | |||
| 136 | private void reBindDevices(String ployId, Set<String> deviceIds) { | ||
| 137 | if (CollectionUtils.isEmpty(deviceIds)) { | ||
| 138 | return; | ||
| 139 | } | ||
| 140 | |||
| 141 | /* 先解绑该策略的设备 */ | ||
| 142 | bindPloyDeviceDao.deleteByPloyId(ployId); | ||
| 143 | |||
| 144 | /* 绑定设备 */ | ||
| 145 | List<BindPloyDevicePO> pos = BindPloyDevicePO.createBinds(ployId, deviceIds); | ||
| 146 | bindPloyDeviceDao.saveBatch(pos); | ||
| 147 | } | ||
| 108 | } | 148 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.application.impl; | 1 | package com.ql.backend.ploycenter.application.impl; |
| 2 | 2 | ||
| 3 | import com.google.common.collect.Sets; | ||
| 3 | import com.ql.backend.core.interfaces.vo.PageVO; | 4 | import com.ql.backend.core.interfaces.vo.PageVO; |
| 4 | import com.ql.backend.ploycenter.application.ShopService; | 5 | import com.ql.backend.ploycenter.application.ShopService; |
| 5 | import com.ql.backend.ploycenter.domain.condition.ShopCondition; | 6 | import com.ql.backend.ploycenter.domain.condition.ShopCondition; |
| 7 | import com.ql.backend.ploycenter.domain.po.BindShopPloyPO; | ||
| 6 | import com.ql.backend.ploycenter.domain.po.ShopPO; | 8 | import com.ql.backend.ploycenter.domain.po.ShopPO; |
| 7 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.ShopConverter; | 9 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.ShopConverter; |
| 10 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.BindShopPloyDao; | ||
| 8 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao; | 11 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao; |
| 9 | import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest; | 12 | import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest; |
| 10 | import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest; | 13 | import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest; |
| ... | @@ -15,9 +18,7 @@ import org.springframework.transaction.annotation.Transactional; | ... | @@ -15,9 +18,7 @@ import org.springframework.transaction.annotation.Transactional; |
| 15 | import org.springframework.util.ObjectUtils; | 18 | import org.springframework.util.ObjectUtils; |
| 16 | 19 | ||
| 17 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 18 | import java.util.Date; | ||
| 19 | import java.util.List; | 21 | import java.util.List; |
| 20 | import java.util.UUID; | ||
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | * @author lirenhao | 24 | * @author lirenhao |
| ... | @@ -30,19 +31,17 @@ public class ShopServiceImpl implements ShopService { | ... | @@ -30,19 +31,17 @@ public class ShopServiceImpl implements ShopService { |
| 30 | @Resource | 31 | @Resource |
| 31 | private ShopDao shopDao; | 32 | private ShopDao shopDao; |
| 32 | 33 | ||
| 34 | @Resource | ||
| 35 | private BindShopPloyDao bindShopPloyDao; | ||
| 36 | |||
| 33 | @Override | 37 | @Override |
| 34 | @Transactional | 38 | @Transactional |
| 35 | public String createShop(ShopCreateRequest request) { | 39 | public String createShop(ShopCreateRequest request) { |
| 36 | ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request); | 40 | ShopPO po = ShopPO.create(request); |
| 37 | po.setShopId(UUID.randomUUID().toString()); | ||
| 38 | po.setGmtCreated(new Date()); | ||
| 39 | po.setGmtModified(new Date()); | ||
| 40 | po.setIsDeleted(Boolean.FALSE); | ||
| 41 | shopDao.save(po); | 41 | shopDao.save(po); |
| 42 | 42 | ||
| 43 | if (!ObjectUtils.isEmpty(request.getBindPloyId())) { | 43 | /* 绑定策略 */ |
| 44 | /* todo 绑定策略 */ | 44 | reBindPloy(po.getShopId(), request.getBindPloyId()); |
| 45 | } | ||
| 46 | 45 | ||
| 47 | return po.getShopId(); | 46 | return po.getShopId(); |
| 48 | } | 47 | } |
| ... | @@ -50,14 +49,11 @@ public class ShopServiceImpl implements ShopService { | ... | @@ -50,14 +49,11 @@ public class ShopServiceImpl implements ShopService { |
| 50 | @Override | 49 | @Override |
| 51 | @Transactional | 50 | @Transactional |
| 52 | public void updateShop(String id, ShopUpdateRequest request) { | 51 | public void updateShop(String id, ShopUpdateRequest request) { |
| 53 | ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request); | 52 | ShopPO po = ShopPO.update(id, request); |
| 54 | po.setShopId(id); | ||
| 55 | po.setGmtModified(new Date()); | ||
| 56 | shopDao.updateById(po); | 53 | shopDao.updateById(po); |
| 57 | 54 | ||
| 58 | if (!ObjectUtils.isEmpty(request.getBindPloyId())) { | 55 | /* 绑定策略 */ |
| 59 | /* todo 绑定策略 */ | 56 | reBindPloy(po.getShopId(), request.getBindPloyId()); |
| 60 | } | ||
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | @Override | 59 | @Override |
| ... | @@ -79,4 +75,17 @@ public class ShopServiceImpl implements ShopService { | ... | @@ -79,4 +75,17 @@ public class ShopServiceImpl implements ShopService { |
| 79 | /* todo 查询策略详情, 并查询绑定的店铺信息 */ | 75 | /* todo 查询策略详情, 并查询绑定的店铺信息 */ |
| 80 | return vo; | 76 | return vo; |
| 81 | } | 77 | } |
| 78 | |||
| 79 | private void reBindPloy(String shopId, String bindPloyId) { | ||
| 80 | if (ObjectUtils.isEmpty(shopId) || ObjectUtils.isEmpty(bindPloyId)) { | ||
| 81 | return; | ||
| 82 | } | ||
| 83 | |||
| 84 | /* 解绑策略 */ | ||
| 85 | bindShopPloyDao.deleteByShopId(shopId); | ||
| 86 | |||
| 87 | /* 绑定策略 */ | ||
| 88 | List<BindShopPloyPO> pos = BindShopPloyPO.createBinds(bindPloyId, Sets.newHashSet(shopId)); | ||
| 89 | bindShopPloyDao.saveBatch(pos); | ||
| 90 | } | ||
| 82 | } | 91 | } | ... | ... |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/domain/po/BindPloyDevicePO.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | import lombok.AllArgsConstructor; | ||
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.NoArgsConstructor; | ||
| 10 | import org.springframework.util.CollectionUtils; | ||
| 11 | import org.springframework.util.ObjectUtils; | ||
| 12 | |||
| 13 | import java.io.Serializable; | ||
| 14 | import java.util.ArrayList; | ||
| 15 | import java.util.List; | ||
| 16 | import java.util.Set; | ||
| 17 | import java.util.stream.Collectors; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @author lirenhao | ||
| 21 | * date: 2022/9/15 09:55 | ||
| 22 | */ | ||
| 23 | @Data | ||
| 24 | @Builder | ||
| 25 | @NoArgsConstructor | ||
| 26 | @AllArgsConstructor | ||
| 27 | @TableName("t_bind_ploy_device") | ||
| 28 | public class BindPloyDevicePO implements Serializable { | ||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; | ||
| 31 | |||
| 32 | @TableId(value = "id", type = IdType.AUTO) | ||
| 33 | private Long id; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * 策略ID | ||
| 37 | */ | ||
| 38 | private String ployId; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * 设备ID | ||
| 42 | */ | ||
| 43 | private String deviceId; | ||
| 44 | |||
| 45 | public static List<BindPloyDevicePO> createBinds(String ployId, Set<String> deviceIds) { | ||
| 46 | if (ObjectUtils.isEmpty(ployId) || CollectionUtils.isEmpty(deviceIds)) { | ||
| 47 | return new ArrayList<>(); | ||
| 48 | } | ||
| 49 | |||
| 50 | return deviceIds.stream() | ||
| 51 | .map(deviceId -> BindPloyDevicePO.builder() | ||
| 52 | .ployId(ployId) | ||
| 53 | .deviceId(deviceId) | ||
| 54 | .build()) | ||
| 55 | .collect(Collectors.toList()); | ||
| 56 | } | ||
| 57 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/domain/po/BindShopPloyPO.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.domain.po; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | import lombok.AllArgsConstructor; | ||
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | ||
| 9 | import lombok.NoArgsConstructor; | ||
| 10 | import org.springframework.util.CollectionUtils; | ||
| 11 | import org.springframework.util.ObjectUtils; | ||
| 12 | |||
| 13 | import java.io.Serializable; | ||
| 14 | import java.util.ArrayList; | ||
| 15 | import java.util.List; | ||
| 16 | import java.util.Set; | ||
| 17 | import java.util.stream.Collectors; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @author lirenhao | ||
| 21 | * date: 2022/9/15 09:55 | ||
| 22 | */ | ||
| 23 | @Data | ||
| 24 | @Builder | ||
| 25 | @NoArgsConstructor | ||
| 26 | @AllArgsConstructor | ||
| 27 | @TableName("t_bind_shop_ploy") | ||
| 28 | public class BindShopPloyPO implements Serializable { | ||
| 29 | |||
| 30 | private static final long serialVersionUID = 1L; | ||
| 31 | |||
| 32 | @TableId(value = "id", type = IdType.AUTO) | ||
| 33 | private Long id; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * 策略ID | ||
| 37 | */ | ||
| 38 | private String ployId; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * 设备ID | ||
| 42 | */ | ||
| 43 | private String shopId; | ||
| 44 | |||
| 45 | public static List<BindShopPloyPO> createBinds(String ployId, Set<String> shopIds) { | ||
| 46 | if (ObjectUtils.isEmpty(ployId) || CollectionUtils.isEmpty(shopIds)) { | ||
| 47 | return new ArrayList<>(); | ||
| 48 | } | ||
| 49 | |||
| 50 | return shopIds.stream() | ||
| 51 | .map(id -> BindShopPloyPO.builder() | ||
| 52 | .ployId(ployId) | ||
| 53 | .shopId(id) | ||
| 54 | .build()) | ||
| 55 | .collect(Collectors.toList()); | ||
| 56 | } | ||
| 57 | } |
| ... | @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType; | ... | @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType; |
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | 4 | import com.baomidou.mybatisplus.annotation.TableField; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; | ||
| 8 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | ||
| 9 | import com.ql.backend.ploycenter.interfaces.request.PloyUpdateRequest; | ||
| 7 | import lombok.AllArgsConstructor; | 10 | import lombok.AllArgsConstructor; |
| 8 | import lombok.Builder; | 11 | import lombok.Builder; |
| 9 | import lombok.Data; | 12 | import lombok.Data; |
| ... | @@ -11,6 +14,7 @@ import lombok.NoArgsConstructor; | ... | @@ -11,6 +14,7 @@ import lombok.NoArgsConstructor; |
| 11 | 14 | ||
| 12 | import java.io.Serializable; | 15 | import java.io.Serializable; |
| 13 | import java.util.Date; | 16 | import java.util.Date; |
| 17 | import java.util.UUID; | ||
| 14 | 18 | ||
| 15 | /** | 19 | /** |
| 16 | * 策略 | 20 | * 策略 |
| ... | @@ -71,4 +75,20 @@ public class PloyPO implements Serializable { | ... | @@ -71,4 +75,20 @@ public class PloyPO implements Serializable { |
| 71 | 75 | ||
| 72 | @TableField(value = "gmt_modified") | 76 | @TableField(value = "gmt_modified") |
| 73 | private Date gmtModified; | 77 | private Date gmtModified; |
| 78 | |||
| 79 | public static PloyPO create(PloyCreateRequest request) { | ||
| 80 | PloyPO po = PloyConverter.INSTANCE.convertRequest2Po(request); | ||
| 81 | po.setPloyId(UUID.randomUUID().toString()); | ||
| 82 | po.setGmtCreated(new Date()); | ||
| 83 | po.setGmtModified(new Date()); | ||
| 84 | po.setIsDeleted(Boolean.FALSE); | ||
| 85 | return po; | ||
| 86 | } | ||
| 87 | |||
| 88 | public static PloyPO update(String ployId, PloyUpdateRequest request) { | ||
| 89 | PloyPO po = PloyConverter.INSTANCE.convertRequest2Po(request); | ||
| 90 | po.setPloyId(ployId); | ||
| 91 | po.setGmtModified(new Date()); | ||
| 92 | return po; | ||
| 93 | } | ||
| 74 | } | 94 | } | ... | ... |
| ... | @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType; | ... | @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType; |
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | 4 | import com.baomidou.mybatisplus.annotation.TableField; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.ShopConverter; | ||
| 8 | import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest; | ||
| 9 | import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest; | ||
| 7 | import lombok.AllArgsConstructor; | 10 | import lombok.AllArgsConstructor; |
| 8 | import lombok.Builder; | 11 | import lombok.Builder; |
| 9 | import lombok.Data; | 12 | import lombok.Data; |
| ... | @@ -11,6 +14,7 @@ import lombok.NoArgsConstructor; | ... | @@ -11,6 +14,7 @@ import lombok.NoArgsConstructor; |
| 11 | 14 | ||
| 12 | import java.io.Serializable; | 15 | import java.io.Serializable; |
| 13 | import java.util.Date; | 16 | import java.util.Date; |
| 17 | import java.util.UUID; | ||
| 14 | 18 | ||
| 15 | /** | 19 | /** |
| 16 | * @author lirenhao | 20 | * @author lirenhao |
| ... | @@ -57,4 +61,20 @@ public class ShopPO implements Serializable { | ... | @@ -57,4 +61,20 @@ public class ShopPO implements Serializable { |
| 57 | 61 | ||
| 58 | @TableField(value = "gmt_modified") | 62 | @TableField(value = "gmt_modified") |
| 59 | private Date gmtModified; | 63 | private Date gmtModified; |
| 64 | |||
| 65 | public static ShopPO create(ShopCreateRequest request) { | ||
| 66 | ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request); | ||
| 67 | po.setShopId(UUID.randomUUID().toString()); | ||
| 68 | po.setGmtCreated(new Date()); | ||
| 69 | po.setGmtModified(new Date()); | ||
| 70 | po.setIsDeleted(Boolean.FALSE); | ||
| 71 | return po; | ||
| 72 | } | ||
| 73 | |||
| 74 | public static ShopPO update(String id, ShopUpdateRequest request) { | ||
| 75 | ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request); | ||
| 76 | po.setShopId(id); | ||
| 77 | po.setGmtModified(new Date()); | ||
| 78 | return po; | ||
| 79 | } | ||
| 60 | } | 80 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.BindPloyDevicePO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/14 15:29 | ||
| 9 | */ | ||
| 10 | public interface BindPloyDeviceDao extends IService<BindPloyDevicePO> { | ||
| 11 | |||
| 12 | void deleteByPloyId(String ployId); | ||
| 13 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.BindShopPloyPO; | ||
| 5 | |||
| 6 | import java.util.Set; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/14 15:29 | ||
| 11 | */ | ||
| 12 | public interface BindShopPloyDao extends IService<BindShopPloyPO> { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * 校验店铺策略是否重复 | ||
| 16 | */ | ||
| 17 | boolean existShopPloy(String ployId, Set<String> shopIds); | ||
| 18 | |||
| 19 | void deleteByPloyId(String ployId); | ||
| 20 | |||
| 21 | void deleteByShopId(String shopId); | ||
| 22 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 5 | import com.ql.backend.ploycenter.domain.po.BindPloyDevicePO; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.BindPloyDeviceDao; | ||
| 7 | import com.ql.backend.ploycenter.infrastructure.persistence.mapper.BindPloyDeviceMapper; | ||
| 8 | import org.springframework.stereotype.Service; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/14 15:30 | ||
| 13 | */ | ||
| 14 | @Service | ||
| 15 | public class BindPloyDeviceDaoImpl extends ServiceImpl<BindPloyDeviceMapper, BindPloyDevicePO> implements BindPloyDeviceDao { | ||
| 16 | |||
| 17 | @Override | ||
| 18 | public void deleteByPloyId(String ployId) { | ||
| 19 | LambdaQueryWrapper<BindPloyDevicePO> wrapper = new LambdaQueryWrapper<>(); | ||
| 20 | wrapper.eq(BindPloyDevicePO::getPloyId, ployId); | ||
| 21 | this.remove(wrapper); | ||
| 22 | } | ||
| 23 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 5 | import com.ql.backend.ploycenter.domain.po.BindShopPloyPO; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.BindShopPloyDao; | ||
| 7 | import com.ql.backend.ploycenter.infrastructure.persistence.mapper.BindShopPloyMapper; | ||
| 8 | import org.springframework.stereotype.Service; | ||
| 9 | |||
| 10 | import java.util.Set; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/14 15:30 | ||
| 15 | */ | ||
| 16 | @Service | ||
| 17 | public class BindShopPloyDaoImpl extends ServiceImpl<BindShopPloyMapper, BindShopPloyPO> implements BindShopPloyDao { | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public boolean existShopPloy(String ployId, Set<String> shopIds) { | ||
| 21 | LambdaQueryWrapper<BindShopPloyPO> wrapper = new LambdaQueryWrapper<>(); | ||
| 22 | wrapper.ne(BindShopPloyPO::getPloyId, ployId) | ||
| 23 | .in(BindShopPloyPO::getShopId, shopIds) | ||
| 24 | .last("LIMIT 1"); | ||
| 25 | return this.count(wrapper) > 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | @Override | ||
| 29 | public void deleteByPloyId(String ployId) { | ||
| 30 | LambdaQueryWrapper<BindShopPloyPO> wrapper = new LambdaQueryWrapper<>(); | ||
| 31 | wrapper.eq(BindShopPloyPO::getPloyId, ployId); | ||
| 32 | this.remove(wrapper); | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public void deleteByShopId(String shopId) { | ||
| 37 | LambdaQueryWrapper<BindShopPloyPO> wrapper = new LambdaQueryWrapper<>(); | ||
| 38 | wrapper.eq(BindShopPloyPO::getShopId, shopId); | ||
| 39 | this.remove(wrapper); | ||
| 40 | } | ||
| 41 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.mapper; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.BindPloyDevicePO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/7 10:10 | ||
| 9 | */ | ||
| 10 | public interface BindPloyDeviceMapper extends BaseMapper<BindPloyDevicePO> { | ||
| 11 | |||
| 12 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.mapper; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.BindShopPloyPO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/7 10:10 | ||
| 9 | */ | ||
| 10 | public interface BindShopPloyMapper extends BaseMapper<BindShopPloyPO> { | ||
| 11 | |||
| 12 | } |
| ... | @@ -27,7 +27,6 @@ public class ShopFacade { | ... | @@ -27,7 +27,6 @@ public class ShopFacade { |
| 27 | return ApiResponse.ok(shopService.createShop(request)); | 27 | return ApiResponse.ok(shopService.createShop(request)); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | |||
| 31 | @PutMapping("/{id}") | 30 | @PutMapping("/{id}") |
| 32 | public ApiResponse<Void> updateShop(@PathVariable("id") String id, @RequestBody ShopUpdateRequest request) { | 31 | public ApiResponse<Void> updateShop(@PathVariable("id") String id, @RequestBody ShopUpdateRequest request) { |
| 33 | shopService.updateShop(id,request); | 32 | shopService.updateShop(id,request); | ... | ... |
| ... | @@ -43,4 +43,9 @@ public class PloyCreateRequest { | ... | @@ -43,4 +43,9 @@ public class PloyCreateRequest { |
| 43 | * 绑定的店铺ID | 43 | * 绑定的店铺ID |
| 44 | */ | 44 | */ |
| 45 | private Set<String> bindShopIds; | 45 | private Set<String> bindShopIds; |
| 46 | |||
| 47 | /** | ||
| 48 | * 绑定的设备ID | ||
| 49 | */ | ||
| 50 | private Set<String> bindDeviceIds; | ||
| 46 | } | 51 | } | ... | ... |
| ... | @@ -43,4 +43,9 @@ public class PloyUpdateRequest { | ... | @@ -43,4 +43,9 @@ public class PloyUpdateRequest { |
| 43 | * 绑定的店铺ID | 43 | * 绑定的店铺ID |
| 44 | */ | 44 | */ |
| 45 | private Set<String> bindShopIds; | 45 | private Set<String> bindShopIds; |
| 46 | |||
| 47 | /** | ||
| 48 | * 绑定的设备ID | ||
| 49 | */ | ||
| 50 | private Set<String> bindDeviceIds; | ||
| 46 | } | 51 | } | ... | ... |
-
Please register or sign in to post a comment