[feat]
1. 定义任务相关模型和接口 2. 定义设备相关模型和接口 3. 定义策略相关模型和接口 4. 定义店铺相关模型和接口
Showing
33 changed files
with
937 additions
and
29 deletions
| ... | @@ -34,6 +34,13 @@ | ... | @@ -34,6 +34,13 @@ |
| 34 | <version>1.0.0-SNAPSHOT</version> | 34 | <version>1.0.0-SNAPSHOT</version> |
| 35 | </dependency> | 35 | </dependency> |
| 36 | 36 | ||
| 37 | <!-- OKHttp3 --> | ||
| 38 | <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> | ||
| 39 | <dependency> | ||
| 40 | <groupId>com.squareup.okhttp3</groupId> | ||
| 41 | <artifactId>okhttp</artifactId> | ||
| 42 | </dependency> | ||
| 43 | |||
| 37 | <!-- easy-rules 执行引擎 --> | 44 | <!-- easy-rules 执行引擎 --> |
| 38 | <dependency> | 45 | <dependency> |
| 39 | <groupId>org.jeasy</groupId> | 46 | <groupId>org.jeasy</groupId> | ... | ... |
| 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.ql.backend.core.interfaces.vo.ApiResponse; | 4 | import com.ql.backend.core.interfaces.vo.ApiResponse; |
| 4 | import com.ql.backend.ploycenter.application.PloyService; | 5 | import com.ql.backend.ploycenter.application.PloyService; |
| 5 | import com.ql.backend.ploycenter.domain.po.PloyPO; | 6 | import com.ql.backend.ploycenter.domain.po.PloyPO; |
| 7 | import com.ql.backend.ploycenter.infrastructure.adapter.ControlCenterAdapter; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; | 8 | import com.ql.backend.ploycenter.infrastructure.converter.mapper.PloyConverter; |
| 7 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; | 9 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; |
| 8 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | 10 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; |
| ... | @@ -24,6 +26,9 @@ import java.util.UUID; | ... | @@ -24,6 +26,9 @@ import java.util.UUID; |
| 24 | public class PloyServiceImpl implements PloyService { | 26 | public class PloyServiceImpl implements PloyService { |
| 25 | 27 | ||
| 26 | @Resource | 28 | @Resource |
| 29 | private ControlCenterAdapter controlCenterAdapter; | ||
| 30 | |||
| 31 | @Resource | ||
| 27 | private PloyDao ployDao; | 32 | private PloyDao ployDao; |
| 28 | 33 | ||
| 29 | @Override | 34 | @Override |
| ... | @@ -39,13 +44,19 @@ public class PloyServiceImpl implements PloyService { | ... | @@ -39,13 +44,19 @@ public class PloyServiceImpl implements PloyService { |
| 39 | 44 | ||
| 40 | @Override | 45 | @Override |
| 41 | public ApiResponse<String> fire(TaskDTO taskDTO) { | 46 | public ApiResponse<String> fire(TaskDTO taskDTO) { |
| 42 | /* todo 执行策略, 创建任务 */ | 47 | /* 执行策略, 创建任务 */ |
| 43 | if (!ObjectUtils.isEmpty(taskDTO.getPloyId())) { | 48 | if (!ObjectUtils.isEmpty(taskDTO.getPloyId())) { |
| 44 | /* 查询策略 */ | 49 | /* 查询策略 */ |
| 50 | PloyPO ployPO = ployDao.getPloyById(taskDTO.getPloyId()); | ||
| 51 | if (ployPO == null) { | ||
| 52 | return ApiResponse.fail("未查询到策略", null); | ||
| 53 | } | ||
| 45 | 54 | ||
| 46 | /* 创建任务 */ | 55 | /* 创建任务 */ |
| 47 | 56 | log.info("[Fire] taskId -> [{}], ployInfo -> [{}]", taskDTO.getTaskId(), JSON.toJSONString(ployPO)); | |
| 57 | return controlCenterAdapter.createTask(ployPO); | ||
| 48 | } | 58 | } |
| 59 | |||
| 49 | return ApiResponse.fail("未查询到策略", null); | 60 | return ApiResponse.fail("未查询到策略", null); |
| 50 | } | 61 | } |
| 51 | } | 62 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.domain.condition; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | import lombok.experimental.SuperBuilder; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/13 10:06 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @SuperBuilder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class CommonPageCondition { | ||
| 20 | |||
| 21 | private int page; | ||
| 22 | |||
| 23 | private int size; | ||
| 24 | } |
| ... | @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ... | @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; |
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; |
| 5 | import com.ql.backend.ploycenter.common.enums.DeviceStatus; | 5 | import com.ql.backend.ploycenter.common.enums.DeviceStatus; |
| 6 | import lombok.AllArgsConstructor; | 6 | import lombok.AllArgsConstructor; |
| 7 | import lombok.Builder; | ||
| 8 | import lombok.Data; | 7 | import lombok.Data; |
| 9 | import lombok.NoArgsConstructor; | 8 | import lombok.NoArgsConstructor; |
| 9 | import lombok.experimental.SuperBuilder; | ||
| 10 | 10 | ||
| 11 | import java.util.Set; | 11 | import java.util.Set; |
| 12 | 12 | ||
| ... | @@ -15,15 +15,15 @@ import java.util.Set; | ... | @@ -15,15 +15,15 @@ import java.util.Set; |
| 15 | * date: 2022/9/5 11:18 | 15 | * date: 2022/9/5 11:18 |
| 16 | */ | 16 | */ |
| 17 | @Data | 17 | @Data |
| 18 | @Builder | 18 | @SuperBuilder |
| 19 | @NoArgsConstructor | 19 | @NoArgsConstructor |
| 20 | @AllArgsConstructor | 20 | @AllArgsConstructor |
| 21 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | 21 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) |
| 22 | public class DeviceCondition { | 22 | public class DeviceCondition extends CommonPageCondition { |
| 23 | |||
| 24 | private int page; | ||
| 25 | |||
| 26 | private int size; | ||
| 27 | 23 | ||
| 28 | private Set<DeviceStatus> deviceStatuses; | 24 | private Set<DeviceStatus> deviceStatuses; |
| 25 | |||
| 26 | public Set<DeviceStatus> getDevice_statuses() { | ||
| 27 | return deviceStatuses; | ||
| 28 | } | ||
| 29 | } | 29 | } | ... | ... |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/domain/condition/PloyCondition.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.domain.condition; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | import lombok.experimental.SuperBuilder; | ||
| 9 | |||
| 10 | import java.util.Set; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/13 10:07 | ||
| 15 | */ | ||
| 16 | @Data | ||
| 17 | @SuperBuilder | ||
| 18 | @NoArgsConstructor | ||
| 19 | @AllArgsConstructor | ||
| 20 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 21 | public class PloyCondition extends CommonPageCondition { | ||
| 22 | |||
| 23 | private Set<String> ployStatus; | ||
| 24 | |||
| 25 | public Set<String> getPloy_status() { | ||
| 26 | return ployStatus; | ||
| 27 | } | ||
| 28 | } |
ql-backend-ploycenter/src/main/java/com/ql/backend/ploycenter/domain/condition/ShopCondition.java
0 → 100644
| 1 | package com.ql.backend.ploycenter.domain.condition; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | import lombok.experimental.SuperBuilder; | ||
| 9 | |||
| 10 | import java.util.Set; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/13 10:07 | ||
| 15 | */ | ||
| 16 | @Data | ||
| 17 | @SuperBuilder | ||
| 18 | @NoArgsConstructor | ||
| 19 | @AllArgsConstructor | ||
| 20 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 21 | public class ShopCondition extends CommonPageCondition { | ||
| 22 | |||
| 23 | private Set<String> shopStatus; | ||
| 24 | |||
| 25 | public Set<String> getShop_status() { | ||
| 26 | return shopStatus; | ||
| 27 | } | ||
| 28 | } |
| 1 | package com.ql.backend.ploycenter.domain.po; | 1 | package com.ql.backend.ploycenter.domain.po; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.annotation.IdType; | 3 | import com.baomidou.mybatisplus.annotation.IdType; |
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | ||
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 6 | import lombok.AllArgsConstructor; | 7 | import lombok.AllArgsConstructor; |
| ... | @@ -9,6 +10,7 @@ import lombok.Data; | ... | @@ -9,6 +10,7 @@ import lombok.Data; |
| 9 | import lombok.NoArgsConstructor; | 10 | import lombok.NoArgsConstructor; |
| 10 | 11 | ||
| 11 | import java.io.Serializable; | 12 | import java.io.Serializable; |
| 13 | import java.util.Date; | ||
| 12 | 14 | ||
| 13 | /** | 15 | /** |
| 14 | * @author lirenhao | 16 | * @author lirenhao |
| ... | @@ -28,4 +30,31 @@ public class ShopPO implements Serializable { | ... | @@ -28,4 +30,31 @@ public class ShopPO implements Serializable { |
| 28 | */ | 30 | */ |
| 29 | @TableId(value = "shop_id", type = IdType.ASSIGN_ID) | 31 | @TableId(value = "shop_id", type = IdType.ASSIGN_ID) |
| 30 | private String shopId; | 32 | private String shopId; |
| 33 | |||
| 34 | /** | ||
| 35 | * 店铺名称 | ||
| 36 | */ | ||
| 37 | @TableField(value = "shop_name") | ||
| 38 | private String shopName; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * 店铺类型 | ||
| 42 | */ | ||
| 43 | @TableField(value = "shop_type") | ||
| 44 | private String shopType; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * 指定策略状态 | ||
| 48 | */ | ||
| 49 | @TableField(value = "ploy_status") | ||
| 50 | private String ployStatus; | ||
| 51 | |||
| 52 | @TableField(value = "is_deleted") | ||
| 53 | private Boolean isDeleted; | ||
| 54 | |||
| 55 | @TableField(value = "gmt_created") | ||
| 56 | private Date gmtCreated; | ||
| 57 | |||
| 58 | @TableField(value = "gmt_modified") | ||
| 59 | private Date gmtModified; | ||
| 31 | } | 60 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.infrastructure.adapter; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * 控制中枢适配器 | ||
| 8 | * | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/9 11:53 | ||
| 11 | */ | ||
| 12 | public interface ControlCenterAdapter { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * 通过策略创建任务 | ||
| 16 | */ | ||
| 17 | ApiResponse<String> createTask(PloyPO ployPO); | ||
| 18 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.adapter.dto; | ||
| 2 | |||
| 3 | import lombok.Builder; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author lirenhao | ||
| 8 | * date: 2022/9/9 14:33 | ||
| 9 | */ | ||
| 10 | @Data | ||
| 11 | @Builder | ||
| 12 | public class CommonControlCenterResponse<T> { | ||
| 13 | |||
| 14 | private int code; | ||
| 15 | |||
| 16 | private String msg; | ||
| 17 | |||
| 18 | private T data; | ||
| 19 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.adapter.dto; | ||
| 2 | |||
| 3 | import lombok.Builder; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | import java.util.List; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author lirenhao | ||
| 10 | * date: 2022/9/9 13:55 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | @Builder | ||
| 14 | public class JobCreateRequestDTO { | ||
| 15 | |||
| 16 | private String jobName; | ||
| 17 | |||
| 18 | private String processDetailUUID; | ||
| 19 | |||
| 20 | private Integer executeTimes; | ||
| 21 | |||
| 22 | private Integer executeType; | ||
| 23 | |||
| 24 | private String cronExpression; | ||
| 25 | |||
| 26 | private Object inputParam; | ||
| 27 | |||
| 28 | private Integer priority; | ||
| 29 | |||
| 30 | private Integer distributionType; | ||
| 31 | |||
| 32 | private List<Object> botList; | ||
| 33 | |||
| 34 | private Integer processChannel; | ||
| 35 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.adapter.impl; | ||
| 2 | |||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | ||
| 5 | import com.ql.backend.ploycenter.infrastructure.adapter.ControlCenterAdapter; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.adapter.utils.ControlCenterApi; | ||
| 7 | import lombok.extern.slf4j.Slf4j; | ||
| 8 | import org.springframework.stereotype.Service; | ||
| 9 | |||
| 10 | import javax.annotation.PostConstruct; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author lirenhao | ||
| 14 | * date: 2022/9/9 11:54 | ||
| 15 | */ | ||
| 16 | @Slf4j | ||
| 17 | @Service | ||
| 18 | public class ControlCenterAdapterImpl implements ControlCenterAdapter { | ||
| 19 | |||
| 20 | private ControlCenterApi controlCenterApi; | ||
| 21 | |||
| 22 | @PostConstruct | ||
| 23 | public void init() { | ||
| 24 | controlCenterApi = new ControlCenterApi( | ||
| 25 | "https://z-commander-api.ai-indeed.com", | ||
| 26 | "111", | ||
| 27 | "111" | ||
| 28 | ); | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | public ApiResponse<String> createTask(PloyPO ployPO) { | ||
| 33 | /* todo 在控制中枢创建任务 */ | ||
| 34 | return ApiResponse.ok("111"); | ||
| 35 | } | ||
| 36 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.adapter.utils; | ||
| 2 | |||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson2.TypeReference; | ||
| 5 | import com.ql.backend.core.interfaces.vo.ApiResponse; | ||
| 6 | import com.ql.backend.ploycenter.infrastructure.adapter.dto.CommonControlCenterResponse; | ||
| 7 | import com.ql.backend.ploycenter.infrastructure.adapter.dto.JobCreateRequestDTO; | ||
| 8 | import com.ql.backend.ploycenter.infrastructure.adapter.dto.JobCreateResponseDTO; | ||
| 9 | import com.ql.backend.ploycenter.infrastructure.okhttp3.interceptor.BasicParamsInterceptor; | ||
| 10 | import lombok.extern.slf4j.Slf4j; | ||
| 11 | import okhttp3.*; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.util.Objects; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @author lirenhao | ||
| 18 | * date: 2022/9/9 11:58 | ||
| 19 | */ | ||
| 20 | @Slf4j | ||
| 21 | public class ControlCenterApi { | ||
| 22 | |||
| 23 | private final String domain; | ||
| 24 | |||
| 25 | private final String appKey; | ||
| 26 | |||
| 27 | private final String appSecret; | ||
| 28 | |||
| 29 | private final OkHttpClient client; | ||
| 30 | |||
| 31 | public ControlCenterApi(String domain, String appKey, String appSecret) { | ||
| 32 | this.domain = domain; | ||
| 33 | this.appKey = appKey; | ||
| 34 | this.appSecret = appSecret; | ||
| 35 | this.client = new OkHttpClient.Builder() | ||
| 36 | .addInterceptor(new BasicParamsInterceptor.Builder() | ||
| 37 | .addHeaderParam("appKey", this.appKey) | ||
| 38 | .addHeaderParam("appSecret", this.appSecret) | ||
| 39 | .build()) | ||
| 40 | .build(); | ||
| 41 | } | ||
| 42 | |||
| 43 | public ApiResponse<String> createJob(JobCreateRequestDTO dto) { | ||
| 44 | final Request request = new Request.Builder() | ||
| 45 | .url(this.domain + "/openAPI/v1/job") | ||
| 46 | .post(RequestBody.create(JSON.toJSONString(dto), MediaType.parse("application/json"))) | ||
| 47 | .build(); | ||
| 48 | try { | ||
| 49 | CommonControlCenterResponse<JobCreateResponseDTO> response = call(request); | ||
| 50 | return ApiResponse.ok(response.getData().getJobUUID()); | ||
| 51 | } catch (Exception e) { | ||
| 52 | return ApiResponse.fail("请求控制中心接口失败"); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | private <T> T call(Request request) throws IOException { | ||
| 57 | Call call = client.newCall(request); | ||
| 58 | Response response = call.execute(); | ||
| 59 | String body = Objects.requireNonNull(response.body()).string(); | ||
| 60 | log.info("Body [{}]", body); | ||
| 61 | return JSON.parseObject(body, new TypeReference<T>() { | ||
| 62 | }.getType()); | ||
| 63 | } | ||
| 64 | } |
| 1 | package com.ql.backend.ploycenter.infrastructure.okhttp3.interceptor; | ||
| 2 | |||
| 3 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||
| 4 | import okhttp3.*; | ||
| 5 | import okio.Buffer; | ||
| 6 | |||
| 7 | import java.io.IOException; | ||
| 8 | import java.util.*; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/9 14:08 | ||
| 13 | */ | ||
| 14 | public class BasicParamsInterceptor implements Interceptor { | ||
| 15 | |||
| 16 | Map<String, String> queryParamsMap = new HashMap<>(); // 添加到 URL 末尾,Get Post 方法都使用 | ||
| 17 | Map<String, String> paramsMap = new HashMap<>(); // 添加到公共参数到消息体,适用 Post 请求 | ||
| 18 | Map<String, String> headerParamsMap = new HashMap<>(); // 公共 Headers 添加 | ||
| 19 | List<String> headerLinesList = new ArrayList<>(); // 消息头 集合形式,一次添加一行 | ||
| 20 | |||
| 21 | // 私有构造器 | ||
| 22 | private BasicParamsInterceptor() { | ||
| 23 | } | ||
| 24 | |||
| 25 | @Override | ||
| 26 | public Response intercept(Chain chain) throws IOException { | ||
| 27 | |||
| 28 | Request request = chain.request(); | ||
| 29 | Request.Builder requestBuilder = request.newBuilder(); | ||
| 30 | |||
| 31 | // process header params inject | ||
| 32 | Headers.Builder headerBuilder = request.headers().newBuilder(); | ||
| 33 | // 以 Entry 添加消息头 | ||
| 34 | if (headerParamsMap.size() > 0) { | ||
| 35 | Iterator iterator = headerParamsMap.entrySet().iterator(); | ||
| 36 | while (iterator.hasNext()) { | ||
| 37 | Map.Entry entry = (Map.Entry) iterator.next(); | ||
| 38 | headerBuilder.add((String) entry.getKey(), (String) entry.getValue()); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | // 以 String 形式添加消息头 | ||
| 42 | if (headerLinesList.size() > 0) { | ||
| 43 | for (String line : headerLinesList) { | ||
| 44 | headerBuilder.add(line); | ||
| 45 | } | ||
| 46 | requestBuilder.headers(headerBuilder.build()); | ||
| 47 | } | ||
| 48 | // process header params end | ||
| 49 | |||
| 50 | |||
| 51 | // process queryParams inject whatever it's GET or POST | ||
| 52 | if (queryParamsMap.size() > 0) { | ||
| 53 | request = injectParamsIntoUrl(request.url().newBuilder(), requestBuilder, queryParamsMap); | ||
| 54 | } | ||
| 55 | |||
| 56 | // process post body inject | ||
| 57 | if (paramsMap.size() > 0) { | ||
| 58 | if (canInjectIntoBody(request)) { | ||
| 59 | FormBody.Builder formBodyBuilder = new FormBody.Builder(); | ||
| 60 | for (Map.Entry<String, String> entry : paramsMap.entrySet()) { | ||
| 61 | formBodyBuilder.add((String) entry.getKey(), (String) entry.getValue()); | ||
| 62 | } | ||
| 63 | |||
| 64 | RequestBody formBody = formBodyBuilder.build(); | ||
| 65 | String postBodyString = bodyToString(request.body()); | ||
| 66 | postBodyString += ((postBodyString.length() > 0) ? "&" : "") + bodyToString(formBody); | ||
| 67 | requestBuilder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded;charset=UTF-8"), postBodyString)); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | request = requestBuilder.build(); | ||
| 71 | return chain.proceed(request); | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * 确认是否是 post 请求 | ||
| 76 | * | ||
| 77 | * @param request 发出的请求 | ||
| 78 | * @return true 需要注入公共参数 | ||
| 79 | */ | ||
| 80 | private boolean canInjectIntoBody(Request request) { | ||
| 81 | if (request == null) { | ||
| 82 | return false; | ||
| 83 | } | ||
| 84 | if (!StringUtils.equals(request.method(), "POST")) { | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | RequestBody body = request.body(); | ||
| 88 | if (body == null) { | ||
| 89 | return false; | ||
| 90 | } | ||
| 91 | MediaType mediaType = body.contentType(); | ||
| 92 | if (mediaType == null) { | ||
| 93 | return false; | ||
| 94 | } | ||
| 95 | if (!StringUtils.equals(mediaType.subtype(), "x-www-form-urlencoded")) { | ||
| 96 | return false; | ||
| 97 | } | ||
| 98 | return true; | ||
| 99 | } | ||
| 100 | |||
| 101 | // func to inject params into url | ||
| 102 | private Request injectParamsIntoUrl(HttpUrl.Builder httpUrlBuilder, Request.Builder requestBuilder, Map<String, String> paramsMap) { | ||
| 103 | if (paramsMap.size() > 0) { | ||
| 104 | Iterator iterator = paramsMap.entrySet().iterator(); | ||
| 105 | while (iterator.hasNext()) { | ||
| 106 | Map.Entry entry = (Map.Entry) iterator.next(); | ||
| 107 | httpUrlBuilder.addQueryParameter((String) entry.getKey(), (String) entry.getValue()); | ||
| 108 | } | ||
| 109 | requestBuilder.url(httpUrlBuilder.build()); | ||
| 110 | return requestBuilder.build(); | ||
| 111 | } | ||
| 112 | return null; | ||
| 113 | } | ||
| 114 | |||
| 115 | private static String bodyToString(final RequestBody request) { | ||
| 116 | try { | ||
| 117 | final RequestBody copy = request; | ||
| 118 | final Buffer buffer = new Buffer(); | ||
| 119 | if (copy != null) { | ||
| 120 | copy.writeTo(buffer); | ||
| 121 | } else { | ||
| 122 | return ""; | ||
| 123 | } | ||
| 124 | return buffer.readUtf8(); | ||
| 125 | } catch (final IOException e) { | ||
| 126 | return "did not work"; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | public static class Builder { | ||
| 131 | |||
| 132 | BasicParamsInterceptor interceptor; | ||
| 133 | |||
| 134 | public Builder() { | ||
| 135 | interceptor = new BasicParamsInterceptor(); | ||
| 136 | } | ||
| 137 | |||
| 138 | // 添加公共参数到 post 消息体 | ||
| 139 | public Builder addParam(String key, String value) { | ||
| 140 | interceptor.paramsMap.put(key, value); | ||
| 141 | return this; | ||
| 142 | } | ||
| 143 | |||
| 144 | // 添加公共参数到 post 消息体 | ||
| 145 | public Builder addParamsMap(Map<String, String> paramsMap) { | ||
| 146 | interceptor.paramsMap.putAll(paramsMap); | ||
| 147 | return this; | ||
| 148 | } | ||
| 149 | |||
| 150 | // 添加公共参数到消息头 | ||
| 151 | public Builder addHeaderParam(String key, String value) { | ||
| 152 | interceptor.headerParamsMap.put(key, value); | ||
| 153 | return this; | ||
| 154 | } | ||
| 155 | |||
| 156 | // 添加公共参数到消息头 | ||
| 157 | public Builder addHeaderParamsMap(Map<String, String> headerParamsMap) { | ||
| 158 | interceptor.headerParamsMap.putAll(headerParamsMap); | ||
| 159 | return this; | ||
| 160 | } | ||
| 161 | |||
| 162 | // 添加公共参数到消息头 | ||
| 163 | public Builder addHeaderLine(String headerLine) { | ||
| 164 | int index = headerLine.indexOf(":"); | ||
| 165 | if (index == -1) { | ||
| 166 | throw new IllegalArgumentException("Unexpected header: " + headerLine); | ||
| 167 | } | ||
| 168 | interceptor.headerLinesList.add(headerLine); | ||
| 169 | return this; | ||
| 170 | } | ||
| 171 | |||
| 172 | // 添加公共参数到消息头 | ||
| 173 | public Builder addHeaderLinesList(List<String> headerLinesList) { | ||
| 174 | for (String headerLine : headerLinesList) { | ||
| 175 | int index = headerLine.indexOf(":"); | ||
| 176 | if (index == -1) { | ||
| 177 | throw new IllegalArgumentException("Unexpected header: " + headerLine); | ||
| 178 | } | ||
| 179 | interceptor.headerLinesList.add(headerLine); | ||
| 180 | } | ||
| 181 | return this; | ||
| 182 | } | ||
| 183 | |||
| 184 | // 添加公共参数到 URL | ||
| 185 | public Builder addQueryParam(String key, String value) { | ||
| 186 | interceptor.queryParamsMap.put(key, value); | ||
| 187 | return this; | ||
| 188 | } | ||
| 189 | |||
| 190 | // 添加公共参数到 URL | ||
| 191 | public Builder addQueryParamsMap(Map<String, String> queryParamsMap) { | ||
| 192 | interceptor.queryParamsMap.putAll(queryParamsMap); | ||
| 193 | return this; | ||
| 194 | } | ||
| 195 | |||
| 196 | public BasicParamsInterceptor build() { | ||
| 197 | return interceptor; | ||
| 198 | } | ||
| 199 | |||
| 200 | } | ||
| 201 | } |
| ... | @@ -9,4 +9,5 @@ import com.ql.backend.ploycenter.domain.po.PloyPO; | ... | @@ -9,4 +9,5 @@ import com.ql.backend.ploycenter.domain.po.PloyPO; |
| 9 | */ | 9 | */ |
| 10 | public interface PloyDao extends IService<PloyPO> { | 10 | public interface PloyDao extends IService<PloyPO> { |
| 11 | 11 | ||
| 12 | PloyPO getPloyById(String ployId); | ||
| 12 | } | 13 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; | 1 | package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 4 | import com.ql.backend.ploycenter.domain.po.PloyPO; | 5 | import com.ql.backend.ploycenter.domain.po.PloyPO; |
| 5 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; | 6 | import com.ql.backend.ploycenter.infrastructure.persistence.dao.PloyDao; |
| ... | @@ -13,4 +14,10 @@ import org.springframework.stereotype.Service; | ... | @@ -13,4 +14,10 @@ import org.springframework.stereotype.Service; |
| 13 | @Service | 14 | @Service |
| 14 | public class PloyDaoImpl extends ServiceImpl<PloyMapper, PloyPO> implements PloyDao { | 15 | public class PloyDaoImpl extends ServiceImpl<PloyMapper, PloyPO> implements PloyDao { |
| 15 | 16 | ||
| 17 | @Override | ||
| 18 | public PloyPO getPloyById(String ployId) { | ||
| 19 | LambdaQueryWrapper<PloyPO> wrapper = new LambdaQueryWrapper<>(); | ||
| 20 | wrapper.eq(PloyPO::getPloyId, ployId); | ||
| 21 | return this.baseMapper.selectOne(wrapper); | ||
| 22 | } | ||
| 16 | } | 23 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.interfaces.facade; | 1 | package com.ql.backend.ploycenter.interfaces.facade; |
| 2 | 2 | ||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; |
| 4 | import com.ql.backend.core.interfaces.vo.PageVO; | ||
| 4 | import com.ql.backend.ploycenter.application.PloyService; | 5 | import com.ql.backend.ploycenter.application.PloyService; |
| 6 | import com.ql.backend.ploycenter.domain.condition.PloyCondition; | ||
| 5 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; | 7 | import com.ql.backend.ploycenter.interfaces.request.PloyCreateRequest; |
| 6 | import org.springframework.web.bind.annotation.PostMapping; | 8 | import com.ql.backend.ploycenter.interfaces.request.PloyUpdateRequest; |
| 7 | import org.springframework.web.bind.annotation.RequestBody; | 9 | import com.ql.backend.ploycenter.interfaces.vo.PloyVO; |
| 8 | import org.springframework.web.bind.annotation.RequestMapping; | 10 | import org.springframework.web.bind.annotation.*; |
| 9 | import org.springframework.web.bind.annotation.RestController; | ||
| 10 | 11 | ||
| 11 | import javax.annotation.Resource; | 12 | import javax.annotation.Resource; |
| 12 | 13 | ||
| ... | @@ -31,9 +32,30 @@ public class PloyFacade { | ... | @@ -31,9 +32,30 @@ public class PloyFacade { |
| 31 | ); | 32 | ); |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 35 | /** | ||
| 36 | * 更新策略 | ||
| 37 | */ | ||
| 38 | @PutMapping("/{id}") | ||
| 39 | public ApiResponse<Void> updatePloy(@PathVariable("id") String id, @RequestBody PloyUpdateRequest request) { | ||
| 34 | /* todo 更新策略 */ | 40 | /* todo 更新策略 */ |
| 41 | return ApiResponse.ok(); | ||
| 42 | } | ||
| 35 | 43 | ||
| 44 | /** | ||
| 45 | * 查询策略列表 | ||
| 46 | */ | ||
| 47 | @GetMapping | ||
| 48 | public ApiResponse<PageVO<PloyVO>> findPloy(PloyCondition condition) { | ||
| 36 | /* todo 查询策略列表 */ | 49 | /* todo 查询策略列表 */ |
| 50 | return ApiResponse.ok(); | ||
| 51 | } | ||
| 37 | 52 | ||
| 53 | /** | ||
| 54 | * 查询策略详情 | ||
| 55 | */ | ||
| 56 | @GetMapping("/{id}") | ||
| 57 | public ApiResponse<PloyVO> getPloy(@PathVariable("id") String id) { | ||
| 38 | /* todo 查询策略详情 */ | 58 | /* todo 查询策略详情 */ |
| 59 | return ApiResponse.ok(); | ||
| 60 | } | ||
| 39 | } | 61 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.interfaces.facade; | 1 | package com.ql.backend.ploycenter.interfaces.facade; |
| 2 | 2 | ||
| 3 | import org.springframework.web.bind.annotation.RequestMapping; | 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; |
| 4 | import org.springframework.web.bind.annotation.RestController; | 4 | import com.ql.backend.core.interfaces.vo.PageVO; |
| 5 | import com.ql.backend.ploycenter.domain.condition.ShopCondition; | ||
| 6 | import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest; | ||
| 7 | import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest; | ||
| 8 | import com.ql.backend.ploycenter.interfaces.vo.ShopVO; | ||
| 9 | import org.springframework.web.bind.annotation.*; | ||
| 5 | 10 | ||
| 6 | /** | 11 | /** |
| 7 | * @author lirenhao | 12 | * @author lirenhao |
| ... | @@ -11,11 +16,34 @@ import org.springframework.web.bind.annotation.RestController; | ... | @@ -11,11 +16,34 @@ import org.springframework.web.bind.annotation.RestController; |
| 11 | @RequestMapping("/ploy-center/v1/shops") | 16 | @RequestMapping("/ploy-center/v1/shops") |
| 12 | public class ShopFacade { | 17 | public class ShopFacade { |
| 13 | 18 | ||
| 19 | @PostMapping | ||
| 20 | public ApiResponse<String> createShop(@RequestBody ShopCreateRequest request) { | ||
| 14 | /* todo 创建店铺 */ | 21 | /* todo 创建店铺 */ |
| 22 | return ApiResponse.ok(); | ||
| 23 | } | ||
| 15 | 24 | ||
| 25 | |||
| 26 | @PutMapping("/{id}") | ||
| 27 | public ApiResponse<String> updateShop(@PathVariable("id") String id, @RequestBody ShopUpdateRequest request) { | ||
| 16 | /* todo 更新店铺信息 */ | 28 | /* todo 更新店铺信息 */ |
| 29 | return ApiResponse.ok(); | ||
| 30 | } | ||
| 17 | 31 | ||
| 32 | /** | ||
| 33 | * 查询店铺列表 | ||
| 34 | */ | ||
| 35 | @GetMapping | ||
| 36 | public ApiResponse<PageVO<ShopVO>> findShop(ShopCondition condition) { | ||
| 18 | /* todo 查询店铺列表 */ | 37 | /* todo 查询店铺列表 */ |
| 38 | return ApiResponse.ok(); | ||
| 39 | } | ||
| 19 | 40 | ||
| 41 | /** | ||
| 42 | * 查询店铺详情 | ||
| 43 | */ | ||
| 44 | @GetMapping("/{id}") | ||
| 45 | public ApiResponse<ShopVO> getShop(@PathVariable("id") String id) { | ||
| 20 | /* todo 查询店铺详情 */ | 46 | /* todo 查询店铺详情 */ |
| 47 | return ApiResponse.ok(); | ||
| 48 | } | ||
| 21 | } | 49 | } | ... | ... |
| ... | @@ -6,6 +6,8 @@ import lombok.AllArgsConstructor; | ... | @@ -6,6 +6,8 @@ import lombok.AllArgsConstructor; |
| 6 | import lombok.Data; | 6 | import lombok.Data; |
| 7 | import lombok.NoArgsConstructor; | 7 | import lombok.NoArgsConstructor; |
| 8 | 8 | ||
| 9 | import java.util.Set; | ||
| 10 | |||
| 9 | /** | 11 | /** |
| 10 | * @author lirenhao | 12 | * @author lirenhao |
| 11 | * date: 2022/9/5 17:40 | 13 | * date: 2022/9/5 17:40 |
| ... | @@ -36,4 +38,9 @@ public class PloyCreateRequest { | ... | @@ -36,4 +38,9 @@ public class PloyCreateRequest { |
| 36 | private Integer priority; | 38 | private Integer priority; |
| 37 | 39 | ||
| 38 | private Integer distributionType; | 40 | private Integer distributionType; |
| 41 | |||
| 42 | /** | ||
| 43 | * 绑定的店铺ID | ||
| 44 | */ | ||
| 45 | private Set<String> bindShopIds; | ||
| 39 | } | 46 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | import java.util.Set; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author lirenhao | ||
| 13 | * date: 2022/9/5 17:40 | ||
| 14 | */ | ||
| 15 | @Data | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class PloyUpdateRequest { | ||
| 20 | |||
| 21 | /** | ||
| 22 | * 策略名称 | ||
| 23 | */ | ||
| 24 | private String ployName; | ||
| 25 | |||
| 26 | private String processDetailUUID; | ||
| 27 | |||
| 28 | private String processChannel; | ||
| 29 | |||
| 30 | private Integer executeTimes; | ||
| 31 | |||
| 32 | private String executeType; | ||
| 33 | |||
| 34 | private String cronExpression; | ||
| 35 | |||
| 36 | private String inputParam; | ||
| 37 | |||
| 38 | private Integer priority; | ||
| 39 | |||
| 40 | private Integer distributionType; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * 绑定的店铺ID | ||
| 44 | */ | ||
| 45 | private Set<String> bindShopIds; | ||
| 46 | } |
| 1 | package com.ql.backend.ploycenter.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/9/5 17:40 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @NoArgsConstructor | ||
| 15 | @AllArgsConstructor | ||
| 16 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 17 | public class ShopCreateRequest { | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 店铺名称 | ||
| 21 | */ | ||
| 22 | private String shopName; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 店铺类型 | ||
| 26 | */ | ||
| 27 | private String shopType; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 绑定策略ID | ||
| 31 | */ | ||
| 32 | private String bindPloyId; | ||
| 33 | } |
| 1 | package com.ql.backend.ploycenter.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/9/5 17:40 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @NoArgsConstructor | ||
| 15 | @AllArgsConstructor | ||
| 16 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 17 | public class ShopUpdateRequest { | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 店铺名称 | ||
| 21 | */ | ||
| 22 | private String shopName; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 店铺类型 | ||
| 26 | */ | ||
| 27 | private String shopType; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 绑定策略ID | ||
| 31 | */ | ||
| 32 | private String bindPloyId; | ||
| 33 | } |
| ... | @@ -7,6 +7,8 @@ import lombok.Builder; | ... | @@ -7,6 +7,8 @@ import lombok.Builder; |
| 7 | import lombok.Data; | 7 | import lombok.Data; |
| 8 | import lombok.NoArgsConstructor; | 8 | import lombok.NoArgsConstructor; |
| 9 | 9 | ||
| 10 | import java.util.List; | ||
| 11 | |||
| 10 | /** | 12 | /** |
| 11 | * @author lirenhao | 13 | * @author lirenhao |
| 12 | * date: 2022/9/5 17:49 | 14 | * date: 2022/9/5 17:49 |
| ... | @@ -18,5 +20,34 @@ import lombok.NoArgsConstructor; | ... | @@ -18,5 +20,34 @@ import lombok.NoArgsConstructor; |
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | 20 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) |
| 19 | public class PloyVO { | 21 | public class PloyVO { |
| 20 | 22 | ||
| 23 | /** | ||
| 24 | * 策略ID | ||
| 25 | */ | ||
| 21 | private String ployId; | 26 | private String ployId; |
| 27 | |||
| 28 | /** | ||
| 29 | * 策略名称 | ||
| 30 | */ | ||
| 31 | private String ployName; | ||
| 32 | |||
| 33 | private String processDetailUUID; | ||
| 34 | |||
| 35 | private String processChannel; | ||
| 36 | |||
| 37 | private Integer executeTimes; | ||
| 38 | |||
| 39 | private String executeType; | ||
| 40 | |||
| 41 | private String cronExpression; | ||
| 42 | |||
| 43 | private String inputParam; | ||
| 44 | |||
| 45 | private Integer priority; | ||
| 46 | |||
| 47 | private Integer distributionType; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * 绑定的店铺信息 | ||
| 51 | */ | ||
| 52 | private List<ShopVO> bindShops; | ||
| 22 | } | 53 | } | ... | ... |
| 1 | package com.ql.backend.ploycenter.interfaces.vo; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Builder; | ||
| 7 | import lombok.Data; | ||
| 8 | import lombok.NoArgsConstructor; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author lirenhao | ||
| 12 | * date: 2022/9/13 16:02 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @Builder | ||
| 16 | @NoArgsConstructor | ||
| 17 | @AllArgsConstructor | ||
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 19 | public class ShopVO { | ||
| 20 | |||
| 21 | /** | ||
| 22 | * 店铺ID | ||
| 23 | */ | ||
| 24 | private String shopId; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 店铺名称 | ||
| 28 | */ | ||
| 29 | private String shopName; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * 店铺类型 | ||
| 33 | */ | ||
| 34 | private String shopType; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * 指定策略状态 | ||
| 38 | */ | ||
| 39 | private String ployStatus; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * 绑定的策略 | ||
| 43 | */ | ||
| 44 | private PloyVO bindPloy; | ||
| 45 | } |
| ... | @@ -19,3 +19,6 @@ mybatis-plus: | ... | @@ -19,3 +19,6 @@ mybatis-plus: |
| 19 | configuration: | 19 | configuration: |
| 20 | # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 | 20 | # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 |
| 21 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl | 21 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
| 22 | global-config: | ||
| 23 | #字段策略 0:"忽略判断",1:"非 NULL 判断",2:"非空判断" | ||
| 24 | field-strategy: 2 | ... | ... |
| ... | @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; | ... | @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; |
| 16 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| 17 | 17 | ||
| 18 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
| 19 | import java.util.Date; | ||
| 19 | import java.util.UUID; | 20 | import java.util.UUID; |
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| ... | @@ -39,6 +40,9 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -39,6 +40,9 @@ public class TaskServiceImpl implements TaskService { |
| 39 | taskPO.setTaskId(UUID.randomUUID().toString()); | 40 | taskPO.setTaskId(UUID.randomUUID().toString()); |
| 40 | taskPO.setTaskStatus(TaskStatus.CREATED); | 41 | taskPO.setTaskStatus(TaskStatus.CREATED); |
| 41 | taskPO.setTaskSubStatus(TaskSubStatus.PENDING); | 42 | taskPO.setTaskSubStatus(TaskSubStatus.PENDING); |
| 43 | taskPO.setGmtCreated(new Date()); | ||
| 44 | taskPO.setGmtModified(new Date()); | ||
| 45 | taskPO.setIsDeleted(Boolean.FALSE); | ||
| 42 | taskDao.save(taskPO); | 46 | taskDao.save(taskPO); |
| 43 | 47 | ||
| 44 | /* 执行策略 */ | 48 | /* 执行策略 */ | ... | ... |
ql-backend-taskmanager/src/main/java/com/ql/backend/taskmanager/domain/condition/TaskCondition.java
0 → 100644
| 1 | package com.ql.backend.taskmanager.domain.condition; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import com.ql.backend.ploycenter.domain.condition.CommonPageCondition; | ||
| 6 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 7 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 8 | import lombok.AllArgsConstructor; | ||
| 9 | import lombok.Data; | ||
| 10 | import lombok.NoArgsConstructor; | ||
| 11 | import lombok.experimental.SuperBuilder; | ||
| 12 | |||
| 13 | import java.util.Set; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author lirenhao | ||
| 17 | * date: 2022/9/13 14:35 | ||
| 18 | */ | ||
| 19 | @Data | ||
| 20 | @SuperBuilder | ||
| 21 | @NoArgsConstructor | ||
| 22 | @AllArgsConstructor | ||
| 23 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 24 | public class TaskCondition extends CommonPageCondition { | ||
| 25 | |||
| 26 | private Set<TaskStatus> taskStatus; | ||
| 27 | |||
| 28 | private Set<TaskSubStatus> taskSubStatus; | ||
| 29 | |||
| 30 | public Set<TaskStatus> getTask_status() { | ||
| 31 | return taskStatus; | ||
| 32 | } | ||
| 33 | |||
| 34 | public Set<TaskSubStatus> getTask_sub_status() { | ||
| 35 | return taskSubStatus; | ||
| 36 | } | ||
| 37 | } |
| 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao; | 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.extension.service.IService; | ||
| 3 | import com.ql.backend.taskmanager.domain.po.TaskPO; | 4 | import com.ql.backend.taskmanager.domain.po.TaskPO; |
| 4 | 5 | ||
| 5 | /** | 6 | /** |
| 6 | * @author lirenhao | 7 | * @author lirenhao |
| 7 | * date: 2022/9/1 11:02 | 8 | * date: 2022/9/1 11:02 |
| 8 | */ | 9 | */ |
| 9 | public interface TaskDao { | 10 | public interface TaskDao extends IService<TaskPO> { |
| 10 | |||
| 11 | TaskPO save(TaskPO po); | ||
| 12 | 11 | ||
| 13 | boolean updateByTaskId(String taskId, TaskPO update); | 12 | boolean updateByTaskId(String taskId, TaskPO update); |
| 14 | 13 | ... | ... |
| 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao.impl; | 1 | package com.ql.backend.taskmanager.infrastructure.persistence.dao.impl; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 3 | import com.ql.backend.taskmanager.domain.po.TaskPO; | 5 | import com.ql.backend.taskmanager.domain.po.TaskPO; |
| 4 | import com.ql.backend.taskmanager.infrastructure.persistence.dao.TaskDao; | 6 | import com.ql.backend.taskmanager.infrastructure.persistence.dao.TaskDao; |
| 7 | import com.ql.backend.taskmanager.infrastructure.persistence.mapper.TaskMapper; | ||
| 5 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 6 | 9 | ||
| 7 | /** | 10 | /** |
| ... | @@ -9,15 +12,13 @@ import org.springframework.stereotype.Service; | ... | @@ -9,15 +12,13 @@ import org.springframework.stereotype.Service; |
| 9 | * date: 2022/9/1 11:02 | 12 | * date: 2022/9/1 11:02 |
| 10 | */ | 13 | */ |
| 11 | @Service | 14 | @Service |
| 12 | public class TaskDaoImpl implements TaskDao { | 15 | public class TaskDaoImpl extends ServiceImpl<TaskMapper, TaskPO> implements TaskDao { |
| 13 | @Override | ||
| 14 | public TaskPO save(TaskPO po) { | ||
| 15 | return null; | ||
| 16 | } | ||
| 17 | 16 | ||
| 18 | @Override | 17 | @Override |
| 19 | public boolean updateByTaskId(String taskId, TaskPO update) { | 18 | public boolean updateByTaskId(String taskId, TaskPO update) { |
| 20 | return false; | 19 | LambdaQueryWrapper<TaskPO> wrapper = new LambdaQueryWrapper<>(); |
| 20 | wrapper.eq(TaskPO::getTaskId, taskId); | ||
| 21 | return this.update(update, wrapper); | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | @Override | 24 | @Override | ... | ... |
| 1 | package com.ql.backend.taskmanager.interfaces.facade; | 1 | package com.ql.backend.taskmanager.interfaces.facade; |
| 2 | 2 | ||
| 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; | 3 | import com.ql.backend.core.interfaces.vo.ApiResponse; |
| 4 | import com.ql.backend.core.interfaces.vo.PageVO; | ||
| 4 | import com.ql.backend.taskmanager.application.TaskService; | 5 | import com.ql.backend.taskmanager.application.TaskService; |
| 6 | import com.ql.backend.taskmanager.domain.condition.TaskCondition; | ||
| 5 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; | 7 | import com.ql.backend.taskmanager.interfaces.request.TaskCreateRequest; |
| 8 | import com.ql.backend.taskmanager.interfaces.request.TaskStatusReport; | ||
| 6 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; | 9 | import com.ql.backend.taskmanager.interfaces.vo.TaskVO; |
| 7 | import org.springframework.web.bind.annotation.*; | 10 | import org.springframework.web.bind.annotation.*; |
| 8 | 11 | ||
| ... | @@ -19,15 +22,37 @@ public class TaskFacade { | ... | @@ -19,15 +22,37 @@ public class TaskFacade { |
| 19 | @Resource | 22 | @Resource |
| 20 | private TaskService taskService; | 23 | private TaskService taskService; |
| 21 | 24 | ||
| 25 | /** | ||
| 26 | * 创建任务 | ||
| 27 | */ | ||
| 22 | @PostMapping | 28 | @PostMapping |
| 23 | public ApiResponse<String> createTask(@RequestBody TaskCreateRequest request) { | 29 | public ApiResponse<String> createTask(@RequestBody TaskCreateRequest request) { |
| 24 | return ApiResponse.ok(taskService.createTask(request)); | 30 | return ApiResponse.ok(taskService.createTask(request)); |
| 25 | } | 31 | } |
| 26 | 32 | ||
| 27 | @GetMapping("/{taskId}") | 33 | /** |
| 28 | public ApiResponse<TaskVO> getTask(@PathVariable("taskId") String taskId) { | 34 | * 更新任务状态 |
| 35 | */ | ||
| 36 | @PutMapping("/{id}") | ||
| 37 | public ApiResponse<String> updateTaskStatus(@PathVariable("id") String id, @RequestBody TaskStatusReport report) { | ||
| 38 | /* todo 设备上报任务状态 */ | ||
| 39 | return ApiResponse.ok(); | ||
| 40 | } | ||
| 41 | |||
| 42 | /** | ||
| 43 | * 获取任务详情 | ||
| 44 | */ | ||
| 45 | @GetMapping("/{id}") | ||
| 46 | public ApiResponse<TaskVO> getTask(@PathVariable("id") String taskId) { | ||
| 29 | return ApiResponse.ok(taskService.getTask(taskId)); | 47 | return ApiResponse.ok(taskService.getTask(taskId)); |
| 30 | } | 48 | } |
| 31 | 49 | ||
| 32 | /* todo 设备上报任务状态 */ | 50 | /** |
| 51 | * 分页查询任务信息 | ||
| 52 | */ | ||
| 53 | @GetMapping | ||
| 54 | public ApiResponse<PageVO<TaskVO>> findTask(TaskCondition condition) { | ||
| 55 | /* todo 分页查询任务信息 */ | ||
| 56 | return ApiResponse.ok(); | ||
| 57 | } | ||
| 33 | } | 58 | } | ... | ... |
| 1 | package com.ql.backend.taskmanager.interfaces.request; | ||
| 2 | |||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| 5 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 6 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 7 | import lombok.Data; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author lirenhao | ||
| 11 | * date: 2022/8/31 18:13 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
| 15 | public class TaskStatusReport { | ||
| 16 | |||
| 17 | private String deviceId; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 任务状态 | ||
| 21 | */ | ||
| 22 | private TaskStatus taskStatus; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 任务子状态 | ||
| 26 | */ | ||
| 27 | private TaskSubStatus taskSubStatus; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 失败原因 | ||
| 31 | */ | ||
| 32 | private String failReason; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * 时间戳 | ||
| 36 | */ | ||
| 37 | private long timestamp; | ||
| 38 | } |
| ... | @@ -2,6 +2,8 @@ package com.ql.backend.taskmanager.interfaces.vo; | ... | @@ -2,6 +2,8 @@ package com.ql.backend.taskmanager.interfaces.vo; |
| 2 | 2 | ||
| 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | 3 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; |
| 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; | 4 | import com.fasterxml.jackson.databind.annotation.JsonNaming; |
| 5 | import com.ql.backend.taskmanager.common.enums.TaskStatus; | ||
| 6 | import com.ql.backend.taskmanager.common.enums.TaskSubStatus; | ||
| 5 | import lombok.AllArgsConstructor; | 7 | import lombok.AllArgsConstructor; |
| 6 | import lombok.Builder; | 8 | import lombok.Builder; |
| 7 | import lombok.Data; | 9 | import lombok.Data; |
| ... | @@ -18,5 +20,36 @@ import lombok.NoArgsConstructor; | ... | @@ -18,5 +20,36 @@ import lombok.NoArgsConstructor; |
| 18 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | 20 | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) |
| 19 | public class TaskVO { | 21 | public class TaskVO { |
| 20 | 22 | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 任务ID | ||
| 26 | */ | ||
| 21 | private String taskId; | 27 | private String taskId; |
| 28 | |||
| 29 | /** | ||
| 30 | * 任务状态 | ||
| 31 | */ | ||
| 32 | private TaskStatus taskStatus; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * 任务子状态 | ||
| 36 | */ | ||
| 37 | private TaskSubStatus taskSubStatus; | ||
| 38 | |||
| 39 | private String shopId; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * 策略ID | ||
| 43 | */ | ||
| 44 | private String ployId; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * 任务参数 | ||
| 48 | */ | ||
| 49 | private String taskParam; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * 失败原因 | ||
| 53 | */ | ||
| 54 | private String failReason; | ||
| 22 | } | 55 | } | ... | ... |
-
Please register or sign in to post a comment