|
@ -0,0 +1,792 @@
|
|
|
package com.yihu.jw.hospital.integrate.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.article.dao.KnowledgeArticleDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.hospital.article.KnowledgeArticleDoctorDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalActivityDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalIntegrateDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalUserActivityDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalUserIntegrateDO;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalActivityDao;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalIntegrateDao;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalUserActivityDao;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalUserIntegrateDao;
|
|
|
import com.yihu.jw.mysql.query.BaseJpaService;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class BaseHospitalUserActivityService extends BaseJpaService<BaseHospitalUserActivityDO, BaseHospitalUserActivityDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private BaseHospitalUserIntegrateDao hospitalUserIntegrateDao;
|
|
|
@Autowired
|
|
|
private HibenateUtils hibenateUtils;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private BaseHospitalUserActivityDao hospitalUserActivityDao;
|
|
|
@Autowired
|
|
|
private BaseHospitalIntegrateDao hospitalIntegrateDao;
|
|
|
@Autowired
|
|
|
private BaseHospitalActivityDao hospitalActivityDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalDao doctorHospitalDao;
|
|
|
@Autowired
|
|
|
private KnowledgeArticleDoctorDao knowledgeArticleDoctorDao;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询活动报名记录
|
|
|
* @param title 活动名称
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop selectUserActivityByCondition(String title,Integer page, Integer size){
|
|
|
String orderBy = " order by hua.create_time desc ";
|
|
|
String condition = " ";
|
|
|
String sql = "SELECT\n" +
|
|
|
"\thua.id,\n" +
|
|
|
"\thua.type,\n" +
|
|
|
"\thua.user,\n" +
|
|
|
"\thua.name,\n" +
|
|
|
"\tha.title,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\thua.create_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS createTime,\n" +
|
|
|
"\thua.relation_code AS relationCode,\n" +
|
|
|
"\thua.relation_name AS relaitonName\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_activity hua,base_hospital_activity ha \n" +
|
|
|
"WHERE\n" +
|
|
|
"\t1 = 1 \n" +
|
|
|
" and hua.relation_code=ha.id ";
|
|
|
if (StringUtils.isNoneBlank(title)){
|
|
|
condition +=" and ha.title LIKE '%"+title+"%' ";
|
|
|
}
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql+condition+orderBy, page, size);
|
|
|
for (Map<String,Object> map:list){
|
|
|
String user = map.get("user").toString();
|
|
|
String type = map.get("type").toString();
|
|
|
if (type.equalsIgnoreCase("1")){
|
|
|
BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(user);
|
|
|
map.put("name",doctorDO.getName());
|
|
|
map.put("sex",doctorDO.getSex());
|
|
|
map.put("age", DateUtil.getAgeForIdcard(doctorDO.getIdcard()));
|
|
|
map.put("mobile",doctorDO.getMobile());
|
|
|
map.put("idcard",doctorDO.getIdcard());
|
|
|
}else if (type.equalsIgnoreCase("2")){
|
|
|
BasePatientDO patientDO = patientDao.findById(user).get();
|
|
|
map.put("name",patientDO.getName());
|
|
|
map.put("sex",patientDO.getSex());
|
|
|
map.put("age", DateUtil.getAgeForIdcard(patientDO.getIdcard()));
|
|
|
map.put("mobile",patientDO.getMobile());
|
|
|
map.put("idcard",patientDO.getIdcard());
|
|
|
}
|
|
|
String integrateSql ="SELECT IFNULL(SUM(integrate),0) as total FROM base_hospital_user_integrate where user='"+user+"' and relation_code='"+map.get("relationCode")+"' ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(integrateSql);
|
|
|
Double count = 0.0;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Double.parseDouble(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
map.put("total",count);
|
|
|
}
|
|
|
String sqlCount ="select COUNT(1) as total from base_hospital_user_activity hua,base_hospital_activity ha where 1=1 and hua.relation_code=ha.id ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount+condition+orderBy);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
return MixEnvelop.getSuccessListWithPage("success", list, page, size, count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询某个活动下某个用户获取的积分详情
|
|
|
* @param user
|
|
|
* @param acticityId
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop selectUserIntegrateByCondition(String user,String acticityId,Integer page, Integer size){
|
|
|
String orderBy = " order by hui.create_time desc ";
|
|
|
String condition = " ";
|
|
|
String sql = " SELECT hui.id,hui.integrate," +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\thui.create_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS createTime \n" +
|
|
|
" FROM base_hospital_user_integrate hui where hui.user = '"+user+"' " +
|
|
|
"and hui.relation_code ='"+acticityId+"' ";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql+condition+orderBy, page, size);
|
|
|
String sqlCount ="select COUNT(1) as total from base_hospital_user_integrate hui where hui.user = '"+user+"' " +
|
|
|
"and hui.relation_code ='"+acticityId+"' ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount+condition+orderBy);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
return MixEnvelop.getSuccessListWithPage("success", list, page, size, count);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据活动报名记录id获取活动报名情况详情
|
|
|
*
|
|
|
* @param userActivityId
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseHospitalUserActivityDO findUserActivityById(String userActivityId){
|
|
|
return hospitalUserActivityDao.findById(userActivityId).get();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询某个用户参与的活动情况
|
|
|
* @param user 用户编码
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop selectUserActivityByUser(String user,Integer page, Integer size){
|
|
|
String orderBy = " order by hua.create_time desc ";
|
|
|
String condition = " ";
|
|
|
String sql = "SELECT\n" +
|
|
|
"\thua.id,\n" +
|
|
|
"\thua.type,\n" +
|
|
|
"\thua.user,\n" +
|
|
|
"\thua.name,\n" +
|
|
|
"\tha.title,\n" +
|
|
|
"\tha.banner,\n" +
|
|
|
"\tha.task_code as taskCode,\n" +
|
|
|
"\tha.content as content,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\tha.end_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS activityTime,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\thua.create_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS createTime,\n" +
|
|
|
"\thua.relation_code AS relationCode,\n" +
|
|
|
"\thua.relation_name AS relaitonName\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_activity hua,base_hospital_activity ha \n" +
|
|
|
"WHERE\n" +
|
|
|
"\t1 = 1\n" +
|
|
|
" and hua.relation_code=ha.id and hua.user='"+user+"' and ha.flag=1 ";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql+condition+orderBy, page, size);
|
|
|
for (Map<String,Object> map:list){
|
|
|
String relationCode= map.get("relationCode").toString();
|
|
|
BaseHospitalIntegrateDO integrateDO = hospitalIntegrateDao.selectByActivityId(relationCode);
|
|
|
map.put("integrate",integrateDO);
|
|
|
String userIntegrateSql = "select * from base_hospital_user_integrate where 1=1 and user='"+user+"' and relation_code ='"+relationCode+"' ";
|
|
|
String outpatientSql = " SELECT * FROM wlyy_outpatient where doctor ='"+user+"' and status>=1 ";
|
|
|
String taskCode= map.get("taskCode").toString();
|
|
|
if (taskCode.equalsIgnoreCase("twzx")){
|
|
|
outpatientSql +=" and outpatient_type =3 and type=1 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("twfz")){
|
|
|
outpatientSql +=" and outpatient_type =1 and type=1 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("spzx")){
|
|
|
outpatientSql +=" and outpatient_type =3 and type=2 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("spfz")){
|
|
|
outpatientSql +=" and outpatient_type =1 and type=2 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("xtmz")){
|
|
|
outpatientSql +=" and outpatient_type =2 ";
|
|
|
}
|
|
|
int j = 0;
|
|
|
int integrate=0;
|
|
|
String createTime = map.get("createTime").toString();
|
|
|
String activityTime=map.get("activityTime").toString();
|
|
|
if (integrateDO!=null){
|
|
|
if (integrateDO.getType()==1){
|
|
|
outpatientSql += " and create_time>='"+createTime+"' and create_time <='"+activityTime+"' ";
|
|
|
List<Map<String,Object>> mapList = jdbcTemplate.queryForList(outpatientSql);
|
|
|
Integer total = mapList.size();
|
|
|
JSONArray array = JSONArray.parseArray(integrateDO.getConditions());
|
|
|
for (int i=0;i<array.size();i++){
|
|
|
JSONObject object = array.getJSONObject(i);
|
|
|
if (StringUtils.isNoneBlank(object.getString("total"))){
|
|
|
if (total>=object.getInteger("total")){
|
|
|
if (integrate!=0){
|
|
|
if (integrate<=object.getInteger("integrate")){
|
|
|
integrate = object.getInteger("integrate");
|
|
|
j = j+1;
|
|
|
}
|
|
|
}else {
|
|
|
j = j+1;
|
|
|
integrate = object.getInteger("integrate");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}else if (integrateDO.getType()==2){
|
|
|
String startTime = DateUtil.getStringDateShort()+" 00:00:00";
|
|
|
String endTime = DateUtil.getStringDateShort()+" 23:59:59";
|
|
|
userIntegrateSql += " and create_time >='"+startTime+"' and create_time <='"+endTime+"' ";
|
|
|
outpatientSql += " and create_time>='"+startTime+"' and create_time <='"+endTime+"' ";
|
|
|
List<Map<String,Object>> mapList = jdbcTemplate.queryForList(outpatientSql);
|
|
|
Integer total = mapList.size();
|
|
|
JSONArray array = JSONArray.parseArray(integrateDO.getConditions());
|
|
|
for (int i=0;i<array.size();i++){
|
|
|
JSONObject object = array.getJSONObject(i);
|
|
|
if (StringUtils.isNoneBlank(object.getString("total"))){
|
|
|
if (total>=object.getInteger("total")){
|
|
|
if (integrate!=0){
|
|
|
if (integrate<=object.getInteger("integrate")){
|
|
|
integrate = object.getInteger("integrate");
|
|
|
j = j+1;
|
|
|
}
|
|
|
}else {
|
|
|
j = j+1;
|
|
|
integrate = object.getInteger("integrate");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
List<Map<String,Object>> mapList = jdbcTemplate.queryForList(userIntegrateSql);
|
|
|
if (j>=1&&mapList.size()==0){
|
|
|
map.put("status","2");//1待完成2待领取3已领取
|
|
|
}else if (j>=1&&mapList.size()>=1){
|
|
|
map.put("status","3");//1待完成2待领取3已领取
|
|
|
}else {
|
|
|
map.put("status","1");//1待完成2待领取3已领取
|
|
|
}
|
|
|
map.put("integrate",integrate);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
String sqlCount ="select COUNT(1) as total from base_hospital_user_activity hua,base_hospital_activity ha where 1=1 and hua.relation_code=ha.id and hua.user='"+user+"' and ha.flag=1 ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount+condition+orderBy);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
return MixEnvelop.getSuccessListWithPage("success", list, page, size, count);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 用户领取积分
|
|
|
* @param user
|
|
|
* @param activityId
|
|
|
* @return
|
|
|
*/
|
|
|
public String receiveIntegrate(String user,String activityId){
|
|
|
BaseHospitalActivityDO activityDO = hospitalActivityDao.findById(activityId).get();
|
|
|
BaseHospitalIntegrateDO integrateDO = hospitalIntegrateDao.selectByActivityId(activityId);
|
|
|
BaseHospitalUserActivityDO userActivityDO = hospitalUserActivityDao.selectByUserAndRelationCode(user,activityId);
|
|
|
String userIntegrateSql = "select * from base_hospital_user_integrate where 1=1 and user='"+user+"' and relation_code ='"+activityId+"' ";
|
|
|
String outpatientSql = " SELECT * FROM wlyy_outpatient where doctor ='"+user+"' and status>=1 ";
|
|
|
String taskCode= activityDO.getTaskCode();
|
|
|
if (taskCode.equalsIgnoreCase("twzx")){
|
|
|
outpatientSql +=" and outpatient_type =3 and type=1 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("twfz")){
|
|
|
outpatientSql +=" and outpatient_type =1 and type=1 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("spzx")){
|
|
|
outpatientSql +=" and outpatient_type =3 and type=2 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("spfz")){
|
|
|
outpatientSql +=" and outpatient_type =1 and type=2 ";
|
|
|
}else if (taskCode.equalsIgnoreCase("xtmz")){
|
|
|
outpatientSql +=" and outpatient_type =2 ";
|
|
|
}
|
|
|
int j = 0;
|
|
|
int integrate=0;
|
|
|
String createTime = DateUtil.dateToStrLong(userActivityDO.getCreateTime());
|
|
|
String activityTime=DateUtil.dateToStrLong(activityDO.getEndTime());
|
|
|
if (integrateDO!=null) {
|
|
|
if (integrateDO.getType() == 1) {
|
|
|
outpatientSql += " and create_time>='" + createTime + "' and create_time <='" + activityTime + "' ";
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(outpatientSql);
|
|
|
Integer total = mapList.size();
|
|
|
JSONArray array = JSONArray.parseArray(integrateDO.getConditions());
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
JSONObject object = array.getJSONObject(i);
|
|
|
if (StringUtils.isNoneBlank(object.getString("total"))) {
|
|
|
if (total >= object.getInteger("total")) {
|
|
|
if (integrate != 0) {
|
|
|
if (integrate <= object.getInteger("integrate")) {
|
|
|
integrate = object.getInteger("integrate");
|
|
|
j = j + 1;
|
|
|
}
|
|
|
} else {
|
|
|
j = j + 1;
|
|
|
integrate = object.getInteger("integrate");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else if (integrateDO.getType() == 2) {
|
|
|
String startTime = DateUtil.getStringDateShort() + " 00:00:00";
|
|
|
String endTime = DateUtil.getStringDateShort() + " 23:59:59";
|
|
|
userIntegrateSql += " and create_time >='" + startTime + "' and create_time <='" + endTime + "' ";
|
|
|
outpatientSql += " and create_time>='" + startTime + "' and create_time <='" + endTime + "' ";
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(outpatientSql);
|
|
|
Integer total = mapList.size();
|
|
|
JSONArray array = JSONArray.parseArray(integrateDO.getConditions());
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
JSONObject object = array.getJSONObject(i);
|
|
|
if (StringUtils.isNoneBlank(object.getString("total"))) {
|
|
|
if (total >= object.getInteger("total")) {
|
|
|
if (integrate != 0) {
|
|
|
if (integrate <= object.getInteger("integrate")) {
|
|
|
integrate = object.getInteger("integrate");
|
|
|
j = j + 1;
|
|
|
}
|
|
|
} else {
|
|
|
j = j + 1;
|
|
|
integrate = object.getInteger("integrate");
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(userIntegrateSql);
|
|
|
if (j >= 1 && mapList.size() == 0) {
|
|
|
BaseHospitalUserIntegrateDO userIntegrateDO = new BaseHospitalUserIntegrateDO();
|
|
|
userIntegrateDO.setUpdateTime(new Date());
|
|
|
userIntegrateDO.setUser(user);
|
|
|
userIntegrateDO.setRelationCode(activityId);
|
|
|
userIntegrateDO.setRelationName(activityDO.getTitle());
|
|
|
userIntegrateDO.setStatus(1);
|
|
|
userIntegrateDO.setIntegrate(+integrate);
|
|
|
userIntegrateDO.setName(userActivityDO.getName());
|
|
|
userIntegrateDO.setType(userActivityDO.getType());
|
|
|
userIntegrateDO.setTaskCode(activityDO.getTaskCode());
|
|
|
userIntegrateDO.setTaskName(activityDO.getTaskName());
|
|
|
userIntegrateDO.setBusinessCode(activityDO.getBusinessCode());
|
|
|
userIntegrateDO.setBusinessName(activityDO.getBusinessName());
|
|
|
userIntegrateDO.setIntegrateType(1);
|
|
|
hospitalUserIntegrateDao.save(userIntegrateDO);
|
|
|
return "领取成功!";
|
|
|
} else if (j >= 1 && mapList.size() >= 1) {
|
|
|
return "已领取过!";
|
|
|
} else {
|
|
|
return "还不达标,不能领取!";
|
|
|
}
|
|
|
}else {
|
|
|
return "无需领取!";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 用户报名
|
|
|
*
|
|
|
* @param user
|
|
|
* @param name
|
|
|
* @param type
|
|
|
* @param activityId
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseHospitalUserActivityDO takeActivity(String user,String name,Integer type,String activityId) throws Exception {
|
|
|
BaseHospitalActivityDO activityDO = hospitalActivityDao.findById(activityId).get();
|
|
|
Date date = new Date();
|
|
|
if (!((date.compareTo(activityDO.getRegistrationStartTime())>0&&date.compareTo(activityDO.getRegistrationEndTime())<0)||date.compareTo(activityDO.getRegistrationStartTime())==0
|
|
|
||date.compareTo(activityDO.getRegistrationEndTime())==0)){
|
|
|
throw new Exception("还未到报名时间!");
|
|
|
}
|
|
|
BaseHospitalUserActivityDO userActivityDO = new BaseHospitalUserActivityDO();
|
|
|
userActivityDO.setType(type);
|
|
|
userActivityDO.setName(name);
|
|
|
userActivityDO.setUser(user);
|
|
|
userActivityDO.setStatus(1);
|
|
|
userActivityDO.setRelationCode(activityDO.getId());
|
|
|
userActivityDO.setRelationName(activityDO.getTitle());
|
|
|
userActivityDO.setCreateTime(new Date());
|
|
|
userActivityDO.setUpdateTime(new Date());
|
|
|
return hospitalUserActivityDao.save(userActivityDO);
|
|
|
}
|
|
|
|
|
|
/* public BaseHospitalUserIntegrateDO insertIntegrate(String user,String userName,String integrateId){
|
|
|
Date startDate= DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 00:00:00");
|
|
|
Date endDate= DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 23:59:59");
|
|
|
BaseHospitalIntegrateDO hospitalIntegrateDO = hospitalIntegrateDao.findById(integrateId).get();
|
|
|
List<BaseHospitalUserIntegrateDO> hospitalUserIntegrateDOS = hospitalUserIntegrateDao.selectByUserAndRelationCode(user,integrateId);//获取用户领取积分情况
|
|
|
List<BaseHospitalUserIntegrateDO> hospitalUserIntegrateDOList = hospitalUserIntegrateDao.selectByUserAndRelationCodeAndCreateTime(user,integrateId,startDate,endDate);//获取当天是否领取
|
|
|
if (hospitalIntegrateDO.getItem().equals("wanshan")){
|
|
|
if (hospitalIntegrateDO.getFlag()==1){
|
|
|
if (hospitalUserIntegrateDOS==null||hospitalUserIntegrateDOS.size()==0){
|
|
|
BaseDoctorDO doctorDO = doctorDao.findById(user).get();
|
|
|
if (StringUtils.isNoneBlank(doctorDO.getPhoto())&StringUtils.isNoneBlank(doctorDO.getName())
|
|
|
&doctorDO.getSex()!=null&StringUtils.isNoneBlank(doctorDO.getIntroduce())
|
|
|
&StringUtils.isNoneBlank(doctorDO.getExpertise())&StringUtils.isNoneBlank(doctorDO.getLearning())
|
|
|
&StringUtils.isNoneBlank(doctorDO.getVisitHospital())&StringUtils.isNoneBlank(doctorDO.getImg())){
|
|
|
BaseHospitalUserIntegrateDO userIntegrateDO = new BaseHospitalUserIntegrateDO();
|
|
|
userIntegrateDO.setIntegrate(hospitalIntegrateDO.getIntegrate());
|
|
|
userIntegrateDO.setUser(user);
|
|
|
userIntegrateDO.setName(userName);
|
|
|
userIntegrateDO.setIntegrateType(1);
|
|
|
userIntegrateDO.setRelationType(hospitalIntegrateDO.getType()+"");
|
|
|
userIntegrateDO.setRelationTypeName(hospitalIntegrateDO.getTypeName());
|
|
|
userIntegrateDO.setRelationItem(hospitalIntegrateDO.getItem());
|
|
|
userIntegrateDO.setRelationItemName(hospitalIntegrateDO.getItemName());
|
|
|
userIntegrateDO.setRelaitonCode(hospitalIntegrateDO.getId());
|
|
|
userIntegrateDO.setRelationName(hospitalIntegrateDO.getName());
|
|
|
userIntegrateDO.setStatus(1);
|
|
|
userIntegrateDO.setCreateTime(new Date());
|
|
|
userIntegrateDO.setUpdateTime(new Date());
|
|
|
hospitalUserIntegrateDao.save(userIntegrateDO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}else if (hospitalIntegrateDO.getItem().equals("doctor")){
|
|
|
String sql = "";
|
|
|
if (hospitalIntegrateDO.getFlag()==2){
|
|
|
if (hospitalUserIntegrateDOList==null&&hospitalUserIntegrateDOList.size()==0){
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
*/
|
|
|
/**
|
|
|
* 需要手动点击签到的情况
|
|
|
* @param signInDates
|
|
|
* @return
|
|
|
*/
|
|
|
private static int persistentDay(List<Date> signInDates) {
|
|
|
//定义一个变量表示连续签到天数,从1开始
|
|
|
int continuousDays = 0;
|
|
|
if (signInDates!=null&&signInDates.size()!=0){
|
|
|
continuousDays=1;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 2. 从最大的时间开始往前比较,因为我们是要拿连续签到的时间,这样才有意义,减少无谓的比较
|
|
|
*/
|
|
|
Calendar later = Calendar.getInstance();
|
|
|
Calendar before = Calendar.getInstance();
|
|
|
for (int i = signInDates.size() - 1; i > 0; i--) {
|
|
|
later.setTime(signInDates.get(i));
|
|
|
before.setTime(signInDates.get(i - 1));
|
|
|
//前一天 + 1天 = 后一天,则视为连续签到
|
|
|
before.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
if (later.get(Calendar.YEAR) == before.get(Calendar.YEAR)
|
|
|
&& later.get(Calendar.MONTH) == before.get(Calendar.MONTH)
|
|
|
&& later.get(Calendar.DAY_OF_YEAR) == before.get(Calendar.DAY_OF_YEAR)) {
|
|
|
continuousDays++;
|
|
|
} else {
|
|
|
//只要遇到不连续的就不用再往前比较了
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return continuousDays;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 医生-个人积分榜单/接诊榜单/单个活动榜单
|
|
|
* @param user 用户id
|
|
|
* @param businessCode 业务
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject selectUserIntegrateListByCondition(String user,String businessCode,String activityId,Integer page, Integer size){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String condition = " ";
|
|
|
if (StringUtils.isNoneBlank(businessCode)){
|
|
|
condition +=" and business_code = '"+businessCode+"' ";
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(activityId)){
|
|
|
condition +=" and relation_code = '"+activityId+"' ";
|
|
|
}
|
|
|
String sql ="SELECT\n" +
|
|
|
"\tt.user,\n" +
|
|
|
"\tt.name,\n" +
|
|
|
"\tt.total ,@i\\:= @i + 1 AS number\n" +
|
|
|
"FROM\n" +
|
|
|
"\t(\n" +
|
|
|
"\t\tSELECT\n" +
|
|
|
"\t\t\tuser,\n" +
|
|
|
"\t\t\tname,\n" +
|
|
|
"\t\t\tSUM(integrate) AS total\n" +
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\tbase_hospital_user_integrate\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
"\t\t\tstatus = 1\n" +
|
|
|
condition+
|
|
|
"\t\tGROUP BY\n" +
|
|
|
"\t\t\tuser\n" +
|
|
|
"\t\tORDER BY\n" +
|
|
|
"\t\t\tSUM(integrate) DESC\n" +
|
|
|
"\t\t\n" +
|
|
|
"\t) t,\n" +
|
|
|
"\t(SELECT @i\\:= "+(page - 1) * size+") AS itable\n ";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, size);
|
|
|
for (Map<String,Object> map:list){
|
|
|
String doctorId =map.get("user").toString();
|
|
|
BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(doctorId);
|
|
|
map.put("doctorDO",doctorDO);//医生信息
|
|
|
List<BaseDoctorHospitalDO> doctorHospitalList = doctorHospitalDao.findByDoctorCode(doctorId);
|
|
|
map.put("doctorHospitalList",doctorHospitalList);
|
|
|
String eulogySql= " SELECT\n" +
|
|
|
"\tIFNULL(COUNT(1), 0) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_knowledge_article_doctor\n" +
|
|
|
"WHERE\n" +
|
|
|
"\t(relation_code IN (\n" +
|
|
|
"\t\tSELECT\n" +
|
|
|
"\t\t\tid\n" +
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\tbase_knowledge_dict\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
"\t\t\tcreate_user = '"+doctorId+"'\n" +
|
|
|
"\t) OR relation_code ='"+doctorId+"' )\n" +
|
|
|
"\tand type=2 ";
|
|
|
List<Map<String, Object>> eulogyRstotal = hibenateUtils.createSQLQuery(eulogySql);
|
|
|
Long eulogyTotal = 0L;
|
|
|
if (eulogyRstotal != null && eulogyRstotal.size() > 0) {
|
|
|
eulogyTotal = Long.parseLong(eulogyRstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
map.put("eulogyTotal",eulogyTotal);//点赞数量
|
|
|
boolean eulogy= false;
|
|
|
List<KnowledgeArticleDoctorDO> knowledgeArticleDoctorDOS = knowledgeArticleDoctorDao.findByRelationCodeAndTypeAndUser(doctorId,2,user);//获取点赞
|
|
|
if (knowledgeArticleDoctorDOS!=null&&knowledgeArticleDoctorDOS.size()>0){
|
|
|
eulogy = true;
|
|
|
}
|
|
|
map.put("eulogy",eulogy);
|
|
|
}
|
|
|
String sqlCount ="SELECT\n" +
|
|
|
"\tCOUNT(1) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\t(\n" +
|
|
|
"\t\tSELECT\n" +
|
|
|
"\t\t\tUSER,\n" +
|
|
|
"\t\t\tSUM(integrate) AS total\n" +
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\t`base_hospital_user_integrate`\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
"\t\t\tSTATUS = 1\n" +
|
|
|
condition+
|
|
|
"\t\tGROUP BY\n" +
|
|
|
"\t\t\tUSER\n" +
|
|
|
"\t\tORDER BY\n" +
|
|
|
"\t\t\tSUM(integrate) DESC\n" +
|
|
|
"\t) t ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
String userSql = " SELECT * FROM (SELECT t.user,t.name,t.total,@i\\:= @i + 1 AS number from \n" +
|
|
|
"(SELECT\n" +
|
|
|
"\tuser,\n" +
|
|
|
"\tname,\n" +
|
|
|
"\tSUM(integrate) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_integrate\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tstatus = 1\n" +
|
|
|
condition+
|
|
|
"GROUP BY\n" +
|
|
|
"\tuser\n" +
|
|
|
"ORDER BY\n" +
|
|
|
"\tSUM(integrate) DESC) t,\n" +
|
|
|
"(SELECT @i\\:=0) AS itable) t1\n" +
|
|
|
"WHERE t1.user='"+user+"'";
|
|
|
List<Map<String,Object>> mapList = hibenateUtils.createSQLQuery(userSql);
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
if (mapList!=null&&mapList.size()!=0){
|
|
|
map = mapList.get(0);
|
|
|
if (map!=null){
|
|
|
String doctorId =map.get("user").toString();
|
|
|
BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(doctorId);
|
|
|
map.put("doctorDO",doctorDO);//医生信息
|
|
|
List<BaseDoctorHospitalDO> doctorHospitalList = doctorHospitalDao.findByDoctorCode(doctorId);
|
|
|
map.put("doctorHospitalList",doctorHospitalList);
|
|
|
String eulogySql= " SELECT\n" +
|
|
|
"\tIFNULL(COUNT(1), 0) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_knowledge_article_doctor\n" +
|
|
|
"WHERE\n" +
|
|
|
"\t(relation_code IN (\n" +
|
|
|
"\t\tSELECT\n" +
|
|
|
"\t\t\tid\n" +
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\tbase_knowledge_dict\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
"\t\t\tcreate_user = '"+doctorId+"'\n" +
|
|
|
"\t) OR relation_code ='"+doctorId+"' )\n" +
|
|
|
"\tand type=2 ";
|
|
|
List<Map<String, Object>> eulogyRstotal = hibenateUtils.createSQLQuery(eulogySql);
|
|
|
Long eulogyTotal = 0L;
|
|
|
if (eulogyRstotal != null && eulogyRstotal.size() > 0) {
|
|
|
eulogyTotal = Long.parseLong(eulogyRstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
map.put("eulogyTotal",eulogyTotal);//点赞数量
|
|
|
boolean eulogy= false;
|
|
|
List<KnowledgeArticleDoctorDO> knowledgeArticleDoctorDOS = knowledgeArticleDoctorDao.findByRelationCodeAndTypeAndUser(doctorId,2,user);//获取点赞
|
|
|
if (knowledgeArticleDoctorDOS!=null&&knowledgeArticleDoctorDOS.size()>0){
|
|
|
eulogy = true;
|
|
|
}
|
|
|
map.put("eulogy",eulogy);
|
|
|
}
|
|
|
}
|
|
|
object.put("mapList",list);
|
|
|
object.put("user",map);
|
|
|
object.put("total",count);
|
|
|
object.put("page",page);
|
|
|
object.put("size",size);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param businessCode
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop selectDeptRomByCondition(String businessCode,Integer page, Integer size){
|
|
|
String condition = " ";
|
|
|
if (StringUtils.isNoneBlank(businessCode)){
|
|
|
condition +=" and business_code = '"+businessCode+"' ";
|
|
|
}
|
|
|
String sql ="SELECT\n" +
|
|
|
"\tt.deptCode,\n" +
|
|
|
"\tt.deptName,\n" +
|
|
|
"\tt.total ,@i\\:= @i + 1 AS number\n" +
|
|
|
"FROM\n" +
|
|
|
"\t(\n" +
|
|
|
"\t\tSELECT\n" +
|
|
|
"\t\t\tdh.dept_code as deptCode,\n" +
|
|
|
"\t\t\tdh.dept_name as deptName,\n" +
|
|
|
"\t\t\tSUM(ui.integrate) AS total\n" +
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\tbase_hospital_user_integrate ui\n" +
|
|
|
"\t\t\tLEFT JOIN base_doctor_hospital dh ON \n" +
|
|
|
"\t\t\tui.user=dh.doctor_code\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
"\t\t\tui.status = 1\n" +
|
|
|
"\t\t\tAND ui.type=1\n" +
|
|
|
condition+
|
|
|
" \t\tGROUP BY\n" +
|
|
|
"\t\t\tdh.dept_code\n" +
|
|
|
"\t\tORDER BY\n" +
|
|
|
"\t\t\tSUM(ui.integrate) DESC\n" +
|
|
|
"\t\t\n" +
|
|
|
"\t) t,\n" +
|
|
|
"\t(SELECT @i\\:= "+(page - 1) * size+") AS itable";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql, page, size);
|
|
|
String sqlCount ="SELECT\n" +
|
|
|
"\tCOUNT(1) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\t(SELECT\n" +
|
|
|
"\tdh.dept_code AS deptCode,\n" +
|
|
|
"\tdh.dept_name AS deptName,\n" +
|
|
|
"\tSUM(ui.integrate) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_integrate ui\n" +
|
|
|
"LEFT JOIN base_doctor_hospital dh ON ui.user = dh.doctor_code\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tui. status = 1\n" +
|
|
|
"AND ui.type = 1\n" +
|
|
|
condition+
|
|
|
"GROUP BY\n" +
|
|
|
"\tdh.dept_code\n" +
|
|
|
"ORDER BY\n" +
|
|
|
"\tSUM(ui.integrate) DESC) t ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
return MixEnvelop.getSuccessListWithPage("success", list, page, size, count);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据用户编码获取积分账户信息及明细
|
|
|
*
|
|
|
* @param user
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject selectIntegrateInfoByUser(String user,String startDate,String endDate,Integer page,Integer size){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String userIntegrateSql = "SELECT IFNULL(SUM(integrate),0) as total FROM base_hospital_user_integrate where user='"+user+"' ";
|
|
|
Map<String,Object> map = jdbcTemplate.queryForMap(userIntegrateSql);
|
|
|
if (map!=null){
|
|
|
object.put("total",map.get("total"));//总积分
|
|
|
}
|
|
|
String dateCondition="";
|
|
|
if (StringUtils.isNoneBlank(startDate)){
|
|
|
dateCondition +=" and create_time >='"+startDate+"' ";
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(endDate)){
|
|
|
dateCondition +=" and create_time <='"+endDate+"' ";
|
|
|
}
|
|
|
String addIntegrateSql =" and integrate_type=1 ";
|
|
|
Map<String,Object> addMap = jdbcTemplate.queryForMap(userIntegrateSql+addIntegrateSql+dateCondition);
|
|
|
if (addMap!=null){
|
|
|
object.put("addTotal",addMap.get("total"));//以获取积分
|
|
|
}
|
|
|
String exchageIngrateSql = " and integrate_type=2 ";
|
|
|
Map<String,Object> exchageMap = jdbcTemplate.queryForMap(userIntegrateSql+exchageIngrateSql+dateCondition);
|
|
|
if (addMap!=null){
|
|
|
object.put("exchageTotal",exchageMap.get("total"));//以获取积分
|
|
|
}
|
|
|
String userIntegrateListSql = "SELECT\n" +
|
|
|
"\tuser,\n" +
|
|
|
"\tname,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\tcreate_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS createTime,\n" +
|
|
|
"\tintegrate,\n" +
|
|
|
"\tintegrate_type AS integrateType,\n" +
|
|
|
"\trelation_code AS relationCode,\n" +
|
|
|
"\trelation_name AS relationName\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_integrate\n" +
|
|
|
"where user='"+user+"' "+dateCondition+" order by create_time desc ";
|
|
|
List<Map<String,Object>> list = hibenateUtils.createSQLQuery(userIntegrateListSql,page,size);
|
|
|
String sqlCount ="SELECT COUNT(1) as total \n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_integrate\n" +
|
|
|
"where user='"+user+"' "+dateCondition+" order by create_time desc ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount);
|
|
|
Long count = 0L;
|
|
|
if (rstotal != null && rstotal.size() > 0) {
|
|
|
count = Long.parseLong(rstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("list",list);
|
|
|
data.put("page",page);
|
|
|
data.put("size",size);
|
|
|
data.put("total",count);
|
|
|
object.put("list",data);//积分明细
|
|
|
return object;
|
|
|
}
|
|
|
}
|