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 @@