5700fca7 康伟

kangwei:

    1 设备运行时,补全日期、月份数据
1 个父辈 f79698db
1 package com.skua.modules.common.service;
2
3 import java.util.List;
4 import java.util.Map;
5
6 /**
7 * @auther kangwei
8 * @create 2024-11-19-12:09
9 */
10 public interface IPgCommonService {
11 List<Map<String, Object>> queryForList(String sql);
12 Map<String, Object> queryForMap(String sql);
13 }
1 package com.skua.modules.common.service.impl;
2
3 import com.baomidou.dynamic.datasource.annotation.DS;
4 import com.skua.modules.common.service.IPgCommonService;
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.jdbc.core.JdbcTemplate;
7 import org.springframework.stereotype.Service;
8
9 import java.util.List;
10 import java.util.Map;
11
12 /**
13 * @auther kangwei
14 * @create 2024-11-19-12:10
15 */
16 @Service
17 @DS("pg-db")
18 public class PgCommonServiceImpl implements IPgCommonService {
19 @Autowired
20 private JdbcTemplate jdbcTemplate;
21 @Override
22 public List<Map<String, Object>> queryForList(String sql) {
23 return jdbcTemplate.queryForList(sql);
24 }
25
26 @Override
27 public Map<String, Object> queryForMap(String sql) {
28 return jdbcTemplate.queryForMap(sql);
29 }
30
31
32 }
...@@ -8,7 +8,7 @@ import com.skua.core.context.SpringContextUtils; ...@@ -8,7 +8,7 @@ import com.skua.core.context.SpringContextUtils;
8 import com.skua.core.service.IFactoryInfoService; 8 import com.skua.core.service.IFactoryInfoService;
9 import com.skua.core.util.ConvertUtils; 9 import com.skua.core.util.ConvertUtils;
10 import com.skua.core.util.DateUtils; 10 import com.skua.core.util.DateUtils;
11 import com.skua.modules.equipment.vo.EquipmentRealTimeVO; 11 import com.skua.modules.common.service.IPgCommonService;
12 import com.skua.modules.erp.vo.MetricInfoVO; 12 import com.skua.modules.erp.vo.MetricInfoVO;
13 import com.skua.modules.erp.vo.RealTimeHistoryDataVO; 13 import com.skua.modules.erp.vo.RealTimeHistoryDataVO;
14 import com.skua.modules.guest.util.DateUtil; 14 import com.skua.modules.guest.util.DateUtil;
...@@ -26,8 +26,10 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -26,8 +26,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RequestParam; 26 import org.springframework.web.bind.annotation.RequestParam;
27 import org.springframework.web.bind.annotation.RestController; 27 import org.springframework.web.bind.annotation.RestController;
28 28
29 import java.text.ParseException; 29 import java.sql.PreparedStatement;
30 import java.text.SimpleDateFormat; 30 import java.sql.ResultSet;
31 import java.sql.ResultSetMetaData;
32 import java.sql.SQLException;
31 import java.util.*; 33 import java.util.*;
32 34
33 @Api(tags="设备-设备运行台时报表") 35 @Api(tags="设备-设备运行台时报表")
...@@ -40,15 +42,20 @@ public class TestMetricInfoController { ...@@ -40,15 +42,20 @@ public class TestMetricInfoController {
40 42
41 @Autowired 43 @Autowired
42 private IFactoryInfoService iFactoryInfoService; 44 private IFactoryInfoService iFactoryInfoService;
43 45 @Autowired
46 private IPgCommonService pgCommonService;
44 47
45 @AutoLog(value = "设备-设备运行台时报表") 48 @AutoLog(value = "设备-设备运行台时报表")
46 @ApiOperation(value = "设备-设备运行台时报表(timeType:1 当日数据,=2表示月数据;=3表示年数据)", notes = "设备-设备运行台时报表") 49 @ApiOperation(value = "设备-设备运行台时报表(timeType:1 当日数据,=2表示月数据;=3表示年数据)", notes = "设备-设备运行台时报表")
47 @GetMapping(value = "/realTimeHistoryData") 50 @GetMapping(value = "/realTimeHistoryData")
48 public Result<RealTimeHistoryDataVO> equipRealTimeHistoryDataCtrl(@RequestParam(value = "departId") String departId, 51 public Result<RealTimeHistoryDataVO> equipRealTimeHistoryDataCtrl(@RequestParam(value = "departId") String departId,
49 @RequestParam(value = "startTime") String startTime, 52 @RequestParam(value = "time") String time,@RequestParam(value = "timeType",defaultValue = "1")String timeType,
50 @RequestParam(value = "endTime") String endTime, 53 @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
51 @RequestParam(value = "timeType",defaultValue = "1")String timeType) { 54
55 if("3".equals(timeType)){
56 startTime = time+"-01-01";
57 endTime = time+"-12-31";
58 }
52 if(StringUtils.isEmpty(startTime)){ 59 if(StringUtils.isEmpty(startTime)){
53 startTime = DateUtil.getCurrentDate() ; 60 startTime = DateUtil.getCurrentDate() ;
54 } 61 }
...@@ -61,6 +68,7 @@ public class TestMetricInfoController { ...@@ -61,6 +68,7 @@ public class TestMetricInfoController {
61 if(endTime != null && endTime.length() < 19){ 68 if(endTime != null && endTime.length() < 19){
62 endTime = endTime+" 23:59:59"; 69 endTime = endTime+" 23:59:59";
63 } 70 }
71
64 Result<RealTimeHistoryDataVO> result = new Result<>(); 72 Result<RealTimeHistoryDataVO> result = new Result<>();
65 RealTimeHistoryDataVO realTimeHistoryDataVO = new RealTimeHistoryDataVO(); 73 RealTimeHistoryDataVO realTimeHistoryDataVO = new RealTimeHistoryDataVO();
66 //String fields = "TCSWSCLC_PLC300_Tag182,TCSWSCLC_PLC300_Tag185"; 74 //String fields = "TCSWSCLC_PLC300_Tag182,TCSWSCLC_PLC300_Tag185";
...@@ -94,113 +102,132 @@ public class TestMetricInfoController { ...@@ -94,113 +102,132 @@ public class TestMetricInfoController {
94 fields = fields.substring(0, fields.length() - 1); 102 fields = fields.substring(0, fields.length() - 1);
95 } 103 }
96 List<Map<String, Object>> pgDataList = queryFactoryInfos(departId, fields, startTime, endTime, timeType); 104 List<Map<String, Object>> pgDataList = queryFactoryInfos(departId, fields, startTime, endTime, timeType);
97
98 List<Map<String, Object>> dataList = null; 105 List<Map<String, Object>> dataList = null;
106 if (timeType.equals("1")){//获取时数据
107 dataList = getHourData(metricInfoVOList ,pgDataList);
108 }else{//获取日数据或月数据
109 dataList = getDaysAndMonthsData(metricInfoVOList ,pgDataList,startTime, endTime,timeType);
110 }
111 realTimeHistoryDataVO.setHeadList( metricInfoVOList);
112 realTimeHistoryDataVO.setDataList( dataList );
113 result.setResult( realTimeHistoryDataVO);
114 return result;
115 }
99 116
117 private List<Map<String, Object>> getHourData( List<MetricInfoVO> metricInfoVOList , List<Map<String, Object>> pgDataList){
118 List<Map<String, Object>> dataList = new ArrayList<>();
100 if(pgDataList != null ) { 119 if(pgDataList != null ) {
101 dataList = new ArrayList<>(pgDataList.size()); 120 dataList = new ArrayList<>(pgDataList.size());
102 Map<String, Object> dataMap = null; 121 Map<String, Object> dataMap = null;
103 //elect ts as time,nm as monitorId,v as monitorValue 122 //select ts as time,nm as monitorId,v as monitorValue
104 String equipmentCode = null;
105 for (Map<String, Object> paramMap : pgDataList) { 123 for (Map<String, Object> paramMap : pgDataList) {
106 dataMap = new HashMap<>(); 124 dataMap = new HashMap<>();
107 dataMap.put("time",paramMap.get("time") ); 125 dataMap.put("time",DateUtils.formatTime(Long.parseLong(paramMap.get("time") + "000")) );
108 if(timeType.equals( "1")){
109 dataMap.put("time",DateUtils.formatTime(Long.parseLong(paramMap.get("time") + "000")) );
110 }
111 for(MetricInfoVO metricInfoVO : metricInfoVOList){ 126 for(MetricInfoVO metricInfoVO : metricInfoVOList){
112 dataMap.put( metricInfoVO.getEquipmentCode()+"_YX" , JSUtils.format(paramMap.get(metricInfoVO.getYxExpress()),"0.00"));//运行 127 dataMap.put( metricInfoVO.getEquipmentCode()+"_YX" , JSUtils.format(paramMap.get(metricInfoVO.getYxExpress()),"0.00"));//运行
113 dataMap.put( metricInfoVO.getEquipmentCode()+"_GZ" , JSUtils.format(paramMap.get(metricInfoVO.getGzExpress()),"0.00"));//故障 128 dataMap.put( metricInfoVO.getEquipmentCode()+"_GZ" , JSUtils.format(paramMap.get(metricInfoVO.getGzExpress()),"0.00"));//故障
114 //时数据 129 //时数据
115 if (timeType.equals("1")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停 130 dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
116 //日数据
117 if (timeType.equals("2")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
118 //月数据
119 if (timeType.equals("3")) dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 30*24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
120 } 131 }
121 dataList.add( dataMap ); 132 dataList.add( dataMap );
122 } 133 }
123 } 134 }
124 /* //拼装数据 135 return dataList;
125 Map<String, Map<String,String>> linkedHashMap = new LinkedHashMap<String, Map<String,String>>();//返回数据结果 136 }
126 String timeTemp = null; 137
127 Map<String,String> dataMap = null; 138 private List<Map<String, Object>> getDaysAndMonthsData( List<MetricInfoVO> metricInfoVOList , List<Map<String, Object>> pgDataList,String startTime, String endTime,String timeType){
128 if(pgDataList != null ){ 139 List<Map<String, Object>> dataList = new ArrayList<>();
129 //elect ts as time,nm as monitorId,v as monitorValue 140 List<String> timeList = null;
130 for( Map<String, Object> paramMap : pgDataList){ 141 Map<String, Object> dataMap = null;//数据变量
131 timeTemp = DateUtils.formatTime(Long.parseLong(paramMap.get("time") + "000")); 142 //日数据
132 dataMap = linkedHashMap.get(timeTemp); 143 if (timeType.equals("2")){
133 if(dataMap == null ){ 144 timeList = DateUtil.getDaysBetween(startTime, endTime,"yyyy-MM-dd HH:mm:ss");
134 dataMap = new HashMap<>(); 145 }
135 dataMap.put("time",timeTemp); 146 //月数据
136 for (Map.Entry<String, String> entry : nameMap.entrySet()) { 147 if (timeType.equals("3")){
137 dataMap.put(entry.getKey(),"0"); 148 timeList = DateUtil.getMonthsBetween(startTime, endTime,"yyyy-MM-dd HH:mm:ss");
138 } 149 }
139 } 150 for(String date : timeList){
140 // 使用For-Each迭代entries,通过Map.entrySet遍历key和value 151 dataMap = new HashMap<>();
141 for (Map.Entry<String, String> entry : nameMap.entrySet()) { 152 dataMap.put("time",date);
142 System.out.println("entry.getKey()" +entry.getKey()+ "****"+"paramMap.get() = "+paramMap.get(entry.getKey())); 153 for(MetricInfoVO metricInfoVO : metricInfoVOList){
143 if(entry.getKey().equals( ConvertUtils.getString(paramMap.get(entry.getKey())) )){ 154 dataMap.put( metricInfoVO.getEquipmentCode()+"_YX" , "0.00");//运行
144 dataMap.put( entry.getValue() , ConvertUtils.getString(paramMap.get(entry.getKey()))); 155 dataMap.put( metricInfoVO.getEquipmentCode()+"_GZ" , "0.00");//故障
156 dataMap.put( metricInfoVO.getEquipmentCode()+"_ZT" ,"0.00" );//暂停
157 }
158 dataList.add(dataMap);
159 }
160
161 if(pgDataList != null ) {
162 for(Map<String, Object> dataMapTemp : dataList){
163 //select ts as time,nm as monitorId,v as monitorValue
164 for (Map<String, Object> paramMap : pgDataList) {
165 if( dataMapTemp.get("time").equals( paramMap.get("time") ) ){
166 for(MetricInfoVO metricInfoVO : metricInfoVOList){
167 dataMapTemp.put( metricInfoVO.getEquipmentCode()+"_YX" , JSUtils.format(paramMap.get(metricInfoVO.getYxExpress()),"0.00"));//运行
168 dataMapTemp.put( metricInfoVO.getEquipmentCode()+"_GZ" , JSUtils.format(paramMap.get(metricInfoVO.getGzExpress()),"0.00"));//故障
169 //时数据
170 if (timeType.equals("1")) dataMapTemp.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
171 //日数据
172 if (timeType.equals("2")) dataMapTemp.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
173 //月数据
174 if (timeType.equals("3")) dataMapTemp.put( metricInfoVO.getEquipmentCode()+"_ZT" ,JSUtils.subtract( 30*24*60, paramMap.get(metricInfoVO.getYxExpress()),paramMap.get(metricInfoVO.getGzExpress()) ) );//暂停
175 }
176 break;
145 } 177 }
146 } 178 }
147 linkedHashMap.put(timeTemp,dataMap);
148 } 179 }
149 }*/ 180 }
150 181 return dataList;
151 realTimeHistoryDataVO.setHeadList( metricInfoVOList);
152 realTimeHistoryDataVO.setDataList( dataList );
153 result.setResult( realTimeHistoryDataVO);
154 return result;
155 } 182 }
156 183
157 public List<Map<String, Object>> queryFactoryInfos(String departId, String fields, String startTime, String endTime, String tableType) { 184
185 public List<Map<String, Object>> queryFactoryInfos(String departId, String fields, String startTime, String endTime, String timeType) {
158 String fieldSqlPart = ""; 186 String fieldSqlPart = "";
159 String[] fieldsArr = fields.split(","); 187 String[] fieldsArr = fields.split(",");
160 188
161 for(int i = 0; i < fieldsArr.length; ++i) { 189 for(int i = 0; i < fieldsArr.length; ++i) {
162 fieldSqlPart = fieldSqlPart + ",'" + fieldsArr[i] + "'"; 190 fieldSqlPart = fieldSqlPart + ",'" + fieldsArr[i] + "'";
163 } 191 }
164
165 if (!StringUtils.isEmpty(fieldSqlPart)) { 192 if (!StringUtils.isEmpty(fieldSqlPart)) {
166 fieldSqlPart = fieldSqlPart.substring(1); 193 fieldSqlPart = fieldSqlPart.substring(1);
167 } 194 }
168
169 JdbcTemplate pgDB = (JdbcTemplate)SpringContextUtils.getBean("pg-db");
170 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); 195 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
171 List<Map<String, Object>> result = new ArrayList(); 196 List<Map<String, Object>> result = new ArrayList();
172 List<Map<String, Object>> factoryDesign = masterDB.queryForList("select * from sys_factory_device where depart_id = '" + departId + "'"); 197 List<Map<String, Object>> factoryDesign = masterDB.queryForList("select * from sys_factory_device where depart_id = '" + departId + "'");
173 if (factoryDesign != null && factoryDesign.size() != 0) { 198 if (factoryDesign != null && factoryDesign.size() != 0) {
174 String countTableName = ConvertUtils.getString(((Map)factoryDesign.get(0)).get("device_id")); 199 String countTableName = ConvertUtils.getString(((Map)factoryDesign.get(0)).get("device_id"));
175 String sql = null; 200 String sql = null;
176 //时数据
177 if (tableType.equals("1")) {
178 sql = "select ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? ";
179 }
180 //日数据
181 if (tableType.equals("2")) {
182 sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from (";
183 sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM-DD') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? ";
184 sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc";
185 }
186 //月数据
187 if (tableType.equals("3")) {
188 sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from (";
189 sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>=? and ts <? ";
190 sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc";
191 }
192 try { 201 try {
193 String tsStartTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm:ss")) / 1000L); 202 String tsStartTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
194 String tsEndTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm:ss")) / 1000L); 203 String tsEndTime = String.valueOf(DateUtils.getMillis(DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm:ss")) / 1000L);
195 List dataList = null; 204 //时数据
205 if (timeType.equals("1")) {
206 sql = "select ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
207 }
208 //日数据
209 if (timeType.equals("2")) {
210 sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from (";
211 sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM-DD') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
212 sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc";
213 }
214 //月数据
215 if (timeType.equals("3")) {
216 sql = "select aaa.date as time , aaa.monitorId ,SUM( to_number ( aaa.monitorValue, '9999999999999999.99' ) )as monitorValue from (";
217 sql += "select to_char(to_timestamp(ts::INT8)::DATE,'YYYY-MM') as date, ts as time,nm as monitorId,v as monitorValue from " + countTableName + "_count where nm in(" + fieldSqlPart + ") and ts>='"+tsStartTime+"' and ts <'"+tsEndTime+"' ";
218 sql += " )aaa group by aaa.date ,aaa.monitorId order by aaa.date asc";
219 }
220 List<Map<String, Object>> dataList = null;
196 try { 221 try {
197 dataList = pgDB.queryForList(sql, new Object[]{tsStartTime, tsEndTime}); 222 // List<Map<String, Object>> pgDataList = iFactoryInfoService.queryFactoryInfos(departId, fields, startTime, endTime, "1");
223 dataList = pgCommonService.queryForList(sql);
198 } catch (DataAccessException var23) { 224 } catch (DataAccessException var23) {
199 Object pgDbSlaveObject = SpringContextUtils.getBean("pg-db-slave"); 225 Object pgDbSlaveObject = SpringContextUtils.getBean("pg-db-slave");
200 if (pgDbSlaveObject != null) { 226 if (pgDbSlaveObject != null) {
201 pgDB = (JdbcTemplate)pgDbSlaveObject; 227 JdbcTemplate pgDB = (JdbcTemplate)pgDbSlaveObject;
202 dataList = pgDB.queryForList(sql, new Object[]{tsStartTime, tsEndTime}); 228 dataList = pgDB.queryForList(sql);
203 } 229 }
230 var23.printStackTrace();
204 } 231 }
205 this.dataRowToCellByTime(result, dataList); 232 this.dataRowToCellByTime(result, dataList);
206 } catch (Exception var24) { 233 } catch (Exception var24) {
...@@ -216,7 +243,6 @@ public class TestMetricInfoController { ...@@ -216,7 +243,6 @@ public class TestMetricInfoController {
216 List<String> orderTsList = new ArrayList(); 243 List<String> orderTsList = new ArrayList();
217 Map<String, Map<String, Object>> resultMap = new HashMap(); 244 Map<String, Map<String, Object>> resultMap = new HashMap();
218 Iterator var5 = dataList.iterator(); 245 Iterator var5 = dataList.iterator();
219
220 while(true) { 246 while(true) {
221 while(var5.hasNext()) { 247 while(var5.hasNext()) {
222 Map<String, Object> tempMap = (Map)var5.next(); 248 Map<String, Object> tempMap = (Map)var5.next();
......
...@@ -2,11 +2,9 @@ package com.skua.modules.guest.util; ...@@ -2,11 +2,9 @@ package com.skua.modules.guest.util;
2 2
3 import java.text.ParseException; 3 import java.text.ParseException;
4 import java.text.SimpleDateFormat; 4 import java.text.SimpleDateFormat;
5 import java.time.LocalDate; 5 import java.time.*;
6 import java.time.LocalDateTime;
7 import java.time.Period;
8 import java.time.ZoneId;
9 import java.time.format.DateTimeFormatter; 6 import java.time.format.DateTimeFormatter;
7 import java.time.temporal.ChronoUnit;
10 import java.util.*; 8 import java.util.*;
11 import java.util.stream.Stream; 9 import java.util.stream.Stream;
12 10
...@@ -97,6 +95,62 @@ public class DateUtil { ...@@ -97,6 +95,62 @@ public class DateUtil {
97 } 95 }
98 96
99 97
98 /***
99 * 获取两个时间的日期
100 * @param start
101 * @param end
102 * @return
103 */
104 public static List<String> getDaysBetween(String start, String end,String format) {
105 List<String> days = new ArrayList<>();
106 if(format == null ){
107 format = "yyyy-MM-dd";
108 }
109 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
110 // 解析日期
111 LocalDate startDate = LocalDate.parse(start, formatter);
112 LocalDate endDate = LocalDate.parse(end, formatter);
113 LocalDate currentDate = LocalDate.now();//创建一个LocalData对象获取当前日期
114 if(endDate.isAfter( currentDate)){
115 endDate = currentDate;
116 }
117 long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);
118 for (int i = 0; i <= numOfDaysBetween; i++) {
119 LocalDate date = startDate.plusDays(i);
120 days.add(date.toString()); // 格式化为 yyyy-MM
121 }
122 return days;
123 }
124 /***
125 * 获取两个时间的月份
126 * @param start
127 * @param end
128 * @return
129 */
130 public static List<String> getMonthsBetween(String start, String end,String format) {
131 if(format == null ){
132 format = "yyyy-MM-dd";
133 }
134 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
135 // 解析日期
136 LocalDate startDate = LocalDate.parse(start, formatter);
137 LocalDate endDate = LocalDate.parse(end, formatter);
138 LocalDate currentDate = LocalDate.now();//创建一个LocalData对象获取当前日期
139 if(endDate.isAfter( currentDate)){
140 endDate = currentDate;
141 }
142 List<String> months = new ArrayList<>();
143 // 获取起始和结束月份
144 YearMonth startMonth = YearMonth.from(startDate);
145 YearMonth endMonth = YearMonth.from(endDate);
146 // 遍历月份并添加到列表
147 YearMonth currentMonth = startMonth;
148 while (!currentMonth.isAfter(endMonth)) {
149 months.add(currentMonth.toString()); // 格式化为 yyyy-MM
150 currentMonth = currentMonth.plusMonths(1);
151 }
152 return months;
153 }
100 154
101 /** 155 /**
102 * 获取两个日期之间的所有日期 (年月日) 156 * 获取两个日期之间的所有日期 (年月日)
...@@ -123,10 +177,9 @@ public class DateUtil { ...@@ -123,10 +177,9 @@ public class DateUtil {
123 if(currentDate.getTime() < endDate.getTime() ){ 177 if(currentDate.getTime() < endDate.getTime() ){
124 endDate = currentDate; 178 endDate = currentDate;
125 } 179 }
126
127 //用Calendar 进行日期比较判断 180 //用Calendar 进行日期比较判断
128 Calendar calendar = Calendar.getInstance(); 181 Calendar calendar = Calendar.getInstance();
129 while (startDate.getTime() < endDate.getTime()){ 182 while (startDate.getTime() <= endDate.getTime()){
130 // 把日期添加到集合 183 // 把日期添加到集合
131 list.add(formatSDF.format(startDate)); 184 list.add(formatSDF.format(startDate));
132 // 设置日期 185 // 设置日期
......
...@@ -121,4 +121,15 @@ public class MaterialInfo { ...@@ -121,4 +121,15 @@ public class MaterialInfo {
121 @Excel(name = "修订过程", width = 15) 121 @Excel(name = "修订过程", width = 15)
122 @ApiModelProperty(value = "修订过程") 122 @ApiModelProperty(value = "修订过程")
123 private String updateHistory; 123 private String updateHistory;
124
125 @ApiModelProperty(value = "文件号")
126 private String fileCode;
127
128 @ApiModelProperty(value = "使用范围")
129 private String useScope;
130
131 @ApiModelProperty(value = "审核状态:0 未发布 1 已发布(待审核)2 审核驳回 3 审核通过")
132 @Dict(dicCode = "purchase_plan_status")
133 private String status;
134
124 } 135 }
......
...@@ -322,4 +322,14 @@ public class ScreenDataServiceImpl implements IScreenDataService { ...@@ -322,4 +322,14 @@ public class ScreenDataServiceImpl implements IScreenDataService {
322 return months; 322 return months;
323 } 323 }
324 324
325 public static void main(String[] args) {
326 String startTime = "2024-01-01";//
327 String endTime = "2024-12-31";
328 String format ="yyyy-MM-dd";
329 List<String> dateList = getMonthsBetween(startTime, endTime);
330 for(String date : dateList){
331 System.out.println("date:"+date);
332 }
333 }
334
325 } 335 }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!