统计报错SQL统计当年12个月份一般隐患和重大隐患数量

main
13233904609 5 months ago
parent 56ce06b84e
commit 9e55658adf

@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -157,6 +158,10 @@ public class EhsIndexStatisticsController extends BaseController {
List<Map<String,Object>> list = ehsIndexStatisticsService.getHiddenDangerTypeMapList();
return AjaxResult.success(list);
}
public static void main(String[] args) {
System.out.println(DateUtil.year(new Date()));
}
/**
*
*/
@ -165,6 +170,9 @@ public class EhsIndexStatisticsController extends BaseController {
public AjaxResult getHiddenDangerDataMapList(String year)
{
JSONArray row = new JSONArray();
if(StringUtils.isEmpty(year)){
year = DateUtil.year(new Date())+"";
}
List<Map<String,Object>> list = ehsIndexStatisticsService.getHiddenDangerDataMapList(year);
if(StringUtils.isNotEmpty(list)){
LinkedHashMap<Object, List<Map<String, Object>>> nameList = list.stream().collect(Collectors.groupingBy(e -> e.get("name"), LinkedHashMap::new, Collectors.toList()));

@ -266,61 +266,20 @@ SELECT
d.dict_value
FROM
(
WITH RECURSIVE months AS (
SELECT
DATE_FORMAT( date_add( CONCAT( #{yearStr}, '-01-01' ), INTERVAL ROW MONTH ), '%Y-%m' ) date_time
FROM
(
CONCAT( #{yearStr}, '-01-01' ) AS month_date UNION ALL
SELECT
@ROW := @ROW + 1 AS ROW
DATE_ADD( month_date, INTERVAL 1 MONTH ) AS month_date
FROM
(
SELECT
0 UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) t,
(
SELECT
0 UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) t2,
( SELECT @ROW :=- 1 ) r
) se
months
WHERE
DATE_FORMAT( date_add( CONCAT( #{yearStr}, '-01-01' ), INTERVAL ROW MONTH ), '%Y-%m' ) &lt;= DATE_FORMAT( CONCAT( #{yearStr}, '-12-01' ), '%Y-%m' )) s,
month_date &lt; CONCAT( #{yearStr}, '-12-01' )
) SELECT
DATE_FORMAT( month_date, '%Y-%m' ) AS date_time
FROM
months
) s,
sys_dict_data d
WHERE
d.dict_type = 'hidden_danger_grade'

Loading…
Cancel
Save