|
@ -1,16 +1,23 @@
|
|
|
package com.yihu.jw.hospital.integrate.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalIntegrateDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalMedalDO;
|
|
|
import com.yihu.jw.entity.hospital.integrate.BaseHospitalUserIntegrateDO;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalIntegrateDao;
|
|
|
import com.yihu.jw.hospital.integrate.dao.BaseHospitalUserIntegrateDao;
|
|
|
import com.yihu.jw.mysql.query.BaseJpaService;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
|
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.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@ -24,6 +31,8 @@ public class BaseHospitalIntegrateService extends BaseJpaService<BaseHospitalInt
|
|
|
private BaseHospitalIntegrateDao hospitalIntegrateDao;
|
|
|
@Autowired
|
|
|
private HibenateUtils hibenateUtils;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
|
|
|
/**
|
|
|
* 新增或者修改积分配置
|
|
@ -122,53 +131,127 @@ public class BaseHospitalIntegrateService extends BaseJpaService<BaseHospitalInt
|
|
|
}
|
|
|
|
|
|
|
|
|
/* public JSONObject selectIntegrateByUser(String user,Integer page,Integer size){
|
|
|
public JSONObject selectIntegrateByUser(String user,Integer page,Integer size){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String orderBy = " order by create_time desc ";
|
|
|
String condition = " ";
|
|
|
String sql = "SELECT\n" +
|
|
|
"\tid,\n" +
|
|
|
"\ttype,\n" +
|
|
|
"\ttype_name AS typeName,\n" +
|
|
|
"\tname,\n" +
|
|
|
"\titem,\n" +
|
|
|
"\titem_name AS itemName,\n" +
|
|
|
"\tbelong,\n" +
|
|
|
"\tstatus,\n" +
|
|
|
"\tflag,\n" +
|
|
|
"\tconditions,\n" +
|
|
|
"\tcontinuity_flag AS continuityFlag,\n" +
|
|
|
"\tdays,\n" +
|
|
|
"\tuser,\n" +
|
|
|
"\tintegrate,\n" +
|
|
|
"\tdaily_limit AS dailyLimit,\n" +
|
|
|
"\tvalidity,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\tstart_validity,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS startValidity,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\tend_validity,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS endValidity,\n" +
|
|
|
"\tdate_format(\n" +
|
|
|
"\t\tcreate_time,\n" +
|
|
|
"\t\t'%Y-%m-%d %H:%i:%S'\n" +
|
|
|
"\t) AS createTime,\n" +
|
|
|
"\tdescription\n" +
|
|
|
"\tintegrate_type AS integrateType,\n" +
|
|
|
"\trelation_type AS relationType,\n" +
|
|
|
"\trelation_code AS relationCode,\n" +
|
|
|
"\trelation_item as relationItem,\n" +
|
|
|
"\tstatus,\n" +
|
|
|
"\tdate_format(create_time,'%Y-%m-%d %H:%i:%S') as createTime\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_integrate\n" +
|
|
|
"WHERE\n" +
|
|
|
"\t1 = 1 ";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql+condition+orderBy, page, size);
|
|
|
String sqlCount ="select COUNT(1) as total from base_hospital_integrate where 1=1 ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount+condition+orderBy);
|
|
|
"\tbase_hospital_user_integrate where 1=1 and user ='"+user+"' ";
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql+orderBy, page, size);
|
|
|
String sqlCount ="select COUNT(1) as total from base_hospital_user_integrate where 1=1 and user ='"+user+"' ";
|
|
|
List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(sqlCount+orderBy);
|
|
|
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("data",data);//积分明细
|
|
|
//剩余积分
|
|
|
String integrateSql ="SELECT\n" +
|
|
|
"\tIFNULL(SUM(integrate),0) AS total\n" +
|
|
|
"FROM\n" +
|
|
|
"\tbase_hospital_user_integrate\n" +
|
|
|
"WHERE\n" +
|
|
|
"\t1 = 1 and user='"+user+"' ";
|
|
|
List<Map<String, Object>> integrateRstotal = hibenateUtils.createSQLQuery(integrateSql);
|
|
|
Double integrateTotal = 0.0;
|
|
|
if (integrateRstotal != null && integrateRstotal.size() > 0) {
|
|
|
integrateTotal = Double.parseDouble(integrateRstotal.get(0).get("total").toString());
|
|
|
}
|
|
|
object.put("integrateTotal",integrateTotal);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
/* 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;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
public insertIntegrate(String user){
|
|
|
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 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;
|
|
|
}
|
|
|
}
|