//导出
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的更多相关文章

  1. Tool1—安装配置Windows Live Writer

    详细步骤请看:http://home.cnblogs.com/group/topic/8550.html . Windows Live Writer手工配置步骤(在博客园配置时输入用户名与密码会自动完 ...

  2. Atitit onvif 协议截图 getSnapshotUri 使用java

    Atitit onvif 协议截图 getSnapshotUri 使用java 1.1. ONVIF Device Test Tool1 1.2. 源码2 1.3. 直接浏览器访问http://192 ...

  3. atitit。wondows 右键菜单的管理与位置存储

    atitit.wondows 右键菜单的管理与位置存储 原理 .这样的功能称为Windows外壳扩展(Shell Extensions) 1 常用右键菜单 atiContentMenu1 通用tool ...

  4. iOS 单例模式 浅叙

    单例模式作用 可以保证在程序运行过程中,一个类只有一个实例,而且该实例易于供外界使用 从而方便地控制了实例个数,并节约系统资源 单例模式使用场合 在整个引用程序中,共享一份资源(这份资源只需要创建初始 ...

  5. 《深入浅出WPF》笔记二

    1.消息驱动与事件驱动 事件 即封装过的消息 2.数据驱动 3.Binding Source.Target.Path.INotifyPropertyChanged结构 this.textBoxName ...

  6. python发布文件(windows)

    怎样发布文件 首先发布本地文件有一个好的用处,就是省去了朋友同import的时候还要使用sys.path,省的自己出错 1.新建文件夹d:\ tool 在的d:\tool文件夹中建立login.py ...

  7. Java开发之单例设计模式

    设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...

  8. android开发之路06(浅谈单例设计模式)

    设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...

  9. 一个空格也可以让html格式显示大不相同

    今天在编写html时出现了bug,有两个标签一直贴近显示,但是两段代码完全一样前一段就没有问题. 错误代码如下 <div id="tool1" style="wid ...

随机推荐

  1. Currtid 函数与性能问题

    对于Oracle ,一条tuple 的 rowid正常是不会变化的(引发row movement的操作除外,如:跨分区迁移update,表收缩),因此,应用设计上可以方便的使用rowid,加快访问速度 ...

  2. KingbaseES R6 集群repmgr witness 手工配置案例

    使用见证服务器: 见证服务器是一个正常的KingbaseES实例,不是流复制群集的一部分; 其目的是,如果发生故障转移情况,则提供证明它是主服务器本身不可用的证据,而不是例如在不同物理位置之间的网络分 ...

  3. Vite+React搭建开发构建环境实践

    前言 使用 Vite 已经有两年了,期间使用它开发过单页面应用,也开发过浏览器扩展插件,对比日常工作中用到的 webpack 构建速度大幅提升,开发体验也好很多. 虽然相比于 webpack 来说简单 ...

  4. linux下安装Elasticsearch(单机版和集群版)

    一.linux下安装Elasticsearch(单机) 1.软件下载 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsea ...

  5. scheduler打印状态到日志

    编辑脚本和目录 # 如下步骤每个proxysql节点都需要操作 [root@ss30 opt]# mkdir -p /opt/proxysql/log [root@ss30 opt]# vim /op ...

  6. 使用 Elastic 技术栈构建 K8S 全栈监控 -2: 用 Metricbeat 对 Kubernetes 集群进行监控

    文章转载自:https://www.qikqiak.com/post/k8s-monitor-use-elastic-stack-2/ 操作步骤 git clone https://github.co ...

  7. 清除已安装的rook-ceph集群

    官方文档地址:https://rook.io/docs/rook/v1.8/ceph-teardown.html 如果要拆除群集并启动新群集,请注意需要清理的以下资源: rook-ceph names ...

  8. 几篇关于MySQL数据同步到Elasticsearch的文章---第四篇:使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch

    文章转载自: https://www.cnblogs.com/dalaoyang/p/11018541.html 1.go-mysql-elasticsearch简介 go-mysql-elastic ...

  9. flutter系列之:深入理解布局的基础constraints

    目录 简介 Tight和loose constraints 理解constraints的原则 总结 简介 我们在flutter中使用layout的时候需要经常对组件进行一些大小的限制,这种限制就叫做c ...

  10. NSIS查找文本中是否包含某个字串

    !include "textfunc.nsh"!include "logiclib.nsh"OutFile "find.exe"#文本文件a ...