08bdd8bd 康伟

kangwei :修改reportUtils工具类

1 个父辈 62269c2c
...@@ -72,9 +72,9 @@ public class ReportViewUtil { ...@@ -72,9 +72,9 @@ public class ReportViewUtil {
72 if(!StringUtils.isEmpty(itemIds)) { 72 if(!StringUtils.isEmpty(itemIds)) {
73 itemIds = itemIds.substring(1); 73 itemIds = itemIds.substring(1);
74 } 74 }
75 sb.append("`a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( "); 75 sb.append(" `a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( ");
76 76
77 sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv v WHERE 1=1 "); 77 sb.append(" SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv v WHERE 1=1 ");
78 if(StringUtils.isNotEmpty(departIds)){ 78 if(StringUtils.isNotEmpty(departIds)){
79 sb.append(" and depart_id in ("+inSqlPart+") "); 79 sb.append(" and depart_id in ("+inSqlPart+") ");
80 } 80 }
...@@ -141,16 +141,16 @@ public class ReportViewUtil { ...@@ -141,16 +141,16 @@ public class ReportViewUtil {
141 itemIds = itemIds.substring(1); 141 itemIds = itemIds.substring(1);
142 } 142 }
143 sb.append("`a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( "); 143 sb.append("`a`.`depart_id` AS `depart_id`,`a`.`data_id` AS `id`,`a`.`data_time` AS `time` from (( ");
144 sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 "); 144 sb.append(" SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 ");
145 if(StringUtils.isNotEmpty(departIds)){ 145 if(StringUtils.isNotEmpty(departIds)){
146 sb.append("and depart_id in ("+inSqlPart+")"); 146 sb.append(" and depart_id in ("+inSqlPart+")");
147 } 147 }
148 if(!StringUtils.isEmpty(dataTime)) { 148 if(!StringUtils.isEmpty(dataTime)) {
149 sb.append("and data_time like'"+dataTime+"%'"); 149 sb.append("and data_time like'"+dataTime+"%'");
150 } 150 }
151 sb.append("and reit_id in ("+itemIds+")"); 151 sb.append(" and reit_id in ("+itemIds+")");
152 152
153 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`)"); 153 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`)");
154 154
155 return sb.toString(); 155 return sb.toString();
156 } 156 }
...@@ -204,17 +204,17 @@ public class ReportViewUtil { ...@@ -204,17 +204,17 @@ public class ReportViewUtil {
204 sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 "); 204 sb.append("SELECT data_id,reit_id,item_value,data_time,depart_id FROM f_report_itemv WHERE 1=1 ");
205 205
206 if(!StringUtils.isEmpty(departIds)) { 206 if(!StringUtils.isEmpty(departIds)) {
207 sb.append(" and depart_id in ("+inSqlPart+")"); 207 sb.append(" and depart_id in ("+inSqlPart+") ");
208 } 208 }
209 if(!StringUtils.isEmpty(startTime)) { 209 if(!StringUtils.isEmpty(startTime)) {
210 sb.append("and data_time >='"+startTime+"'"); 210 sb.append(" and data_time >='"+startTime+"' ");
211 } 211 }
212 if(!StringUtils.isEmpty(endTime)) { 212 if(!StringUtils.isEmpty(endTime)) {
213 sb.append("and data_time <='"+endTime+"'"); 213 sb.append(" and data_time <='"+endTime+"' ");
214 } 214 }
215 sb.append("and reit_id in ("+itemIds+")"); 215 sb.append(" and reit_id in ("+itemIds+") ");
216 216
217 sb.append(") `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`depart_id`)"); 217 sb.append(") `a` left join `f_report_item` `d` on((`a`.`reit_id` = `d`.`id`))) where 1=1 group by `a`.`depart_id`) ");
218 218
219 return sb.toString(); 219 return sb.toString();
220 } 220 }
......
...@@ -64,15 +64,16 @@ public class DateVO { ...@@ -64,15 +64,16 @@ public class DateVO {
64 this.nowYear = Integer.parseInt(DateUtils.dateformat(currentDate,"yyyy")); 64 this.nowYear = Integer.parseInt(DateUtils.dateformat(currentDate,"yyyy"));
65 //同比时间 65 //同比时间
66 this.lastYear = nowYear -1 ;//去年 66 this.lastYear = nowYear -1 ;//去年
67 this.lastYearMonth = DateUtils.getHbMonth(currentDate); 67 this.lastYearMonth = DateUtils.getTbMonth(this.nowMonth);
68 System.out.println(" lastYearMonth "+lastYearMonth); 68 //System.out.println(" lastYearMonth "+lastYearMonth);
69 this.lastYearMonthStartTime = lastYearMonth+"-01"; 69 this.lastYearMonthStartTime = lastYearMonth+"-01";
70 this.lastYearMonthStartTime = lastYearMonth+"-31"; 70 this.lastYearMonthEndTime = lastYearMonth+"-31";
71 this.lastYearStartDate = this.lastYear+"-01-01"; 71 this.lastYearStartDate = this.lastYear+"-01-01";
72 this.lastYearEndDate = this.lastYear+"-12-31"; 72 this.lastYearEndDate = this.lastYear+"-12-31";
73 73
74 //环比时间 74 //环比时间
75 this.lastMonth = DateUtils.getHbMonth(currentDate);// 75 this.lastMonth = DateUtils.getHbMonth(this.nowMonth);//
76 System.out.println(" lastMonth "+lastMonth);
76 this.lastMonthStartTime = lastMonth+"-01"; 77 this.lastMonthStartTime = lastMonth+"-01";
77 this.lastMonthEndTime = lastMonth+"-31"; 78 this.lastMonthEndTime = lastMonth+"-31";
78 79
......
...@@ -51,6 +51,7 @@ public class DigitalUtils { ...@@ -51,6 +51,7 @@ public class DigitalUtils {
51 if(StringUtils.isNotEmpty(val2)){ 51 if(StringUtils.isNotEmpty(val2)){
52 BigDecimal num2 = new BigDecimal(val2); 52 BigDecimal num2 = new BigDecimal(val2);
53 result = result.add( num2 ); 53 result = result.add( num2 );
54 result = result.multiply( num2).setScale(2, BigDecimal.ROUND_HALF_UP);
54 } 55 }
55 return result.toString(); 56 return result.toString();
56 } 57 }
......
...@@ -19,23 +19,51 @@ import java.util.regex.Pattern; ...@@ -19,23 +19,51 @@ import java.util.regex.Pattern;
19 */ 19 */
20 public class JSUtils { 20 public class JSUtils {
21 21
22 // 表达式字符合法性校验正则模式,静态常量化可以降低每次使用都要编译地消耗 22 public static String add(Object obj1 , Object obj2){
23 private static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9\\.+-/*()= ]+"); 23 String expression = obj1+ "+" + obj2;
24 // 运算符优先级map 24 return executeExpression(expression,"0.00");
25 private static final Map<String, Integer> OPT_PRIORITY_MAP = new HashMap<String, Integer>() { 25 }
26 private static final long serialVersionUID = 6968472606692771458L; 26 public static String subtract(Object obj1 , Object obj2){
27 { 27 String expression = obj1+ "-" + obj2;
28 put("(", 0); 28 return executeExpression(expression,"0.00");
29 put("+", 2); 29 }
30 put("-", 2); 30 public static String multiply(Object obj1 , Object obj2){
31 put("*", 3); 31 String expression = obj1+ "*" + obj2;
32 put("/", 3); 32 return executeExpression(expression,"0.00");
33 put(")", 7); 33 }
34 put("=", 20); 34 public static String divide(Object obj1 , Object obj2){
35 } 35 String expression = obj1+ "/" + obj2;
36 }; 36 return executeExpression(expression,"0.00");
37 }
37 38
39 /***
40 * 格式化结果,保留两位小数
41 * @param obj1
42 * @return
43 */
44 public static String format(Object obj1 ){
45 return format(obj1,null);
46 }
38 47
48 /***
49 * 格式化结果,指定格式,默认保留两位小数
50 * @param obj1
51 * @param decimalFormat
52 * @return
53 */
54 public static String format(Object obj1 , String decimalFormat){
55 String result = null;
56 try{
57 if(obj1 != null ){
58 if(decimalFormat == null ) decimalFormat = "0.00";
59 DecimalFormat df = new DecimalFormat(decimalFormat);
60 result = df.format(Double.parseDouble(obj1.toString()));
61 }
62 }catch(Exception e){
63 e.printStackTrace();
64 }
65 return result;
66 }
39 /** 67 /**
40 * 输入加减乘除表达式字符串,返回计算结果 68 * 输入加减乘除表达式字符串,返回计算结果
41 * 69 *
...@@ -50,10 +78,29 @@ public class JSUtils { ...@@ -50,10 +78,29 @@ public class JSUtils {
50 DecimalFormat df = new DecimalFormat(decimalFormat); 78 DecimalFormat df = new DecimalFormat(decimalFormat);
51 result = df.format(aDouble); 79 result = df.format(aDouble);
52 }catch(Exception e ){ 80 }catch(Exception e ){
53 // e.printStackTrace(); 81 // e.printStackTrace();
54 } 82 }
55 return result; 83 return result;
56 } 84 }
85
86 // 表达式字符合法性校验正则模式,静态常量化可以降低每次使用都要编译地消耗
87 private static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9\\.+-/*()= ]+");
88 // 运算符优先级map
89 private static final Map<String, Integer> OPT_PRIORITY_MAP = new HashMap<String, Integer>() {
90 private static final long serialVersionUID = 6968472606692771458L;
91 {
92 put("(", 0);
93 put("+", 2);
94 put("-", 2);
95 put("*", 3);
96 put("/", 3);
97 put(")", 7);
98 put("=", 20);
99 }
100 };
101
102
103
57 public static double executeExpression(String expression) { 104 public static double executeExpression(String expression) {
58 // 非空校验 105 // 非空校验
59 if (null == expression || "".equals(expression.trim())) { 106 if (null == expression || "".equals(expression.trim())) {
......
1 package com.skua.modules.algorithm.service.impl;
2
3 import com.skua.common.report.ReportViewUtil;
4 import com.skua.core.context.SpringContextUtils;
5 import org.springframework.jdbc.core.JdbcTemplate;
6 import org.springframework.stereotype.Service;
7
8
9 /**
10 * @auther kangwei
11 * @create 2024-11-01-10:09
12 */
13 @Service("reportItemvService")
14 public class ReportItemvService {
15
16
17 String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";// 水 COD TP TN NH3H
18 String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";//能耗报表
19 String view4411 = "4411ed3d78634bcdcd700f6e33724025";//生产运营周报
20
21 private JdbcTemplate getJdbcTemplate(){
22 //主库数据源
23 JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
24 return masterDB;
25 }
26
27 public String getSumCSL(String departId ,String startTime ,String endTime){
28 String dataViewName2119 = ReportViewUtil.buildViewLike(view2119,"CSL", departId, startTime,endTime);
29 String sql = "select sum(aaa.CSL) from " + dataViewName2119+ "aaa";
30 String csl = getJdbcTemplate().queryForObject(sql,String.class);
31 return csl;
32 }
33 /* public List<Map<String,Object>> getDeptCSL(String departId , String startTime , String endTime){
34
35 }*/
36
37 public String getSumDLHJ(String departId ,String startTime ,String endTime){
38 String dataViewName3a24 = ReportViewUtil.buildViewLike(view3a24,"DLHJ", departId, startTime,endTime);
39 String sql = "select sum(aaa.DLHJ) from " + dataViewName3a24+ "aaa";
40 String dlhj = getJdbcTemplate().queryForObject(sql,String.class);
41 return dlhj;
42 }
43 /* public List<Map<String,Object>> getDeptDLHJ(String departId , String startTime , String endTime){
44
45 }*/
46 }
...@@ -23,13 +23,12 @@ import javax.servlet.http.HttpServletRequest; ...@@ -23,13 +23,12 @@ import javax.servlet.http.HttpServletRequest;
23 * @create 2024-10-14-16:46 23 * @create 2024-10-14-16:46
24 */ 24 */
25 @Slf4j 25 @Slf4j
26 @Api(tags="在线考试-试卷") 26 @Api(tags="测试报表")
27 @RestController("testReportController") 27 @RestController("testReportController")
28 @RequestMapping("/web/edu/paper")
29 public class TestReportSqlController { 28 public class TestReportSqlController {
30 29
31 @AutoLog(value = "在线考试--构造填报报表视图") 30 @AutoLog(value = "测试报表")
32 @ApiOperation(value="在线考试-构造填报报表视图", notes="在线考试-构造填报报表视图") 31 @ApiOperation(value="测试报表", notes="测试报表")
33 @GetMapping(value = "/testReportSql") 32 @GetMapping(value = "/testReportSql")
34 public Result<String> testReportSql( 33 public Result<String> testReportSql(
35 @RequestParam(name="reportId") String reportId, 34 @RequestParam(name="reportId") String reportId,
......
...@@ -89,8 +89,6 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { ...@@ -89,8 +89,6 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
89 } 89 }
90 // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title"))); 90 // resultMap.put(ConvertUtils.getString(dataMap.get("id")), ConvertUtils.getString(dataMap.get("create_by"))+""+ConvertUtils.getString(dataMap.get("title")));
91 } 91 }
92
93
94 factoryInfoVOList = new ArrayList(factoryInfoMap.values()); 92 factoryInfoVOList = new ArrayList(factoryInfoMap.values());
95 93
96 // 添加:中冶数据 94 // 添加:中冶数据
...@@ -239,9 +237,12 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService { ...@@ -239,9 +237,12 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
239 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 "); 237 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 ");
240 sql.append(" "+dataViewName2119 +" aaa "); 238 sql.append(" "+dataViewName2119 +" aaa ");
241 System.out.println(sql.toString()); 239 System.out.println(sql.toString());
242 waterQualityVO = getJdbcTemplate().queryForObject(sql.toString(),new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class)); 240 List<WaterQualityVO> waterQualityVOList = getJdbcTemplate().query(sql.toString(),new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
243 241 if(waterQualityVOList != null && !waterQualityVOList.isEmpty()){
244 242 waterQualityVO = waterQualityVOList.get(0);
243 }else{
244 waterQualityVO = new WaterQualityVO();
245 }
245 // if(waterQualityVO == null )waterQualityVO = new WaterQualityVO(); 246 // if(waterQualityVO == null )waterQualityVO = new WaterQualityVO();
246 //负荷率 CSL/设计规模 () 247 //负荷率 CSL/设计规模 ()
247 String factoryProScaleSql = "select round( ("+waterQualityVO.getCsl() +"/(pro_scale * 100) ),2) fhl from sys_factory_info where depart_id = '"+departId+"'"; 248 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 { ...@@ -257,10 +258,15 @@ public class JTDisplayScreenServiceImpl implements IJTDisplayScreenService {
257 sql2.append( " "+dataViewName3a24+" aaa "); 258 sql2.append( " "+dataViewName3a24+" aaa ");
258 259
259 System.out.println("sql2 = "+sql2.toString()); 260 System.out.println("sql2 = "+sql2.toString());
260 WaterQualityVO waterQualityVOTemp = getJdbcTemplate().queryForObject( sql2.toString(), new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class)); 261 waterQualityVOList = getJdbcTemplate().query( sql2.toString(), new BeanPropertyRowMapper<WaterQualityVO>(WaterQualityVO.class));
261 waterQualityVO.setTnl(waterQualityVOTemp.getTnl() ); 262 if(waterQualityVOList != null && !waterQualityVOList.isEmpty() ){
262 waterQualityVO.setDsdh(waterQualityVOTemp.getDsdh()); 263 WaterQualityVO waterQualityVOTemp = waterQualityVOList.get(0);
263 waterQualityVO.setDsyh(waterQualityVOTemp.getDsyh()); 264 waterQualityVO.setTnl(waterQualityVOTemp.getTnl() );
265 waterQualityVO.setDsdh(waterQualityVOTemp.getDsdh());
266 waterQualityVO.setDsyh(waterQualityVOTemp.getDsyh());
267 }
268
269
264 270
265 return waterQualityVO; 271 return waterQualityVO;
266 } 272 }
......
...@@ -33,7 +33,7 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -33,7 +33,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
33 33
34 String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";// 水 COD TP TN NH3H 34 String view2119 = "2119ecbf53a1d2d0708258ff67cfd9e1";// 水 COD TP TN NH3H
35 String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";//能耗报表 35 String view3a24 = "3a243d5715b9e1a3753c180872ca0df9";//能耗报表
36 String view4411 = "4411ed3d78634bcdcd700f6e33724025"; 36 String view4411 = "4411ed3d78634bcdcd700f6e33724025";//生产运营周报
37 37
38 private JdbcTemplate getJdbcTemplate(){ 38 private JdbcTemplate getJdbcTemplate(){
39 JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master"); 39 JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
......
...@@ -34,4 +34,10 @@ public class FRportlCommandCenterVO implements Serializable { ...@@ -34,4 +34,10 @@ public class FRportlCommandCenterVO implements Serializable {
34 this.valueTb = valueTb; 34 this.valueTb = valueTb;
35 this.valueHb = valueHb; 35 this.valueHb = valueHb;
36 } 36 }
37 public FRportlCommandCenterVO(String title ,String value, String valueTb, String valueHb) {
38 this.title = title;
39 this.value = value;
40 this.valueTb = valueTb;
41 this.valueHb = valueHb;
42 }
37 } 43 }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!