Commit 0815483e authored by 韩桐桐's avatar 韩桐桐

feat(ys): F1-C1应急保障统计

parent c1065979
......@@ -3,12 +3,19 @@ package com.yeejoin.amos.boot.module.ys.biz.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.ys.biz.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
*
* @author system_generator
* @date 2024-09-24
*/
......@@ -17,13 +24,17 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(value = "/common")
public class CommonController extends BaseController {
@Autowired
private CommonService commonService;
@Autowired
private CommonService commonService;
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation(httpMethod = "GET",value = "模板下载", notes = "模板下载")
// @RequestMapping(value = "/templateDownload", method = RequestMethod.GET)
// public void queryForPage(HttpServletResponse response, @RequestParam(value = "path") String path) {
// commonService.templateDownload(response,path);
// }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "应急保障四项统计", notes = "应急保障四项统计")
@RequestMapping(value = "/emergencySupportStatistics/{businessType}/{componentType}", method = RequestMethod.GET)
public ResponseModel<Object> queryForPage(
@ApiParam(value = "业务类型(教育培训:education、体系建设:construct、应急演练:rehearsal、应急预案:prePlan)", required = true)
@PathVariable(value = "businessType") String businessType,
@ApiParam(value = "组件类型(饼图:pieChart、富文本:richText)", required = true)
@PathVariable(value = "componentType") String componentType) {
return ResponseHelper.buildResponse(commonService.emergencySupportStatistics(businessType, componentType));
}
}
......@@ -2,5 +2,6 @@ package com.yeejoin.amos.boot.module.ys.biz.service;
public interface CommonService {
Object emergencySupportStatistics(String businessType, String componentType);
}
package com.yeejoin.amos.boot.module.ys.biz.service.impl;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.module.common.biz.service.impl.DynamicFormInstanceServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.ys.api.entity.YsEmergencyPlan;
import com.yeejoin.amos.boot.module.ys.api.entity.YsEmergencyRehearsal;
import com.yeejoin.amos.boot.module.ys.api.enums.MaintenanceExpiredEarlyWarningEnum;
import com.yeejoin.amos.boot.module.ys.api.vo.SortVo;
import com.yeejoin.amos.boot.module.ys.biz.service.CommonService;
import org.apache.lucene.queryparser.classic.QueryParser;
......@@ -16,10 +24,13 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
......@@ -37,9 +48,47 @@ public class CommonServiceImpl implements CommonService {
*/
public final static String EQU_CATEGORY_CYLINDER = "2300";
/**
* 应急保障四项统计使用 - 饼图
*/
public final static String PIECHART = "pieChart";
/**
* 应急保障四项统计使用 - 饼图模板
*/
public final static String PIECHART_TEMPLATE = "[{\"name\": \"%s\",\"value\": %s},{\"name\": \"其他\",\"value\": %s}]";
/**
* 应急保障四项统计使用 - 富文本
*/
public final static String RICHTEXT = "richText";
/**
* 应急保障四项统计使用 - 富文本模板
*/
public final static String RICHTEXT_TEMPLATE = "{\"total\": %s,\"%s\": %s}";
/**
* 应急保障四项统计使用 - 业务类型
*/
public final static JSONObject businessTypeJSON = new JSONObject();
private static final Logger log = LoggerFactory.getLogger(CommonServiceImpl.class);
@Autowired
private RestHighLevelClient restHighLevelClient;
@Autowired
private DynamicFormInstanceServiceImpl dynamicFormInstanceService;
@Autowired
private YsEmergencyRehearsalServiceImpl ysEmergencyRehearsalService;
@Autowired
private YsEmergencyPlanServiceImpl ysEmergencyPlanService;
static {
businessTypeJSON
.fluentPut("education", "教育培训数").fluentPut("construct", "体系建设数")
.fluentPut("rehearsal", "应急演练数").fluentPut("prePlan", "应急预案数");
}
/**
* 排序 :页面列表排序功能支持,将 "字段,ascend" 或 "字段,descend" 转化为对应JSONObject
*
......@@ -116,6 +165,7 @@ public class CommonServiceImpl implements CommonService {
/**
* 八大类设备数量统计
*
* @param equTypeCode
* @param cylinderNum
* @param orgCode
......@@ -161,4 +211,55 @@ public class CommonServiceImpl implements CommonService {
return result.get();
}
/**
* 应急保障四项统计
*
* @param businessType 业务类型(教育培训:education、体系建设:construct、应急演练:rehearsal、应急预案:prePlan)
* @param componentType 组件类型(饼图:pieChart、富文本:richText)
* @return 模板数据
*/
@Override
public Object emergencySupportStatistics(String businessType, String componentType) {
// 教育培训数
long educationNum = dynamicFormInstanceService.pageList(1, 1, MaintenanceExpiredEarlyWarningEnum.JYPX.getGroupCode()).getTotal();
// 体系建设数
long constructNum = dynamicFormInstanceService.pageList(1, 1, MaintenanceExpiredEarlyWarningEnum.TXJS.getGroupCode()).getTotal();
// 应急演练数
int rehearsalNum = ysEmergencyRehearsalService.getBaseMapper().selectCount(new LambdaQueryWrapper<YsEmergencyRehearsal>().eq(YsEmergencyRehearsal::getIsDelete, Boolean.FALSE));
// 应急预案数
int prePlanNum = ysEmergencyPlanService.getBaseMapper().selectCount(new LambdaQueryWrapper<YsEmergencyPlan>().eq(YsEmergencyPlan::getIsDelete, Boolean.FALSE));
// 四项总数
BigDecimal totalNum = NumberUtil.add(educationNum, constructNum, rehearsalNum, prePlanNum);
// 其他数量
BigDecimal otherNum = new BigDecimal(0);
// 请求类型数量
BigDecimal valueNum = new BigDecimal(0);
switch (businessType) {
case "education":
valueNum = BigDecimal.valueOf(educationNum);
otherNum = NumberUtil.sub(totalNum, educationNum);
break;
case "construct":
valueNum = BigDecimal.valueOf(constructNum);
otherNum = NumberUtil.sub(totalNum, constructNum);
break;
case "rehearsal":
valueNum = BigDecimal.valueOf(rehearsalNum);
otherNum = NumberUtil.sub(totalNum, rehearsalNum);
break;
case "prePlan":
valueNum = BigDecimal.valueOf(prePlanNum);
otherNum = NumberUtil.sub(totalNum, prePlanNum);
break;
}
if (PIECHART.equals(componentType)) {
// 组装 饼图 模板数据
return JSONArray.parseArray(String.format(PIECHART_TEMPLATE, businessTypeJSON.get(businessType).toString(), valueNum, otherNum));
}
if (RICHTEXT.equals(componentType)) {
// 组装 富文本 模板数据
return JSONObject.parseObject(String.format(RICHTEXT_TEMPLATE, totalNum, businessType, valueNum));
}
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment