tool1
//导出
public void excel(List<Long> ids, HttpServletResponse response) {
List<StockPageVo> excel = stockMapper.excel(ids);
try {
ExportParams params = new ExportParams();
params.setSheetName("历史入库导出");//设置sheet名
Workbook workbook = ExcelExportUtil.exportExcel(params, StockPageVo.class, excel);
//返回头设置下载,并设置文件名,返回
DownloadUtils.setExportExcelFormat(response, workbook, "历史入库");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setExportExcelFormat(HttpServletResponse response, Workbook workbook, String fileName) throws Exception {
response.reset();
response.setContentType("application/vnd.ms-excel");//下载
fileName = fileName + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1) + ".xls");
try (ServletOutputStream outStream = response.getOutputStream()) {
workbook.write(outStream);
}
}
//导入
public void test123(MultipartFile file) throws Exception {
//创建导入对象
ImportParams params = new ImportParams();
params.setTitleRows(1); //表格标题行数,默认0
params.setHeadRows(1); //表头行数,默认1
//获取导入数据
InputStream inputStream = file.getInputStream();
List<User> users = ExcelImportUtil.importExcel(inputStream,User.class, params);
for (User user : users) {
System.out.println(user.toString());
}
}
//图片上传
public static String upload(MultipartFile file) {
if (file == null) throw new BusinessException("图片为空");
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
String uuid = Utility.generateShortUuid() + "." + extension;
try {
//图片上传的路径
String path = IntegerFaceConfig.EXCEP_Path;
file.transferTo(new File(path + uuid));
return path + uuid;
} catch (IOException e) {
e.printStackTrace();
}
return throw new BusinessException("图片上传失败");
}
//图片的删除
File file123 = new File(ImgUser);//图片的路径
file123.delete();
//校验id和端口
public static boolean checkIp(String ipAddress) {
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
Pattern pattern = Pattern.compile(ip);
Matcher matcher = pattern.matcher(ipAddress);
return matcher.matches();
}
public static boolean checkPort(String port) {
//端口号验证 1 ~ 65535
String regex = "^([1-9]|[1-9]\\d{1,3}|[1-6][0-5][0-5][0-3][0-5])$";
return Pattern.matches(regex, port);
}
//校验电话号码
public static boolean isMobileNo(String mobiles) {
// ^ 匹配输入字符串开始的位置
// \d 匹配一个或多个数字,其中 \ 要转义,所以是 \\d
// $ 匹配输入字符串结尾的位置
String regExp = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])" +
"|(18[0-9])|(19[8,9]))\\d{8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(mobiles);
return m.matches();
}
//对参数格式的校验
public static Boolean isNull(String str) {
if (str==null) return false;
boolean blank = StringUtils.isBlank(str);
if (!blank) {
return !str.equals("''");
} else {
return false;
}
}
//获取当前时间
public static String getTimestamps() {
Date date = new Date();
DateTime dateTime = new DateTime();
String endOfDay = getEndOfDay(date);
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
String formats = sdf.format(endOfDay);*/
return endOfDay;
}
public static String getEndOfDay(Date date) {
Calendar calendar = Calendar.getInstance();
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 new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
}
//获取当前年月日
public static String getDate() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
//获取本年
public static String getYear() {
Calendar c = Calendar.getInstance();
String getCurrentTime = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return String.valueOf(c.get(Calendar.YEAR));
}
//获取当月的第一天和最后一天
public static Map<String, String> getFirLast() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月第一天:
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
String first = format.format(c.getTime());
System.out.println("===============first:" + first);
//获取当前月最后一天
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String last = format.format(ca.getTime());
System.out.println("===============last:" + last);
Map<String, String> map = new HashMap<>();
map.put("first", first);
map.put("last", last);
return map;
}
//计算两个日期相差的月份
public static BigDecimal getMonth(Date start, Date end) {
//前大 后小 计算前到后相差的月份
return BigDecimal.valueOf(getMonth1(start, end));
}
static int getMonth1(Date start, Date end) {
if (start.after(end)) {
Date t = start;
start = end;
end = t;
}
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(start);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(end);
Calendar temp = Calendar.getInstance();
temp.setTime(end);
temp.add(Calendar.DATE, 1);
int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) == 1)) {
return year * 12 + month + 1;
} else if ((startCalendar.get(Calendar.DATE) != 1) && (temp.get(Calendar.DATE) == 1)) {
return year * 12 + month;
} else if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) != 1)) {
return year * 12 + month;
} else {
return (year * 12 + month - 1) < 0 ? 0 : (year * 12 + month);
}
}
//计算两个日期相差的天数
public static int differentDays(String date11, String date22) {
//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date1 = null;
Date date2 = null;
try {
date1 = sdf.parse(date11);
date2 = sdf.parse(date22);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if (year1 != year2) //同一年
{
int timeDistance = 0;
for (int i = year1; i < year2; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) //闰年
{
timeDistance += 366;
} else {
//不是闰年
timeDistance += 365;
}
}
return timeDistance + (day2 - day1);
} else {
//不同年
//System.out.println("判断day2 - day1 : " + (day2 - day1));
return day2 - day1;
}
}
//计算两个数占得百分比
public static String getPercent(int x, int y) {
double d1 = x * 1.0;
double d2 = y * 1.0;
NumberFormat percentInstance = NumberFormat.getPercentInstance();
// 设置保留几位小数,这里设置的是保留两位小数
percentInstance.setMinimumFractionDigits(2);
return percentInstance.format(d1 / d2);
}
//根据日期获得是周几
public static String getCycle(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = null;
try {
date1 = format.parse(date);
String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"};
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
//System.out.println(weekDays[w]);
return weekDays[w];
} catch (ParseException e) {
throw new BusinessException("错误信息");
}
}
//对两个相同的集合进行操作
public static List<ChangeVo> mergeChange(List<ChangeVo> list) {
if (list.size() != 0) {
List<ChangeVo> result = list.stream()
.collect(Collectors.toMap(ChangeVo::getMonth, a -> a, (o1, o2) -> {
o1.setNumber(o1.getNumber() + o2.getNumber());
o1.setPrice(o1.getPrice().add(o2.getPrice()));
return o1;
})).values().stream().collect(Collectors.toList());
return result;
} else {
return new ArrayList<>();
}
}
tool1的更多相关文章
- Tool1—安装配置Windows Live Writer
详细步骤请看:http://home.cnblogs.com/group/topic/8550.html . Windows Live Writer手工配置步骤(在博客园配置时输入用户名与密码会自动完 ...
- Atitit onvif 协议截图 getSnapshotUri 使用java
Atitit onvif 协议截图 getSnapshotUri 使用java 1.1. ONVIF Device Test Tool1 1.2. 源码2 1.3. 直接浏览器访问http://192 ...
- atitit。wondows 右键菜单的管理与位置存储
atitit.wondows 右键菜单的管理与位置存储 原理 .这样的功能称为Windows外壳扩展(Shell Extensions) 1 常用右键菜单 atiContentMenu1 通用tool ...
- iOS 单例模式 浅叙
单例模式作用 可以保证在程序运行过程中,一个类只有一个实例,而且该实例易于供外界使用 从而方便地控制了实例个数,并节约系统资源 单例模式使用场合 在整个引用程序中,共享一份资源(这份资源只需要创建初始 ...
- 《深入浅出WPF》笔记二
1.消息驱动与事件驱动 事件 即封装过的消息 2.数据驱动 3.Binding Source.Target.Path.INotifyPropertyChanged结构 this.textBoxName ...
- python发布文件(windows)
怎样发布文件 首先发布本地文件有一个好的用处,就是省去了朋友同import的时候还要使用sys.path,省的自己出错 1.新建文件夹d:\ tool 在的d:\tool文件夹中建立login.py ...
- Java开发之单例设计模式
设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...
- android开发之路06(浅谈单例设计模式)
设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...
- 一个空格也可以让html格式显示大不相同
今天在编写html时出现了bug,有两个标签一直贴近显示,但是两段代码完全一样前一段就没有问题. 错误代码如下 <div id="tool1" style="wid ...
随机推荐
- MySQL源码分析之SQL函数执行
1.MySQL中执行一条SQL的总体流程 2.SQL函数执行过程 1.MySQL中执行一条SQL的总体流程 一条包含函数的SQL语句,在mysql中会经过: 客户端发送,服务器连接,语法解析,语句执行 ...
- Java Web中MVC设计模式与IOC
MVC是由Model(模型).View(视图).Controller(控制器)三个模块组成 视图:用于做数据展示以及和用户交互的一个界面(html页面) 控制层:能够接受客户端的请求,具体的业务功能还 ...
- 记一次用arthas排查jvm中CPU占用过高问题
记一次使用arthas排查jvm中CPU占用过高问题.这工具屌爆了 碾压我目前使用的全部JVM工具. 安装 小试 curl -O https://arthas.aliyun.com/arthas-bo ...
- Dubbo-Adaptive实现原理
前言 前面我们已经分析Dubbo SPI相关的源码,看过的小伙伴相信已经知晓整个加载过程,我们也留下两个问题,今天我们先来处理下其中关于注解Adaptive的原理. 什么是@Adaptive 对应于A ...
- 高清地图转换(xord转apollo的bin文件)
目标 将carla中的OpenDrive地图(carla\Unreal\CarlaUE4\Content\Carla\Maps\OpenDrive)转换为Apollo中可识别的地图格式(bin与txt ...
- 学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(完)
学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应用程序(上) 学习ASP.NET Core Blazor编程系 ...
- uniapp路由守卫
项目地址:https://hhyang.cn/v2/start/quickstart.html 按照他的方法安装,创建相应的js即可,有点基础的自己捣鼓一下就可以了.我的应用场景是:没有登录痕迹- ...
- 安装MySQL8 工具集
下载地址:https://downloads.mysql.com/archives/utilities/ # wget https://downloads.mysql.com/archives/get ...
- 15. 第十四篇 安装CoreDNS
文章转载自:https://mp.weixin.qq.com/s?__biz=MzI1MDgwNzQ1MQ==&mid=2247483850&idx=1&sn=4bfdb26f ...
- 关于使用kuboard安装其自带的监控应用的注意事项
在安装过程中若想监控kube-controller-manager和kube-scheduler,需要按步骤中的如下说明操作 在这里,所有master节点的这俩文件都需要修改,不用apply,等一分钟 ...