Jelajahi Sumber

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

huangwenjie 7 tahun lalu
induk
melakukan
472026c98b

+ 5 - 6
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticlePatientDTO.java

@ -33,7 +33,7 @@ public class HealthEduArticlePatientDTO {
    // 文章内容
    private String content;
    // 是否已读:0已读,1未读
    private Integer read;
    private Integer isRead;
    // 发布时间
    private Date czrq;
    // 签约类型 1三师 2家庭
@ -151,13 +151,12 @@ public class HealthEduArticlePatientDTO {
        this.content = content;
    }
    @Column(name = "is_read")
    public Integer getRead() {
        return read;
    public Integer getIsRead() {
        return isRead;
    }
    public void setRead(Integer read) {
        this.read = read;
    public void setIsRead(Integer isRead) {
        this.isRead = isRead;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")

+ 21 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyAnswers.java

@ -26,6 +26,9 @@ public class SurveyAnswers extends IdEntity implements Serializable {
//    创建时间
    private Date createTime;
//    用户openId
    private String openId;
    public SurveyAnswers() {
    }
@ -38,6 +41,16 @@ public class SurveyAnswers extends IdEntity implements Serializable {
        this.createTime = createTime;
    }
    public SurveyAnswers(String code, String surveyCode, String patient, String questionCode, String content, Date createTime, String openId) {
        this.code = code;
        this.surveyCode = surveyCode;
        this.patient = patient;
        this.questionCode = questionCode;
        this.content = content;
        this.createTime = createTime;
        this.openId = openId;
    }
    public Date getCreateTime() {
        return createTime;
    }
@ -85,4 +98,12 @@ public class SurveyAnswers extends IdEntity implements Serializable {
    public void setContent(String content) {
        this.content = content;
    }
    public String getOpenId() {
        return openId;
    }
    public void setOpenId(String openId) {
        this.openId = openId;
    }
}

+ 24 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyOptionAnswers.java

@ -30,6 +30,9 @@ public class SurveyOptionAnswers extends IdEntity implements Serializable {
//    创建时间
    private Date createTime;
//    用户openId
    private String openId;
    public SurveyOptionAnswers() {
    }
@ -44,6 +47,19 @@ public class SurveyOptionAnswers extends IdEntity implements Serializable {
        this.createTime = createTime;
    }
    public SurveyOptionAnswers(String code, String patient, String surveyCode, String questionCode, String optionsCode, String optionComment, int answerType, Date createTime,String openId) {
        this.code = code;
        this.patient = patient;
        this.surveyCode = surveyCode;
        this.questionCode = questionCode;
        this.optionsCode = optionsCode;
        this.optionComment = optionComment;
        this.answerType = answerType;
        this.createTime = createTime;
        this.openId = openId;
    }
    public Date getCreateTime() {
        return createTime;
    }
@ -107,4 +123,12 @@ public class SurveyOptionAnswers extends IdEntity implements Serializable {
    public void setAnswerType(int answerType) {
        this.answerType = answerType;
    }
    public String getOpenId() {
        return openId;
    }
    public void setOpenId(String openId) {
        this.openId = openId;
    }
}

+ 13 - 13
common/common-entity/src/main/java/com/yihu/wlyy/entity/questionnaire/QuestionnaireUsers.java

@ -34,8 +34,8 @@ public class QuestionnaireUsers extends IdEntity implements Serializable {
	//现居住地
	private String address;
	
	private Date create_time;
	private Date update_time;
	private Date createTime;
	private Date updateTime;
	
	public String getCode() {
		return code;
@ -92,21 +92,21 @@ public class QuestionnaireUsers extends IdEntity implements Serializable {
	public void setAddress(String address) {
		this.address = address;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreate_time() {
		return create_time;
	public Date getCreateTime() {
		return createTime;
	}
	
	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getUpdate_time() {
		return update_time;
	public Date getUpdateTime() {
		return updateTime;
	}
	
	public void setUpdate_time(Date update_time) {
		this.update_time = update_time;
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
}

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java

@ -14,6 +14,9 @@ public interface SurveyTemplateOptionsDao extends PagingAndSortingRepository<Sur
    @Query("select t from  SurveyTemplateOptions t where  t.templateQuestionCode = ?1 and t.templateCode = ?2 and t.del = 1 ")
    List<SurveyTemplateOptions> findById(String qstcode, String tempCode);
    @Query("select t from  SurveyTemplateOptions t where t.templateCode = ?1 and t.del = 1 ")
    List<SurveyTemplateOptions> findByQuestionCode(String qstcode);
    @Modifying
    @Query("update SurveyTemplateOptions t set t.haveComment=?4,t.content=?5," +
            "t.questionCodeNext=?6,t.isRequired=?7,t.sort=?8 where  t.templateQuestionCode = ?2 and t.templateCode = ?1 and t.code=?3")

+ 23 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/questionnaire/QuestionnaireUsersDao.java

@ -0,0 +1,23 @@
package com.yihu.wlyy.repository.questionnaire;
import com.yihu.wlyy.entity.questionnaire.QuestionnaireUsers;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface QuestionnaireUsersDao extends PagingAndSortingRepository<QuestionnaireUsers, Long> {
    @Query("select u from  QuestionnaireUsers u where  u.openid=?1")
    QuestionnaireUsers findByOpoenId(String openId);
    @Modifying
    @Query("update QuestionnaireUsers t set t.name=?2,t.idcard=?3," +
            "t.mobile=?4,t.census=?5,t.address=?6,t.updateTime = ?7  where  t.code=?1")
    int modifyOption(String code, String name, String idCard, String mobile, String census, String address, Date updateTime);
}

+ 32 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/questionnaire/QuestionnaireUsersService.java

@ -0,0 +1,32 @@
package com.yihu.wlyy.service.questionnaire;
import com.yihu.wlyy.entity.questionnaire.QuestionnaireUsers;
import com.yihu.wlyy.repository.questionnaire.QuestionnaireUsersDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by Reece on 2017/3/14.
 */
@Service
@Transactional
public class QuestionnaireUsersService extends BaseService {
    @Autowired
    private QuestionnaireUsersDao questionnaireUsersDao;
    public void userInfo(String openId){
        QuestionnaireUsers questionnaireUsers = questionnaireUsersDao.findByOpoenId(openId);
        if (questionnaireUsers!=null){
            //TODO 根据身份证判断是否抽过奖,去es里查询,如果有抽过奖则返回code,没有返回实体类。
        }
    }
    public void SaveUser(QuestionnaireUsers questionnaireUsers){
    }
}

+ 78 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.service.survey;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.questionnaire.QuestionnaireUsersDao;
import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -9,6 +10,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -34,6 +36,13 @@ public class PatientQuestionnaireService extends BaseService {
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    @Autowired
    private  SurveyTemplateQuestionsDao surveyTemplateQuestionsDao;
    @Autowired
    private SurveyTemplateOptionsDao surveyTemplateOptionsDao;
    @Autowired
    private QuestionnaireUsersDao questionnaireUsersDao;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public JSONObject getSurveySummary(String patient, String id) throws Exception {
@ -221,4 +230,73 @@ public class PatientQuestionnaireService extends BaseService {
        surveyUserDao.modifyStatus(surveyCode, patient);
    }
    /**
     * 抽奖问卷调查获取所有的问卷题目
     * @param surveyTemplateCode
     * @return
     * @throws Exception
     */
    public JSONObject getAllQuestions(String surveyTemplateCode)throws Exception{
        JSONObject json = new JSONObject();
        List<SurveyTemplateQuestions> questionList = surveyTemplateQuestionsDao.findById(surveyTemplateCode);
        List<SurveyTemplateOptions> optionsList = surveyTemplateOptionsDao.findByQuestionCode(surveyTemplateCode);
        for (SurveyTemplateQuestions surveyTemplateQuestions : questionList){
            Map<String,Object> map = new HashMap<>();
            String qusCode = surveyTemplateQuestions.getCode();
            List<SurveyTemplateOptions>  resultOptionList = new ArrayList<>();
            for (SurveyTemplateOptions option : optionsList){
                if (option.getTemplateQuestionCode().equals(qusCode)){
                    resultOptionList.add(option);
                }
            }
            map.put("question",surveyTemplateQuestions);
            map.put("option",resultOptionList);
            json.put(surveyTemplateQuestions.getSort()+"",map);
        }
        return  json;
    }
    public String saveAnswerAndLotto(JSONObject jsonData) throws Exception {
        System.out.println("********jsonData********* " + jsonData);
        //解析json保存各种答案
        String surveyCode = jsonData.get("surveyCode").toString();
        String openId = jsonData.get("openId").toString();
        String userCode = "";
        //userCode = questionnaireUsersDao.findByOpoenId(openId).getCode();
        Date createTime = new Date();
        //获取一维数组
        JSONArray questions = jsonData.getJSONArray("questions");
        for (int i = 0; i < questions.length(); i++) {
            //获取每一道题的信息
            JSONObject question = new JSONObject(questions.get(i).toString());
            String qstCode = question.get("qstCode").toString();
            int type = Integer.parseInt(question.get("type").toString());
            if (type != 2) {
                if (question.has("options")) {
                    //获取每道题的所有选项
                    JSONArray options = question.getJSONArray("options");
                    for (int j = 0; j < options.length(); j++) {
                        JSONObject option = new JSONObject(options.get(j).toString());
                        String code = getCode();
                        String optionCode = option.get("optionCode").toString();
                        String comment = null;
                        int haveComment = 0;
                        if (option.has("comment")) {
                            comment = option.get("comment").toString();
                            haveComment = 1;
                        }
                        //保存到选择题答案表
                        SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, userCode, surveyCode, qstCode, optionCode, comment, type, createTime,openId);
                        surveyOptionAnswersDao.save(optionAnswer);
                        //选择题修改统计表数量
                        surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode);
                    }
                }
            }
        }
        return  UUID.randomUUID().toString();
    }
}

+ 74 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/util/CaptchaController.java

@ -5,6 +5,8 @@ import com.google.code.kaptcha.util.Config;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Encoder;
@ -30,6 +32,9 @@ import java.util.concurrent.ConcurrentHashMap;
@RestController
@RequestMapping(value = "/patient/captcha", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class CaptchaController extends BaseController {
    @Autowired
    private StringRedisTemplate redisTemplate;
    private Map<String, String> captchaCache = new ConcurrentHashMap<>();
    private DefaultKaptcha captchaProducer = new DefaultKaptcha();
@ -108,4 +113,73 @@ public class CaptchaController extends BaseController {
    private void cleanCaptcha(String key){
        captchaCache.remove(key);
    }
    //=======================抽奖活动要结合openid生成验证码和校验验证码==========================//
    @RequestMapping(value = "/withOpenId/{openId}",method = RequestMethod.POST)
    @ApiOperation("结合openid生成验证码,用于第一次请求")
    public String createCaptchaOpenId(@PathVariable("openId") String openId){
        try{
            return generatiCaptchaOpenId(openId);
        } catch (Exception e){
            error(e);
            return error(500, e.getMessage());
        }
    }
    private String generatiCaptchaOpenId(String openId)throws Exception{
        String captchaText = captchaProducer.createText();
        BufferedImage image = captchaProducer.createImage(captchaText);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "png", outputStream);
        String base64Img = new BASE64Encoder().encode(outputStream.toByteArray());
        String uuid = UUID.randomUUID().toString();
        String key = "captcha:" + openId +"_"+uuid + ":text";
        Map<String, String> data = new HashMap<>();
        data.put("key", "captcha:" +uuid + ":text");
        data.put("image", base64Img);
        data.put("format", "png");
        redisTemplate.opsForValue().set(key,captchaText.toLowerCase());
        return write(200, "ok", "data", data);
    }
    @RequestMapping(value = "/refresh/{legacy_key}", method = RequestMethod.POST)
    @ApiOperation("刷新验证码,需提供第一次生成验证码返回的key")
    public String refreshCaptchaOpenId(@PathVariable("legacy_key") String legacyKey,
                                       @RequestParam("openId") String openId){
        try{
            legacyKey = legacyKey.replaceFirst(":",":"+openId+"_");
            redisTemplate.delete(legacyKey);
            return generatiCaptchaOpenId(openId);
        } catch (Exception e){
            error(e);
            return error(500, e.getMessage());
        }
    }
    @RequestMapping(value = "/verifyWithOpenId/{key}", method = RequestMethod.POST)
    @ApiOperation("校验证码,提供key及用户输入的验证码")
    public String verifyCaptcha(@PathVariable("key") String key,
                                @RequestParam("openId") String openId,
                                @RequestParam("text") String text){
        try{
            boolean pass = false;
            key = key.replaceFirst(":",":"+openId+"_");
            String captcha = redisTemplate.opsForValue().get(key);
            if (captcha != null && captcha.equals(text.toLowerCase())){
                pass = true;
                redisTemplate.delete(key);
            }
            return write(200, "ok", "pass", pass);
        } catch (Exception e){
            error(e);
            return error(500, e.getMessage());
        }
    }
}

+ 39 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/questionnaire/QuestionnaireUsersController.java

@ -0,0 +1,39 @@
package com.yihu.wlyy.web.patient.questionnaire;
import com.yihu.wlyy.service.questionnaire.QuestionnaireUsersService;
import com.yihu.wlyy.service.survey.PatientQuestionnaireService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
 * Created by Reece on 2017/3/14.
 */
@Controller
@RequestMapping(value = "/questionnaireUser/")
@Api(description = "居民端问卷调查用户信息")
public class QuestionnaireUsersController extends BaseController {
    @Autowired
    private QuestionnaireUsersService questionnaireUsersService;
    @RequestMapping(value = "getUserInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取用户信息并且判断是否已经抽过奖")
    @ResponseBody
    public String getSurveySummary(@ApiParam(name = "openId")@RequestParam(value = "openId")String openId) {
    return "";
    }
}

+ 54 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/survey/PatientQuestionnaireController.java

@ -1,5 +1,7 @@
package com.yihu.wlyy.web.patient.survey;
import com.google.gson.JsonObject;
import com.yihu.wlyy.rest.model.common.SimpleResult;
import com.yihu.wlyy.service.survey.PatientQuestionnaireService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
@ -7,12 +9,17 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
 * Created by Reece on 2017/3/14.
 */
@ -23,6 +30,9 @@ public class PatientQuestionnaireController extends BaseController {
    @Autowired
    private PatientQuestionnaireService patientQuestionnaireService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @RequestMapping(value = "getSurveySummary", method = RequestMethod.GET)
    @ApiOperation(value = "居民端获取问卷概述")
    @ResponseBody
@ -74,4 +84,48 @@ public class PatientQuestionnaireController extends BaseController {
        }
    }
    @RequestMapping(value = "/getAllQuestions",method = RequestMethod.GET)
    @ApiOperation(value = "电影票抽奖获取所有问卷题目")
    @ResponseBody
    public String getAllQuestions(@ApiParam(name = "surveyTemplateCode",value = "问卷模板id")@RequestParam(value = "surveyTemplateCode",required = true)String surveyTemplateCode){
        try {
            JSONObject jsonObject = patientQuestionnaireService.getAllQuestions(surveyTemplateCode);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "/saveAnswerAndLotto", method = RequestMethod.POST)
    @ApiOperation(value = "保存用户答案并且参与抽奖")
    @ResponseBody
    public String saveAnswerAndLotto(
            @RequestParam(value = "jsonData") String jsonData) {
        try {
            JSONObject json = new JSONObject(jsonData);
            //验证码验证
            String key = String.valueOf(json.get("key"));
            String text = String.valueOf(json.get("text"));
            String openId = String.valueOf(json.get("openId"));
            boolean pass = false;
            key = key.replaceFirst(":",":"+openId+"_");
            String captcha = redisTemplate.opsForValue().get(key);
            if (captcha != null && captcha.equals(text.toLowerCase())){
                pass = true;
                redisTemplate.delete(key);
            }
            //验证成功,保存问卷进行抽奖
            if (pass){
                return write(200, "操作成功!","data",patientQuestionnaireService.saveAnswerAndLotto(json));
            }else{
                return write(-1, "验证码错误!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "操作失败!");
        }
    }
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java

@ -860,7 +860,7 @@ public class EduArticleService {
                    }
                }
                //数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
                if (healthEduArticlePatient.getRead() == null) {
                if (healthEduArticlePatient.getIsRead() == null) {
                    healthEduArticleES.setIsRead(1);
                    healthEduArticleES.setCzrq(healthEduArticlePatient.getCzrq());
                } else {
@ -1071,7 +1071,7 @@ public class EduArticleService {
                    }
                }
                //数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
                if (healthEduArticlePatient.getRead() == null) {
                if (healthEduArticlePatient.getIsRead() == null) {
                    healthEduArticleES.setIsRead(1);
                    healthEduArticleES.setCzrq(healthEduArticlePatient.getCzrq());
                } else {