From 482e2225f16d909d5364f5b09c0eb1749088ed27 Mon Sep 17 00:00:00 2001 From: Yifei Kuang Date: Mon, 18 Nov 2024 13:41:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=AF=81=E4=BA=8C=E8=A6=81?= =?UTF-8?q?=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ghy-admin/pom.xml | 25 +++++++++ .../web/controller/order/OrderController.java | 1 + .../order/OrderMasterController.java | 20 ++++--- .../controller/tool/AliCloudController.java | 52 +++++++++++++++++++ .../com/ghy/web/core/config/AliApiConfig.java | 38 ++++++++++++++ .../ghy/web/pojo/vo/CertNoTwoElementReq.java | 14 +++++ .../com/ghy/web/service/AliCloudService.java | 14 +++++ .../web/service/impl/AliCloudServiceImpl.java | 38 ++++++++++++++ .../service/impl/InsuranceServiceImpl.java | 15 ++++-- ghy-admin/src/main/resources/application.yaml | 7 +++ .../mapper/order/OrderDetailMapper.xml | 11 ++-- .../mapper/order/OrderMasterMapper.xml | 11 ++-- .../resources/mapper/worker/WorkerMapper.xml | 1 + 13 files changed, 223 insertions(+), 24 deletions(-) create mode 100644 ghy-admin/src/main/java/com/ghy/web/controller/tool/AliCloudController.java create mode 100644 ghy-admin/src/main/java/com/ghy/web/core/config/AliApiConfig.java create mode 100644 ghy-admin/src/main/java/com/ghy/web/pojo/vo/CertNoTwoElementReq.java create mode 100644 ghy-admin/src/main/java/com/ghy/web/service/AliCloudService.java create mode 100644 ghy-admin/src/main/java/com/ghy/web/service/impl/AliCloudServiceImpl.java diff --git a/ghy-admin/pom.xml b/ghy-admin/pom.xml index 6ea58c80..ad5ca01f 100644 --- a/ghy-admin/pom.xml +++ b/ghy-admin/pom.xml @@ -23,6 +23,31 @@ 1.0.3 + + + com.aliyun + dytnsapi20200217 + 2.9.0 + + + + com.aliyun + tea-openapi + 0.3.6 + + + + com.aliyun + tea-console + 0.0.1 + + + + com.aliyun + tea-util + 0.2.23 + + diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index d875ce8c..88bc5ecc 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -166,6 +166,7 @@ public class OrderController extends BaseController { return AjaxResult.success(orderGoodsList); } catch (Exception e) { e.printStackTrace(); + logger.error("派单失败:" + ExceptionUtils.getMessage(e)); return AjaxResult.error(e.getMessage()); } } diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java index 7e189ac9..42a48c0c 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java @@ -1360,11 +1360,17 @@ public class OrderMasterController extends BaseController { @PostMapping("/edit") @ResponseBody public AjaxResult editSave(@Validated OrderMaster orderMaster) throws BaseAdaPayException { - if (UserConstants.ORDER_CODE_NOT_UNIQUE.equals(orderMasterService.checkOrderMasterCodeUnique(orderMaster))) { - return error("修改主订单'" + orderMaster.getCode() + "'失败,主订单编码已存在"); + try { + if (UserConstants.ORDER_CODE_NOT_UNIQUE.equals(orderMasterService.checkOrderMasterCodeUnique(orderMaster))) { + return error("修改主订单'" + orderMaster.getCode() + "'失败,主订单编码已存在"); + } + orderMaster.setUpdateBy(getLoginName()); + return toAjax(orderMasterService.updateOrderMaster(orderMaster)); + }catch (Exception e){ + e.printStackTrace(); + logger.error("修改订单信息失败:" + e.getMessage()); + return AjaxResult.error(); } - orderMaster.setUpdateBy(getLoginName()); - return toAjax(orderMasterService.updateOrderMaster(orderMaster)); } /** @@ -1384,13 +1390,14 @@ public class OrderMasterController extends BaseController { }); } // 下单 - if(OrderStatus.PLAIN.code() == orderMaster.getOrderStatus()){ + if(orderMaster.getOrderStatus() != null && OrderStatus.PLAIN.code() == orderMaster.getOrderStatus()){ OrderMaster model = orderMasterService.selectById(orderMaster.getId()); insuranceService.orderInsurance(model.getCode()); } return AjaxResult.success(""); } catch (Exception e) { e.printStackTrace(); + logger.error("派单失败:" + ExceptionUtils.getMessage(e)); return AjaxResult.error(e.getMessage()); } } @@ -1411,7 +1418,8 @@ public class OrderMasterController extends BaseController { customerAddressService.updateCustomerAddress(address2Update); return AjaxResult.success(); } catch (Exception e) { - logger.error(ExceptionUtils.getStackTrace(e)); + e.printStackTrace(); + logger.error("修改服务时间失败:" + ExceptionUtils.getStackTrace(e)); return AjaxResult.error("修改失败"); } } diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/tool/AliCloudController.java b/ghy-admin/src/main/java/com/ghy/web/controller/tool/AliCloudController.java new file mode 100644 index 00000000..54c4840c --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/controller/tool/AliCloudController.java @@ -0,0 +1,52 @@ +package com.ghy.web.controller.tool; + +import cn.hutool.json.JSONUtil; +import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.utils.StringUtils; +import com.ghy.web.pojo.vo.CertNoTwoElementReq; +import com.ghy.web.service.AliCloudService; +import com.ghy.worker.domain.Worker; +import com.ghy.worker.service.WorkerService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Slf4j +@Tag(name = "阿里云Api接口") +@Controller +@RequestMapping("/tool/ali") +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class AliCloudController { + + private final AliCloudService aliCloudService; + + private final WorkerService workerService; + + @Operation(summary = "身份证二要素校验") + @PostMapping("/certNoTwoElementVerification") + @ResponseBody + public AjaxResult certNoTwoElementVerification(@RequestBody CertNoTwoElementReq certNoTwoElementReq){ + try { + Worker worker = workerService.selectById(certNoTwoElementReq.getWorkerId()); + if(StringUtils.isNotEmpty(worker.getRemark())){ + return AjaxResult.success("操作成功!"); + }else { + aliCloudService.certNoTwoElementVerification(certNoTwoElementReq); + worker.setRemark(JSONUtil.toJsonStr(certNoTwoElementReq)); + workerService.updateWorker(worker); + return AjaxResult.success(); + } + }catch (Exception e){ + log.error("身份证二要素校验失败:{}", e.getMessage(), e); + return AjaxResult.success(e.getMessage(), "身份证二要素校验失败!"); + } + } + +} diff --git a/ghy-admin/src/main/java/com/ghy/web/core/config/AliApiConfig.java b/ghy-admin/src/main/java/com/ghy/web/core/config/AliApiConfig.java new file mode 100644 index 00000000..6dbdde8e --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/core/config/AliApiConfig.java @@ -0,0 +1,38 @@ +package com.ghy.web.core.config; + +import com.aliyun.dytnsapi20200217.Client; +import com.aliyun.teaopenapi.models.Config; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +public class AliApiConfig { + + @Value("${aliyun.accessKey}") + private String accessKey; + + @Value("${aliyun.accessSecret}") + private String accessSecret; + + @Value("${aliyun.endpoint}") + private String endpoint; + + @Value("${aliyun.authCode}") + private String authCode; + + @Bean + public Client createClient() throws Exception { + // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。 + Config config = new Config() + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。 + .setAccessKeyId(accessKey) + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 + .setAccessKeySecret(accessSecret) + .setEndpoint(endpoint); + return new Client(config); + } + +} diff --git a/ghy-admin/src/main/java/com/ghy/web/pojo/vo/CertNoTwoElementReq.java b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/CertNoTwoElementReq.java new file mode 100644 index 00000000..1cd0d67c --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/CertNoTwoElementReq.java @@ -0,0 +1,14 @@ +package com.ghy.web.pojo.vo; + +import lombok.Data; + +@Data +public class CertNoTwoElementReq { + + private Long workerId; + + private String certNo; + + private String certName; + +} diff --git a/ghy-admin/src/main/java/com/ghy/web/service/AliCloudService.java b/ghy-admin/src/main/java/com/ghy/web/service/AliCloudService.java new file mode 100644 index 00000000..3067be29 --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/service/AliCloudService.java @@ -0,0 +1,14 @@ +package com.ghy.web.service; + +import com.ghy.web.pojo.vo.CertNoTwoElementReq; +import org.springframework.web.bind.annotation.RequestBody; + +/** + *

阿里云api合集,二次包装在服务内

+ * @author clunt + */ +public interface AliCloudService { + + void certNoTwoElementVerification(@RequestBody CertNoTwoElementReq certNoTwoElementReq) throws Exception; + +} diff --git a/ghy-admin/src/main/java/com/ghy/web/service/impl/AliCloudServiceImpl.java b/ghy-admin/src/main/java/com/ghy/web/service/impl/AliCloudServiceImpl.java new file mode 100644 index 00000000..39b97f67 --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/service/impl/AliCloudServiceImpl.java @@ -0,0 +1,38 @@ +package com.ghy.web.service.impl; + +import cn.hutool.core.lang.Assert; +import cn.hutool.json.JSONUtil; +import com.aliyun.dytnsapi20200217.Client; +import com.aliyun.dytnsapi20200217.models.CertNoTwoElementVerificationRequest; +import com.aliyun.dytnsapi20200217.models.CertNoTwoElementVerificationResponse; +import com.ghy.web.core.config.AliApiConfig; +import com.ghy.web.pojo.vo.CertNoTwoElementReq; +import com.ghy.web.service.AliCloudService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class AliCloudServiceImpl implements AliCloudService { + + private final AliApiConfig aliApiConfig; + + + @Override + public void certNoTwoElementVerification(CertNoTwoElementReq certNoTwoElementReq) throws Exception{ + // 校验是否是历史记录 + Client client = aliApiConfig.createClient(); + CertNoTwoElementVerificationRequest request = new CertNoTwoElementVerificationRequest(); + request.setAuthCode(aliApiConfig.getAuthCode()); + request.setCertNo(certNoTwoElementReq.getCertNo()); + request.setCertName(certNoTwoElementReq.getCertName()); + log.info("调用身份证二要素校验接口,入参:{}", certNoTwoElementReq); + CertNoTwoElementVerificationResponse response =client.certNoTwoElementVerification(request); + log.info("调用身份证二要素校验接口,响应:{}", JSONUtil.toJsonStr(response.getBody())); + Assert.isTrue("OK".equals(response.getBody().getCode()), Exception::new); + Assert.isTrue("1".equals(response.getBody().getData().getIsConsistent()), "身份二要素验证失败!"); + } +} diff --git a/ghy-admin/src/main/java/com/ghy/web/service/impl/InsuranceServiceImpl.java b/ghy-admin/src/main/java/com/ghy/web/service/impl/InsuranceServiceImpl.java index 1a26369c..8ac071dc 100644 --- a/ghy-admin/src/main/java/com/ghy/web/service/impl/InsuranceServiceImpl.java +++ b/ghy-admin/src/main/java/com/ghy/web/service/impl/InsuranceServiceImpl.java @@ -11,10 +11,13 @@ import com.ghy.customer.domain.CustomerAddress; import com.ghy.customer.service.CustomerAddressService; import com.ghy.order.domain.OrderMaster; import com.ghy.order.service.OrderMasterService; +import com.ghy.web.pojo.vo.CertNoTwoElementReq; import com.ghy.web.pojo.vo.InsuranceOrderReq; import com.ghy.web.service.InsuranceService; +import com.ghy.worker.domain.Worker; import com.ghy.worker.domain.WorkerCertification; import com.ghy.worker.service.IWorkerCertificationService; +import com.ghy.worker.service.WorkerService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,6 +41,9 @@ public class InsuranceServiceImpl implements InsuranceService { @Autowired private IWorkerCertificationService workerCertificationService; + @Autowired + private WorkerService workerService; + @Override public void orderInsurance(String orderCode) throws Exception{ InsuranceOrderReq req = new InsuranceOrderReq(); @@ -49,10 +55,11 @@ public class InsuranceServiceImpl implements InsuranceService { CustomerAddress customerAddress = customerAddressService.selectByCustomerAddressId(master.getAddressId()); req.setCustomerAddress(customerAddress.getAddress()); req.setCustomerPhone(customerAddress.getPhone()); - // 查询师傅信息 - WorkerCertification workerCertification = workerCertificationService.selectByWorkerId(master.getWorkerId()); - req.setWorkerID(workerCertification.getIdCardNum()); - req.setWorkName(workerCertification.getLegalPersionName()); + // 查师傅信息 + Worker worker = workerService.selectById(master.getWorkerId()); + CertNoTwoElementReq certNoTwoElementReq = JSONUtil.toBean(worker.getRemark(), CertNoTwoElementReq.class); + req.setWorkerID(certNoTwoElementReq.getCertNo()); + req.setWorkName(certNoTwoElementReq.getCertName()); req.setOrderStartat(DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, 30), DatePattern.NORM_DATETIME_PATTERN)); req.setOrderEndat(DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, 30),DatePattern.NORM_DATETIME_PATTERN)); log.info("调用保险请求url:{},内容:{}", baseUrl+"/platInterface/order", JSONUtil.toJsonStr(req)); diff --git a/ghy-admin/src/main/resources/application.yaml b/ghy-admin/src/main/resources/application.yaml index 31afcf1c..fcb161bf 100644 --- a/ghy-admin/src/main/resources/application.yaml +++ b/ghy-admin/src/main/resources/application.yaml @@ -138,3 +138,10 @@ sms: account: '8a216da85f008800015f0eb223620557' appId: '8a216da85f008800015f0eb224db055d' token: '3cef1bc80d814637a236d93004e7ffa5' + +# 阿里云api接口, 这里是身份证二要素的 +aliyun: + accessKey: LTAI5tDmv3T3Ze1Mt9wi5Be6 + accessSecret: EV4dzWRfKTQaPRjf3tFziMuVBCsThU + endpoint: dytnsapi.aliyuncs.com + authCode: od2FgE9a9g \ No newline at end of file diff --git a/ghy-order/src/main/resources/mapper/order/OrderDetailMapper.xml b/ghy-order/src/main/resources/mapper/order/OrderDetailMapper.xml index 215f247e..b308e01c 100644 --- a/ghy-order/src/main/resources/mapper/order/OrderDetailMapper.xml +++ b/ghy-order/src/main/resources/mapper/order/OrderDetailMapper.xml @@ -480,16 +480,13 @@ diff --git a/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml b/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml index bd8681fe..df1acb0a 100644 --- a/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml +++ b/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml @@ -543,16 +543,13 @@ diff --git a/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml b/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml index f0daa3c2..6f0a87a7 100644 --- a/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml +++ b/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml @@ -171,6 +171,7 @@ update worker type = #{type}, + remark = #{remark}, status = #{status}, wx_open_id = #{wxOpenId}, store_status = #{storeStatus},