|
@ -62,16 +62,36 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
* @return
|
|
|
*/
|
|
|
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
|
|
|
public MixEnvelop<Boolean, Boolean> insert(ActivityDO activityDO,String value1,String value2,String value3){
|
|
|
public MixEnvelop<Boolean, Boolean> insert(ActivityDO activityDO,String value1,String value2,String value3,String registrationNumber){
|
|
|
if (value2 != null && value2 !=""){
|
|
|
JSONObject object = JSONObject.parseObject(value2);
|
|
|
activityDO.setActivityOfflineTime(object.getDate("activityOfflineTime"));
|
|
|
activityDO.setRegistrationTime(object.getDate("registrationTime"));
|
|
|
activityDO.setDeadLine(object.getDate("deadLine"));
|
|
|
String activityOfflineTime = object.getString("activityOfflineTime");
|
|
|
String[] str = activityOfflineTime.split(",");
|
|
|
if (str.length == 2){
|
|
|
activityDO.setActivityOfflineTime(DateUtil.strToDate(str[1]));
|
|
|
}else {
|
|
|
activityDO.setActivityOfflineTime(DateUtil.strToDate(str[0]));
|
|
|
}
|
|
|
String registrationTime = object.getString("registrationTime");
|
|
|
String[] str1 = registrationTime.split(",");
|
|
|
if(str1.length==2){
|
|
|
activityDO.setRegistrationTime(DateUtil.strToDate(str1[1]));
|
|
|
}else {
|
|
|
activityDO.setRegistrationTime(DateUtil.strToDate(str1[0]));
|
|
|
}
|
|
|
String deadLine = object.getString("deadLine");
|
|
|
String[] str2 = deadLine.split(",");
|
|
|
if (str2.length==2){
|
|
|
activityDO.setDeadLine(DateUtil.strToDate(str2[1]));
|
|
|
}else {
|
|
|
activityDO.setDeadLine(DateUtil.strToDate(str2[0]));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
activityDO.setCreateTime(new Date());
|
|
|
activityDO.setUpdateTime(new Date());
|
|
|
activityDO.setDelFlag(1);
|
|
|
activityDO.setRegistrationNumber(registrationNumber);
|
|
|
activityDO= activityDao.save(activityDO);
|
|
|
if (value3 !=null && value3 !=""){
|
|
|
JSONObject object = JSONObject.parseObject(value3);
|
|
@ -138,7 +158,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
* @throws ParseException
|
|
|
*/
|
|
|
public MixEnvelop<ActivityDO, ActivityDO> findByCondition(ActivityDO activityDO, Integer page, Integer size) throws ParseException {
|
|
|
String sql = new ISqlUtils().getSql(activityDO,page,size,"*");
|
|
|
String sql = new ISqlUtils().getSql(activityDO,page,size,"sort");
|
|
|
List<ActivityDO> activityDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
|
|
|
for (ActivityDO activityDO1:activityDOS){
|
|
|
String taskSql = "SELECT" +
|
|
@ -190,17 +210,36 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
* @return
|
|
|
*/
|
|
|
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
|
|
|
public MixEnvelop<Boolean, Boolean> update(ActivityDO activityDO, String value1, String value2, String value3) throws Exception {
|
|
|
public MixEnvelop<Boolean, Boolean> update(ActivityDO activityDO, String value1, String value2, String value3,String registrationNumber) throws Exception {
|
|
|
if (StringUtils.isBlank(activityDO.getId())) {
|
|
|
throw new Exception("活动id不能为空!");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(value2)){
|
|
|
JSONObject object = JSONObject.parseObject(value2);
|
|
|
activityDO.setActivityOfflineTime(object.getDate("activityOfflineTime"));
|
|
|
activityDO.setRegistrationTime(object.getDate("registrationTime"));
|
|
|
activityDO.setDeadLine(object.getDate("deadLine"));
|
|
|
String activityOfflineTime = object.getString("activityOfflineTime");
|
|
|
String[] str = activityOfflineTime.split(",");
|
|
|
if (str.length == 2){
|
|
|
activityDO.setActivityOfflineTime(DateUtil.strToDate(str[1]));
|
|
|
}else {
|
|
|
activityDO.setActivityOfflineTime(DateUtil.strToDate(str[0]));
|
|
|
}
|
|
|
String registrationTime = object.getString("registrationTime");
|
|
|
String[] str1 = registrationTime.split(",");
|
|
|
if(str1.length==2){
|
|
|
activityDO.setRegistrationTime(DateUtil.strToDate(str1[1]));
|
|
|
}else {
|
|
|
activityDO.setRegistrationTime(DateUtil.strToDate(str1[0]));
|
|
|
}
|
|
|
String deadLine = object.getString("deadLine");
|
|
|
String[] str2 = deadLine.split(",");
|
|
|
if (str2.length==2){
|
|
|
activityDO.setDeadLine(DateUtil.strToDate(str2[1]));
|
|
|
}else {
|
|
|
activityDO.setDeadLine(DateUtil.strToDate(str2[0]));
|
|
|
}
|
|
|
}
|
|
|
activityDO.setRegistrationNumber(registrationNumber);
|
|
|
activityDO.setUpdateTime(new Date());
|
|
|
activityDO.setDelFlag(1);
|
|
|
//删除活动任务与奖品
|
|
@ -268,7 +307,7 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
"wlyy_health_bank_task_patient_detail" +
|
|
|
" WHERE " +
|
|
|
" patient_idcard = '"+activityDO.getPatientIdcard()+"' "+ condition+")" +
|
|
|
" )" +
|
|
|
" ) AND del_flag =1 " +
|
|
|
" LIMIT "+(page-1)*size +","+size;
|
|
|
List<ActivityDO> activityDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
|
|
|
for (ActivityDO activityDO1:activityDOS){
|
|
@ -432,8 +471,12 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
ActivityRuleDO activityRuleDO= activityRuleDao.selectByActivityId(id);
|
|
|
if("3".equals(type)){
|
|
|
//推荐
|
|
|
activityDO.setRecommended(1);
|
|
|
|
|
|
List<ActivityDO> activityDOS = activityDao.findByIdAndRecommended(1);
|
|
|
if (activityDOS!=null&& activityDOS.size()>=3){
|
|
|
throw new Exception("只允许推荐三个!");
|
|
|
}else {
|
|
|
activityDO.setRecommended(1);
|
|
|
}
|
|
|
}else if("4".equals(type)){
|
|
|
//取消推荐
|
|
|
activityDO.setRecommended(0);
|
|
@ -443,12 +486,12 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
activityDO.setStatus(2);
|
|
|
}else if("0".equals(type)){
|
|
|
//判断该活动是不是竞走,只能存在一条有效竞走
|
|
|
if("竞走".equals(activityDO.getType())){
|
|
|
/*if("竞走".equals(activityDO.getType())){
|
|
|
List<ActivityDO> lst= activityDao.findByIdAndType(activityDO.getType());
|
|
|
if(null!=lst&&lst.size()>0){
|
|
|
throw new Exception("已存在一条上线的竞走活动!");
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
//上线
|
|
|
if(null!=activityRuleDO){
|
|
|
String ruleJson=activityRuleDO.getValue2();
|
|
@ -456,11 +499,35 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
//报名截止时间
|
|
|
Date registrationTime=(null!=obj.get("registrationTime")? sdf2.parse(obj.get("registrationTime").toString()):null);
|
|
|
String registrationTime1 = obj.getString("registrationTime");
|
|
|
String[] str1 = registrationTime1.split(",");
|
|
|
String s = null;
|
|
|
if (str1.length==2) {
|
|
|
s=str1[1];
|
|
|
}else {
|
|
|
s=str1[0];
|
|
|
}
|
|
|
Date registrationTime=(""!=s&&null!=s? sdf2.parse(s):null);
|
|
|
//参与截止时间
|
|
|
Date deadLine=(null!=obj.get("deadLine")? sdf2.parse(obj.get("deadLine").toString()):null);
|
|
|
String deadLine2 = obj.getString("deadLine");
|
|
|
String[] str2 = deadLine2.split(",");
|
|
|
String s1= null;
|
|
|
if (str2.length==2){
|
|
|
s1=str2[1];
|
|
|
}else {
|
|
|
s1=str2[0];
|
|
|
}
|
|
|
Date deadLine=(null!=s1&&""!=s1? sdf2.parse(s1):null);
|
|
|
//活动下线时间
|
|
|
Date activityOfflineTime=(null!=obj.get("activityOfflineTime")? sdf2.parse(obj.get("activityOfflineTime").toString()):null);
|
|
|
String activityOfflineTime1 = obj.getString("activityOfflineTime");
|
|
|
String[] str = activityOfflineTime1.split(",");
|
|
|
String s2= null;
|
|
|
if (str.length==2){
|
|
|
s2=str[1];
|
|
|
}else {
|
|
|
s2=str[0];
|
|
|
}
|
|
|
Date activityOfflineTime=(""!=s2&&null!=s2 ? sdf2.parse(s2):null);
|
|
|
//获取当前时间
|
|
|
Date now = DateUtil.strToDate(sdf2.format(new Date()),"yyyy-MM-dd HH:mm");
|
|
|
if(null!=activityOfflineTime&&activityOfflineTime.compareTo(now)<=0){
|
|
@ -1046,4 +1113,174 @@ public class ActivityService extends BaseJpaService<ActivityDO,ActivityDao> {
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询排序
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ActivityDO> select(){
|
|
|
return activityDao.selectBySort();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 调整活动的顺序
|
|
|
*
|
|
|
* @param array
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop updateSort(JSONArray array){
|
|
|
MixEnvelop envelop = new MixEnvelop();
|
|
|
for (int i=0;i<array.size();i++){
|
|
|
JSONObject jsonObject = array.getJSONObject(i);
|
|
|
ActivityDO activityDO = activityDao.selectById(jsonObject.getString("id"));
|
|
|
activityDO.setSort(jsonObject.getInteger("sort"));
|
|
|
activityDao.save(activityDO);
|
|
|
}
|
|
|
envelop.setObj(true);
|
|
|
return envelop;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询参与的竟步走活动
|
|
|
*
|
|
|
* @param unionId
|
|
|
* @param patient
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop<ActivityDO,ActivityDO> selectByUnionId(String unionId,String patient,String idCard,Integer page,Integer size){
|
|
|
String sql ="select hba.* from wlyy_health_bank_activity hba right join wlyy_health_bank_task_patient_detail htpd on htpd.activity_id=hba.id " +
|
|
|
"AND htpd.union_id='"+unionId+"' AND htpd.patient_id ='"+patient+"' and htpd.patient_idcard ='"+idCard+"' " +
|
|
|
"where hba.del_flag=1 and hba.type='竞走' order by hba.create_time desc LIMIT " + (page-1)*size+","+size;
|
|
|
List<ActivityDO> activityDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
|
|
|
for (ActivityDO activityDO:activityDOList){
|
|
|
ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityDO.getId());
|
|
|
JSONObject object = JSONObject.parseObject(activityRuleDO.getValue2());
|
|
|
String activityOfflineTime = object.getString("activityOfflineTime");
|
|
|
List<String> idList = Arrays.asList(activityOfflineTime.split(","));
|
|
|
if (idList !=null && idList.size()!=0){
|
|
|
String startTime = idList.get(0);
|
|
|
String endTime = idList.get(1);
|
|
|
String nowTime = DateUtil.dateToStrLong(DateUtil.getNowDate());
|
|
|
if((startTime.compareTo(nowTime)==-1&&endTime.compareTo(nowTime)==1)||startTime.compareTo(nowTime)==0||endTime.compareTo(nowTime)==0){
|
|
|
activityDO.setFlag(1);
|
|
|
}else {
|
|
|
activityDO.setFlag(0);
|
|
|
}
|
|
|
}
|
|
|
activityDO.setActivityRuleDO(activityRuleDO);
|
|
|
List<TaskDO> taskDOS = taskDao.selectByActivityId(activityDO.getId());
|
|
|
if (taskDOS!=null&&taskDOS.size()!=0){
|
|
|
activityDO.setTaskDOS(taskDOS);
|
|
|
String sqlCount1 = "select sum(integrate) as total from wlyy_health_bank_credits_detail where transaction_id='"+taskDOS.get(0).getId()+"' and patient_id = '"+patient+"'" +
|
|
|
"and create_time >= '"+DateUtils.getDayBegin()+"' and create_time <='"+DateUtils.getDayEnd()+"'";
|
|
|
List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(sqlCount1);
|
|
|
Long count1 = 0L;
|
|
|
if(rstotal1!=null&&rstotal1.size()>0){
|
|
|
Object count = rstotal1.get(0).get("total");
|
|
|
if (count!=null&&count!=""){
|
|
|
count1 =Long.parseLong(count.toString()) ;
|
|
|
}
|
|
|
}
|
|
|
activityDO.setNowTotal(count1);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
String sqlCount ="select count(1) AS total from wlyy_health_bank_activity hba right join wlyy_health_bank_task_patient_detail htpd on htpd.activity_id=hba.id " +
|
|
|
"where hba.del_flag=1 and hba.type='竞走' order by hba.create_time desc ";
|
|
|
List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlCount);
|
|
|
Long count = 0L;
|
|
|
if(rstotal!=null&&rstotal.size()>0){
|
|
|
count = (Long) rstotal.get(0).get("total");
|
|
|
}
|
|
|
return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success,activityDOList,page,size,count);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取当前居民参加的活动
|
|
|
*
|
|
|
* @param unionId
|
|
|
* @param patient
|
|
|
* @param idCard
|
|
|
* @return
|
|
|
*/
|
|
|
public List<ActivityDO> selectNowByUnionId(String unionId,String patient,String idCard){
|
|
|
String sql ="select hba.* from wlyy_health_bank_activity hba right join wlyy_health_bank_task_patient_detail htpd on htpd.activity_id=hba.id " +
|
|
|
"AND htpd.union_id='"+unionId+"' AND htpd.patient_id ='"+patient+"' and htpd.patient_idcard ='"+idCard+"' " +
|
|
|
"where hba.del_flag=1 and hba.type='竞走' order by hba.create_time desc " ;
|
|
|
List<ActivityDO> activityDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ActivityDO.class));
|
|
|
List<ActivityDO> activityDOS = new ArrayList<>();
|
|
|
for (ActivityDO activityDO:activityDOList){
|
|
|
ActivityRuleDO activityRuleDO = activityRuleDao.selectByActivityId(activityDO.getId());
|
|
|
JSONObject object = JSONObject.parseObject(activityRuleDO.getValue2());
|
|
|
String activityOfflineTime = object.getString("activityOfflineTime");
|
|
|
List<String> idList = Arrays.asList(activityOfflineTime.split(","));
|
|
|
activityDO.setActivityRuleDO(activityRuleDO);
|
|
|
List<TaskDO> taskDOS = taskDao.selectByActivityId(activityDO.getId());
|
|
|
if (taskDOS!=null&&taskDOS.size()!=0){
|
|
|
activityDO.setTaskDOS(taskDOS);
|
|
|
}
|
|
|
if (idList !=null && idList.size()!=0){
|
|
|
String startTime = idList.get(0);
|
|
|
String endTime = idList.get(1);
|
|
|
String nowTime = DateUtil.dateToStrLong(DateUtil.getNowDate());
|
|
|
if((startTime.compareTo(nowTime)==-1&&endTime.compareTo(nowTime)==1)||startTime.compareTo(nowTime)==0||endTime.compareTo(nowTime)==0){
|
|
|
activityDO.setFlag(1);
|
|
|
activityDOS.add(activityDO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return activityDOS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 小程序活动排名
|
|
|
*
|
|
|
* @param patients
|
|
|
* @param taskId
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject selectAppletsRanking(JSONArray patients,String taskId,Integer size,String patient){
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
if (patients!= null&&patients.size()!=0){
|
|
|
buffer.append("and bcd.patient_id IN(");
|
|
|
for (int i=0;i<patients.size();i++){
|
|
|
buffer.append("'"+patients.getString(i)+"',");
|
|
|
}
|
|
|
buffer.deleteCharAt(buffer.length()-1);
|
|
|
buffer.append(") ");
|
|
|
}
|
|
|
String sql = "SELECT @rownum :=@rownum + 1 AS rank, r.sum, r.patient_id AS patient FROM " +
|
|
|
"(SELECT@rowNum := 0) b," +
|
|
|
" (SELECT count(bcd.integrate) AS sum, bcd.patient_id, bcd.create_time FROM wlyy_health_bank_credits_detail bcd " +
|
|
|
"WHERE bcd.transaction_id = '"+taskId+"' " +buffer+
|
|
|
"GROUP BY bcd.patient_id) r ORDER BY r.sum DESC,r.create_time DESC LIMIT 0,"+size;
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
String sql1= "select s.rank,s.sum,s.patient_id from (SELECT @rownum :=@rownum + 1 AS rank, r.sum, r.patient_id FROM " +
|
|
|
"(SELECT@rowNum := 0) b," +
|
|
|
" (SELECT count(bcd.integrate) AS sum, bcd.patient_id, bcd.create_time FROM wlyy_health_bank_credits_detail bcd\n" +
|
|
|
"WHERE bcd.transaction_id = '"+taskId+"' " +buffer+
|
|
|
"GROUP BY bcd.patient_id) r ORDER BY r.sum DESC,r.create_time DESC)s where s.patient_id ='"+patient+"'";
|
|
|
List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql1);
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("list",list);
|
|
|
if (list1!=null&&list1.size()!=0){
|
|
|
object.put("patient",list1.get(0));
|
|
|
}else {
|
|
|
object.put("patient",null);
|
|
|
}
|
|
|
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|