Trick 6 years ago
parent
commit
b78c175ebf

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateConfigDO.java

@ -30,6 +30,7 @@ public class WxTemplateConfigDO extends UuidIdentityEntityWithOperator implement
    private String keyword7;//项目
    private String appid;//跳转小程序的appid
    private String pagepath;//跳转小程序路径
    private Integer status;//状态 1:正常 -1:删除
    @Column(name = "wechat_id")
    public String getWechatId() {
@ -185,4 +186,13 @@ public class WxTemplateConfigDO extends UuidIdentityEntityWithOperator implement
    public void setPagepath(String pagepath) {
        this.pagepath = pagepath;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 2 - 10
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateDO.java

@ -17,8 +17,6 @@ public class WxTemplateDO extends UuidIdentityEntityWithOperator implements java
    // Fields
    private String title;//模板标题
    private String wechatId;//关联的微信code 关联表 Wx_Wechat
    @Transient
    private String wechatName;
    private String templateId;//微信模板id
    private String templateName;//模板名称(模板检索名称)
    private String content;//模板内容
@ -76,10 +74,11 @@ public class WxTemplateDO extends UuidIdentityEntityWithOperator implements java
        this.content = content;
    }
    @Column(name = "status", length = 2)
    public Integer getStatus() {
        return status;
    }
    // Constructors
    public void setStatus(Integer status) {
        this.status = status;
@ -94,11 +93,4 @@ public class WxTemplateDO extends UuidIdentityEntityWithOperator implements java
        this.remark = remark;
    }
    public String getWechatName() {
        return wechatName;
    }
    public void setWechatName(String wechatName) {
        this.wechatName = wechatName;
    }
}

+ 2 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -263,10 +263,12 @@ public class BaseRequestMapping {
        public static final String findWxReplySceneExist ="/findWxReplySceneExist";
        public static final String findWxReplyScene ="/findWxReplyScene";
        public static final String saveWxTemp ="/saveWxTemp";
        public static final String findWxTempExist ="/findWxTempExist";
        public static final String findWxtemp ="/findWxtemp";
        public static final String saveWxTempConfig ="/saveWxTempConfig";
        public static final String findWxTempConfigList ="/findWxTempConfigList";
        public static final String findWxTemplateConfig ="/findWxTemplateConfig";
        public static final String findWxTemplateConfigExist ="/findWxTemplateConfigExist";
        public static final String getAllTemp ="/getAllTemp";
        public static final String getusersummary ="/getusersummary";
        public static final String getusercumulate ="/getusercumulate";

+ 4 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxTemplateConfigDao.java

@ -5,11 +5,15 @@ import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/8/21.
 */
public interface WxTemplateConfigDao extends PagingAndSortingRepository<WxTemplateConfigDO, String>, JpaSpecificationExecutor<WxTemplateConfigDO> {
    WxTemplateConfigDO findByWechatIdAndTemplateNameAndSceneAndStatus(String wechatId, String templateName, String scene,Integer status);
    WxTemplateConfigDO findByWechatIdAndTemplateNameAndScene(String wechatId, String templateName, String scene);
    List<WxTemplateConfigDO> findByWechatIdAndScene(String wechatId,String scene);
}

+ 5 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxTemplateDao.java

@ -18,4 +18,9 @@ public interface WxTemplateDao extends PagingAndSortingRepository<WxTemplateDO,
    @Query("from WxTemplateDO w where w.wechatId = ?1 and w.status =1")
    List<WxTemplateDO> findByWxId(String wechatId);
    List<WxTemplateDO> findByTemplateIdAndWechatId(String templateId,String wechatId);
    List<WxTemplateDO> findByTemplateNameAndWechatId(String templateId,String wechatId);
}

+ 26 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java

@ -256,6 +256,17 @@ public class WechatController extends EnvelopRestEndpoint {
        return wechatService.saveWxTemp(wxTemplate);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.findWxTempExist)
    @ApiOperation(value = "判断微信模板(模板id且模板名称)是否存在", notes = "判断微信模板(模板id且模板名称)是否存在")
    public Envelop findWxTempExist(@ApiParam(name = "wechatId", value = "微信id")
                                   @RequestParam(value = "wechatId", required = true)String wechatId,
                                   @ApiParam(name = "templateName", value = "微信id")
                                   @RequestParam(value = "templateName", required = true)String templateName,
                                   @ApiParam(name = "templateId", value = "微信模板id(微信的同步的id)")
                                   @RequestParam(value = "templateId", required = true)String templateId) {
       return success(BaseRequestMapping.WeChat.api_success,wechatService.findWxTempExist(wechatId,templateId,templateName));
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxtemp)
    @ApiOperation(value = "获取微信模板消息基础信息(列表)", notes = "获取微信模板消息基础信息(列表)")
    public MixEnvelop<WxTemplateVO,WxTemplateVO> findWxtemp(@ApiParam(name = "wechatId", value = "微信id")
@ -287,13 +298,17 @@ public class WechatController extends EnvelopRestEndpoint {
                                                                                  @RequestParam(value = "wechatId", required = true)String wechatId,
                                                                                  @ApiParam(name = "scene", value = "微信场景值")
                                                                                  @RequestParam(value = "scene", required = true)String scene,
                                                                                  @ApiParam(name = "templateId", value = "微信公众号模板id")
                                                                                  @RequestParam(value = "templateId", required = true)String templateId,
                                                                                  @ApiParam(name = "page", value = "第几页")
                                                                                  @RequestParam(value = "page", required = true)Integer page,
                                                                                  @ApiParam(name = "size", value = "分页大小")
                                                                                  @RequestParam(value = "size", required = true)Integer size) {
        return wechatService.findWxTempConfigList(wechatId, scene, page, size);
        return wechatService.findWxTempConfigList(wechatId,templateId,scene, page, size);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxTemplateConfig)
    @ApiOperation(value = "获取微信模板列表(单条)", notes = "获取微信模板列表(单条)")
    public ObjEnvelop<WxTemplateConfigVO>  findWxTemplateConfig(@ApiParam(name = "wechatId", value = "微信id")
@ -303,12 +318,20 @@ public class WechatController extends EnvelopRestEndpoint {
                                                                @ApiParam(name = "scene", value = "场景值")
                                                                @RequestParam(value = "scene", required = true)String scene) {
        return success(wechatService.findWxTemplateConfig(wechatId,name,scene), WxTemplateConfigVO.class);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxTemplateConfigExist)
    @ApiOperation(value = "判断微信配置模板场景值是否存在", notes = "判断微信配置模板场景值是否存在(单条)")
    public Envelop findWxTemplateConfigExist(@ApiParam(name = "wechatId", value = "微信id")
                                             @RequestParam(value = "wechatId", required = true)String wechatId,
                                             @ApiParam(name = "scene", value = "场景值")
                                             @RequestParam(value = "scene", required = true)String scene) {
        return success(BaseRequestMapping.WeChat.api_success,wechatService.findWxTemplateConfigExist(wechatId,scene));
    }
    @PostMapping(value = BaseRequestMapping.WeChat.getAllTemp)
    @ApiOperation(value = "获取所有微信模板", notes = "获取所有微信模板")
    public String  getAllTemp(@ApiParam(name = "wechatId", value = "微信id")
    @ApiOperation(value = "获取所有微信模板(微信拉取)", notes = "获取所有微信模板(微信拉取)")
    public Envelop getAllTemp(@ApiParam(name = "wechatId", value = "微信id")
                              @RequestParam(value = "wechatId", required = true)String wechatId) {
        return wxTemplateService.getAllTemp(wechatId);
    }

+ 2 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WxTemplateController.java

@ -1,6 +1,7 @@
package com.yihu.jw.base.endpoint.wx;
import com.yihu.jw.base.service.wx.WxTemplateService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.WechatRequestMapping;
import io.swagger.annotations.Api;
@ -30,7 +31,7 @@ public class WxTemplateController extends EnvelopRestEndpoint {
    @PostMapping(value = WechatRequestMapping.WxTemplate.api_getAllTemplate, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取所有微信模板", notes = "获取所有微信模板")
    public String  getAllTemp(String wechatId) {
    public Envelop getAllTemp(String wechatId) {
        return wxTemplateService.getAllTemp(wechatId);
    }

+ 29 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WechatService.java

@ -460,6 +460,18 @@ public class WechatService {
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Boolean findWxTempExist(String wechatId,String templateId,String templateName){
        List<WxTemplateDO> list = wxTemplateDao.findByTemplateIdAndWechatId(templateId,wechatId);
        if(list!=null&&list.size()>0){
            return true;
        }
        List<WxTemplateDO> list2 = wxTemplateDao.findByTemplateNameAndWechatId(templateName,wechatId);
        if(list2!=null&&list2.size()>0){
            return true;
        }
        return false;
    }
    public MixEnvelop findWxtemp(String wechatId,Integer status,String name,String key,Integer page,Integer size){
        String totalSql = "SELECT " +
                " COUNT(1) AS total " +
@ -511,7 +523,7 @@ public class WechatService {
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public MixEnvelop findWxTempConfigList(String wechatId,String scene,Integer page,Integer size){
    public MixEnvelop findWxTempConfigList(String wechatId,String templateId,String scene,Integer page,Integer size){
        String totalSql ="SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
@ -521,6 +533,9 @@ public class WechatService {
        if(StringUtils.isNotBlank(scene)){
            totalSql += " AND g.scene = '"+scene+"'";
        }
        if(StringUtils.isNotBlank(templateId)){
            totalSql += " AND g.template_id = '"+templateId+"'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
@ -557,6 +572,9 @@ public class WechatService {
        if(StringUtils.isNotBlank(scene)){
            sql += " AND g.scene = '"+scene+"'";
        }
        if(StringUtils.isNotBlank(templateId)){
            totalSql += " AND g.template_id = '"+templateId+"'";
        }
        sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxTemplateConfigVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxTemplateConfigVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
@ -566,6 +584,16 @@ public class WechatService {
        WxTemplateConfigDO wxTemplateConfigDO =  wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,name,scene);
        return wxTemplateConfigDO;
    }
    public Boolean findWxTemplateConfigExist(String wechatId,String scene){
        List<WxTemplateConfigDO> list =  wxTemplateConfigDao.findByWechatIdAndScene(wechatId,scene);
        if(list!=null&&list.size()>0){
            return true;
        }
        return false;
    }
    //===================模板消息end=======================================
    //===================微信统计==========================================

+ 56 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WxTemplateService.java

@ -1,8 +1,15 @@
package com.yihu.jw.base.service.wx;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.wx.WxTemplateConfigDao;
import com.yihu.jw.base.dao.wx.WxTemplateDao;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.base.wx.WxTemplateDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.base.WechatRequestMapping;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import org.slf4j.Logger;
@ -10,6 +17,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@ -20,6 +31,8 @@ public class WxTemplateService {
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    @Autowired
    private WxTemplateDao wxTemplateDao;
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
@ -28,20 +41,60 @@ public class WxTemplateService {
    private WeixinMessagePushUtils weixinMessagePushUtils;
    public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,"template_survey","test");
        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_survey","test",1);
        config.setFirst(config.getFirst().replace("key1","小明"));
        config.setKeyword2("2018-08-21");
        weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),openid,config);
        return "success";
    }
    public String  getAllTemp(String wechatId){
    public Envelop getAllTemp(String wechatId){
        String url ="https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token="+wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken();
        String result = HttpUtil.sendGet(url);
        return result;
        JSONObject tempJsons = JSON.parseObject(result);
        //获取所有本地模板
        List<String> localTemps = findAllTempDos(wechatId);
        //解析公众号模板
        JSONArray temps = tempJsons.getJSONArray("template_list");
        List<WxTemplateDO> savelist = new ArrayList<>();
        if(temps!=null&&!temps.isEmpty()){
            for(int i=0;i<temps.size();i++){
                JSONObject tp = (JSONObject) temps.get(i);
                String tpid = tp.getString("template_id");
                if(!localTemps.contains(tpid)){
                    WxTemplateDO wxTemplateDO = new WxTemplateDO();
                    wxTemplateDO.setWechatId(wechatId);
                    wxTemplateDO.setTemplateId(tpid);
                    wxTemplateDO.setTitle(tp.getString("title"));
                    wxTemplateDO.setContent(tp.getString("content"));
                    wxTemplateDO.setStatus(1);
                    wxTemplateDO.setCreateTime(new Date());
                    savelist.add(wxTemplateDO);
                }
            }
            wxTemplateDao.save(savelist);
        }
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public List<String> findAllTempDos(String wechatId){
        List<WxTemplateDO> list =  wxTemplateDao.findByWxId(wechatId);
        List<String> rs = new ArrayList<>();
        if(list!=null&&list.size()>0){
            for(WxTemplateDO wxTemplateDO:list){
                rs.add(wxTemplateDO.getTemplateId());
            }
        }
        return rs;
    }
//    public WxTemplateDO createWxTemplate(WxTemplateDO wxTemplate) {
//        if (StringUtils.isEmpty(wxTemplate.getTemplateId())) {