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 acb21f1f..c657505d 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 @@ -12,6 +12,8 @@ import com.ghy.customer.domain.Customer; import com.ghy.customer.service.CustomerService; import com.ghy.system.domain.SysDeptConfig; import com.ghy.system.service.ISysDeptConfigService; +import com.ghy.worker.domain.Worker; +import com.ghy.worker.service.WorkerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -40,6 +42,9 @@ public class WxController extends BaseController { @Autowired private CustomerService customerService; + @Autowired + private WorkerService workerService; + @PostMapping("/addUser") @ResponseBody public AjaxResult addUser(@RequestBody Customer customer){ @@ -66,6 +71,32 @@ public class WxController extends BaseController { } } + @PostMapping("/addWorker") + @ResponseBody + public AjaxResult addUser(@RequestBody Worker worker){ + try { + int result = workerService.insertWorker(worker); + if(result>0){ + return AjaxResult.success("新增师傅成功"); + }else { + return AjaxResult.warn("新增师傅失败!"); + } + }catch (Exception e){ + logger.error(ExceptionUtil.getExceptionMessage(e)); + return AjaxResult.error(e.getMessage()); + } + } + + @PostMapping("/getWorkerInfo") + @ResponseBody + public AjaxResult getUserInfo(@RequestBody Worker worker){ + try { + return AjaxResult.success(workerService.selectByOpenId(worker)); + }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-worker/src/main/java/com/ghy/worker/mapper/WorkerMapper.java b/ghy-worker/src/main/java/com/ghy/worker/mapper/WorkerMapper.java index 5ca0cd0c..2dc3ec26 100644 --- a/ghy-worker/src/main/java/com/ghy/worker/mapper/WorkerMapper.java +++ b/ghy-worker/src/main/java/com/ghy/worker/mapper/WorkerMapper.java @@ -12,4 +12,10 @@ public interface WorkerMapper { */ List getWorkerList(Worker worker); + /** + * @param worker 师傅信息 + * @return 新增成功条数 + */ + int insertWorker(Worker worker); + } diff --git a/ghy-worker/src/main/java/com/ghy/worker/service/WorkerService.java b/ghy-worker/src/main/java/com/ghy/worker/service/WorkerService.java index 9e418d42..fa28592d 100644 --- a/ghy-worker/src/main/java/com/ghy/worker/service/WorkerService.java +++ b/ghy-worker/src/main/java/com/ghy/worker/service/WorkerService.java @@ -12,5 +12,16 @@ public interface WorkerService { */ List getWorkList(Worker worker); + /** + * @param worker 微信唯一id + * @return worker师傅 + */ + Worker selectByOpenId(Worker worker); + + /** + * @param worker 师傅信息 + * @return 新增成功条数 + */ + int insertWorker(Worker worker); } diff --git a/ghy-worker/src/main/java/com/ghy/worker/service/impl/WorkerServiceImpl.java b/ghy-worker/src/main/java/com/ghy/worker/service/impl/WorkerServiceImpl.java index 99b11df1..c0195fa5 100644 --- a/ghy-worker/src/main/java/com/ghy/worker/service/impl/WorkerServiceImpl.java +++ b/ghy-worker/src/main/java/com/ghy/worker/service/impl/WorkerServiceImpl.java @@ -1,17 +1,19 @@ package com.ghy.worker.service.impl; +import com.ghy.common.utils.StringUtils; import com.ghy.worker.domain.Worker; import com.ghy.worker.mapper.WorkerMapper; import com.ghy.worker.service.WorkerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.List; @Service public class WorkerServiceImpl implements WorkerService { - @Autowired + @Resource private WorkerMapper workerMapper; @Override @@ -19,4 +21,19 @@ public class WorkerServiceImpl implements WorkerService { return workerMapper.getWorkerList(worker); } + @Override + public Worker selectByOpenId(Worker worker) { + List list = workerMapper.getWorkerList(worker); + if(StringUtils.isNotEmpty(list)){ + return list.get(0); + }else { + return null; + } + } + + @Override + public int insertWorker(Worker worker) { + return workerMapper.insertWorker(worker); + } + } diff --git a/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml b/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml index b85660e1..22bd3c65 100644 --- a/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml +++ b/ghy-worker/src/main/resources/mapper/worker/WorkerMapper.xml @@ -34,5 +34,32 @@ + + insert into worker( + name, + account, + phone, + password, + open_id, + dept_id, + status, + worker_logo_url, + remark, + create_by, + create_time + )values( + #{name}, + #{account}, + #{phone}, + #{password}, + #{openId}, + #{deptId}, + #{status}, + #{workerLogoUrl}, + #{remark}, + #{createBy}, + sysdate() + ) + \ No newline at end of file