08bdd8bd 康伟

kangwei :修改reportUtils工具类

1 个父辈 62269c2c
......@@ -72,9 +72,9 @@ public class ReportViewUtil {
if(!StringUtils.isEmpty(itemIds)) {
itemIds = itemIds.substring(1);
}
sb.append("`a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( ");
sb.append(" `a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( ");
sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv v WHERE 1=1 ");
sb.append(" SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv v WHERE 1=1 ");
if(StringUtils.isNotEmpty(departIds)){
sb.append(" and depart_id in ("+inSqlPart+") ");
}
......@@ -141,16 +141,16 @@ public class ReportViewUtil {
itemIds = itemIds.substring(1);
}
sb.append("`a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( ");
sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 ");
sb.append(" SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 ");
if(StringUtils.isNotEmpty(departIds)){
sb.append("and depart_id in ("+inSqlPart+")");
sb.append(" and depart_id in ("+inSqlPart+")");
}
if(!StringUtils.isEmpty(dataTime)) {
sb.append("and data_time like'"+dataTime+"%'");
}
sb.append("and reit_id in ("+itemIds+")");
sb.append(" and reit_id in ("+itemIds+")");
sb.append(") `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`data_id`,`a`.`depart_id`,`a`.`data_time` order by `a`.`data_time`)");
sb.append(" ) `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`data_id`,`a`.`depart_id`,`a`.`data_time` order by `a`.`data_time`)");
return sb.toString();
}
......@@ -204,17 +204,17 @@ public class ReportViewUtil {
sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 ");
if(!StringUtils.isEmpty(departIds)) {
sb.append(" and depart_id in ("+inSqlPart+")");
sb.append(" and depart_id in ("+inSqlPart+") ");
}
if(!StringUtils.isEmpty(startTime)) {
sb.append("and data_time >='"+startTime+"'");
sb.append(" and data_time >='"+startTime+"' ");
}
if(!StringUtils.isEmpty(endTime)) {
sb.append("and data_time <='"+endTime+"'");
sb.append(" and data_time <='"+endTime+"' ");
}
sb.append("and reit_id in ("+itemIds+")");
sb.append(" and reit_id in ("+itemIds+") ");
sb.append(") `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`depart_id`)");
sb.append(") `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`depart_id`) ");
return sb.toString();
}
......
......@@ -64,15 +64,16 @@ public class DateVO {
this.nowYear = Integer.parseInt(DateUtils.dateformat(currentDate,"yyyy"));
//同比时间
this.lastYear = nowYear -1 ;//去年
this.lastYearMonth = DateUtils.getHbMonth(currentDate);
System.out.println(" lastYearMonth "+lastYearMonth);
this.lastYearMonth = DateUtils.getTbMonth(this.nowMonth);
//System.out.println(" lastYearMonth "+lastYearMonth);
this.lastYearMonthStartTime = lastYearMonth+"-01";
this.lastYearMonthStartTime = lastYearMonth+"-31";
this.lastYearMonthEndTime = lastYearMonth+"-31";
this.lastYearStartDate = this.lastYear+"-01-01";
this.lastYearEndDate = this.lastYear+"-12-31";
//环比时间
this.lastMonth = DateUtils.getHbMonth(currentDate);//
this.lastMonth = DateUtils.getHbMonth(this.nowMonth);//
System.out.println(" lastMonth "+lastMonth);
this.lastMonthStartTime = lastMonth+"-01";
this.lastMonthEndTime = lastMonth+"-31";
......
......@@ -51,6 +51,7 @@ public class DigitalUtils {
if(StringUtils.isNotEmpty(val2)){
BigDecimal num2 = new BigDecimal(val2);
result = result.add( num2 );
result = result.multiply( num2).setScale(2, BigDecimal.ROUND_HALF_UP);
}
return result.toString();
}
......
......@@ -19,23 +19,51 @@ import java.util.regex.Pattern;
*/
public class JSUtils {
// 表达式字符合法性校验正则模式,静态常量化可以降低每次使用都要编译地消耗
private static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9\\.+-/*()= ]+");
// 运算符优先级map
private static final Map<String, Integer> OPT_PRIORITY_MAP = new HashMap<String, Integer>() {
private static final long serialVersionUID = 6968472606692771458L;
{
put("(", 0);
put("+", 2);
put("-", 2);
put("*", 3);
put("/", 3);
put(")", 7);
put("=", 20);
}
};
public static String add(Object obj1 , Object obj2){
String expression = obj1+ "+" + obj2;
return executeExpression(expression,"0.00");
}
public static String subtract(Object obj1 , Object obj2){
String expression = obj1+ "-" + obj2;
return executeExpression(expression,"0.00");
}
public static String multiply(Object obj1 , Object obj2){
String expression = obj1+ "*" + obj2;
return executeExpression(expression,"0.00");
}
public static String divide(Object obj1 , Object obj2){
String expression = obj1+ "/" + obj2;
return executeExpression(expression,"0.00");
}
/***
* 格式化结果,保留两位小数
* @param obj1
* @return
*/
public static String format(Object obj1 ){
return format(obj1,null);
}
/***
* 格式化结果,指定格式,默认保留两位小数
* @param obj1
* @param decimalFormat
* @return
*/
public static String format(Object obj1 , String decimalFormat){
String result = null;
try{
if(obj1 != null ){
if(decimalFormat == null ) decimalFormat = "0.00";
DecimalFormat df = new DecimalFormat(decimalFormat);
result = df.format(Double.parseDouble(obj1.toString()));
}
}catch(Exception e){
e.printStackTrace();
}
return result;
}
/**
* 输入加减乘除表达式字符串,返回计算结果
*
......@@ -50,10 +78,29 @@ public class JSUtils {
DecimalFormat df = new DecimalFormat(decimalFormat);
result = df.format(aDouble);
}catch(Exception e ){
// e.printStackTrace();
// e.printStackTrace();
}
return result;
}
// 表达式字符合法性校验正则模式,静态常量化可以降低每次使用都要编译地消耗
private static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9\\.+-/*()= ]+");
// 运算符优先级map
private static final Map<String, Integer> OPT_PRIORITY_MAP = new HashMap<String, Integer>() {
private static final long serialVersionUID = 6968472606692771458L;
{
put("(", 0);
put("+", 2);
put("-", 2);
put("*", 3);
put("/", 3);
put(")", 7);
put("=", 20);
}
};
public static double executeExpression(String expression) {
// 非空校验
if (null == expression || "".equals(expression.trim())) {
......
package com.skua.modules.algorithm.service.impl;
import com.skua.common.report.ReportViewUtil;
import com.skua.core.context.SpringContextUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
/**
* @auther kangwei
* @create 2024-11-01-10:09
*/
@Service("reportItemvService")
public class ReportItemvService {
String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";// 水 COD TP TN NH3H
String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";//能耗报表
String view4411 = "4411ed3d78634bcdcd700f6e33724025";//生产运营周报
private JdbcTemplate getJdbcTemplate(){
//主库数据源
JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
return masterDB;
}
public String getSumCSL(String departId ,String startTime ,String endTime){
String dataViewName2119 = ReportViewUtil.buildViewLike(view2119,"CSL", departId, startTime,endTime);
String sql = "select sum(aaa.CSL) from " + dataViewName2119+ "aaa";
String csl = getJdbcTemplate().queryForObject(sql,String.class);
return csl;
}
/* public List<Map<String,Object>> getDeptCSL(String departId , String startTime , String endTime){
}*/
public String getSumDLHJ(String departId ,String startTime ,String endTime){
String dataViewName3a24 = ReportViewUtil.buildViewLike(view3a24,"DLHJ", departId, startTime,endTime);
String sql = "select sum(aaa.DLHJ) from " + dataViewName3a24+ "aaa";
String dlhj = getJdbcTemplate().queryForObject(sql,String.class);
return dlhj;
}
/* public List<Map<String,Object>> getDeptDLHJ(String departId , String startTime , String endTime){
}*/
}
......@@ -23,13 +23,12 @@ import javax.servlet.http.HttpServletRequest;
* @create 2024-10-14-16:46
*/
@Slf4j
@Api(tags="在线考试-试卷")
@Api(tags="测试报表")
@RestController("testReportController")
@RequestMapping("/web/edu/paper")
public class TestReportSqlController {
@AutoLog(value = "在线考试--构造填报报表视图")
@ApiOperation(value="在线考试-构造填报报表视图", notes="在线考试-构造填报报表视图")
@AutoLog(value = "测试报表")
@ApiOperation(value="测试报表", notes="测试报表")
@GetMapping(value = "/testReportSql")
public Result<String> testReportSql(
@RequestParam(name="reportId") String reportId,
......
......@@ -89,8 +89,6 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
}
// resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title")));
}
factoryInfoVOList = new ArrayList(factoryInfoMap.values());
// 添加:中冶数据
......@@ -239,9 +237,12 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
StringBuffer sql = new StringBuffer("select round(aaa.CSL,2) 'csl',round(( aaa.JSCOD - aaa.CSCOD ),2) 'codxjl', round(( aaa.JSAD -aaa.CSAD ),2) 'adxjl' from ");
sql.append(" "+dataViewName2119 +" aaa ");
System.out.println(sql.toString());
waterQualityVO = getJdbcTemplate().queryForObject(sql.toString(),new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
List<WaterQualityVO> waterQualityVOList = getJdbcTemplate().query(sql.toString(),new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
if(waterQualityVOList != null && !waterQualityVOList.isEmpty()){
waterQualityVO = waterQualityVOList.get(0);
}else{
waterQualityVO = new WaterQualityVO();
}
// if(waterQualityVO == null )waterQualityVO = new WaterQualityVO();
//负荷率 CSL/设计规模 ()
String factoryProScaleSql = "select round( ("+waterQualityVO.getCsl() +"/(pro_scale * 100) ),2) fhl from sys_factory_info where depart_id = '"+departId+"'";
......@@ -257,10 +258,15 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
sql2.append( " "+dataViewName3a24+" aaa ");
System.out.println("sql2 = "+sql2.toString());
WaterQualityVO waterQualityVOTemp = getJdbcTemplate().queryForObject( sql2.toString(), new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
waterQualityVO.setTnl(waterQualityVOTemp.getTnl() );
waterQualityVO.setDsdh(waterQualityVOTemp.getDsdh());
waterQualityVO.setDsyh(waterQualityVOTemp.getDsyh());
waterQualityVOList = getJdbcTemplate().query( sql2.toString(), new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
if(waterQualityVOList != null && !waterQualityVOList.isEmpty() ){
WaterQualityVO waterQualityVOTemp = waterQualityVOList.get(0);
waterQualityVO.setTnl(waterQualityVOTemp.getTnl() );
waterQualityVO.setDsdh(waterQualityVOTemp.getDsdh());
waterQualityVO.setDsyh(waterQualityVOTemp.getDsyh());
}
return waterQualityVO;
}
......
......@@ -33,7 +33,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";// 水 COD TP TN NH3H
String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";//能耗报表
String view4411 = "4411ed3d78634bcdcd700f6e33724025";
String view4411 = "4411ed3d78634bcdcd700f6e33724025";//生产运营周报
private JdbcTemplate getJdbcTemplate(){
JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
......
......@@ -34,4 +34,10 @@ public class FRportlCommandCenterVO implements Serializable {
this.valueTb = valueTb;
this.valueHb = valueHb;
}
public FRportlCommandCenterVO(String title ,String value, String valueTb, String valueHb) {
this.title = title;
this.value = value;
this.valueTb = valueTb;
this.valueHb = valueHb;
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!