统计当天的数据,统计本周的数据,统计本月的数据,统计近30天的数据
/**
* 查询接种管理统计
*/
@GetMapping("/count")
public IndexCount listCount()
{
IndexCount indexCount = vaccinesIndexService.selectVaccinesInoculationList();
return indexCount;
}
/**
* 折线图统计
*/
@GetMapping("/lineChart")
public List<Map> lineChart()
{
List<Map> maps = vaccinesIndexService.selectDiscountStatistics();
return maps;
}
接口Service 层
public interface VaccinesIndexService extends IService<VaccineOrder> {
/**
* 查询接种管理列表
* @return 接种管理集合
*/
public IndexCount selectVaccinesInoculationList();
/**
* @param
* @return com.vaccine.system.domain.IndexCount
* @描述:折现统计图
* @创建时间:2024/3/22 14:32
*/
public List<Map> selectDiscountStatistics();
}
@Service
public class VaccinesIndexServiceImpl extends ServiceImpl<VaccinesIndexMapper, VaccineOrder> implements VaccinesIndexService {
/**
* 查询接种管理列表
* @return 接种管理
*/
@Override
public IndexCount selectVaccinesInoculationList() {
IndexCount indexCount = new IndexCount();
// 查寻今日
int subscribeTimeCount = baseMapper.selectTodayList1();
int subscribeTimeOverCount = baseMapper.selectTodayList2();
int timeTodayCount = baseMapper.selectTodayList3();
System.out.println("统计今日待接种: " + subscribeTimeCount + ",统计今日已接种" + subscribeTimeOverCount + ",今日新增预约量: " + timeTodayCount);
// 统计本周的数据
int weekOnrCount = baseMapper.selectWeekList1();
int weekTwoCount = baseMapper.selectWeekList2();
System.out.println("本周待接种: " + weekOnrCount + ",本周已接种" + weekTwoCount);
// 统计月数据
int monthOneCount = baseMapper.selectMouthList1();
int monthTwoCount = baseMapper.selectMouthList2();
indexCount.setSubscribeTimeCount(subscribeTimeCount);
indexCount.setSubscribeTimeOverCount(subscribeTimeOverCount);
indexCount.setTimeTodayCount(timeTodayCount);
indexCount.setWeekOnrCount(weekOnrCount);
indexCount.setWeekTwoCount(weekTwoCount);
indexCount.setMonthOneCount(monthOneCount);
indexCount.setMonthTwoCount(monthTwoCount);
return indexCount;
}
/**
* @描述: 折线图统计
* @创建人:Lixueying
* @创建时间:2024/3/25 18:06
* @param
* @return com.vaccine.system.domain.DiscountStatistics
*/
@Override
public List<Map> selectDiscountStatistics() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// 统计近三十天数据(过去式)
List<Map> vaccineOrders = baseMapper.selectThirtyDaysList();
return vaccineOrders;
}
}
Mapper 层
public interface VaccinesIndexMapper extends BaseMapperPlus<VaccinesIndexMapper, VaccineOrder, VaccineOrder> {
/**
* 查询接种管理
* @return 接种管理
*/
public int selectMouthList1();
public int selectMouthList2();
public int selectWeekList1();
public int selectWeekList2();
public int selectTodayList1();
public int selectTodayList2();
public int selectTodayList3();
public List<Map> selectThirtyDaysList();
}
Sql 层
<sql id="selectVaccineOrderVo">
select pk_id, id, patient_id, name, phone, age, id_card, vaccine_id, vaccine_num, dept_id, org_id, user_id, book_time, book_status, affirm_time, cancel_reason, cancel_time, ack_time, is_deleted, gmt_deleted, gmt_created, gmt_modified, user_created, user_modified from vaccine_order
</sql>
<select id="selectMouthList1" resultType="int">
SELECT
count(*)
FROM
`vaccine_order`
WHERE
book_time >= DATE_FORMAT(NOW(),'%Y-%m-01')
and book_time <= LAST_DAY(NOW())
AND book_status = 1;
</select>
<select id="selectMouthList2" resultType="int">
SELECT
count(*)
FROM
`vaccine_order`
WHERE
book_time >= DATE_FORMAT(NOW(),'%Y-%m-01')
and book_time <= LAST_DAY(NOW())
AND book_status = 2;
</select>
<select id="selectWeekList1" resultType="int">
SELECT
count(*)
FROM
`vaccine_order`
WHERE
WEEK ( book_time, 1 ) = WEEK ( CURRENT_DATE, 1 )
AND book_status = 1;;
</select>
<select id="selectWeekList2" resultType="int">
SELECT
count(*)
FROM
`vaccine_order`
WHERE
WEEK ( book_time, 1 ) = WEEK ( CURRENT_DATE, 1 )
AND book_status = 2;;
</select>
<select id="selectTodayList1" resultType="int">
SELECT
COUNT(*)
FROM
vaccine_order
WHERE
book_status = 1
AND DATE (book_time) = CURDATE()
</select>
<select id="selectTodayList2" resultType="int">
SELECT
COUNT(*)
FROM
vaccine_order
WHERE
book_status = 2
AND DATE (book_time) = CURDATE()
</select>
<select id="selectTodayList3" resultType="int">
SELECT
COUNT(*)
FROM
vaccine_order
WHERE
DATE(book_time) = CURDATE()
AND DATE(gmt_created) = CURDATE()
</select>
<select id="selectThirtyDaysList" resultType="java.util.Map">
SELECT
a.create_time "time",
count( b.id ) "num"
FROM
( SELECT DATE_SUB( CURRENT_DATE, INTERVAL num - 1 DAY ) create_time FROM sys_num WHERE num BETWEEN 0 AND 31 ) a
LEFT JOIN vaccine_order b ON a.create_time = DATE_FORMAT( b.affirm_time, '%Y-%m-%d' )
AND b.book_status = 2
GROUP BY
a.create_time DESC
</select>