Преглед изворни кода

1.增加微信中控平台自动回复消息配置。

tomatozq пре 5 година
родитељ
комит
c2a1f0b92d
22 измењених фајлова са 786 додато и 28 уклоњено
  1. 0 7
      picc-common/pom.xml
  2. 19 0
      picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/CompanyController.java
  3. 31 5
      picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/InsuranceApplicationController.java
  4. 18 3
      picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/InsurancePolicyController.java
  5. 27 0
      weixin-middleware/pom.xml
  6. 6 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/WeixinMiddlewareApplication.java
  7. 0 8
      weixin-middleware/src/main/java/com/jpsoft/weixin/callback/EventCallback.java
  8. 138 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/controller/ReplyMessageController.java
  9. 25 3
      weixin-middleware/src/main/java/com/jpsoft/weixin/controller/WeixinController.java
  10. 20 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/dao/ReplyMessageDAO.java
  11. 50 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/dto/MessageResult.java
  12. 32 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/dto/Sort.java
  13. 97 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/entity/ReplyMessage.java
  14. 19 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/service/ReplyMessageService.java
  15. 76 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/service/impl/ReplyMessageServiceImpl.java
  16. 73 0
      weixin-middleware/src/main/java/com/jpsoft/weixin/utils/PojoUtil.java
  17. 1 1
      weixin-middleware/src/main/java/com/jpsoft/weixin/utils/WeixinUtil.java
  18. 4 0
      weixin-middleware/src/main/resources/application-dev.yml
  19. 4 0
      weixin-middleware/src/main/resources/application-production.yml
  20. 4 0
      weixin-middleware/src/main/resources/application-test.yml
  21. 64 1
      weixin-middleware/src/main/resources/application.yml
  22. 78 0
      weixin-middleware/src/main/resources/mapper/ReplyMessage.xml

+ 0 - 7
picc-common/pom.xml

@@ -81,13 +81,6 @@
             <version>5.2.0</version>
         </dependency>
 
-        <!--mysql pagehelper-->
-        <dependency>
-            <groupId>com.github.pagehelper</groupId>
-            <artifactId>pagehelper-spring-boot-starter</artifactId>
-            <version>LATEST</version>
-        </dependency>
-
         <!-- veloctiy -->
         <dependency>
             <groupId>org.apache.velocity</groupId>

+ 19 - 0
picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/CompanyController.java

@@ -5,10 +5,12 @@ import com.jpsoft.picc.modules.base.entity.CompanyUser;
 import com.jpsoft.picc.modules.base.service.CompanyService;
 import com.jpsoft.picc.modules.base.service.CompanyUserService;
 import com.jpsoft.picc.modules.common.dto.MessageResult;
+import com.jpsoft.picc.modules.common.utils.DES3;
 import com.jpsoft.picc.modules.common.utils.PojoUtils;
 import com.jpsoft.picc.modules.pub.dto.CompanyInfoDTO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.jasig.cas.client.authentication.AttributePrincipal;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.UUID;
 
+@Slf4j
 @CrossOrigin
 @Api(description="企业信息管理")
 @RestController
@@ -116,6 +119,20 @@ public class CompanyController {
             }
 
             CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
+
+            if(companyUser==null){
+                //可能直接通过cas统一登录页面登录,所以没有记录用户信息
+                companyUser = new CompanyUser();
+                companyUser.setId(UUID.randomUUID().toString());
+                companyUser.setUserName(principal.getName());
+                DES3 des3 = new DES3();
+                companyUser.setPassword(des3.encrypt(DES3.DEFAULT_KEY, "123456"));
+                companyUser.setDelFlag(false);
+                companyUser.setCreateTime(new Date());
+
+                companyUserService.insert(companyUser);
+            }
+
             companyUser.setCompanyId(company.getId());
             companyUser.setUpdateTime(new Date());
             companyUserService.update(companyUser);
@@ -123,6 +140,8 @@ public class CompanyController {
             messageResult.setResult(true);
         }
         catch (Exception ex){
+            log.error(ex.getMessage(),ex);
+
             messageResult.setResult(false);
             messageResult.setMessage(ex.getMessage());
         }

+ 31 - 5
picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/InsuranceApplicationController.java

@@ -104,12 +104,21 @@ public class InsuranceApplicationController {
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             HttpServletRequest request){
         AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
-        CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
-        Company company = companyService.get(companyUser.getCompanyId());
 
         MessageResult<Map> msgResult = new MessageResult<>();
 
         try {
+            CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
+            Company company = null;
+
+            if (companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+                company = companyService.get(companyUser.getCompanyId());
+            }
+
+            if (company==null){
+                throw new Exception("请先填写企业信息!");
+            }
+
             Map<String, Object> searchParams = new HashMap<>();
 
             List<Sort> sortList = new ArrayList<>();
@@ -580,14 +589,23 @@ public class InsuranceApplicationController {
             }
 
             AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
-            Company company = companyService.findByCreateBy(principal.getName());
+            CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
+            Company company = null;
+
+            if(companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+                company = companyService.get(companyUser.getCompanyId());
+            }
 
             String serialNumber = (String)principal.getAttributes().get("serialNumber");
 
             TransactionRecord transactionRecord = new TransactionRecord();
             transactionRecord.setId(UUID.randomUUID().toString());
             transactionRecord.setApplicationId(applicationId);
-            transactionRecord.setCompanyId(company.getId());
+
+            if(company!=null) {
+                transactionRecord.setCompanyId(company.getId());
+            }
+
             transactionRecord.setAmount(insuranceApplication.getInsuranceFee());
             transactionRecord.setPaymentStatus("0");
             transactionRecord.setOrderNo(DateTime.now().toString("yyyyMMddHHmmssSSS"));
@@ -655,8 +673,13 @@ public class InsuranceApplicationController {
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
                                           HttpServletRequest request){
         AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
+
         CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
-        Company company = companyService.get(companyUser.getCompanyId());
+        Company company = null;
+
+        if(companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+            company = companyService.get(companyUser.getCompanyId());
+        }
 
         MessageResult<Map> msgResult = new MessageResult<>();
         Map<String, Object> dataMap = new HashMap<>();
@@ -670,6 +693,9 @@ public class InsuranceApplicationController {
             if (company!=null && StringUtils.isNotEmpty(company.getId())) {
                 searchParams.put("companyId", company.getId());
             }
+            else{
+                searchParams.put("companyId", "");
+            }
 
             if (StringUtils.isNotEmpty(definitionId)) {
                 searchParams.put("definitionId", definitionId);

+ 18 - 3
picc-enterprise-server/src/main/java/com/jpsoft/picc/modules/auth/controller/InsurancePolicyController.java

@@ -256,7 +256,15 @@ public class InsurancePolicyController {
         try {
             AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
             CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
-            Company company = companyService.get(companyUser.getCompanyId());
+            Company company = null;
+
+            if (companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+                company = companyService.get(companyUser.getCompanyId());
+            }
+
+            if (company==null){
+                throw new Exception("请先填写企业信息!");
+            }
 
             Map<String, Object> searchParams = new HashMap<>();
 
@@ -574,16 +582,23 @@ public class InsurancePolicyController {
         try {
             AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
             CompanyUser companyUser = companyUserService.findByUserName(principal.getName());
-            Company company = companyService.get(companyUser.getCompanyId());
+            Company company = null;
+
+            if(companyUser!=null && StringUtils.isNotEmpty(companyUser.getCompanyId())) {
+                company = companyService.get(companyUser.getCompanyId());
+            }
 
             Map<String, Object> searchParams = new HashMap<>();
 
             List<Sort> sortList = new ArrayList<>();
             sortList.add(new Sort("create_time", "desc"));
 
-            if (StringUtils.isNotEmpty(company.getId())) {
+            if (company!=null && StringUtils.isNotEmpty(company.getId())) {
                 searchParams.put("companyId", company.getId());
             }
+            else{
+                searchParams.put("companyId", "");
+            }
 
             if (StringUtils.isNotEmpty(definitionId)) {
                 searchParams.put("definitionId", definitionId);

+ 27 - 0
weixin-middleware/pom.xml

@@ -67,6 +67,33 @@
             <version>0.2.7</version>
         </dependency>
         <!--logging end-->
+
+<!--        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>-->
+        <!-- 数据库相关 start-->
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+            <version>LATEST</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+            <version>1.1.10</version>
+        </dependency>
+        <!-- 数据库相关 end-->
     </dependencies>
 
 

+ 6 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/WeixinMiddlewareApplication.java

@@ -1,11 +1,17 @@
 package com.jpsoft.weixin;
 
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 @SpringBootApplication
+@EnableTransactionManagement
+@EnableScheduling
+@MapperScan("com.jpsoft.weixin.**.dao")
 public class WeixinMiddlewareApplication extends SpringBootServletInitializer {
     public static void main(String[] args) {
         SpringApplication.run(WeixinMiddlewareApplication.class, args);

+ 0 - 8
weixin-middleware/src/main/java/com/jpsoft/weixin/callback/EventCallback.java

@@ -1,25 +1,17 @@
 package com.jpsoft.weixin.callback;
 
-import cn.hutool.json.JSONObject;
-import com.jpsoft.weixin.util.WeixinUtil;
 import lombok.Data;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.util.EntityUtils;
 
-import javax.servlet.http.HttpServletResponse;
-import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.List;
 

+ 138 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/controller/ReplyMessageController.java

@@ -0,0 +1,138 @@
+package com.jpsoft.weixin.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.weixin.dto.MessageResult;
+import com.jpsoft.weixin.dto.Sort;
+import com.jpsoft.weixin.entity.ReplyMessage;
+import com.jpsoft.weixin.service.ReplyMessageService;
+import com.jpsoft.weixin.utils.PojoUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import java.util.*;
+
+@RestController
+@RequestMapping("/replyMessage")
+@Api(description = "微信自动回复消息配置")
+public class ReplyMessageController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private ReplyMessageService replyMessageService;
+
+    @ApiOperation(value="添加信息")
+    @PostMapping("add")
+    public MessageResult<ReplyMessage> add(ReplyMessage replyMessage){
+        MessageResult<ReplyMessage> msgResult = new MessageResult<>();
+
+        try {
+            replyMessage.setCreateTime(new Date());
+
+            int affectCount = replyMessageService.insert(replyMessage);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(replyMessage);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="获取信息")
+    @GetMapping("edit/{id}")
+    public MessageResult<ReplyMessage> edit(@PathVariable("id") String id){
+        MessageResult<ReplyMessage> msgResult = new MessageResult<>();
+
+        try {
+            ReplyMessage replyMessage = replyMessageService.get(id);
+
+            if (replyMessage != null) {
+                msgResult.setResult(true);
+                msgResult.setData(replyMessage);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新用户")
+    @PostMapping("update")
+    public MessageResult<ReplyMessage> update(ReplyMessage replyMessage){
+        MessageResult<ReplyMessage> msgResult = new MessageResult<>();
+
+        try {
+            replyMessage.setUpdateTime(new Date());
+            
+            int affectCount = replyMessageService.update(replyMessage);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(replyMessage);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库更新失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    public MessageResult<Map> pageList(
+            String id,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("create_time","asc"));
+
+        if (StringUtils.isNotEmpty(id)) {
+            searchParams.put("id","%" + id + "%");
+        }
+
+        Page<ReplyMessage> page = replyMessageService.pageSearch(searchParams,pageIndex,pageSize,sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtil.pageWrapper(page));
+
+        return msgResult;
+    }
+}

+ 25 - 3
weixin-middleware/src/main/java/com/jpsoft/weixin/controller/WeixinController.java

@@ -6,7 +6,9 @@ import com.jpsoft.weixin.callback.PromotionCallback;
 import com.jpsoft.weixin.config.PICCAdminScanConfig;
 import com.jpsoft.weixin.config.PICCEntScanConfig;
 import com.jpsoft.weixin.config.WeixinConfig;
-import com.jpsoft.weixin.util.WeixinUtil;
+import com.jpsoft.weixin.entity.ReplyMessage;
+import com.jpsoft.weixin.service.ReplyMessageService;
+import com.jpsoft.weixin.utils.WeixinUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -24,10 +26,10 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.stereotype.Controller;
-import org.springframework.util.StreamUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -59,6 +61,9 @@ public class WeixinController {
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
+    @Autowired
+    private ReplyMessageService replyMessageService;
+
     @ApiOperation(value="验证服务器地址的有效性")
     @GetMapping("/")
     @ResponseBody
@@ -157,8 +162,11 @@ public class WeixinController {
             response.setContentType("text/html; charset=UTF-8");
             response.setCharacterEncoding("UTF-8");
 
+            String event = requestJson.getStr("Event");
             String eventKey = requestJson.getStr("EventKey");
+            //微信公众号编号
             String toUserName = requestJson.getStr("ToUserName");
+            //扫码用户openID
             String fromUserName = requestJson.getStr("FromUserName");
 
             List<EventCallback> callbackList = registerCallbackList();
@@ -182,7 +190,21 @@ public class WeixinController {
 
             if(!processed) {
                 String responseText = "success";
-                response.getWriter().print(responseText);
+
+                if(event.equals("subscribe")){
+                    ReplyMessage replyMessage = replyMessageService.findByEvent(toUserName,event);
+
+                    if(replyMessage!=null) {
+                        WeixinUtil.replyTextMessage(response, toUserName, fromUserName, replyMessage.getMessage());
+                    }
+                    else{
+                        log.warn(fromUserName + ",事件:" + event + "未设置自动回复!");
+                        response.getWriter().print(responseText);
+                    }
+                }
+                else {
+                    response.getWriter().print(responseText);
+                }
             }
         }
         catch (Exception ex){

+ 20 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/dao/ReplyMessageDAO.java

@@ -0,0 +1,20 @@
+package com.jpsoft.weixin.dao;
+
+import java.util.List;
+
+import com.jpsoft.weixin.dto.Sort;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.weixin.entity.ReplyMessage;
+import java.util.Map;
+
+@Repository
+public interface ReplyMessageDAO {
+	int insert(ReplyMessage entity);
+	int update(ReplyMessage entity);
+	int exist(String id);
+	ReplyMessage get(String id);
+	int delete(String id);
+	List<ReplyMessage> list();
+	List<ReplyMessage> search(Map<String,Object> searchParams,List<Sort> sortList);
+	ReplyMessage findByEvent(String id, String event);
+}

+ 50 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/dto/MessageResult.java

@@ -0,0 +1,50 @@
+package com.jpsoft.weixin.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.ToString;
+
+@ApiModel(value = "返回消息体")
+@ToString
+public class MessageResult<T> {
+    private boolean result;
+    private String message;
+    private T data;
+    private int code = 200;
+
+    @ApiModelProperty(value = "返回调用结果")
+    public boolean isResult() {
+        return result;
+    }
+
+    public void setResult(boolean result) {
+        this.result = result;
+    }
+
+    @ApiModelProperty(value = "返回消息")
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    @ApiModelProperty(value = "返回数据")
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    @ApiModelProperty(value = "返回代码")
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+}

+ 32 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/dto/Sort.java

@@ -0,0 +1,32 @@
+package com.jpsoft.weixin.dto;
+
+import java.io.Serializable;
+
+public class Sort implements Serializable {
+    private String name;
+    private String order;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getOrder() {
+        return order;
+    }
+
+    public void setOrder(String order) {
+        this.order = order;
+    }
+
+    public Sort() {
+    }
+
+    public Sort(String name, String order) {
+        this.name = name;
+        this.order = order;
+    }
+}

+ 97 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/entity/ReplyMessage.java

@@ -0,0 +1,97 @@
+package com.jpsoft.weixin.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+
+/**
+  描述:wechat_reply_message的实体类
+ */
+@ApiModel(value = "自动回复消息设置")
+public class ReplyMessage {
+    @ApiModelProperty(value = "微信号")
+	private String id;
+    @ApiModelProperty(value = "事件")
+	private String event;
+    @ApiModelProperty(value = "回复消息")
+	private String message;
+    @ApiModelProperty(value = "创建时间")
+	private Date createTime;
+    @ApiModelProperty(value = "更新时间")
+	private Date updateTime;
+
+	/**
+	 *获取微信号
+	 */
+    	public String getId(){
+		return id;
+	}
+	
+	/**
+	 *设置微信号
+	 */
+	public void setId(String id){
+		this.id = id;
+	}
+	/**
+	 *获取事件
+	 */
+    	public String getEvent(){
+		return event;
+	}
+	
+	/**
+	 *设置事件
+	 */
+	public void setEvent(String event){
+		this.event = event;
+	}
+	/**
+	 *获取回复消息
+	 */
+    	public String getMessage(){
+		return message;
+	}
+	
+	/**
+	 *设置回复消息
+	 */
+	public void setMessage(String message){
+		this.message = message;
+	}
+	/**
+	 *获取创建时间
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+		public Date getCreateTime(){
+		return createTime;
+	}
+	
+	/**
+	 *设置创建时间
+	 */
+	public void setCreateTime(Date createTime){
+		this.createTime = createTime;
+	}
+	/**
+	 *获取更新时间
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+		public Date getUpdateTime(){
+		return updateTime;
+	}
+	
+	/**
+	 *设置更新时间
+	 */
+	public void setUpdateTime(Date updateTime){
+		this.updateTime = updateTime;
+	}
+}

+ 19 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/service/ReplyMessageService.java

@@ -0,0 +1,19 @@
+package com.jpsoft.weixin.service;
+
+import java.util.List;
+import java.util.Map;
+
+import com.jpsoft.weixin.dto.Sort;
+import com.jpsoft.weixin.entity.ReplyMessage;
+import com.github.pagehelper.Page;
+
+public interface ReplyMessageService {
+	ReplyMessage get(String id);
+	boolean exist(String id);
+	int insert(ReplyMessage model);
+	int update(ReplyMessage model);
+	int delete(String id);
+	List<ReplyMessage> list();
+	Page<ReplyMessage> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,List<Sort> sortList);
+	ReplyMessage findByEvent(String fromUserName, String event);
+}

+ 76 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/service/impl/ReplyMessageServiceImpl.java

@@ -0,0 +1,76 @@
+package com.jpsoft.weixin.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+
+import com.jpsoft.weixin.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.weixin.dao.ReplyMessageDAO;
+import com.jpsoft.weixin.entity.ReplyMessage;
+import com.jpsoft.weixin.service.ReplyMessageService;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="replyMessageService")
+public class ReplyMessageServiceImpl implements ReplyMessageService {
+	@Resource(name="replyMessageDAO")
+	private ReplyMessageDAO replyMessageDAO;
+
+	@Override
+	public ReplyMessage get(String id) {
+		// TODO Auto-generated method stub
+		return replyMessageDAO.get(id);
+	}
+
+	@Override
+	public int insert(ReplyMessage model) {
+		// TODO Auto-generated method stub
+		//model.set${PkFieldName}(UUID.randomUUID().toString());
+		
+		return replyMessageDAO.insert(model);
+	}
+
+	@Override
+	public int update(ReplyMessage model) {
+		// TODO Auto-generated method stub
+		return replyMessageDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return replyMessageDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = replyMessageDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<ReplyMessage> list() {
+		// TODO Auto-generated method stub
+		return replyMessageDAO.list();
+	}
+		
+	@Override
+	public Page<ReplyMessage> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
+        Page<ReplyMessage> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
+            replyMessageDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+
+	@Override
+	public ReplyMessage findByEvent(String id, String event) {
+		return replyMessageDAO.findByEvent(id,event);
+	}
+}

+ 73 - 0
weixin-middleware/src/main/java/com/jpsoft/weixin/utils/PojoUtil.java

@@ -0,0 +1,73 @@
+package com.jpsoft.weixin.utils;
+
+import com.github.dozermapper.core.DozerBeanMapperBuilder;
+import com.github.dozermapper.core.Mapper;
+import com.github.pagehelper.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.HashMap;
+import java.util.Map;
+
+public class PojoUtil {
+    private static Logger logger = LoggerFactory.getLogger("root");
+    private static Mapper MAPPER = DozerBeanMapperBuilder.buildDefault();
+
+    public static <T> T map(Object source, Class<T> destinationClass) {
+        if (source == null) {
+            return null;
+        }
+        return MAPPER.map(source, destinationClass);
+    }
+
+    public static void map(Object source, Object destination) {
+        MAPPER.map(source, destination);
+    }
+
+    public static <T> Map<String, Object> pojo2map(T t) {
+        // TODO Auto-generated method stub
+        Map<String, Object> map = new HashMap<String, Object>();
+
+        try {
+            BeanInfo beanInfo = Introspector.getBeanInfo(t.getClass());
+            PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
+
+            for (PropertyDescriptor pd : props) {
+                if (pd.getReadMethod() != null) {
+                    try {
+                        Object srcValue = pd.getReadMethod().invoke(t);
+                        map.put(pd.getName(), srcValue);
+                    } catch (Exception ex) {
+                        logger.error(ex.getMessage(), ex);
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+
+        return map;
+    }
+
+
+    public static Map pageWrapper(Page page) {
+        Map<String, Object> pageMap = new HashMap<>();
+
+        //记录总数
+        pageMap.put("recordsTotal", page.getTotal());
+        pageMap.put("recordsFiltered", page.getTotal());
+        //总页数
+        pageMap.put("totalPage", page.getPages());
+        //当前页
+        pageMap.put("pageNumber", page.getPageNum());
+        //每页条数
+        pageMap.put("pageSize", page.getPageSize());
+        //本页数据
+        pageMap.put("data", page.getResult());
+
+        return pageMap;
+    }
+}

+ 1 - 1
weixin-middleware/src/main/java/com/jpsoft/weixin/util/WeixinUtil.java → weixin-middleware/src/main/java/com/jpsoft/weixin/utils/WeixinUtil.java

@@ -1,4 +1,4 @@
-package com.jpsoft.weixin.util;
+package com.jpsoft.weixin.utils;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.json.JSONObject;

+ 4 - 0
weixin-middleware/src/main/resources/application-dev.yml

@@ -1,4 +1,8 @@
 spring:
+  datasource:
+    url: jdbc:log4jdbc:mysql://127.0.0.1:3306/picc?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: root
   devtools:
     add-properties: false
     restart:

+ 4 - 0
weixin-middleware/src/main/resources/application-production.yml

@@ -1,4 +1,8 @@
 spring:
+  datasource:
+    url: jdbc:log4jdbc:mysql://hbjpsoft.mysql.rds.aliyuncs.com:3306/picc?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: picc
+    password: picc@8121234
   devtools:
     add-properties: false
     restart:

+ 4 - 0
weixin-middleware/src/main/resources/application-test.yml

@@ -1,4 +1,8 @@
 spring:
+  datasource:
+    url: jdbc:log4jdbc:mysql://10.100.145.22:3307/picc?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: jpsoft
   devtools:
     add-properties: false
     restart:

+ 64 - 1
weixin-middleware/src/main/resources/application.yml

@@ -32,4 +32,67 @@ spring:
       # 连接池中的最小空闲连接
       min-idle: 0
       # 连接超时时间(毫秒)
-      timeout: 0
+      timeout: 0
+  datasource:
+    driver-class-name: net.sf.log4jdbc.DriverSpy
+    type: com.alibaba.druid.pool.DruidDataSource
+    druid:
+      # 连接池的配置信息
+      # 初始化大小,最小,最大
+      initial-size: 5
+      min-idle: 5
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      validationQuery: SELECT 1
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      # 打开PSCache,并且指定每个连接上PSCache的大小
+      poolPreparedStatements: true
+      maxPoolPreparedStatementPerConnectionSize: 20
+      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      filters: stat,wall
+      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
+      connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
+      # 配置DruidStatFilter
+      web-stat-filter:
+        enabled: false
+        url-pattern: "/*"
+        exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
+      # 配置DruidStatViewServlet
+      stat-view-servlet:
+        url-pattern: "/druid/*"
+        # IP白名单(没有配置或者为空,则允许所有访问)
+        allow:
+        # IP黑名单 (存在共同时,deny优先于allow)
+        deny:
+        #  禁用HTML页面上的“Reset All”功能
+        reset-enable: false
+        # 登录名
+        login-username: admin
+        # 登录密码
+        login-password: jpsoft
+
+management:
+  endpoints:
+    enabled: true
+    web:
+      base-path: /actuator2020  # 访问根路径
+      exposure:
+        include: "*"
+  endpoint:
+    shutdown:
+      enabled: true
+    refresh:
+      enabled: true
+
+mybatis:
+  typeAliasesPackage: com.jpsoft.weixin.**.entity
+  mapperLocations: classpath*:mapper/**/*.xml
+  configuration:
+    default-statement-timeout: 60

+ 78 - 0
weixin-middleware/src/main/resources/mapper/ReplyMessage.xml

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.weixin.dao.ReplyMessageDAO">
+	<resultMap id="ReplyMessageMap" type="com.jpsoft.weixin.entity.ReplyMessage">
+		<id property="id" column="id_" />
+			<result property="event" column="event_" />
+			<result property="message" column="message_" />
+			<result property="createTime" column="create_time" />
+			<result property="updateTime" column="update_time" />
+			</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.weixin.entity.ReplyMessage">
+	<!--
+	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+		select sys_guid() from dual
+	</selectKey>
+	-->
+	<![CDATA[
+		insert into wechat_reply_message
+	    (id_,event_,message_,create_time,update_time)
+		values
+		(
+			#{id,jdbcType=VARCHAR}
+			,#{event,jdbcType=VARCHAR}
+			,#{message,jdbcType=VARCHAR}
+			,#{createTime,jdbcType= TIMESTAMP }
+			,#{updateTime,jdbcType= TIMESTAMP }
+		)
+	]]>
+	</insert>
+	<delete id="delete" parameterType="string">
+		delete from wechat_reply_message where id_=#{id,jdbcType=VARCHAR}
+	</delete>
+	<update id="update" parameterType="com.jpsoft.weixin.entity.ReplyMessage">
+		update wechat_reply_message
+		<set>
+				<if test="event!=null">
+		event_=#{event,jdbcType=VARCHAR},
+		</if>
+				<if test="message!=null">
+		message_=#{message,jdbcType=VARCHAR},
+		</if>
+				<if test="createTime!=null">
+		create_time=#{createTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="updateTime!=null">
+		update_time=#{updateTime,jdbcType= TIMESTAMP },
+		</if>
+		</set>
+	where id_=#{id}
+	</update>
+	<select id="get" parameterType="string" resultMap="ReplyMessageMap">
+		select * from wechat_reply_message where id_=#{0}
+	</select>
+	<select id="exist" parameterType="string" resultType="int">
+		select count(*) from wechat_reply_message where id_=#{0}
+	</select>
+	<select id="list" resultMap="ReplyMessageMap">
+		select * from wechat_reply_message
+	</select>
+	<select id="search" parameterType="hashmap" resultMap="ReplyMessageMap">
+		<![CDATA[
+			select * from wechat_reply_message
+		]]>
+		<where>
+			<if test="searchParams.id != null">
+				and ID_ like #{searchParams.id}
+			</if>
+		</where>
+		<foreach item="sort" collection="sortList"  open="order by" separator=",">
+	        ${sort.name} ${sort.order}
+	 	</foreach>
+	</select>
+	<select id="findByEvent" resultMap="ReplyMessageMap">
+		select * from wechat_reply_message where id_=#{id} and event_=#{event} limit 1
+	</select>
+</mapper>