From 6fa3dada3da68dd791dc6b093dc403becd849c21 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 27 Jun 2023 11:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/common/util/CryptUtils.java | 68 +++++++ .../ningdatech/pmapi/common/util/HmacAuthUtil.java | 82 ++++++++ .../com/ningdatech/pmapi/common/util/HttpUtil.java | 217 +++++++++++++++++++++ .../com/ningdatech/pmapi/common/util/Md5Utils.java | 46 +++++ .../pmapi/common/util/RefreshKeyUtil.java | 34 ++++ .../manage/IndicatorTemplateManage.java | 1 + ...PerformanceIndicatorProjectTemplateSaveDTO.java | 3 + .../model/dto/ProjectTemplateDetailDTO.java | 45 +++++ .../PerformanceIndicatorProjectTemplateDetail.java | 53 +++++ .../controller/ProjectApplicationController.java | 41 ++++ .../pmapi/projectlib/manage/ApplicationManage.java | 53 +++++ .../model/dto/ApplicationAppCodeSaveDTO.java | 32 +++ .../model/entity/ProjectApplication.java | 3 + .../projectlib/model/vo/ProjectApplicationVO.java | 3 + 14 files changed, 681 insertions(+) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/CryptUtils.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/HmacAuthUtil.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/Md5Utils.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/util/RefreshKeyUtil.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/ProjectTemplateDetailDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/performance/model/entity/PerformanceIndicatorProjectTemplateDetail.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/projectlib/controller/ProjectApplicationController.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ApplicationManage.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ApplicationAppCodeSaveDTO.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/CryptUtils.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/CryptUtils.java new file mode 100644 index 0000000..2a2c0f7 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/CryptUtils.java @@ -0,0 +1,68 @@ +package com.ningdatech.pmapi.common.util; + +import org.apache.commons.codec.binary.Hex; + +import javax.crypto.Mac; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * 加密工具 + * @author hank + */ +public class CryptUtils { + + /** + * 默认的算法 + */ + private static final String DE_KEY_MAC = "HmacMD5"; + + /** + * 默认的字符集 + */ + private static final Charset DE_CHARSET = StandardCharsets.UTF_8; + + + /** + * 使用默认的算法(HmacMD5) 得到hmac 16进制字符串 + * @param inputStr 需要加密的串 + * @param key key + * @return 16进制字符串 + * @throws Exception + */ + public static String encryptHMAC(String inputStr, String key) throws Exception { + return encryptHMAC(inputStr, key, DE_KEY_MAC); + } + /** + * 使用指定的算法得到hmac 16进制字符串 + * @param inputStr 需要加密的串 + * @param key key + * @param keyMac hmac算法 + * @return 16进制字符串 + * @throws Exception + */ + public static String encryptHMAC(String inputStr, String key, String keyMac) throws Exception { + return Hex.encodeHexString(encryptHMAC(inputStr.getBytes(DE_CHARSET), key, keyMac)); + } + + public static String MD5Encode(String origin) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("MD5"); + return Hex.encodeHexString(md.digest(origin.getBytes(DE_CHARSET))); + } + + private static byte[] encryptHMAC(byte[] data, String key, String keyMac) throws Exception { + + SecretKey secretKey = new SecretKeySpec(key.getBytes(DE_CHARSET), keyMac); + Mac mac = Mac.getInstance(secretKey.getAlgorithm()); + mac.init(secretKey); + return mac.doFinal(data); + } + + public static void main(String[] args) throws Exception{ + System.out.println("HMACStr:\n" + encryptHMAC("a", "hank")); + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HmacAuthUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HmacAuthUtil.java new file mode 100644 index 0000000..e58447d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HmacAuthUtil.java @@ -0,0 +1,82 @@ +package com.ningdatech.pmapi.common.util; + +import javafx.util.Pair; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +public class HmacAuthUtil { + /** + * 构造http请求 header + * + * @param url 请求url,全路径格式,比如:https://bcdsg.zj.gov.cn/api/p/v1/user.get + * @param requestMethod 请求方法,大写格式,如:GET, POST + * @param accessKey 应用的 AK + * @param secretKey 应用的 SK + * @return + */ + public static Map generateHeader(String url, String requestMethod, String accessKey, String secretKey) { + Map header = new HashMap<>(); + try { + DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + String date = dateFormat.format(new Date()); + URI uri = URI.create(url); + String canonicalQueryString = getCanonicalQueryString(uri.getQuery()); + String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + accessKey + "\n" + date + "\n"; + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")); + byte[] hash = mac.doFinal(message.getBytes()); + // to lowercase hexits + DatatypeConverter.printHexBinary(hash); + // to base64 + String sign = DatatypeConverter.printBase64Binary(hash); + header.put("X-BG-HMAC-SIGNATURE", sign); + header.put("X-BG-HMAC-ALGORITHM", "hmac-sha256"); + header.put("X-BG-HMAC-ACCESS-KEY", accessKey); + header.put("X-BG-DATE-TIME", date); + System.out.println(date); + } catch (Exception e) { + throw new RuntimeException("generate jc brain header error", e); + } + return header; + } + + private static String getCanonicalQueryString(String query) { + if (query == null || query.trim().length() == 0) { + return ""; + } + List> queryParamList = new ArrayList<>(); + String[] params = query.split("&"); + for (String param : params) { + String[] keyValue = param.split("="); + Pair pair = new Pair(keyValue[0], keyValue.length > 1 ? keyValue[1] : ""); + queryParamList.add(pair); + } + List> sortedParamList = queryParamList.stream().sorted(Comparator.comparing(param -> param.getKey() + "=" + Optional.ofNullable(param.getValue()).orElse(""))).collect(Collectors.toList()); + List> encodeParamList = new ArrayList<>(); + sortedParamList.stream().forEach(param -> { + try { + String key = URLEncoder.encode(param.getKey(), "utf-8"); + String value = URLEncoder.encode(Optional.ofNullable(param.getValue()).orElse(""), "utf-8"); + encodeParamList.add(new Pair<>(key, value)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("encoding error"); + } + }); + StringBuilder queryParamString = new StringBuilder(64); + for (Pair encodeParam : encodeParamList) { + queryParamString.append(encodeParam.getKey()).append("=").append(Optional.ofNullable(encodeParam.getValue()).orElse("")); + queryParamString.append("&"); + } + return queryParamString.substring(0, queryParamString.length() - 1); + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java new file mode 100644 index 0000000..fcc5333 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java @@ -0,0 +1,217 @@ +package com.ningdatech.pmapi.common.util; + +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.util.PublicSuffixMatcher; +import org.apache.http.conn.util.PublicSuffixMatcherLoader; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +public class HttpUtil { + private Logger logger = LoggerFactory.getLogger(getClass()); + private RequestConfig requestConfig = RequestConfig.custom() + .setSocketTimeout(15000) + .setConnectTimeout(15000) + .setConnectionRequestTimeout(15000) + .build(); + private static HttpUtil instance = null; + private HttpUtil(){} + + public static HttpUtil getInstance(){ + if (instance == null) { + instance = new HttpUtil(); + } + return instance; + } + + /** + * 发送 post 请求 + * @param httpUrl 地址 + */ + public String sendHttpPost(String httpUrl) { + HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost + return sendHttpPost(httpPost); + } + + /** + * 发送 post 请求 + * @param httpUrl 地址 + * @param params 参数(格式:key1=value1&key2=value2) + */ + public String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost + try { + //设置参数 + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(stringEntity); + } catch (Exception e) { + logger.error(e.getMessage(),e); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 post 请求 + * @param httpUrl 地址 + * @param maps 参数 + */ + public String sendHttpPost(String httpUrl, Map maps) { + HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost + // 创建参数队列 + List nameValuePairs = new ArrayList(); + for (String key : maps.keySet()) { + nameValuePairs.add(new BasicNameValuePair(key, maps.get(key))); + } + try { + httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } catch (Exception e) { + logger.error(e.getMessage(),e); + } + return sendHttpPost(httpPost); + } + + /** + * 发送 Post请求 + * @param httpPost + *@return + */ + private String sendHttpPost(HttpPost httpPost) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 创建默认的 httpClient 实例. + httpClient = HttpClients.createDefault(); + httpPost.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpPost); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + logger.error(e.getMessage(),e); + } finally { + try { + // 关闭连接,释放资源 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + logger.error(e.getMessage(),e); + } + } + return responseContent; + } + + /** + * 发送 get 请求 + * @param httpUrl + */ + public String sendHttpGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 创建 get 请求 + return sendHttpGet(httpGet); + } + + /** + * 发送 get请求 Https + * @param httpUrl + */ + public String sendHttpsGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 创建 get 请求 + return sendHttpsGet(httpGet); + } + + /** + * 发送 Get请求 + * @param httpGet + *@return + */ + private String sendHttpGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 创建默认的 httpClient 实例. + httpClient = HttpClients.createDefault(); + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + logger.error(e.getMessage(),e); + } finally { + try { + // 关闭连接,释放资源 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + logger.error(e.getMessage(),e); + } + } + return responseContent; + } + + /** + * 发送 Get请求 Https + *@return + */ + private String sendHttpsGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 创建默认的 httpClient 实例. + PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new + URL(httpGet.getURI().toString())); + DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); + httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build(); + httpGet.setConfig(requestConfig); + // 执行请求 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + logger.error(e.getMessage(),e); + } finally { + try { + // 关闭连接,释放资源 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + logger.error(e.getMessage(),e); + } + } + return responseContent; + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/Md5Utils.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/Md5Utils.java new file mode 100644 index 0000000..6254ec3 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/Md5Utils.java @@ -0,0 +1,46 @@ +package com.ningdatech.pmapi.common.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.security.MessageDigest; + +public class Md5Utils { + private static final Logger LOGGER = LoggerFactory.getLogger(Md5Utils.class); + public static byte[] md5(String s) { + MessageDigest algorithm; + try { + algorithm = MessageDigest.getInstance("MD5"); + algorithm.reset(); + algorithm.update(s.getBytes("UTF-8")); + byte[] messageDigest = algorithm.digest(); + return messageDigest; + } catch (Exception e) { + LOGGER.error("MD5 Error...", e); + } + return null; + } + private static final String toHex(byte hash[]) { + if (hash == null) { + return null; + } + StringBuffer buf = new StringBuffer(hash.length * 2); + int i; + for (i = 0; i < hash.length; i++) { + if ((hash[i] & 0xff) < 0x10) { + buf.append("0"); + } + buf.append(Long.toString(hash[i] & 0xff, 16)); + } + return buf.toString(); + } + + public static String hash(String s) { + try { + return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8"); + } catch (Exception e) { + LOGGER.error("not supported charset...{}", e); + return s; + } + } +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/RefreshKeyUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/RefreshKeyUtil.java new file mode 100644 index 0000000..7d76d4d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/RefreshKeyUtil.java @@ -0,0 +1,34 @@ +package com.ningdatech.pmapi.common.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; + +import java.util.Objects; + +/** + * @Classname RefreshKeyUtil + * @Description + * @Date 2023/6/27 10:03 + * @Author PoffyZhang + */ +@Slf4j +public class RefreshKeyUtil { + public static String getRequestSecret(String appKey, String appSecret) { + Long requestTime = System.currentTimeMillis(); + // 刷新秘钥 + HttpUtil httpUtil = HttpUtil.getInstance(); + log.info("请求密钥" + appSecret); + String refreshSign = Md5Utils.hash (appKey + appSecret + requestTime); + String refreshUrl = String.format ("http://59.202.38.178/gateway/app/refreshTokenByKey.htm" + + "?appKey=%s&requestTime=%s&sign=%s", appKey, requestTime +"",refreshSign); + log.info(refreshUrl); + String result = httpUtil.sendHttpGet(refreshUrl); + log.info(result); + JSONObject dataJson = JSON.parseObject(result).getJSONObject("datas"); + if(Objects.nonNull(dataJson)){ + return dataJson.getString("requestSecret"); + } + return result; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/performance/manage/IndicatorTemplateManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/performance/manage/IndicatorTemplateManage.java index 7893860..a0465f6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/performance/manage/IndicatorTemplateManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/performance/manage/IndicatorTemplateManage.java @@ -81,6 +81,7 @@ public class IndicatorTemplateManage { template.setUpdateOn(LocalDateTime.now()); template.setUpdateBy(user.getUsername()); if(indicatorTemplateService.saveOrUpdate(template)){ + //保存 模板的详情 return "保存成功"; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/PerformanceIndicatorProjectTemplateSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/PerformanceIndicatorProjectTemplateSaveDTO.java index 25106fb..36dcba5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/PerformanceIndicatorProjectTemplateSaveDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/PerformanceIndicatorProjectTemplateSaveDTO.java @@ -32,4 +32,7 @@ public class PerformanceIndicatorProjectTemplateSaveDTO implements Serializable @ApiModelProperty("项目资金范围 1.500万元以下、2.500-2000万元,3.2000万元及以上") private Integer amountRange; + + @ApiModelProperty("绩效指标详情") + private ProjectTemplateDetailDTO templateDetail; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/ProjectTemplateDetailDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/ProjectTemplateDetailDTO.java new file mode 100644 index 0000000..843220a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/dto/ProjectTemplateDetailDTO.java @@ -0,0 +1,45 @@ +package com.ningdatech.pmapi.performance.model.dto; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @Classname PerformanceIndicatorProjectTemplateDetail + * @Description 绩效评价考核项目指标模板 + * @Date 2023/6/19 14:02 + * @Author PoffyZhang + */ +@Data +@ApiModel(value = "绩效评价考核项目指标模板详情保存树", description = "绩效评价考核项目指标模板详情保存树") +public class ProjectTemplateDetailDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("关联模板ID") + private Long templateId; + + @ApiModelProperty("指标名称") + private String name; + + @ApiModelProperty("指标类型 0阶段 1一级指标 2二级指标 3三级指标") + private Integer type; + + @ApiModelProperty("父级指标id") + private Long parentId; + + @ApiModelProperty("分数 3级指标才有") + private Integer score; + + @ApiModelProperty("分数细则 3级指标才有") + private String scoreRubric; + + @ApiModelProperty("子指标") + private ProjectTemplateDetailDTO children; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/entity/PerformanceIndicatorProjectTemplateDetail.java b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/entity/PerformanceIndicatorProjectTemplateDetail.java new file mode 100644 index 0000000..006ff62 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/performance/model/entity/PerformanceIndicatorProjectTemplateDetail.java @@ -0,0 +1,53 @@ +package com.ningdatech.pmapi.performance.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @Classname PerformanceIndicatorProjectTemplateDetail + * @Description 绩效评价考核项目指标模板 + * @Date 2023/6/19 14:02 + * @Author PoffyZhang + */ +@Data +@TableName("nd_performance_indicator_project_template_detail") +@ApiModel(value = "绩效评价考核项目指标模板详情", description = "绩效评价考核项目指标模板详情") +public class PerformanceIndicatorProjectTemplateDetail implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键") + @TableId(type = IdType.AUTO) + private Long id; + + private LocalDateTime createOn; + private LocalDateTime updateOn; + private String createBy; + private String updateBy; + + + @ApiModelProperty("关联模板ID") + private Long templateId; + + @ApiModelProperty("指标名称") + private String name; + + @ApiModelProperty("指标类型 0阶段 1一级指标 2二级指标 3三级指标") + private Integer type; + + @ApiModelProperty("父级指标id") + private Long parentId; + + @ApiModelProperty("分数 3级指标才有") + private Integer score; + + @ApiModelProperty("分数细则 3级指标才有") + private String scoreRubric; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/controller/ProjectApplicationController.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/controller/ProjectApplicationController.java new file mode 100644 index 0000000..4658fc0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/controller/ProjectApplicationController.java @@ -0,0 +1,41 @@ +package com.ningdatech.pmapi.projectlib.controller; + +import com.ningdatech.log.annotation.WebLog; +import com.ningdatech.pmapi.projectlib.manage.ApplicationManage; +import com.ningdatech.pmapi.projectlib.model.dto.ApplicationAppCodeSaveDTO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * @Classname ProjectApplicationController + * @Description + * @Date 2023/6/27 11:32 + * @Author PoffyZhang + */ +@RestController +@RequiredArgsConstructor +@Api(tags = "项目应用控制器") +@RequestMapping("/api/v1/application") +public class ProjectApplicationController { + + private final ApplicationManage applicationManage; + + @GetMapping("/get-report") + @ApiOperation("获取应用 试运行报告") + @WebLog("获取应用 试运行报告") + public String getReport(@Valid @RequestBody ApplicationAppCodeSaveDTO dto) { + return applicationManage.getReport(dto); + } + + @PostMapping("/save-appcode") + @ApiOperation("保存应用注册的appCode") + @WebLog("保存应用注册的appCode") + public String saveAppCode(@Valid @RequestBody ApplicationAppCodeSaveDTO dto) { + return applicationManage.saveAppCode(dto); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ApplicationManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ApplicationManage.java new file mode 100644 index 0000000..53de5f1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ApplicationManage.java @@ -0,0 +1,53 @@ +package com.ningdatech.pmapi.projectlib.manage; + +import com.ningdatech.basic.function.VUtils; +import com.ningdatech.pmapi.projectlib.model.dto.ApplicationAppCodeSaveDTO; +import com.ningdatech.pmapi.projectlib.model.entity.ProjectApplication; +import com.ningdatech.pmapi.projectlib.service.IProjectApplicationService; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Objects; + +/** + *

+ * ApplicationManage + *

+ * + * @author ZPF + * @since 14:19 2023/2/1 + */ +@Component +@RequiredArgsConstructor +@Slf4j +public class ApplicationManage { + + private final IProjectApplicationService applicationService; + + /** + * 保存 appCode + * @param dto + * @return + */ + public String saveAppCode(ApplicationAppCodeSaveDTO dto) { + Long userId = LoginUserUtil.getUserId(); + ProjectApplication app = applicationService.getById(dto.getId()); + VUtils.isTrue(Objects.isNull(app)).throwMessage("该应用不存在"); + + app.setAppCode(dto.getAppCode()); + app.setUpdateOn(LocalDateTime.now()); + app.setUpdateBy(userId); + if(applicationService.updateById(app)){ + return "保存成功"; + } + return "保存失败"; + } + + public String getReport(ApplicationAppCodeSaveDTO dto) { + + return null; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ApplicationAppCodeSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ApplicationAppCodeSaveDTO.java new file mode 100644 index 0000000..d2fe905 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/dto/ApplicationAppCodeSaveDTO.java @@ -0,0 +1,32 @@ +package com.ningdatech.pmapi.projectlib.model.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + *

+ * 项目应用保存appCode + *

+ * + * @author ZPF + * @since 2023-06-21 + */ +@Data +@ApiModel(value = "ProjectApplicationSaveDTO", description = "项目应用保存appCode") +public class ApplicationAppCodeSaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("应用的id") + @NotNull(message = "应用id必填") + private Long id; + + @ApiModelProperty("应用编码") + @NotBlank(message = "请输入应用编码") + private String appCode; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java index d053af0..cb476e9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/entity/ProjectApplication.java @@ -31,6 +31,9 @@ public class ProjectApplication implements Serializable { @ApiModelProperty("项目ID") private Long projectId; + @ApiModelProperty("应用编码") + private String appCode; + @ApiModelProperty("是否初次建设 0否 1是") private Integer isFirst; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java index feb42b4..c26a88b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/model/vo/ProjectApplicationVO.java @@ -27,6 +27,9 @@ public class ProjectApplicationVO implements Serializable { @ApiModelProperty("项目ID") private Long projectId; + @ApiModelProperty("应用编码") + private String appCode; + @ApiModelProperty("是否初次建设 0否 1是") private Integer isFirst;