Преглед на файлове

Merge branch 'dev' of chenweida/patient-co-management into dev

chenweida преди 7 години
родител
ревизия
bff2b85777

+ 19 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/wechat/WechatTag.java

@ -12,10 +12,13 @@ import java.util.Date;
@Entity
@Table(name = "wx_tag")
public class WechatTag extends IdEntity {
    private Integer tagId;
    private String tagName;
    private Date createTime;
    private Integer del;
    private String townCode;//区code
    private String townName;//区名称
    public Integer getTagId() {
        return tagId;
@ -48,4 +51,20 @@ public class WechatTag extends IdEntity {
    public void setDel(Integer del) {
        this.del = del;
    }
    public String getTownCode() {
        return townCode;
    }
    public void setTownCode(String townCode) {
        this.townCode = townCode;
    }
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
}

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/wechat/WechatTagDao.java

@ -18,6 +18,9 @@ public interface WechatTagDao extends PagingAndSortingRepository<WechatTag, Long
    @Query(" from WechatTag where tagId=? and del=1")
    WechatTag findByTagId(Integer tagId);
    @Query(" from WechatTag where townCode=? and del=1")
    WechatTag findByTownCode(String townCode);
    @Query(" update WechatTag set del=0 where tagId=?1 ")
    @Modifying
    void deleteTag(Integer tagId);

+ 16 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -33,6 +33,7 @@ import com.yihu.wlyy.task.SignUploadTask;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import com.yihu.wlyy.wechat.util.WeiXinTagUtil;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.sql.Select;
import org.json.JSONArray;
@ -127,6 +128,9 @@ public class FamilyContractService extends BaseService {
    private SignFamilyRenewDao signFamilyRenewDao;
    @Autowired
    private SignFamilyMappingDao signFamilyMappingDao;
    @Autowired
    private WeiXinTagUtil weiXinTagUtil;
    @Autowired
    private ImUtill ImUtill;
    @Autowired
@ -1180,6 +1184,10 @@ public class FamilyContractService extends BaseService {
            ImUtill.sendImMsg(doc.getCode(), doc.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, "0", "家庭医生代理签约成功!", "1");
        }
        BusinessLogs.info(BusinessLogs.BusinessType.sign, signDoctorCode, sf.getPatient(), new JSONObject(sf));
        //签约成功之后给患者新增标签
        String openId=sf.getOpenid();
       hospital=sf.getHospital();
        weiXinTagUtil.addTagWithOpenid(openId,hospital);
        return temp;
    }
@ -1524,6 +1532,10 @@ public class FamilyContractService extends BaseService {
        }
        result.put("status", 1);
        BusinessLogs.info(BusinessLogs.BusinessType.sign, caller, sf.getPatient(), new JSONObject(sf));
        //签约成功之后给患者新增标签
        String openId=sf.getOpenid();
        String hospital=sf.getHospital();
        weiXinTagUtil.addTagWithOpenid(openId,hospital);
        return result;
    }
@ -1657,6 +1669,10 @@ public class FamilyContractService extends BaseService {
            }
        }
        //根据openId给患者清掉标签
        String openId=sf.getOpenid();
        String hospital=sf.getHospital();
        weiXinTagUtil.deleteTagWithOpenid(openId,hospital);
        return 1;
    }

+ 113 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinTagUtil.java

@ -6,11 +6,13 @@ import com.yihu.wlyy.entity.wechat.WechatTag;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.wechat.WechatTagDao;
import com.yihu.wlyy.util.HttpUtil;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
@ -47,7 +49,7 @@ public class WeiXinTagUtil {
    /**
     * 根据openID给用户打标签,并且同步更新用户表
     * 根据openID给用户打标签, 
     *
     * @param openIds
     * @param tagId
@ -78,7 +80,86 @@ public class WeiXinTagUtil {
    }
    /**
     * 根据openID给用户取消标签,并且同步更新用户表
     * 根据openID给用户打标签, 
     *
     * @param openid
     * @param tagId
     * @return
     */
    public String addTagWithOpenid(String openid, Integer tagId) {
        try {
            net.sf.json.JSONObject params = new net.sf.json.JSONObject();
            net.sf.json.JSONArray ja = new JSONArray();
            ja.add(openid);
            params.put("openid_list", ja);
            params.put("tagid", tagId);
            String result = httpUtil.sendPost(add_user_tag + weiXinAccessTokenUtils.getAccessToken(), params.toString());
            net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
            if (resultJson.containsKey("errcode")) {
                Integer status = resultJson.getInt("errcode");
                if (status != 0) {
                    throw new Exception("创建失败," + result);
                }
            }
            return result;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return null;
        }
    }
    /**
     * 根据openID给用户打标签, 
     *
     * @param openid
     * @param hospital
     * @return
     */
    public String addTagWithOpenid(String openid, String hospital) {
        try {
            if (!StringUtils.isEmpty(hospital)) {
                String town=hospital.substring(0,6);
                //根据机构获取tagId
                WechatTag tagId = wechatTagDao.findByTownCode(town);
                if (tagId != null) {
                    return addTagWithOpenid(openid, tagId.getTagId());
                }
            }
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return null;
        }
    }
    /**
     * 根据openID给用户取消标签,
     *
     * @param openid
     * @param hospital
     * @return
     */
    public String deleteTagWithOpenid(String openid, String hospital) {
        try {
            if (!StringUtils.isEmpty(hospital)) {
                String town=hospital.substring(0,6);
                //根据机构获取tagId
                WechatTag tagId = wechatTagDao.findByTownCode(town);
                if (tagId != null) {
                    return deleteTagWithOpenid(openid, tagId.getTagId());
                }
            }
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return null;
        }
    }
    /**
     * 根据openID给用户取消标签, 
     *
     * @param openIds
     * @param tagId
@ -107,7 +188,37 @@ public class WeiXinTagUtil {
            return null;
        }
    }
    /**
     * 根据openID给用户取消标签,
     *
     * @param openIds
     * @param tagId
     * @return
     */
    public String deleteTagWithOpenid(String openIds, Integer tagId) {
        try {
            net.sf.json.JSONObject params = new net.sf.json.JSONObject();
            net.sf.json.JSONArray ja=new JSONArray();
            ja.add(openIds);
            params.put("openid_list", ja);
            params.put("tagid", tagId);
            String result = httpUtil.sendPost(delete_user_tag + weiXinAccessTokenUtils.getAccessToken(), params.toString());
            net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
            if (resultJson.containsKey("errcode")) {
                Integer status = resultJson.getInt("errcode");
                if (status != 0) {
                    throw new Exception("创建失败," + result);
                }
            }
            return result;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return null;
        }
    }
    /**
     * 获取用户身上的标签列表
     *