From f1b54cd54bf643361c528b5e2ef5e2001daf44bf Mon Sep 17 00:00:00 2001 From: clunt Date: Thu, 19 May 2022 16:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E6=A0=A1=E9=AA=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F=E6=B3=A8=E5=86=8C=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E6=9C=AA=E6=B3=A8=E5=86=8C=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ghy/web/controller/tool/WxController.java | 42 +++++++++++++++++-- .../ghy/customer/service/CustomerService.java | 6 +++ .../service/impl/CustomerServiceImpl.java | 11 +++++ .../mapper/customer/CustomerMapper.xml | 5 +++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/tool/WxController.java b/ghy-admin/src/main/java/com/ghy/web/controller/tool/WxController.java index 8f298373..397b4c64 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/tool/WxController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/tool/WxController.java @@ -4,14 +4,15 @@ import com.alibaba.fastjson.JSONObject; import com.ghy.common.config.WxConfig; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.utils.ExceptionUtil; +import com.ghy.common.utils.StringUtils; import com.ghy.common.utils.WxUtils; import com.ghy.common.utils.http.HttpUtils; +import com.ghy.customer.domain.Customer; +import com.ghy.customer.service.CustomerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -31,6 +32,39 @@ public class WxController extends BaseController { @Autowired private WxConfig wxConfig; + @Autowired + private CustomerService customerService; + + @PostMapping("/addUser") + @ResponseBody + public AjaxResult addUser(Customer customer){ + try { + int result = customerService.insertCustomer(customer); + if(result>0){ + return AjaxResult.success("新增用户成功"); + }else { + return AjaxResult.warn("新增用户失败!"); + } + }catch (Exception e){ + logger.error(ExceptionUtil.getExceptionMessage(e)); + return AjaxResult.error(e.getMessage()); + } + } + + @PostMapping("/getUserInfo") + @ResponseBody + public AjaxResult getUserInfo(@RequestBody Customer customer){ + try { + Customer result = customerService.selectByOpenId(customer); + if(StringUtils.isNull(result)){ + return AjaxResult.error("用户不存在"); + } + return AjaxResult.success(result); + }catch (Exception e){ + return AjaxResult.error(e.getMessage()); + } + } + @GetMapping("/token") @ResponseBody public String token(String timestamp, String nonce, String signature, String echostr) throws IOException { diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java index 893791e7..688eb835 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java @@ -10,6 +10,12 @@ import java.util.List; */ public interface CustomerService { + /** + * @param customer 查询信息 + * @return 消费者信息 + */ + Customer selectByOpenId(Customer customer); + /** * @param customer 消费者筛选条件 * @return 消费者列表 diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java index 0bd08b1c..293b096e 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java @@ -2,6 +2,7 @@ package com.ghy.customer.service.impl; import com.ghy.common.core.text.Convert; import com.ghy.common.exception.ServiceException; +import com.ghy.common.utils.StringUtils; import com.ghy.customer.domain.Customer; import com.ghy.customer.mapper.CustomerMapper; import com.ghy.customer.service.CustomerService; @@ -30,6 +31,16 @@ public class CustomerServiceImpl implements CustomerService { return customerMapper.getCustomerList(customer); } + @Override + public Customer selectByOpenId(Customer customer) { + List list = customerMapper.getCustomerList(customer); + if(StringUtils.isNotEmpty(list)){ + return list.get(0); + }else { + return null; + } + } + @Override public int deleteByIds(String ids) { Long [] customerIds = Convert.toLongArray(ids); diff --git a/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml b/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml index 099b628a..35235082 100644 --- a/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml +++ b/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml @@ -29,6 +29,11 @@