Browse Source

1.咨询统计
2.微信率
3.添加家庭成员改造

trick9191 8 years ago
parent
commit
dd499154d7

+ 88 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/patient/PatientFamilyTemp.java

@ -0,0 +1,88 @@
package com.yihu.wlyy.entity.patient;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2017/4/18.
 */
@Entity
@Table(name = "wlyy_patient_family_temp")
public class PatientFamilyTemp extends IdEntity {
    //处理人
    private String dealer;
    //患者code
    private String patient;
    //患者姓名
    private String patientName;
    //患者家人code
    private String familyMember;
    //患者家庭关系
    private String familyRelation;
    //添加时间
    private Date czrq;
    //状态标识
    // 0 :未处理;1:已同意;2:已拒绝
    private String state;
    public String getDealer() {
        return dealer;
    }
    public void setDealer(String dealer) {
        this.dealer = dealer;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getFamilyMember() {
        return familyMember;
    }
    public void setFamilyMember(String familyMember) {
        this.familyMember = familyMember;
    }
    public String getFamilyRelation() {
        return familyRelation;
    }
    public void setFamilyRelation(String familyRelation) {
        this.familyRelation = familyRelation;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
}

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientFamilyTempDao.java

@ -0,0 +1,16 @@
package com.yihu.wlyy.repository.patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.entity.patient.PatientFamilyTemp;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2017/4/18.
 */
public interface PatientFamilyTempDao extends PagingAndSortingRepository<PatientFamilyTemp, Long>,
        JpaSpecificationExecutor<PatientFamilyMember> {
}

+ 115 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java

@ -4,21 +4,24 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.invitation.PatientInvitationLog;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.repository.patient.PatientInvitationLogDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct;
import java.util.Date;
@ -43,6 +46,9 @@ public class FamilyMemberService extends BaseService {
    private PatientInvitationLogDao patientInviteLogDao;
    @Autowired
    FamilyContractService contractService;
    @Autowired
    private AccessTokenService accessTokenService;
    @Autowired
    JdbcTemplate jdbcTemplate;
@ -140,7 +146,8 @@ public class FamilyMemberService extends BaseService {
        return 1;
    }
    public int addMember(Patient p, String member,int type) throws Exception{
    public int addMember(Patient p, String member, int type) throws Exception {
        if (p.getCode().equals(member)) {
            return 0;
        }
@ -368,9 +375,9 @@ public class FamilyMemberService extends BaseService {
     * @return
     */
    public JSONArray getPatientMembers(String patient, String doctorCode, boolean isContain, String current) {
        JSONArray resultArray = getPatientFamilyMembers(patient,doctorCode);
        JSONArray resultArray = getPatientFamilyMembers(patient, doctorCode);
        if(resultArray == null){
        if (resultArray == null) {
            resultArray = new JSONArray();
        }
@ -487,4 +494,108 @@ public class FamilyMemberService extends BaseService {
        return relationTrans;
    }
    /**
     * 验证添加的家庭成员
     *
     * @param code 用于查询openId
     * @param menber 预绑定成员
     * @return 0未绑定微信,1仅绑定微信,2仅绑定手机,3手机微信都绑定
     */
    public JSONObject checkFamilyMember(String code, String menber,String sus) throws Exception {
        JSONObject r = new JSONObject();
        //未绑定微信,未绑定手机
        int result = 0;
        //1.判断微信过滤
        //判断是否绑定微信,如果版绑定了微信,将状态改变为 1
        if(sus.equals("1")){
                result = 1;
        }
        //2.判断手机过滤
        //判断是否绑定了手机
        Patient p = patientDao.findByCode(menber);
        if(StringUtils.isNoneBlank(p.getMobile())){
            //如果用户绑定了微信,将状态更改为4
            if(result == 1){
                result = 3;
            //如果用户未绑定微信,将状态更改为2
            }else if(result == 0){
                result = 2 ;
            }
        }
        //返回过滤后的状态
        r.put("state",result);
        if(result==0){
            r.put("mes","未绑定微信和手机");
        }else if(result==1){
            r.put("mes","仅绑定微信");
        }else if(result==2){
            r.put("mes","仅绑定手机");
        }else if(result==3){
            r.put("mes","手机和微信皆绑定");
        }
      return r;
    }
    /**
     * 获取微信的access_token
     *
     * @return
     */
    public String getAccessToken() throws Exception {
        Iterable<AccessToken> accessTokens = accessTokenService.findAccessToken();
        if (accessTokens != null) {
            for (AccessToken accessToken : accessTokens) {
                if ((System.currentTimeMillis() - accessToken.getAdd_timestamp()) < (accessToken.getExpires_in() * 1000)) {
                    return accessToken.getAccess_token();
                } else {
                    accessTokenService.delAccessToken(accessToken);
                    break;
                }
            }
        }
        String token_url = "https://api.weixin.qq.com/cgi-bin/token";
        String params = "grant_type=client_credential&appid=" + SystemConf.getInstance().getAppId() + "&secret=" + SystemConf.getInstance().getAppSecret();
        String result = HttpUtil.sendGet(token_url, params);
        JSONObject json = new JSONObject(result);
        if (json.has("access_token")) {
            String token = json.get("access_token").toString();
            String expires_in = json.get("expires_in").toString();
            AccessToken newaccessToken = new AccessToken();
            newaccessToken.setAccess_token(token);
            newaccessToken.setExpires_in(Long.parseLong(expires_in));
            accessTokenService.addAccessToken(newaccessToken);
            return token;
        } else {
            return null;
        }
    }
    /**
     * 查询所有待处理列表
     * @param code
     * @return
     */
    public JSONObject getFamilyMesList(String code){
        JSONObject result = new JSONObject();
        List<Map<String,Object>> list = jdbcTemplate.queryForList(getFamilyMesListSql(code));
        result.put("mes",list);
        return result;
    }
    public String getFamilyMesListSql(String code){
        StringBuffer sql = new StringBuffer("SELECT t.*,p.idcard,p.mobile FROM wlyy_patient_family_temp t,wlyy_patient p WHERE t.patient = p.code AND t.dealer ="+code);
        return sql.toString();
    }
}

+ 132 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java

@ -2233,4 +2233,136 @@ public class StatisticsAllService extends BaseService {
        }
    }
    /**
     * 查询某个级别的某个指标到达量
     *
     * @param date
     * @param area
     * @param level
     * @param index
     * @param sort
     * @param lowLevel
     * @return
     * @throws Exception
     */
    public JSONArray getLowLevelTotal2(String date, String area, int level, String index, int sort, String lowLevel) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (date.compareTo(dateFormat.format(new Date())) >= 0) {
            resultList = getTodayLowLevelTotal(area, level, index, sort, lowLevel);
        } else {
            resultList = getTodayBeforeLowLevelTotal(date, area, level, index, sort, lowLevel);
        }
        // 结果为空时,自建结果集
        if (resultList == null || resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
        }
        if (resultList != null) {
            DecimalFormat df = new DecimalFormat("0.0000");
            for (Map<String, Object> map : resultList) {
                map.put("amount", map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L);
                if (!low_level.equals("1")) {
                    String redisNum = "";
                    try {
                        redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
                    } catch (Exception e) {
                        redisNum = "";
                    }
                    if (StringUtils.isEmpty(redisNum)) {
                        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Calendar.getInstance().get(Calendar.YEAR));
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                            map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getTaskNum() * 100));
                            map.put("targetRate", df.format(peopleNum.getTaskNum() * 1.0000 / peopleNum.getNum() * 100));
                            map.put("rateString", map.get("amount") +"/"+ peopleNum.getNum());
                            map.put("taskRateString", map.get("amount")+"/"+  peopleNum.getTaskNum());
                            map.put("targetRateString",peopleNum.getTaskNum()+"/"+ peopleNum.getNum());
                            map.put("num", peopleNum.getNum());
                            map.put("task", peopleNum.getTaskNum());
                        }
                    } else {
                        JSONObject peopleNum = new JSONObject(redisNum);
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
                            map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("taskNum") * 100));
                            map.put("targetRate", df.format(peopleNum.getInt("taskNum") * 1.0000 / peopleNum.getInt("num") * 100));
                            map.put("rateString", map.get("amount") +"/"+ peopleNum.getInt("num") );
                            map.put("taskRateString",map.get("amount") +"/"+peopleNum.getInt("taskNum") );
                            map.put("targetRateString",peopleNum.getInt("taskNum") +"/"+ peopleNum.getInt("num"));
                            map.put("num", peopleNum.getInt("num"));
                            map.put("task", peopleNum.getInt("taskNum"));
                        }
                    }
                }
            }
            Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    long map1value = (long) o1.get("amount");
                    long map2value = (long) o2.get("amount");
                    if (map1value - map2value > 0) {
                        return sort == 1 ? -1 : 1;
                    } else if (map1value - map2value < 0) {
                        return sort == 1 ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            });
            for(Map<String, Object> map :resultList){
                Long signCout = getQuoTaResult(level,area);
                Long bindCout = (Long)map.get("amount");
                if((signCout!=null&&signCout!=0)&&(bindCout!=null&&bindCout!=0)){
                    double rate = (double)bindCout/signCout*100;
                    DecimalFormat decimalFormat  = new DecimalFormat("0.00");
                    map.put("bindRate",decimalFormat.format(rate)+"%");
                }else{
                    map.put("bindRate","0.00%");
                }
            }
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }
    /**
     *  查询签约人数
     * @param level
     * @param code
     * @return
     */
    public Long getQuoTaResult(int level,String code){
        StringBuffer sql = new StringBuffer("SELECT t.result FROM wlyy_quota_result t WHERE t.quato_code ='1'AND t.quota_date = DATE_SUB(curdate(),INTERVAL 1 DAY) AND t.level1_type ="+level);
        if(level ==1){
            //1:
            sql.append(" AND t.qkdoctor_code = "+code);
        }else if(level == 2){
            //2社区机构
            sql.append(" AND t.org_code = "+code);
        }else if(level == 3){
            //3区级
            sql.append(" AND t.town = "+code);
        }else if(level == 4){
            //4市级
            sql.append(" AND t.city = "+code);
        }
            List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql.toString());
        if(resultList!=null&&resultList.size()>0){
            return Long.parseLong((String)resultList.get(0).get("result"));
        }
        return 0L;
    }
}

+ 37 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -1246,4 +1246,41 @@ public class StatisticsService extends BaseService {
        }
        return sql.toString();
    }
    /**
     * 统计微信绑定率
     * @return
     */
    public JSONObject getBindingRate(){
        JSONObject result = new JSONObject();
        Long bindCout = jdbcTemplate.queryForObject(getBindingCountSQL(),Long.class);
        Long signCout = jdbcTemplate.queryForObject(getSignCountSQL(),Long.class);
        if((bindCout != null || bindCout != 0) && (signCout != null&&signCout != 0)){
            double rate = (double)bindCout/signCout*100;
            DecimalFormat df  = new DecimalFormat("###.00");
            result.put("bindRate",df.format(rate)+"%");
        }else{
            result.put("bindRate","0.00%");
        }
        return result;
    }
    /**
     * 获取绑定人数SQL
     * @return
     */
    public String getBindingCountSQL(){
        StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM wlyy_patient t WHERE t.openid IS NOT NULL");
        return sql.toString();
    }
    /**
     * 获取签约数SQL
     eturn
     */
    public String getSignCountSQL(){
        StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM wlyy_sign_family f WHERE f.type='2' AND f.`status`>0 AND f.expenses_status='1' ");
        return sql.toString();
    }
}

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -453,6 +453,8 @@ public class PushMsgTask {
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                logger.info("type=====>openId " + openid);
            }else if(type == 12){
            }
            temp.setData(m);

+ 46 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/WeixinBaseController.java

@ -490,4 +490,50 @@ public class WeixinBaseController extends BaseController {
		return is;
	}
	/**
	 * 获取Open
	 * @param code
	 * @return
	 * @throws Exception
     */
	public String getOpenId(String code) throws Exception {
		String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
		String params = "appid=" + SystemConf.getInstance().getAppId() + "&secret=" + SystemConf.getInstance().getAppSecret() + "&code=" + code + "&grant_type=authorization_code";
		String result = HttpUtil.sendGet(token_url, params);
		JSONObject json = new JSONObject(result);
		if (json.has("openid")) {
			return json.get("openid").toString();
		} else {
			return null;
		}
	}
	/**
	 * 获取subscribe
	 * @param openid
	 * @return
	 * @throws Exception
     */
	public String getIsSus(String openid) throws Exception{
		String userInfo_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + getAccessToken() + "&openid=" + openid + "&lang=zh_CN";
		String params = "";
		String result = HttpUtil.sendGet(userInfo_url, params);
		JSONObject json = new JSONObject(result);
		if (json.has("subscribe")) {
			return json.get("subscribe").toString();
		} else {
			return null;
		}
	}
	/**
	 * 获取Subscribe
	 * @param code
	 * @return
	 * @throws Exception
     */
	public String getSubscribeByCode(String code)throws Exception{
		return getIsSus(getOpenid(code));
	}
}

+ 40 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java

@ -1,8 +1,7 @@
package com.yihu.wlyy.web.patient.family;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
@ -22,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/patient/family")
@Api(description = "家庭成员")
public class FamilyMemberController extends BaseController {
public class FamilyMemberController extends WeixinBaseController {
    @Autowired
    FamilyMemberService familyMemberService;
@ -180,4 +179,42 @@ public class FamilyMemberController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    /**
     * 验证家庭成员微信及手机绑定情况
     * @param code 由于查找openid
     * @param memberCode
     * @return
     */
    @RequestMapping(value = "/check_member", method = RequestMethod.GET)
    @ApiOperation(value = "验证家庭成员微信及手机绑定情况")
    public String checkFamilyMember(@RequestParam("code") String code,
                                     @RequestParam("memberCode")String memberCode){
        try {
            JSONObject result = familyMemberService.checkFamilyMember(code,memberCode,getSubscribeByCode(code));
            return write(200, "验证成功", "data", result);
        }catch (Exception e){
            return error(-1, "验证失败");
        }
    }
    /**
     * 获取用户消息列表
     * @param code 业务主键
     * @return
     */
    @RequestMapping(value = "/getFamilyMesList", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户消息列表")
    public String getFamilyMesList(@RequestParam("code") String code){
        try {
            JSONObject result = familyMemberService.getFamilyMesList(code);
            return write(200, "查询成功", "data", result);
        }catch (Exception e){
            return error(-1, "验证失败");
        }
    }
    public String addMemberByPw(){
        return "";
    }
}

+ 18 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -429,7 +429,9 @@ public class StatisticsController extends BaseController {
                for (String idx : indexes) {
                    if (idx.equals("18") || index.equals("19")) {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
                    } else {
                    }else if(idx.equals("1") || index.equals("21")){
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal2(date, area, level, idx, sort, lowLevel));
                    }else {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
                    }
                }
@ -550,4 +552,19 @@ public class StatisticsController extends BaseController {
        }
    }
    /**
     * 获取绑定率
     * 1、选定绑定微信指标,下面排行内,在绑定微信数后新增:"绑定率:xx.22%"
     * 2、绑定率=绑定数/已签约数
     * @return
     */
    @RequestMapping("/bindingRate_stat")
    @ResponseBody
    public String getBindingRate(){
        try{
            return write(200, "查询成功", "data", statisticsService.getBindingRate());
        }catch (Exception e){
            return error(-1, "查询失败");
        }
    }
}