Browse Source

全部统计

master
zhizhi wu 4 years ago
parent
commit
672cdc89eb
  1. 37
      src/main/java/com/ccsens/carbasics/api/StatisticalController.java
  2. 42
      src/main/java/com/ccsens/carbasics/bean/dto/StatisticalDto.java
  3. 2
      src/main/java/com/ccsens/carbasics/bean/vo/StatisticalVo.java
  4. 22
      src/main/java/com/ccsens/carbasics/persist/dao/FirstAidRecordDao.java
  5. 16
      src/main/java/com/ccsens/carbasics/service/IStatisticalService.java
  6. 57
      src/main/java/com/ccsens/carbasics/service/StatisticalService.java
  7. 143
      src/main/resources/mapper_dao/FirstAidRecordDao.xml

37
src/main/java/com/ccsens/carbasics/api/StatisticalController.java

@ -71,15 +71,6 @@ public class StatisticalController {
log.info("统计列表结果:{}", common);
return JsonResponse.newInstance().ok(common);
}
@MustLogin
@ApiOperation(value = "分项-溶栓率", notes = "分项-溶栓率")
@RequestMapping(value = "/thrombosisRate", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<StatisticalVo.Common> thrombosisRate(@ApiParam @Validated @RequestBody QueryDto<StatisticalDto.ThrombosisRate> params) {
log.info("统计列表:{}", params);
StatisticalVo.Common common = statisticalService.thrombosisRate(params.getParam(), params.getUserId());
log.info("统计列表结果:{}", common);
return JsonResponse.newInstance().ok(common);
}
@MustLogin
@ApiOperation(value = "手术方式/来院统计", notes = "zy")
@ -110,5 +101,33 @@ public class StatisticalController {
return JsonResponse.newInstance().ok(common);
}
@MustLogin
@ApiOperation(value = "分项-溶栓率", notes = "分项-溶栓率(总溶栓率除以100保留2位小数显示)")
@RequestMapping(value = "/thrombosisRate", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<StatisticalVo.Common> thrombosisRate(@ApiParam @Validated @RequestBody QueryDto<StatisticalDto.ThrombosisRate> params) {
log.info("分项-溶栓率:{}", params);
StatisticalVo.Common common = statisticalService.thrombosisRate(params.getParam(), params.getUserId());
log.info("分项-溶栓率结果:{}", common);
return JsonResponse.newInstance().ok(common);
}
@MustLogin
@ApiOperation(value = "分项-中位数", notes = "分项-中位数")
@RequestMapping(value = "/timeMedian", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<StatisticalVo.Common> timeMedian(@ApiParam @Validated @RequestBody QueryDto<StatisticalDto.Median> params) {
log.info("分项-中位数:{}", params);
StatisticalVo.Common common = statisticalService.timeMedian(params.getParam(), params.getUserId());
log.info("分项-中位数结果:{}", common);
return JsonResponse.newInstance().ok(common);
}
@MustLogin
@ApiOperation(value = "各地-中位数", notes = "各地-中位数")
@RequestMapping(value = "/areaMedian", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<StatisticalVo.CommonList> areaMedian(@ApiParam @Validated @RequestBody QueryDto<StatisticalDto.AreaMedian> params) {
log.info("各地-中位数:{}", params);
StatisticalVo.CommonList common = statisticalService.areaMedian(params.getParam(), params.getUserId());
log.info("各地-中位数结果:{}", common);
return JsonResponse.newInstance().ok(common);
}
}

42
src/main/java/com/ccsens/carbasics/bean/dto/StatisticalDto.java

@ -45,6 +45,29 @@ public class StatisticalDto {
private Byte countType;
}
@Data
@ApiModel("分项-中位数-请求")
public static class Median {
@NotNull(message = "项目id不能为空")
@ApiModelProperty("项目ID")
private Long projectId;
@NotNull
@ApiModelProperty("开始时间")
private Long startTime;
@NotNull
@ApiModelProperty("开始时间")
private Long endTime;
@NotNull
@ApiModelProperty("统计类型(0-每小时 1-每天 2-每月)")
private Byte countType;
@NotBlank
@ApiModelProperty("减数code,例:ONT中位数 开始静脉溶栓时间-发病时间√")
private String subtractionCode;
@NotBlank
@ApiModelProperty("被减数code,例:ONT中位数 开始静脉溶栓时间(√ 统计时间依据)-发病时间")
private String minuendCode;
}
@ApiModel("分项-时间窗患者-请求")
@Data
public static class TimeAndType {
@ -97,4 +120,23 @@ public class StatisticalDto {
private String accordCode;
}
@Data
@ApiModel("地市-中位数-请求")
public static class AreaMedian {
@NotNull(message = "请选择对应的省份信息")
@ApiModelProperty("省质控code")
private String code;
@NotNull
@ApiModelProperty("开始时间")
private Long startTime;
@NotNull
@ApiModelProperty("开始时间")
private Long endTime;
@NotBlank
@ApiModelProperty("减数code,例:ONT中位数 开始静脉溶栓时间-发病时间√")
private String subtractionCode;
@NotBlank
@ApiModelProperty("被减数code,例:ONT中位数 开始静脉溶栓时间(√ 统计时间依据)-发病时间")
private String minuendCode;
}
}

2
src/main/java/com/ccsens/carbasics/bean/vo/StatisticalVo.java

@ -18,7 +18,7 @@ public class StatisticalVo {
@Data
public static class Common{
@ApiModelProperty("总数")
private Long total;
private String total;
@ApiModelProperty("统计列表")
private List<Item> list;
}

22
src/main/java/com/ccsens/carbasics/persist/dao/FirstAidRecordDao.java

@ -5,6 +5,7 @@ import com.ccsens.carbasics.bean.vo.StatisticalVo;
import com.ccsens.carbasics.persist.mapper.FirstAidRecordMapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
/**
@ -61,7 +62,7 @@ public interface FirstAidRecordDao extends FirstAidRecordMapper {
* @param endTime 结束时间
* @return 统计指定的中位数
*/
Long countMedian(@Param("minuendCode") String minuendCode, @Param("subtractionCode") String subtractionCode, @Param("hospitalIds") List<Long> hospitalIds, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
BigDecimal countMedian(@Param("minuendCode") String minuendCode, @Param("subtractionCode") String subtractionCode, @Param("hospitalIds") List<Long> hospitalIds, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
/**
* 统计累计收录病例数
@ -98,4 +99,23 @@ public interface FirstAidRecordDao extends FirstAidRecordMapper {
* @return 分项-统计时间窗患者数
*/
List<StatisticalVo.Item> countTimeWindowPatientFx(@Param("hospitalIds") List<Long> hospitalIds,@Param("startTime") Long startTime,@Param("endTime") Long endTime,@Param("type") String type);
/**
* 分项溶栓率
* @param minuendCode
* @param subtractionCode
* @param hospitalIds
* @param startTime
* @param endTime
* @param countType
* @return
*/
List<StatisticalVo.Item> countTimeMedian(@Param("minuendCode") String minuendCode, @Param("subtractionCode") String subtractionCode, @Param("hospitalIds")List<Long> hospitalIds, @Param("startTime")Long startTime, @Param("endTime") Long endTime, @Param("type")Byte countType);
/**
* 地区中位数
* @param param 请求参数
* @return 地区中位数
*/
List<StatisticalVo.Item> countAreaMedian(@Param("param") StatisticalDto.AreaMedian param);
}

16
src/main/java/com/ccsens/carbasics/service/IStatisticalService.java

@ -63,4 +63,20 @@ public interface IStatisticalService {
* @return 统计结果
*/
StatisticalVo.Common timeWindowsPatient(StatisticalDto.TimeAndType param, Long userId);
/**
* 分项-中位数
* @param param 请求参数
* @param userId 用户ID
* @return 统计结果
*/
StatisticalVo.Common timeMedian(StatisticalDto.Median param, Long userId);
/**
* 各地-中位数
* @param param 请求参数
* @param userId 用户ID
* @return 统计结果
*/
StatisticalVo.CommonList areaMedian(StatisticalDto.AreaMedian param, Long userId);
}

57
src/main/java/com/ccsens/carbasics/service/StatisticalService.java

@ -55,7 +55,7 @@ public class StatisticalService implements IStatisticalService {
Constant.Statistical.Ich.ANSWER, Constant.Statistical.Ich.TIME_CODE,
hospitalIds, param.getStartTime(), param.getEndTime());
StatisticalVo.Common common = new StatisticalVo.Common();
common.setTotal(timeWindowPatient);
common.setTotal(timeWindowPatient + "");
List<StatisticalVo.Item> items = new ArrayList<>();
items.add(new StatisticalVo.Item(Constant.Statistical.Thrombosis.NAME, ""+thrombosis));
items.add(new StatisticalVo.Item(Constant.Statistical.Mechanical.NAME, ""+mechanical));
@ -64,8 +64,6 @@ public class StatisticalService implements IStatisticalService {
return common;
}
@Override
public StatisticalVo.Common dnt(StatisticalDto.Time param, Long userId) {
List<Long> hospitalIds = getHospitalIds(param.getProjectId());
@ -74,7 +72,7 @@ public class StatisticalService implements IStatisticalService {
dnt = new StatisticalVo.Dnt();
}
StatisticalVo.Common common = new StatisticalVo.Common();
common.setTotal(dnt.sum());
common.setTotal(dnt.sum() + "");
List<StatisticalVo.Item> items = new ArrayList<>();
items.add(new StatisticalVo.Item(Constant.Statistical.Dnt.ONE, ""+dnt.getOne()));
items.add(new StatisticalVo.Item(Constant.Statistical.Dnt.TWO, ""+dnt.getTwo()));
@ -92,7 +90,7 @@ public class StatisticalService implements IStatisticalService {
dpt = new StatisticalVo.Dpt();
}
StatisticalVo.Common common = new StatisticalVo.Common();
common.setTotal(dpt.sum());
common.setTotal(dpt.sum() + "");
List<StatisticalVo.Item> items = new ArrayList<>();
items.add(new StatisticalVo.Item(Constant.Statistical.Dpt.ONE, ""+dpt.getOne()));
items.add(new StatisticalVo.Item(Constant.Statistical.Dpt.TWO, ""+dpt.getTwo()));
@ -131,11 +129,11 @@ public class StatisticalService implements IStatisticalService {
hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.Ich.NAME, ""+ich));
// DNT中位数
Long dntMedian = firstAidRecordDao.countMedian(Constant.Statistical.Dnt.MINUEND_CODE, Constant.Statistical.Dnt.SUBTRACTION_CODE, hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.DNT_MEDIAN_NAME, "" + dntMedian));
BigDecimal dntMedian = firstAidRecordDao.countMedian(Constant.Statistical.Dnt.MINUEND_CODE, Constant.Statistical.Dnt.SUBTRACTION_CODE, hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.DNT_MEDIAN_NAME, dntMedian.toString()));
// DPT中位数
Long dptMedian = firstAidRecordDao.countMedian(Constant.Statistical.Dpt.MINUEND_CODE, Constant.Statistical.Dpt.SUBTRACTION_CODE, hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.DPT_MEDIAN_NAME, "" + dptMedian));
BigDecimal dptMedian = firstAidRecordDao.countMedian(Constant.Statistical.Dpt.MINUEND_CODE, Constant.Statistical.Dpt.SUBTRACTION_CODE, hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.DPT_MEDIAN_NAME, dptMedian.toString()));
// 累计收录病例数
Long total = firstAidRecordDao.countPatient(hospitalIds, param.getStartTime(), param.getEndTime());
items.add(new StatisticalVo.Item(Constant.Statistical.PATIENT_TOTAL_NAME, "" + total));
@ -150,7 +148,16 @@ public class StatisticalService implements IStatisticalService {
List<Long> hospitalIds = getHospitalIds(param.getProjectId());
List<StatisticalVo.Item> items = firstAidRecordDao.countThrombosisRateDate(param.getCountType(), hospitalIds, param.getStartTime(), param.getEndTime());
StatisticalVo.Common common = new StatisticalVo.Common();
common.setTotal(getTotal(items));
// 时间窗患者
Long timeWindowPatient = firstAidRecordDao.countTimeWindowPatient(hospitalIds, param.getStartTime(), param.getEndTime());
//统计溶栓例数(开始静脉溶栓时间)
Long thrombosis = firstAidRecordDao.countSpecifyAnswer(Constant.Statistical.Thrombosis.QUESTION_CODE,
Constant.Statistical.Thrombosis.ANSWER, Constant.Statistical.Thrombosis.TIME_CODE,
hospitalIds, param.getStartTime(), param.getEndTime());
// 溶栓率 四舍五入,保留两位 52.33%
String rate = timeWindowPatient == null || timeWindowPatient == 0 ? "" :
new BigDecimal(thrombosis*100.00).divide(new BigDecimal(timeWindowPatient), 2, BigDecimal.ROUND_HALF_UP) + "%";
common.setTotal(rate);
List<StatisticalVo.Item> newItems = fillItems(items, param.getStartTime(), param.getEndTime(), param.getCountType());
common.setList(newItems);
return common;
@ -179,9 +186,9 @@ public class StatisticalService implements IStatisticalService {
while (calendar.getTimeInMillis() <= endTime) {
String format = sdf.format(calendar.getTime());
if (map.containsKey(format)) {
newItems.add(map.get(format));
newItems.add(new StatisticalVo.Item(calendar.getTimeInMillis() + "", map.get(format).getValue()));
} else {
newItems.add(new StatisticalVo.Item(format, null));
newItems.add(new StatisticalVo.Item(calendar.getTimeInMillis() + "", null));
}
calendar.add(unit, 1);
}
@ -209,6 +216,26 @@ public class StatisticalService implements IStatisticalService {
return common;
}
@Override
public StatisticalVo.Common timeMedian(StatisticalDto.Median param, Long userId) {
List<Long> hospitalIds = getHospitalIds(param.getProjectId());
List<StatisticalVo.Item> items = firstAidRecordDao.countTimeMedian(param.getMinuendCode(), param.getSubtractionCode(), hospitalIds, param.getStartTime(), param.getEndTime(), param.getCountType());
StatisticalVo.Common common = new StatisticalVo.Common();
BigDecimal median = firstAidRecordDao.countMedian(Constant.Statistical.Dnt.MINUEND_CODE, Constant.Statistical.Dnt.SUBTRACTION_CODE, hospitalIds, param.getStartTime(), param.getEndTime());
common.setTotal(median.toString());
List<StatisticalVo.Item> newItems = fillItems(items, param.getStartTime(), param.getEndTime(), param.getCountType());
common.setList(newItems);
return common;
}
@Override
public StatisticalVo.CommonList areaMedian(StatisticalDto.AreaMedian param, Long userId) {
List<StatisticalVo.Item> items = firstAidRecordDao.countAreaMedian(param);
StatisticalVo.CommonList common = new StatisticalVo.CommonList();
common.setList(items);
return common;
}
/**
* 查找项目对应的医院ID或对应下级医院ID
* @param projectId 项目ID
@ -253,18 +280,18 @@ public class StatisticalService implements IStatisticalService {
}
//封装返回
StatisticalVo.Common common = new StatisticalVo.Common();
common.setTotal(total);
common.setTotal(total + "");
common.setList(items);
return common;
}
private long getTotal(List<StatisticalVo.Item> items) {
private String getTotal(List<StatisticalVo.Item> items) {
long total = 0L;
if(CollectionUtil.isNotEmpty(items)){
for (StatisticalVo.Item item : items){
total += Long.parseLong(item.getValue());
}
}
return total;
return total + "";
}
}

143
src/main/resources/mapper_dao/FirstAidRecordDao.xml

@ -56,7 +56,7 @@
</foreach>
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
</select>
<select id="countMedian" resultType="java.lang.Long">
<select id="countMedian" resultType="java.math.BigDecimal">
SELECT AVG(dd.val) as num
FROM (
SELECT d.val, @rownum:=@rownum+1 as `row_number`, @total_rows:=@rownum
@ -86,16 +86,37 @@
and unix_timestamp(create_at)*1000 &gt;= #{startTime} and unix_timestamp(create_at)*1000 &lt;= #{endTime} and rec_status = 0
</select>
<select id="countThrombosisRateDate" resultType="com.ccsens.carbasics.bean.vo.StatisticalVo$Item">
select t1.date as name, round(t2.part * 100 / t1.total, 2) as value from
(select FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date, count(*) as total from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
select t1.date as name, concat(round(t2.part * 100 / t1.total, 2), '%') as value from
(select
<choose>
<when test="type == 0">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d %H') as date,</when>
<when test="type == 1">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date,</when>
<when test="type == 2">FROM_UNIXTIME(r2.answer/1000,'%Y-%m') as date,</when>
<otherwise>FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date,</otherwise>
</choose>
count(*) as total from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and r1.question_code = 'JBXX-FBSJ'
and a.id = r2.first_aid_id and r1.question_code = 'JBXX-DYSJ'
and r2.answer + 0 &gt;= 0 and r2.answer + 0 &lt;= 0
and a.hospital_id in (0)
and r2.answer - r1.answer &lt; 6 * 60 * 60 * 1000
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
group by FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d')) t1,
(select FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date, count(a.id) as part from t_qcp_first_aid a, t_qcp_first_aid_record r1, t_qcp_first_aid_record r2
group by
<choose>
<when test="type == 0">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d %H')</when>
<when test="type == 1">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') </when>
<when test="type == 2">FROM_UNIXTIME(r2.answer/1000,'%Y-%m') </when>
<otherwise>FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') </otherwise>
</choose>
) t1,
(select
<choose>
<when test="type == 0">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d %H') as date,</when>
<when test="type == 1">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date,</when>
<when test="type == 2">FROM_UNIXTIME(r2.answer/1000,'%Y-%m') as date,</when>
<otherwise>FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') as date,</otherwise>
</choose>
count(a.id) as part from t_qcp_first_aid a, t_qcp_first_aid_record r1, t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and a.id = r2.first_aid_id
and r1.question_code = 'ZLFA-JMRS' and r1.answer = '是'
and r2.question_code = 'JMRSSJ' and r2.answer + 0 &gt;= #{startTime} and r2.answer + 0 &lt;= #{endTime}
@ -103,7 +124,14 @@
#{id}
</foreach>
and a.rec_status = 0 and r1.rec_status = 0
group by FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d'))t2
group by
<choose>
<when test="type == 0">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d %H')</when>
<when test="type == 1">FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') </when>
<when test="type == 2">FROM_UNIXTIME(r2.answer/1000,'%Y-%m') </when>
<otherwise>FROM_UNIXTIME(r2.answer/1000,'%Y-%m-%d') </otherwise>
</choose>
)t2
where t1.date = t2.date
</select>
<select id="toCourtStatistics" resultType="com.ccsens.carbasics.bean.vo.StatisticalVo$Item">
@ -161,4 +189,107 @@
GROUP BY
FROM_UNIXTIME(r2.answer / 1000, #{type})
</select>
<select id="countTimeMedian" resultType="com.ccsens.carbasics.bean.vo.StatisticalVo$Item">
select t1.date as name, avg(t1.val) as value from
(select date, val, @team,
case @team when date then @rk := @rk+1 else @rk := 1 end rk,
@team := date
from
(select
<choose>
<when test="type == 0">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d %H') as date,</when>
<when test="type == 1">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d') as date,</when>
<when test="type == 2">FROM_UNIXTIME(r1.answer/1000,'%Y-%m') as date,</when>
<otherwise>FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d') as date,</otherwise>
</choose>
ROUND((r1.answer - r2.answer)/60000, 2) as val
from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and r1.question_code = #{minuendCode}
and a.id = r2.first_aid_id and r2.question_code = #{subtractionCode}
and r1.answer + 0 &gt;= #{startTime} and r1.answer + 0 &lt;= #{endTime}
<foreach collection="hospitalIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
) d,
(select @rk := 0, @team := '') t
order by date, val) t1
left join (
select
<choose>
<when test="type == 0">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d %H') as date,</when>
<when test="type == 1">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d') as date,</when>
<when test="type == 2">FROM_UNIXTIME(r1.answer/1000,'%Y-%m') as date,</when>
<otherwise>FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d') as date,</otherwise>
</choose>
count(*) as cnt
from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and r1.question_code = #{minuendCode}
and a.id = r2.first_aid_id and r2.question_code = #{subtractionCode}
and r1.answer + 0 &gt;= #{startTime} and r1.answer + 0 &lt;= #{endTime}
<foreach collection="hospitalIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
group by
<choose>
<when test="type == 0">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d %H') </when>
<when test="type == 1">FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d')</when>
<when test="type == 2">FROM_UNIXTIME(r1.answer/1000,'%Y-%m')</when>
<otherwise>FROM_UNIXTIME(r1.answer/1000,'%Y-%m-%d')</otherwise>
</choose>
) t2 on t1.date = t2.date
where t1.rk IN (t2.cnt + 0.5, t2.cnt, t2.cnt + 1)
group by t1.date
</select>
<select id="countAreaMedian" resultType="com.ccsens.carbasics.bean.vo.StatisticalVo$Item">
select b.id,b.shortName as name, avg(b.val) as value from
(select id,shortName,val,@team,
case @team when id then @rk := @rk + 1 else @rk := 1 end rk,
@team := id
from (
select city.id, city.short_name as shortName, aid.val from
(select city.id, city.short_name from t_organization o, t_organization_parent p, t_organization city
where o.id = p.parent_id and p.organization_id = city.id
and o.code = #{param.code} and o.rec_status = 0 and p.rec_status = 0 and city.rec_status = 0) city
left join
(select o.id, o.name, p.parent_id from t_organization o, t_organization_parent p where o.id = p.organization_id and o.organization_type = 3 and o.rec_status = 0 and p.rec_status = 0) hospital on city.id = hospital.parent_id
left join
(
select
a.hospital_id,
ROUND((r1.answer - r2.answer)/60000, 2) as val
from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and r1.question_code = #{param.minuendCode}
and a.id = r2.first_aid_id and r2.question_code = #{param.subtractionCode}
and r1.answer + 0 &gt;= #{startTime} and r1.answer + 0 &lt;= #{endTime}
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
) aid on hospital.id = aid.hospital_id
) t1, (select @rk := 0, @team := '') a order by id,val) b
left join
(
select city.id, city.short_name as shortName, count(aid.id) as cnt from
(select city.id, city.short_name from t_organization o, t_organization_parent p, t_organization city
where o.id = p.parent_id and p.organization_id = city.id
and o.code = #{param.code} and o.rec_status = 0 and p.rec_status = 0 and city.rec_status = 0) city
left join
(select o.id, o.name, p.parent_id from t_organization o, t_organization_parent p where o.id = p.organization_id and o.organization_type = 3 and o.rec_status = 0 and p.rec_status = 0) hospital on city.id = hospital.parent_id
left join
(
select
a.id,
a.hospital_id,
ROUND((r1.answer - r2.answer)/60000, 2) as val
from t_qcp_first_aid a, t_qcp_first_aid_record r1 , t_qcp_first_aid_record r2
where a.id = r1.first_aid_id and r1.question_code = #{param.minuendCode}
and a.id = r2.first_aid_id and r2.question_code = #{param.subtractionCode}
and r1.answer + 0 &gt;= #{startTime} and r1.answer + 0 &lt;= #{endTime}
and a.rec_status = 0 and r1.rec_status = 0 and r2.rec_status = 0
) aid on hospital.id = aid.hospital_id
group by city.id
)c
on b.id = c.id
where b.rk IN (c.cnt + 0.5, c.cnt, c.cnt + 1)
group by id
</select>
</mapper>

Loading…
Cancel
Save