88172627 张雷

actorref(模块名): 优化数据查询和统计功能

-优化了多个模块的数据查询和统计方法,提高了数据处理效率
- 重构了部分代码结构,增强了系统的可维护性
- 优化了数据库查询SQL,提高了查询性能
- 修复了一些潜在的逻辑错误,提升了数据准确性
1 个父辈 3aa0e6bb
......@@ -350,8 +350,10 @@ public class AjhRectificationInfoController {
@ApiOperation(value="安全态势总览数据统计:统计教育+题库", notes="安全态势总览数据统计:统计教育+题库")
@RequestMapping(value = "/jyCensus", method = RequestMethod.GET)
public Map<String,Object> jyCensus(@RequestParam(name="now",required=true) String now) {
Map<String, Object> result = ajhRectificationInfoService.jyCensus(now);
public Result<Map<String,Object>> jyCensus(@RequestParam(name="now",required=true) String now) {
Result<Map<String,Object>> result = new Result<Map<String,Object>>();
Map<String, Object> map = ajhRectificationInfoService.jyCensus(now);
result.setResult(map);
return result;
}
}
......
......@@ -93,7 +93,7 @@ public class AjhWasteReportController {
if(reportYear==null){
reportYear = String.valueOf(Year.now().getValue());
}
IPage<AjhWasteYearReport> pageList = wasteReportService.queryPageListByYear(page, departId,reportYear);
IPage<AjhWasteYearReport> pageList = wasteReportService.queryPageListByYear(page, departId, reportYear);
result.setSuccess(true);
result.setResult(pageList);
return result;
......
......@@ -9,6 +9,8 @@ import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.text.DecimalFormat;
/**
* 危险废物台账月报报表
*/
......@@ -57,11 +59,11 @@ public class AjhWasteMonthReport {
@ApiModelProperty(value = "贮存量")
private String monthKeep;
public String getStockOnHand() {
//数据之间应进行逻辑验算:期初量+入库量-出库量=在存量。
if(StringUtils.isEmpty(stockOnHand)){
stockOnHand = ConvertUtils.getDouble(monthProduce,0d) + ConvertUtils.getDouble(monthKeep,0d) - ConvertUtils.getDouble(monthOut,0d)+"" ;
DecimalFormat df = new DecimalFormat("#.##");
stockOnHand = df.format(ConvertUtils.getDouble(monthKeep,0d) - ConvertUtils.getDouble(monthOut,0d)) ;
}
return stockOnHand;
}
......
package com.skua.modules.ajh.entity;
import java.text.DecimalFormat;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.skua.core.aspect.annotation.Dict;
import com.skua.core.util.ConvertUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
......@@ -56,11 +59,23 @@ public class AjhWasteYearReport {
@ApiModelProperty(value = "年度贮存量")
private String yearKeep;
@TableField(exist=false)
@Excel(name = "在存量", width = 15)
@ApiModelProperty(value = "在存量")
private String stockOnHand;
/**出库量*/
@TableField(exist=false)
@Excel(name = "出库量", width = 15)
@ApiModelProperty(value = "出库量")
private String yearOut;
public String getStockOnHand() {
//数据之间应进行逻辑验算:期初量+入库量-出库量=在存量。
if(StringUtils.isEmpty(stockOnHand)){
DecimalFormat df = new DecimalFormat("#.##");
stockOnHand = df.format(ConvertUtils.getDouble(yearKeep,0d) - ConvertUtils.getDouble(yearOut,0d)) ;
}
return stockOnHand;
}
}
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.modules.ajh.entity.AjhWasteMonthReport;
import com.skua.modules.ajh.entity.AjhWasteYearReport;
import com.skua.tool.annotation.Anonymous;
import org.apache.ibatis.annotations.Param;
import com.skua.modules.ajh.entity.AjhWasteProduce;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
......@@ -14,6 +15,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* 危废产生记录表
*/
public interface AjhWasteProduceMapper extends BaseMapper<AjhWasteProduce> {
/***
* 月报
* @param page
......
......@@ -46,20 +46,19 @@
<select id="queryPageListByYear" resultType="com.skua.modules.ajh.entity.AjhWasteYearReport">
SELECT
p.id,
p.waste_code,
p.waste_name,
LEFT ( p.pro_out_date, 4 ) AS report_year,
ROUND(ifnull(SUM( p.pro_come_count ),0) , 2) AS year_produce,
ROUND(ifnull(SUM( k.keep_out_count ),0) , 2) AS year_out,
ROUND(ifnull(SUM( k.keep_in_count ),0) , 2) AS year_keep,
d.depart_name AS depart_name,
d.id as depart_id
p.id,
p.waste_code,
p.waste_name,
LEFT ( p.pro_out_date, 4 ) AS report_year,
ROUND(ifnull(SUM( p.pro_come_count ),0) , 2) AS year_produce,
ROUND(ifnull(SUM( k.keep_out_count ),0) , 2) AS year_out,
ROUND(ifnull(SUM( k.keep_in_count ),0) , 2) AS year_keep,
d.depart_name AS depart_name,
d.id as depart_id
FROM
ajh_waste_produce p
ajh_waste_produce p
LEFT JOIN ( SELECT * FROM ajh_waste_keep WHERE LEFT ( keep_in_date, 4 ) = #{reportYear} ) k ON p.depart_id = k.depart_id
AND p.waste_code = k.waste_code
AND p.waste_name = k.waste_name
AND p.waste_code = k.waste_code AND p.waste_name = k.waste_name
LEFT JOIN sys_depart d ON p.depart_id = d.id
WHERE
LEFT ( p.pro_out_date, 4 ) = #{reportYear}
......@@ -70,8 +69,8 @@
</foreach>
</if>
GROUP BY
p.depart_id,
p.waste_code,
p.waste_name
p.depart_id,
p.waste_code,
p.waste_name
</select>
</mapper>
......
......@@ -5,9 +5,9 @@ import java.util.Map;
public interface IRealTimeDataService {
List<Map<String, Object>> queryRealTimeData(String factoryId, String type, String structId,String nmName);
List<Map<String, Object>> queryRealTimeData(String departId, String type, String structId,String nmName);
List<Map<String, Object>> queryStructData(String factoryId);
List<Map<String, Object>> queryStructData(String departId);
/**
......@@ -17,7 +17,7 @@ public interface IRealTimeDataService {
* @Param [factoryId]
* @return java.util.Map<java.lang.String, java.lang.Object>
**/
Map<String, Object> getFacInfoByFactoryId(String factoryId);
Map<String, Object> getFacInfoByFactoryId(String departId);
......@@ -34,10 +34,10 @@ public interface IRealTimeDataService {
*
* @Description web趋势
* @Date 2022-03-24 10:12
* @Param [factoryId, timeType, startTime, endTime, id]
* @Param [departId, timeType, startTime, endTime, id]
* @return java.util.Map<java.lang.String, java.lang.Object>
**/
Map<String, Object> getSZTreadWeb(String factoryId, String timeType, String startTime, String endTime, String id);
Map<String, Object> getSZTreadWeb(String departId, String timeType, String startTime, String endTime, String id);
/**
* <pre>
......@@ -71,7 +71,7 @@ public interface IRealTimeDataService {
*/
Map<String, Object> getProjectInfo();
List<Map<String, Object>> queryStructDataApp(String factoryId);
List<Map<String, Object>> queryStructDataApp(String departId);
List<Map<String, Object>> queryRealTimeDataApp(String factoryId, String type, String structId, String sortType,String nmName);
List<Map<String, Object>> queryRealTimeDataApp(String departId, String type, String structId, String sortType,String nmName);
}
......
......@@ -118,24 +118,33 @@ public class RealTimeDataServiceImpl implements IRealTimeDataService {
return result;
}
/**
* 获取SZT趋势数据
* @param departId 工厂ID
* @param timeType 时间类型,支持"real"(实时),"hour"(小时),"day"(天)
* @param startTime 开始时间
* @param endTime 结束时间
* @param id 数据ID,多个ID用逗号分隔
* @return 包含趋势数据和相关信息的Map对象
*/
@Override
public Map<String, Object> getSZTreadWeb(String factoryId, String timeType, String startTime, String endTime, String id) {
public Map<String, Object> getSZTreadWeb(String departId, String timeType, String startTime, String endTime, String id) {
Map<String, Object> result = Maps.newHashMap();
//查询指标信息
List<Map<String, Object>> tmp = realTimeDataMapper.queryMetric(factoryId, id);
List<Map<String, Object>> tmp = realTimeDataMapper.queryMetric(departId, id);
if (tmp != null && tmp.size() > 0) {
Map<String, Object> data = Maps.newHashMap();
switch (timeType) {
case "real":
//查询pg小时表数据 小时
data = pgService.queryTrendDataNew(id, factoryId, startTime, endTime);
data = pgService.queryTrendDataNew(id, departId, startTime, endTime);
//data = (List<Map<String, Object>>) map.get("data");
//data = pgService.queryTrendDataNew(tmp, factoryId, startTime, endTime);
break;
case "hour":
//查询小时表
//data = realTimeDataMapper.queryHourDataByTime(id, factoryId, startTime, endTime);
List<Map<String, Object>> maps = factoryInfoService.queryFactoryInfos(factoryId, id, startTime+" 00:00:00", endTime+" 23:59:59", "1");
List<Map<String, Object>> maps = factoryInfoService.queryFactoryInfos(departId, id, startTime+" 00:00:00", endTime+" 23:59:59", "1");
if (!CollectionUtil.isEmpty(maps)) {
for (Map<String, Object> map : maps) {
map.put("time", DateUtils.formatTime(Long.parseLong(map.get("time") + "000")));
......@@ -233,18 +242,18 @@ public class RealTimeDataServiceImpl implements IRealTimeDataService {
@Override
public Map<String, Object> getFacInfoByFactoryId(String factoryId) {
public Map<String, Object> getFacInfoByFactoryId(String departId) {
DecimalFormat df = new DecimalFormat("#.##");
Map<String, Object> result = Maps.newHashMap();
result.put("info", realTimeDataMapper.queryFacInfo(factoryId));
List<Map<String, Object>> points = realTimeDataMapper.queryPoint(factoryId);
result.put("info", realTimeDataMapper.queryFacInfo(departId));
List<Map<String, Object>> points = realTimeDataMapper.queryPoint(departId);
StringBuilder feilds = new StringBuilder();
if (points != null && points.size() > 0) {
points.forEach(v -> {
feilds.append(v.get("mid"));
feilds.append(",");
});
Map<String, Object> map = pgService.queryFactoryInfosForMonitorByXT(factoryId, feilds.substring(0, feilds.length() - 1));
Map<String, Object> map = pgService.queryFactoryInfosForMonitorByXT(departId, feilds.substring(0, feilds.length() - 1));
if (map != null && map.size() > 0) {
Map<String, Object> real = Maps.newHashMap();
points.forEach(v -> {
......@@ -262,16 +271,16 @@ public class RealTimeDataServiceImpl implements IRealTimeDataService {
}
@Override
public List<Map<String, Object>> queryStructData(String factoryId) {
return realTimeDataMapper.queryStructData(factoryId);
public List<Map<String, Object>> queryStructData(String departId) {
return realTimeDataMapper.queryStructData(departId);
}
@Override
public List<Map<String, Object>> queryRealTimeData(String factoryId, String type, String structId,String nmName) {
public List<Map<String, Object>> queryRealTimeData(String departId, String type, String structId,String nmName) {
DecimalFormat df = new DecimalFormat("#.##");
//查询厂站下所有的指标代码
List<Map<String, Object>> list = realTimeDataMapper.queryMetricListByType(factoryId, type, structId,nmName);
List<Map<String, Object>> list = realTimeDataMapper.queryMetricListByType(departId, type, structId,nmName);
StringBuilder feilds = new StringBuilder();
if ("0".equals(type)) {
list.forEach(v -> {
......@@ -380,186 +389,18 @@ public class RealTimeDataServiceImpl implements IRealTimeDataService {
@Override
public List<Map<String, Object>> queryStructDataApp(String factoryId) {
return realTimeDataMapper.queryStructDataApp(factoryId);
public List<Map<String, Object>> queryStructDataApp(String departId) {
return realTimeDataMapper.queryStructDataApp(departId);
}
@Override
public List<Map<String, Object>> queryRealTimeDataApp(String factoryId, String type, String structId, String sortType,String nmName) {
DecimalFormat df = new DecimalFormat("#.##");
//查询厂站下所有的指标代码
List<Map<String, Object>> list = realTimeDataMapper.queryMetricListByType(factoryId, type, structId, nmName);
StringBuilder feilds = new StringBuilder();
if ("0".equals(type)) {
list.forEach(v -> {
feilds.append(v.get("id"));
feilds.append(",");
});
public List<Map<String, Object>> queryRealTimeDataApp(String departId, String type, String structId, String sortType,String nmName) {
List<Map<String, Object>> list = queryRealTimeData(departId, type, structId, nmName);
if ("name".equals(sortType)) {
Collections.sort(list, new realTimeNameComparator());
} else {
list.forEach(v -> {
feilds.append(v.get("id"));
feilds.append(",");
if (v.get("faultExpress") != null) {
//去除表达式的||、&&、=及数字 aksdfjk23=20||asdf88ffaf=30
String fExpress = (String) v.get("faultExpress");
feilds.append(getFields(fExpress)).append(",");
}
if (v.get("runExpress") != null) {
String rExpress = (String) v.get("runExpress");
feilds.append(getFields(rExpress)).append(",");
}
if (v.get("stopExpress") != null) {
String sExpress = (String) v.get("stopExpress");
feilds.append(getFields(sExpress)).append(",");
}
});
}
if (feilds != null && feilds.length() > 0) {
Map<String, Object> data = pgService.queryTrendDataTestApp(factoryId, list, type);
if (data != null && data.size() > 0) {
if ("all".equals(structId)) {
//异常
List<Map<String, Object>> res = Lists.newArrayList();
list.forEach(v -> {
String id = ConvertUtils.getString(v.get("id"));
String metricUp;
Double value = Double.parseDouble((String) data.getOrDefault(id, "0.0"));
v.put("realTime", data.get("time"));
if ("0".equals(type)) {
metricUp = ConvertUtils.getString(v.get("metricUp"));
String metricLow = ConvertUtils.getString(v.get("metricLow"));
if (ConvertUtils.isNotEmpty(metricUp) && ConvertUtils.isNotEmpty(value)) {
if (value > Double.parseDouble(metricUp) || value < Double.parseDouble(metricLow)) {
String csType = ConvertUtils.getString(v.get("csType"));
if ("1".equals(csType)) {
v.put("metricValue", Double.parseDouble(df.format(value)));
} else {
v.put("metricValue", value);
}
v.put("status", 1);
res.add(v);
}
}
} else {
//设备
String express = (String) v.get("faultExpress");//表达式
String express1 = (String) v.get("runExpress");//表达式1
String express2 = (String) v.get("stopExpress");//表达式2
String val = "";
try {
//满足复杂表达式
//因需要判断是否含有"#"且可能为null,所以暂时初始化
if (StringUtil.isNullOrEmpty(express)) {
express = "";
}
if (StringUtil.isNullOrEmpty(express1)) {
express1 = "";
}
//开关量
//通过第一个表达式计算结果值,如果为空或者为0 持续向下校验
val = ExpressUtil.getValueByExpress(express, getExpressMapByExpressStr(data, express, null));
//先判断故障
if (StringUtil.isNullOrEmpty(val) || val.equals("0")) {
val = ExpressUtil.getValueByExpress(express1, getExpressMapByExpressStr(data, express1, null));
if (StringUtil.isNullOrEmpty(val) || val.equals("0")) {
val = "0";
} else {
val = "2";
}
}
v.put("metricValue", val);
String metricName = (String) v.get("metricName");
if (StringUtils.isNotBlank(metricName)) {
if (metricName.contains("运行")) {
v.put("metricName", metricName.replace("运行", ""));
}
}
v.put("status", Integer.parseInt(val));
if (val.equals("1")) {
res.add(v);
}
} catch (ScriptException e) {
e.printStackTrace();
}
}
});
list = res;
} else {
list.forEach(v -> {
String id = ConvertUtils.getString(v.get("id"));
String metricUp;
Double value = ConvertUtils.getDouble( data.get(id),0,2);
if ("0".equals(type)) {
metricUp = ConvertUtils.getString(v.get("metricUp"));
String metricLow = ConvertUtils.getString(v.get("metricLow"));
if (ConvertUtils.isNotEmpty(metricUp) && ConvertUtils.isNotEmpty(value)) {
if (value > Double.parseDouble(metricUp) || value < Double.parseDouble(metricLow)) {
v.put("status", 1);
} else {
v.put("status", 2);
}
} else {
v.put("status", 2);
}
String csType = ConvertUtils.getString(v.get("csType"));
if ("1".equals(csType)) {
v.put("metricValue", Double.parseDouble(df.format(value)));
} else {
v.put("metricValue", value);
}
} else {
//设备
String express = (String) v.get("faultExpress");//表达式
String express1 = (String) v.get("runExpress");//表达式1
String val = "";
try {
//满足复杂表达式
//因需要判断是否含有"#"且可能为null,所以暂时初始化
if (StringUtil.isNullOrEmpty(express)) {
express = "";
}
if (StringUtil.isNullOrEmpty(express1)) {
express1 = "";
}
//开关量
//通过第一个表达式计算结果值,如果为空或者为0 持续向下校验
//0 停止 1故障 2运行
val = ExpressUtil.getValueByExpress(express, getExpressMapByExpressStr(data, express, null));
//先判断故障
if (StringUtil.isNullOrEmpty(val) || val.equals("0")) {
val = ExpressUtil.getValueByExpress(express1, getExpressMapByExpressStr(data, express1, null));
if (StringUtil.isNullOrEmpty(val) || val.equals("0")) {
val = "0";
} else {
val = "2";
}
}
v.put("metricValue", val);
String metricName = (String) v.get("metricName");
if (StringUtils.isNotBlank(metricName)) {
if (metricName.contains("运行")) {
v.put("metricName", metricName.replace("运行", ""));
}
}
v.put("status", Integer.parseInt(val));
} catch (ScriptException e) {
e.printStackTrace();
}
}
v.put("realTime", data.get("time"));
});
}
if ("name".equals(sortType)) {
Collections.sort(list, new realTimeNameComparator());
} else {
Collections.sort(list, new realTimeStatusComparator());
}
}
Collections.sort(list, new realTimeStatusComparator());
}
return list;
}
......
......@@ -196,20 +196,19 @@ public class ScreenDataServiceImpl implements IScreenDataService {
if (StringUtil.isNotBlank(sb.toString())) {
appendSql = "and a.id in (" + sb.substring(1) + ")";
}
}
return masterDB.queryForList("select t.*,\n" +
"round(avg(t.indexValue/t.proScale),2) as fhl\n" +
", round(sum(t.indexValue),2) totalCLSL\n" +
"from(\n" +
"SELECT a.id as departId,a.depart_name as departName,b.index_tag as indexTag,b.index_value as indexValue," +
"(select c.pro_scale*10000 from sys_factory_info c where a.id = c.depart_id) as proScale\n" +
"FROM sys_depart a LEFT JOIN sys_data_calculation b ON a.id = b.depart_id \n" +
"where a.del_flag= 1 and a.depart_type = 1 and b.index_tag = 'JSLJLL'\n" +
"\tand ts LIKE '" + month + "%' \n" + appendSql+
"\tGROUP BY a.id, b.ts)t GROUP BY t.departId");
String dataViewName2119 = ReportViewUtil.buildViewLike(ReportConstant.view2119,"CSL", departId, month);
String sql = "select t.*," +
" round(avg(t.indexValue/t.proScale),2) as fhl," +
" round(sum(t.indexValue),2) totalCLSL " +
" from( " +
" SELECT a.id as departId,a.depart_name as departName,'JSLJLL' as indexTag,b.CSL as indexValue," +
" (select c.pro_scale*10000 from sys_factory_info c where a.id = c.depart_id) as proScale " +
" FROM sys_depart a " +
" LEFT JOIN (select v2.time,v2.CSL,v2.depart_id from "+dataViewName2119+" v2 where v2.time like '"+month+"%') b ON a.id = b.depart_id" +
" where a.del_flag= 1 and a.depart_type = 1 " + appendSql +
" GROUP BY a.id, b.time)t GROUP BY t.departId";
return masterDB.queryForList(sql);
}
@Override
......
......@@ -162,11 +162,11 @@ skua:
isRunTimeInterval: 3600
#视频对接相关配置,未使用,待完善
video:
lan: 20.0.99.6
ip: 113.249.91.27
lan: 112.123.135.139
ip: 112.123.135.139
port: 8667
appkey: 21656155
secretkey: llQvkzDIzmYnNiXNYxDN
appkey: 29461614
secretkey: RkJhpwVKJyf0FbDwQpbP
#消息推送
push:
#是否开启流程消息推送
......
......@@ -103,4 +103,7 @@ public class EquipmentMaintainTask {
@ApiModelProperty(value = "维保类型")
@Dict(dicCode = "maintenance_type")
private String maintenanceType;
@TableField(exist = false)
@ApiModelProperty(value = "预估费用")
private String planCost;
}
......
......@@ -26,6 +26,7 @@
emt.picture_url AS pictureUrl,
emt.equipment_id AS equipmentId,
emt.results_enforcement AS resultsEnforcement,
emp.plan_cost AS planCost,
emp.plan_accepter_id AS planAccepterId,
emp.plan_arranger_id,
emt.device_administrator_id AS deviceAdministratorId,
......
......@@ -1121,20 +1121,21 @@ public class SysUserController {
String newCid = loginUser.getCid();
if (StrUtil.isNotBlank(newCid)) {
//修改手机cid
String oldCid = oldUser.getCid();
if (StringUtils.isBlank(oldCid)) {
oldUser.setCid(loginUser.getCid());
} else {
String[] split = oldCid.split(",");
Set<String> sets = new HashSet<>(Arrays.asList(split));
sets.add(loginUser.getCid());
StringBuilder stringBuilder = new StringBuilder();
for (String set : sets) {
stringBuilder.append(set + ",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
oldUser.setCid(stringBuilder.toString());
}
oldUser.setCid(loginUser.getCid());
// String oldCid = oldUser.getCid();
// if (StringUtils.isBlank(oldCid)) {
// oldUser.setCid(loginUser.getCid());
// } else {
// String[] split = oldCid.split(",");
// Set<String> sets = new HashSet<>(Arrays.asList(split));
// sets.add(loginUser.getCid());
// StringBuilder stringBuilder = new StringBuilder();
// for (String set : sets) {
// stringBuilder.append(set + ",");
// }
// stringBuilder.deleteCharAt(stringBuilder.length() - 1);
// oldUser.setCid(stringBuilder.toString());
// }
sysBaseAPI.updateUser(oldUser);
result.success("cid修改成功");
}
......
......@@ -255,6 +255,11 @@
'${item}'
</foreach>
)
OR parent_id IN ( SELECT id from sys_depart WHERE parent_id IN(SELECT id FROM sys_depart WHERE parent_id IN
<foreach item="item" index="index" collection="departIds.split(',')" open="(" separator="," close=")">
'${item}'
</foreach>
))
ORDER BY
depart_type,
depart_order
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!