就诊人数统计增加数量为0的日期

master
gongzhenkun 2 years ago
parent ebb2edfb76
commit ebd20ea1da

@ -5,12 +5,12 @@ import com.ruoyi.system.domain.resp.PlatformDayPlanResp;
import com.ruoyi.system.domain.resp.WeekMonthPersonCountResp;
import com.ruoyi.system.domain.resp.WeekMonthTimeResp;
import com.ruoyi.system.mapper.TRecordMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author zhuqing
@ -64,7 +64,32 @@ public class PlatformService {
* @return
*/
public List<WeekMonthPersonCountResp> weekMonthPersonCount(Long hospitalId, Long doctorId,Long weekMonth) {
return tRecordMapper.weekMonthPersonCount(hospitalId, doctorId,weekMonth);
List<WeekMonthPersonCountResp> list = tRecordMapper.weekMonthPersonCount(hospitalId, doctorId,weekMonth);
//定义返回值
List<WeekMonthPersonCountResp> result = new ArrayList<>();
if(CollectionUtils.isNotEmpty(list)){
Map<Date,Integer> map = list.stream().collect(Collectors.toMap(WeekMonthPersonCountResp::getCreateTime,WeekMonthPersonCountResp::getCount,(key1, key2)->key2));
//获取开始日期
Date startDate = list.get(0).getCreateTime();
//获取结束日期
Date endDate = list.get(list.size()-1).getCreateTime();
while(startDate.compareTo(endDate) <= 0){
WeekMonthPersonCountResp resp = new WeekMonthPersonCountResp();
if(map.containsKey(startDate)){
resp.setCreateTime(startDate);
resp.setCount(map.get(startDate));
}else{
resp.setCreateTime(startDate);
resp.setCount(0);
}
result.add(resp);
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.DAY_OF_MONTH,1);
startDate = cal.getTime();
}
}
return result;
}
/**

@ -201,7 +201,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="weekMonthPersonCount" resultType="com.ruoyi.system.domain.resp.WeekMonthPersonCountResp">
select date_format(create_time, '%Y-%m-%d') createTime, count(*) count
select date_format(X.create_time, '%Y-%m-%d') createTime, count(*) count
from
<if test="weekMonth == 1 || weekMonth == null">
(select * from t_record where DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(create_time)) X
@ -212,7 +212,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where X.status = '1'
<if test="doctorId != null "> and X.doctor_id = #{doctorId}</if>
<if test="hospitalId != null "> and X.hospital_id = #{hospitalId}</if>
group by date_format(X.create_time, '%Y-%m-%d');
group by date_format(X.create_time, '%Y-%m-%d')
order by date_format(X.create_time, '%Y-%m-%d' ) asc
</select>
<select id="ageCount" resultType="com.ruoyi.system.domain.TPatient">

Loading…
Cancel
Save