parent
2ad52b9e3a
commit
eec6bc7627
12 changed files with 781 additions and 4 deletions
@ -0,0 +1,18 @@ |
|||||||
|
package org.energy.modules.system.config; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by edwong on 2018/4/28. |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@Data |
||||||
|
public class DataConfig { |
||||||
|
|
||||||
|
@Value("${file.upload_path}") |
||||||
|
private String uploadPath; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,89 @@ |
|||||||
|
package org.energy.modules.system.controller; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.dayu.daf.core.log.exception.ServiceException; |
||||||
|
import com.dayu.daf.core.tool.api.R; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.energy.modules.auth.utils.TokenUtil; |
||||||
|
import org.energy.modules.system.config.DataConfig; |
||||||
|
import org.energy.modules.system.service.IDeptService; |
||||||
|
import org.energy.modules.system.service.IFileService; |
||||||
|
import org.energy.modules.system.util.DateTimeUtils; |
||||||
|
import org.energy.modules.system.util.EnumFileInfoType; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
import springfox.documentation.annotations.ApiIgnore; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by edwong on 2024/7/8. |
||||||
|
* 文件控制器 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/system/file") |
||||||
|
@AllArgsConstructor |
||||||
|
@ApiIgnore |
||||||
|
@Slf4j |
||||||
|
@Api(value = "文件", tags = "文件") |
||||||
|
public class FileController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
DataConfig dataConfig; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IFileService fileService; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 附件上载 |
||||||
|
*/ |
||||||
|
@ApiOperation("附件上载") |
||||||
|
@PostMapping(value = "/upload") |
||||||
|
@ResponseBody |
||||||
|
public R upload(@RequestPart("file") MultipartFile picture, |
||||||
|
@RequestParam("fileType") String fileType) { |
||||||
|
Map<String, Object> resultMap = new HashMap<>(); |
||||||
|
try { |
||||||
|
if (null != picture) { |
||||||
|
String sUniqueNewImageName = UUID.randomUUID().toString(); |
||||||
|
String sOriginalFilename = picture.getOriginalFilename();//picture.getOriginalFilename();
|
||||||
|
int suffixIndex = sOriginalFilename.lastIndexOf("."); |
||||||
|
String suffix = ""; |
||||||
|
if (suffixIndex > 0) { |
||||||
|
suffix = sOriginalFilename.substring(suffixIndex); |
||||||
|
} |
||||||
|
String fileSavePath = dataConfig.getUploadPath(); |
||||||
|
fileSavePath = fileSavePath + EnumFileInfoType.getKeyDesc(fileType) + "/" + DateTimeUtils.getFormatDate(new Date(), DateTimeUtils.YEAR_MONTH_DATE_FORMAT) + "/"; |
||||||
|
|
||||||
|
String filePath = "/data/file/actual/" + EnumFileInfoType.getKeyDesc(fileType) + "/" + DateTimeUtils.getFormatDate(new Date(), DateTimeUtils.YEAR_MONTH_DATE_FORMAT) + "/"; |
||||||
|
if (!new File(fileSavePath).exists()) { |
||||||
|
new File(fileSavePath).mkdirs(); |
||||||
|
} |
||||||
|
picture.transferTo(new File(fileSavePath + sUniqueNewImageName + suffix)); |
||||||
|
|
||||||
|
resultMap = fileService.saveFileInfo(fileType, filePath, sUniqueNewImageName, suffix, sOriginalFilename); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
log.error(e.getMessage(), e); |
||||||
|
throw new ServiceException("上传图片出错"); |
||||||
|
} |
||||||
|
return R.data(JSON.toJSONString(resultMap)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,32 @@ |
|||||||
|
package org.energy.modules.system.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.dayu.daf.core.mp.base.BaseEntity; |
||||||
|
import java.io.Serializable; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
/** |
||||||
|
* 实体类 |
||||||
|
* |
||||||
|
* @author Daf |
||||||
|
* @since 2024-07-08 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("sys_file") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value = "File对象", description = "File对象") |
||||||
|
public class File extends BaseEntity { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private Long id; |
||||||
|
private String fileType; |
||||||
|
private String filePath; |
||||||
|
private String fileName; |
||||||
|
private String fileSuffix; |
||||||
|
private String fileOldName; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package org.energy.modules.system.mapper; |
||||||
|
|
||||||
|
import org.energy.modules.system.entity.File; |
||||||
|
import org.energy.modules.system.vo.FileVO; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper 接口 |
||||||
|
* |
||||||
|
* @author Daf |
||||||
|
* @since 2024-07-08 |
||||||
|
*/ |
||||||
|
public interface FileMapper extends BaseMapper<File> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page |
||||||
|
* @param file |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
List<FileVO> selectFilePage(IPage page, FileVO file); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="org.energy.modules.system.mapper.FileMapper"> |
||||||
|
|
||||||
|
<!-- 通用查询映射结果 --> |
||||||
|
<resultMap id="fileResultMap" type="org.energy.modules.system.entity.File"> |
||||||
|
<id column="id" property="id"/> |
||||||
|
<result column="create_user" property="createUser"/> |
||||||
|
<result column="create_dept" property="createDept"/> |
||||||
|
<result column="create_time" property="createTime"/> |
||||||
|
<result column="update_user" property="updateUser"/> |
||||||
|
<result column="update_time" property="updateTime"/> |
||||||
|
<result column="is_deleted" property="isDeleted"/> |
||||||
|
<result column="status" property="status"/> |
||||||
|
<result column="file_type" property="fileType"/> |
||||||
|
<result column="file_path" property="filePath"/> |
||||||
|
<result column="file_name" property="fileName"/> |
||||||
|
<result column="file_suffix" property="fileSuffix"/> |
||||||
|
<result column="file_old_name" property="fileOldName"/> |
||||||
|
</resultMap> |
||||||
|
|
||||||
|
|
||||||
|
<select id="selectFilePage" resultMap="fileResultMap"> |
||||||
|
select * from sys_file where is_deleted = 0 |
||||||
|
</select> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,29 @@ |
|||||||
|
package org.energy.modules.system.service; |
||||||
|
|
||||||
|
import org.energy.modules.system.entity.File; |
||||||
|
import org.energy.modules.system.vo.FileVO; |
||||||
|
import com.dayu.daf.core.mp.base.BaseService; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务类 |
||||||
|
* |
||||||
|
* @author Daf |
||||||
|
* @since 2024-07-08 |
||||||
|
*/ |
||||||
|
public interface IFileService extends BaseService<File> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page |
||||||
|
* @param file |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
IPage<FileVO> selectFilePage(IPage<FileVO> page, FileVO file); |
||||||
|
|
||||||
|
Map<String, Object> saveFileInfo(String fileType, String filePath, String fileName, String fileSuffix, String oldFileName); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package org.energy.modules.system.service.impl; |
||||||
|
|
||||||
|
import org.energy.modules.system.entity.File; |
||||||
|
import org.energy.modules.system.vo.FileVO; |
||||||
|
import org.energy.modules.system.mapper.FileMapper; |
||||||
|
import org.energy.modules.system.service.IFileService; |
||||||
|
import com.dayu.daf.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务实现类 |
||||||
|
* |
||||||
|
* @author Daf |
||||||
|
* @since 2024-07-08 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class FileServiceImpl extends BaseServiceImpl<FileMapper, File> implements IFileService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<FileVO> selectFilePage(IPage<FileVO> page, FileVO file) { |
||||||
|
return page.setRecords(baseMapper.selectFilePage(page, file)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, Object> saveFileInfo(String fileType, String filePath, String fileName, String fileSuffix, String oldFileName) { |
||||||
|
File file = new File(); |
||||||
|
file.setFileType(fileType); |
||||||
|
file.setFilePath(filePath); |
||||||
|
file.setFileName(fileName); |
||||||
|
file.setFileSuffix(fileSuffix); |
||||||
|
boolean saveFlag = super.save(file); |
||||||
|
Map<String, Object> map = new HashMap<>(); |
||||||
|
if (saveFlag) { |
||||||
|
map.put("id", file.getId()); |
||||||
|
map.put("filePath", file.getFilePath() + file.getFileName() + file.getFileSuffix()); |
||||||
|
return map; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,440 @@ |
|||||||
|
package org.energy.modules.system.util; |
||||||
|
|
||||||
|
|
||||||
|
import io.micrometer.core.instrument.util.StringUtils; |
||||||
|
|
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.text.DateFormat; |
||||||
|
import java.text.ParseException; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 日期处理工具类 |
||||||
|
*/ |
||||||
|
public class DateTimeUtils { |
||||||
|
|
||||||
|
public static final String FULL_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
||||||
|
public static final String FULL_DATE_FORMAT_CN = "yyyy年MM月dd日 HH时mm分ss秒"; |
||||||
|
public static final String PART_DATE_FORMAT = "yyyy-MM-dd"; |
||||||
|
public static final String PART_DATE_FORMAT_CN = "yyyy年MM月dd日"; |
||||||
|
public static final String YEAR_DATE_FORMAT = "yyyy"; |
||||||
|
public static final String MONTH_DATE_FORMAT = "MM"; |
||||||
|
public static final String DAY_DATE_FORMAT = "dd"; |
||||||
|
public static final String WEEK_DATE_FORMAT = "week"; |
||||||
|
public static final String YEAR_MONTH_DATE_FORMAT = "yyyyMMdd"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 将日期类型转换为字符串 |
||||||
|
* |
||||||
|
* @param date 日期 |
||||||
|
* @param xFormat 格式 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getFormatDate(Date date, String xFormat) { |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
xFormat = StringUtils.isNotEmpty(xFormat) == true ? xFormat : FULL_DATE_FORMAT; |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(xFormat); |
||||||
|
return sdf.format(date); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 比较日期大小 |
||||||
|
* |
||||||
|
* @param dateX |
||||||
|
* @param dateY |
||||||
|
* @return x < y return [-1]; |
||||||
|
* x = y return [0] ; |
||||||
|
* x > y return [1] ; |
||||||
|
*/ |
||||||
|
public static int compareDate(Date dateX, Date dateY) { |
||||||
|
return dateX.compareTo(dateY); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 将日期字符串转换为日期格式类型 |
||||||
|
* |
||||||
|
* @param xDate |
||||||
|
* @param xFormat 为NULL则转换如:2012-06-25 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Date parseString2Date(String xDate, String xFormat) { |
||||||
|
while (!isNotDate(xDate)) { |
||||||
|
xFormat = StringUtils.isNotEmpty(xFormat) == true ? xFormat : PART_DATE_FORMAT; |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(xFormat); |
||||||
|
Date date = null; |
||||||
|
try { |
||||||
|
date = sdf.parse(xDate); |
||||||
|
} catch (ParseException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
return date; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 判断需要转换类型的日期字符串是否符合格式要求 |
||||||
|
* |
||||||
|
* @param xDate |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isNotDate(String xDate) { |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(PART_DATE_FORMAT); |
||||||
|
try { |
||||||
|
if (StringUtils.isEmpty(xDate)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
sdf.parse(xDate); |
||||||
|
return false; |
||||||
|
} catch (ParseException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean isDate(String xDate) { |
||||||
|
return !isDate(xDate); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取俩个日期之间相差天数 |
||||||
|
* |
||||||
|
* @param dateX |
||||||
|
* @param dateY |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static int getDiffDays(Date dateX, Date dateY) { |
||||||
|
if ((dateX == null) || (dateY == null)) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int dayX = (int) (dateX.getTime() / (60 * 60 * 1000 * 24)); |
||||||
|
int dayY = (int) (dateY.getTime() / (60 * 60 * 1000 * 24)); |
||||||
|
|
||||||
|
return dayX > dayY ? dayX - dayY : dayY - dayX; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取俩个日期之间相差天数(日期) |
||||||
|
* |
||||||
|
* @param dateX |
||||||
|
* @param dateY |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static int getDiffDaysNoABS(Date dateX, Date dateY) { |
||||||
|
if ((dateX == null) || (dateY == null)) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int dayX = (int) (dateX.getTime() / (60 * 60 * 1000 * 24)); |
||||||
|
int dayY = (int) (dateY.getTime() / (60 * 60 * 1000 * 24)); |
||||||
|
|
||||||
|
return dayX - dayY; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取传值日期之后几天的日期并转换为字符串类型 |
||||||
|
* |
||||||
|
* @param date 需要转换的日期 date 可以为NULL 此条件下则获取当前日期 |
||||||
|
* @param after 天数 |
||||||
|
* @param xFormat 转换字符串类型 (可以为NULL) |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getAfterCountDate(Date date, int after, String xFormat) { |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
xFormat = StringUtils.isNotEmpty(xFormat) == true ? xFormat : PART_DATE_FORMAT; |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, after); |
||||||
|
return getFormatDate(calendar.getTime(), xFormat); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取传值日期之前几天的日期并转换为字符串类型 |
||||||
|
* |
||||||
|
* @param date 需要转换的日期 date 可以为NULL 此条件下则获取当前日期 |
||||||
|
* @param before 天数 |
||||||
|
* @param xFormat 转换字符串类型 (可以为NULL) |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getBeforeCountDate(Date date, int before, String xFormat) { |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
xFormat = StringUtils.isNotEmpty(xFormat) == true ? xFormat : PART_DATE_FORMAT; |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, -before); |
||||||
|
return getFormatDate(calendar.getTime(), xFormat); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取日期的参数 如:年 , 月 , 日 , 星期几 |
||||||
|
* |
||||||
|
* @param xDate 日期 可以为日期格式,可以是字符串格式; 为NULL或者其他格式时都判定为当前日期 |
||||||
|
* @param xFormat 年 yyyy 月 MM 日 dd 星期 week ;其他条件下都返回0 |
||||||
|
*/ |
||||||
|
public static int getDateTimeParam(Object xDate, String xFormat) { |
||||||
|
xDate = xDate == null ? new Date() : xDate; |
||||||
|
Date date = null; |
||||||
|
if (xDate instanceof String) { |
||||||
|
date = parseString2Date(xDate.toString(), null); |
||||||
|
} else if (xDate instanceof Date) { |
||||||
|
date = (Date) xDate; |
||||||
|
} else { |
||||||
|
date = new Date(); |
||||||
|
} |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
if (StringUtils.isNotEmpty(xFormat) |
||||||
|
&& (xFormat.equals(YEAR_DATE_FORMAT) |
||||||
|
|| xFormat.equals(MONTH_DATE_FORMAT) |
||||||
|
|| xFormat.equals(DAY_DATE_FORMAT))) { |
||||||
|
return Integer.parseInt(getFormatDate(date, xFormat)); |
||||||
|
} else if (StringUtils.isNotEmpty(xFormat) |
||||||
|
&& (WEEK_DATE_FORMAT.equals(xFormat))) { |
||||||
|
Calendar cal = Calendar.getInstance(); |
||||||
|
cal.setTime(date); |
||||||
|
int week = cal.get(Calendar.DAY_OF_WEEK) - 1 == 0 ? |
||||||
|
7 : cal.get(Calendar.DAY_OF_WEEK) - 1; |
||||||
|
return week; |
||||||
|
} else { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 日期格式转换为时间戳 |
||||||
|
* |
||||||
|
* @param time |
||||||
|
* @param format |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Long getLongTime(String time, String format) { |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(format); |
||||||
|
Date date = null; |
||||||
|
try { |
||||||
|
date = sdf.parse(time); |
||||||
|
return (date.getTime() / 1000); |
||||||
|
} catch (ParseException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取星期字符串 |
||||||
|
* |
||||||
|
* @param xDate |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getWeekString(Object xDate) { |
||||||
|
int week = getDateTimeParam(xDate, WEEK_DATE_FORMAT); |
||||||
|
switch (week) { |
||||||
|
case 1: |
||||||
|
return "星期一"; |
||||||
|
case 2: |
||||||
|
return "星期二"; |
||||||
|
case 3: |
||||||
|
return "星期三"; |
||||||
|
case 4: |
||||||
|
return "星期四"; |
||||||
|
case 5: |
||||||
|
return "星期五"; |
||||||
|
case 6: |
||||||
|
return "星期六"; |
||||||
|
case 7: |
||||||
|
return "星期日"; |
||||||
|
default: |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获得十位时间 |
||||||
|
*/ |
||||||
|
public static Long getTenBitTimestamp() { |
||||||
|
return System.currentTimeMillis() / 1000; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获得某天的结束时间 |
||||||
|
*/ |
||||||
|
public static Date getDateEnd(Date date) { |
||||||
|
return new Date(date.getTime() + (86400 - 1) * 1000); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 日期格式转换为毫秒 |
||||||
|
* |
||||||
|
* @param time |
||||||
|
* @param format |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Long getLongDateTime(String time, String format) { |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(format); |
||||||
|
Date date = null; |
||||||
|
try { |
||||||
|
date = sdf.parse(time); |
||||||
|
return date.getTime(); |
||||||
|
} catch (ParseException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取某天开始时间戳_10位 |
||||||
|
*/ |
||||||
|
public static Long getStartTimestamp(Date date) { |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
calendar.setTime(date); |
||||||
|
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
||||||
|
calendar.set(Calendar.MINUTE, 0); |
||||||
|
calendar.set(Calendar.SECOND, 0); |
||||||
|
calendar.set(Calendar.MILLISECOND, 0); |
||||||
|
|
||||||
|
return calendar.getTime().getTime() / 1000; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取某天结束时间戳_10位 |
||||||
|
*/ |
||||||
|
public static Long getEndTimestamp(Date date) { |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
calendar.setTime(date); |
||||||
|
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 23); |
||||||
|
calendar.set(Calendar.MINUTE, 59); |
||||||
|
calendar.set(Calendar.SECOND, 59); |
||||||
|
calendar.set(Calendar.MILLISECOND, 999); |
||||||
|
|
||||||
|
return calendar.getTime().getTime() / 1000; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取昨天日期 |
||||||
|
* |
||||||
|
* @param date |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Date getYesterday(Date date) { |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, -1); |
||||||
|
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 9); |
||||||
|
calendar.set(Calendar.MINUTE, 59); |
||||||
|
calendar.set(Calendar.SECOND, 59); |
||||||
|
calendar.set(Calendar.MILLISECOND, 999); |
||||||
|
date = calendar.getTime(); |
||||||
|
return date; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取明天时间(参数时间+1天) |
||||||
|
* |
||||||
|
* @param date |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Date getTomorrowday(Date date) { |
||||||
|
Calendar c = Calendar.getInstance(); |
||||||
|
c.setTime(date); |
||||||
|
c.add(Calendar.DAY_OF_YEAR, +1); |
||||||
|
return c.getTime(); |
||||||
|
} |
||||||
|
|
||||||
|
/* 10位int型的时间戳转换为String(yyyy-MM-dd HH:mm:ss) |
||||||
|
* |
||||||
|
* @param time |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String timestampToString(Integer time, String format) { |
||||||
|
// int转long时,先进行转型再进行计算,否则会是计算结束后在转型
|
||||||
|
long temp = (long) time * 1000; |
||||||
|
Timestamp ts = new Timestamp(temp); |
||||||
|
String tsStr = ""; |
||||||
|
DateFormat dateFormat = new SimpleDateFormat(format); |
||||||
|
try { |
||||||
|
// 方法一
|
||||||
|
tsStr = dateFormat.format(ts); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return tsStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取某天开始时间 |
||||||
|
*/ |
||||||
|
public static Date getStartTime(Date date) { |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
calendar.setTime(date); |
||||||
|
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0); |
||||||
|
calendar.set(Calendar.MINUTE, 0); |
||||||
|
calendar.set(Calendar.SECOND, 0); |
||||||
|
calendar.set(Calendar.MILLISECOND, 0); |
||||||
|
|
||||||
|
return calendar.getTime(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取某天结束时间 |
||||||
|
*/ |
||||||
|
public static Date getEndTime(Date date) { |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
date = date == null ? new Date() : date; |
||||||
|
calendar.setTime(date); |
||||||
|
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 23); |
||||||
|
calendar.set(Calendar.MINUTE, 59); |
||||||
|
calendar.set(Calendar.SECOND, 59); |
||||||
|
calendar.set(Calendar.MILLISECOND, 999); |
||||||
|
|
||||||
|
return calendar.getTime(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Date类型转换为10位时间戳 |
||||||
|
* |
||||||
|
* @param time |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Integer DateToTimestamp(Date time) { |
||||||
|
Timestamp ts = new Timestamp(time.getTime()); |
||||||
|
|
||||||
|
return (int) ((ts.getTime()) / 1000); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前时间之前或之后几分钟 |
||||||
|
* |
||||||
|
* @param minute |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getTimeByMinute(int minute, Date time) { |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(time); |
||||||
|
calendar.add(Calendar.MINUTE, minute); |
||||||
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
package org.energy.modules.system.util; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by edwong on 2024/07/08. |
||||||
|
*/ |
||||||
|
public enum EnumFileInfoType { |
||||||
|
|
||||||
|
STATIC_LEDGER_DOCUMENT_INVENTORY("0", "STATIC_LEDGER_DOCUMENT_INVENTORY", "静态台账文档清册"), |
||||||
|
; |
||||||
|
|
||||||
|
private String key; |
||||||
|
private String keyDesc; |
||||||
|
private String desc; |
||||||
|
|
||||||
|
EnumFileInfoType(String key, String keyDesc, String desc) { |
||||||
|
this.key = key; |
||||||
|
this.keyDesc = keyDesc; |
||||||
|
this.desc = desc; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getDesc(String type) { |
||||||
|
for (EnumFileInfoType en : EnumFileInfoType.values()) { |
||||||
|
if (en.key.equals(type)) { |
||||||
|
return en.desc; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getKeyDesc(String type) { |
||||||
|
for (EnumFileInfoType en : EnumFileInfoType.values()) { |
||||||
|
if (en.key.equals(type)) { |
||||||
|
return en.keyDesc; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public String getKeyDesc() { |
||||||
|
return keyDesc; |
||||||
|
} |
||||||
|
|
||||||
|
public String getKey() { |
||||||
|
return key; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDesc() { |
||||||
|
return desc; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package org.energy.modules.system.vo; |
||||||
|
|
||||||
|
import org.energy.modules.system.entity.File; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
|
||||||
|
/** |
||||||
|
* 视图实体类 |
||||||
|
* |
||||||
|
* @author Daf |
||||||
|
* @since 2024-07-08 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value = "FileVO对象", description = "FileVO对象") |
||||||
|
public class FileVO extends File { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue