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 ...
随机推荐
- [开源精品] C#.NET im 聊天通讯架构设计 -- FreeIM 支持集群、职责分明、高性能
FreeIM 是什么? FreeIM 使用 websocket 协议实现简易.高性能(单机支持5万+连接).集群即时通讯组件,支持点对点通讯.群聊通讯.上线下线事件消息等众多实用性功能. ImCore ...
- python数据精度问题
一.python运算时精度问题: 1.运行时精度问题在Python中(其他语言中也存在这个问题,这是计算机采用二进制导致的),有时候由于二进制和十进制之间对应问题会导致数值的精度问题,比如无法用有限个 ...
- Altium Designer 18学习
目录 目录 快捷键 通孔 敷铜 修改铜皮与导线之间的间隔 去除指定敷铜区域 DRC设计规则检查问题: 快捷键 EJC 快速跳转到器件 M 移动 CTRL+M 测量距离 通孔 敷铜 放置多边形平面 -- ...
- KingbaseES V8R6集群维护案例之--修改securecmdd工具服务端口
案例说明: 在一些生产环境,为了系统安全,不支持ssh互信,或限制root用户使用ssh登录,KingbaseES V8R6可以使用securecmdd工具支持主机之间的通讯.securecmdd工具 ...
- 为什么Index Only Scan却还需要访问表
在实际SQL优化工作中,我们经常会发现SQL 执行计划明明是 "Index Only Scan",但执行计划后面却有 "Heap Fetches: x" ,也就 ...
- with function 语法支持
通过with子句,我们可以把很多原本需要存储过程来实现的复杂逻辑用一句SQL来进行表达.KingbaseES 从V008R006C004B0021 版本开始,支持 with function 语法.例 ...
- 发布日志 - kratos v2.1.0 版本发布
github https://github.com/go-kratos/kratos/releases/tag/v2.1.0 新的功能 新增客户端负载均衡器(load balancing)和路由选择器 ...
- Minio设置永久下载链接
目前了解到的有如下两种方法 建议采用第二种办法 第一种方法:设置Access Policy为public 不论文件是否已经操作过分享动作,只要存储桶中有这个文件就能通过如下形式直接访问: http:/ ...
- ECON 模式
ECON模式通过调节发动机和空调系统的性能,有效提高燃油经济性. 在D行驶档的时候开启
- 第一个Django应用 - 第三部分:Django视图和模板
一.概述 一个视图就是一个页面,通常提供特定的功能,使用特定的模板.例如:在一个博客应用中,你可能会看到下列视图: 博客主页:显示最新发布的一些内容 每篇博客的详细页面:博客的永久链接 基于年的博客页 ...