Commit 59a23605 authored by taabe's avatar taabe

添加common包

parent c192fdeb
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-biz-common</artifactId>
<name>AMOS-BOOT-BIZ-COMMON</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent> <parent>
<artifactId>amos-biz-boot</artifactId> <artifactId>amos-biz-boot</artifactId>
<groupId>com.amosframework.boot</groupId> <groupId>com.amosframework.boot</groupId>
<version>1.0.0</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>amos-boot-biz-common</artifactId>
<dependencies> <dependencies>
</dependencies> </dependencies>
......
package org.amos.boot.biz.common;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package org.amos.boot.biz.common.bo;
import java.util.List;
/**
* 公司实体vo
*
* @author DELL
***/
public class CompanyBo {
private String address;
private String companyName;
private Integer companyOrgCode;
private String email;
private String landlinePhone;
private String latitude;
private String level;
private String longitude;
private String orgCode;
private Long parentId;
private Long sequenceNbr;
private List<CompanyBo> children;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public Integer getCompanyOrgCode() {
return companyOrgCode;
}
public void setCompanyOrgCode(Integer companyOrgCode) {
this.companyOrgCode = companyOrgCode;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLandlinePhone() {
return landlinePhone;
}
public void setLandlinePhone(String landlinePhone) {
this.landlinePhone = landlinePhone;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public List<CompanyBo> getChildren() {
return children;
}
public void setChildren(List<CompanyBo> children) {
this.children = children;
}
}
package org.amos.boot.biz.common.bo;
import java.util.List;
/**
* 部门vo
*
* @author DELL
**/
public class DepartmentBo {
private String departmentName;
private String level;
private Integer deptOrgCode;
private String orgCode;
private String departmentDesc;
private Long companySeq;
private Long sequenceNbr;
private Long parentId;
private List<DepartmentBo> children;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Integer getDeptOrgCode() {
return deptOrgCode;
}
public void setDeptOrgCode(Integer deptOrgCode) {
this.deptOrgCode = deptOrgCode;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getDepartmentDesc() {
return departmentDesc;
}
public void setDepartmentDesc(String departmentDesc) {
this.departmentDesc = departmentDesc;
}
public Long getCompanySeq() {
return companySeq;
}
public void setCompanySeq(Long companySeq) {
this.companySeq = companySeq;
}
public Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public List<DepartmentBo> getChildren() {
return children;
}
public void setChildren(List<DepartmentBo> children) {
this.children = children;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
}
package org.amos.boot.biz.common.bo;
import java.io.Serializable;
/***
*
* 用户选择保存实体类
* @author Dell
* **/
public class ReginParams implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private CompanyBo company;
private RoleBo role;
private DepartmentBo department;
public CompanyBo getCompany() {
return company;
}
public void setCompany(CompanyBo company) {
this.company = company;
}
public RoleBo getRole() {
return role;
}
public void setRole(RoleBo role) {
this.role = role;
}
public DepartmentBo getDepartment() {
return department;
}
public void setDepartment(DepartmentBo department) {
this.department = department;
}
}
package org.amos.boot.biz.common.bo;
/***
*
* 角色实体vo
*
* @author DELL*/
public class RoleBo {
private String roleName;
private String roleType;
private Long sequenceNbr;
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getRoleType() {
return roleType;
}
public void setRoleType(String roleType) {
this.roleType = roleType;
}
public Long getSequenceNbr() {
return sequenceNbr;
}
public void setSequenceNbr(Long sequenceNbr) {
this.sequenceNbr = sequenceNbr;
}
}
package org.amos.boot.biz.common.constants;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
/**
* @Description: 通用常量类
* @Author: DELL
* @Date: 2021/5/26
*/
public interface CommonConstant {
String RESULT_SUCCESS = "SUCCESS";
String RESULT_FAILURE = "FAILURE";
}
package org.amos.boot.biz.common.controller;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.amos.boot.biz.common.bo.ReginParams;
import org.amos.boot.biz.common.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.TransactionSystemException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException;
import java.util.HashMap;
/**
* 基础控制器
*
* @author
*/
@ApiIgnore
@RestController
@RequestMapping("/base")
public class BaseController {
/**
* 成功返回状态
*/
protected static final String SUCCESS = "SUCCESS";
/**
* 失败返回状态
*/
protected static final String FAILED = "FAILED";
/**
* 默认页大小
*/
protected static final int DEFAULT_PAGE_SIZE = 10;
@Autowired
protected HttpServletRequest request;
@Autowired
private RedisUtils redisUtils;
/**
* 获取token
**/
protected String getToken() {
String authToken = request.getHeader("token");
if (authToken == null) {
authToken = request.getHeader("X-Access-Token");
}
return authToken;
}
/**
* 获取Product
**/
protected String getProduct() {
String product = request.getHeader("product");
if (product == null) {
product = request.getParameter("product");
}
return product;
}
/**
* 获取AppKey
**/
protected String getAppKey() {
String appKey = request.getHeader("appKey");
if (appKey == null) {
appKey = request.getParameter("appKey");
}
return appKey;
}
/**
* redi缓存选择的用户信息key
*
* @param userId
* @param token
* @return
*/
private String buildKey(String userId, String token) {
return "region_" + userId + "_" + token;
}
/**
* 用户选择信息保存redis
*/
protected void saveSelectedOrgInfo(ReginParams reginParams) {
redisUtils.set(buildKey(getUserId(), getToken()), JSONObject.toJSONString(reginParams));
}
/**
* 获取结构code
*
* @return
*/
protected String getOrgCode() {
ReginParams reginParams = getSelectedOrgInfo();
if (reginParams == null) {
return null;
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getOrgCode();
}
return null;
}
/**
* 用户选择信心redis获取
**/
protected ReginParams getSelectedOrgInfo() {
return JSONObject.parseObject(redisUtils.get(buildKey(getUserId(), getToken())).toString(), ReginParams.class);
}
/**
* 当前登录用户信息
*/
protected AgencyUserModel getUserInfo() {
AgencyUserModel userModel = null;
if (getToken() != null) {
RequestContext.setToken(getToken());
RequestContext.setProduct(getProduct());
RequestContext.setAppKey(getAppKey());
FeignClientResult<?> feignClientResult;
try {
feignClientResult = Privilege.agencyUserClient.getme();
userModel = (AgencyUserModel) feignClientResult.getResult();
} catch (InnerInvokException e) {
throw new RuntimeException(e.getMessage());
}
}
return userModel;
}
/**
* 获取当前登录用户id
**/
protected String getUserId() {
String userId = null;
if (getUserInfo() != null) {
userId = getUserInfo().getUserId();
}
return userId;
}
/**
* 获取请求的cookies
*
* @return
*/
protected HashMap<String, String> getCookInfoMap() {
HashMap<String, String> map = new HashMap<String, String>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie ck : cookies) {
map.put(ck.getName(), ck.getValue());
}
}
return map;
}
/**
* 获取登录用户getLoginOrgCode
**/
protected String getLoginOrgCode(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getDepartment() != null) {
return reginParams.getDepartment().getOrgCode();
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getOrgCode();
}
return null;
}
/**
* 获取部门id
**/
protected Long getDepartmentId(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getDepartment() != null) {
return reginParams.getDepartment().getSequenceNbr();
}
return null;
}
/**
* 获取公司id
**/
protected Long getCompanyId(ReginParams reginParams) {
if (reginParams == null) {
return null;
}
if (reginParams.getCompany() != null) {
return reginParams.getCompany().getSequenceNbr();
}
return null;
}
/**
* <pre>
* 提取错误异常中的错误消息
* </pre>
*
* <p>
* 当实体类中对属相注解了以下类似的注解,需要用try.catch语句捕获异常,使用 #getErrorMessage(Exception)
* 提取出异常信息NotNull(message = "属性不能为空!")
* </p>
*
* @param e
* @return
* @see {@code NotBlank} ... NotNull、NotEmpty...
* @see {@code Valid}
*/
public String getErrorMessage(Exception e) {
StringBuilder message = new StringBuilder();
if (e instanceof TransactionSystemException) {
TransactionSystemException exception = (TransactionSystemException) e;
if (exception.getRootCause() instanceof ConstraintViolationException) {
ConstraintViolationException root = (ConstraintViolationException) exception.getRootCause();
root.getConstraintViolations().forEach(constraintViolation -> {
message.append(constraintViolation.getMessageTemplate());
});
} else {
message.append(e.getMessage());
}
} else if (e instanceof ConstraintViolationException) {
((ConstraintViolationException) e).getConstraintViolations()
.forEach(constraintViolation -> message.append(constraintViolation.getMessageTemplate()));
} else {
message.append("操作异常!");
}
return message.toString();
}
}
package org.amos.boot.biz.common.utils;
import org.amos.boot.biz.common.constants.CommonConstant;
import org.springframework.http.HttpStatus;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
*/
public class CommonResponseUtil {
public static ResponseModel success() {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_SUCCESS);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel success(Object obj) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(CommonConstant.RESULT_SUCCESS);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel success(Object obj, String message) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(message);
res.setStatus(HttpStatus.OK.value());
return res;
}
public static ResponseModel failure() {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
public static ResponseModel failure(String message) {
ResponseModel res = new ResponseModel();
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setMessage(message);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
public static ResponseModel failure(Object obj, String message) {
ResponseModel res = new ResponseModel();
res.setResult(obj);
res.setDevMessage(CommonConstant.RESULT_FAILURE);
res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return res;
}
}
package org.amos.boot.biz.common.utils;
import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @description: 时间工具类
* @author: DELL
* @create: 2021-05-26
**/
public class DateUtils {
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
public static final String HOUR_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_PATTERN = "yyyy-MM-dd";
public static final String MONTH_PATTERN = "yyyy-MM";
public static final String YEAR_PATTERN = "yyyy";
public static final String MINUTE_ONLY_PATTERN = "mm";
public static final String HOUR_ONLY_PATTERN = "HH";
/**
* 获取当前时间
*
* @return 当前日期时间
*/
public static Date getDateNow() {
return new Date();
}
/**
* 获取当前时间
*
* @return 当前日期时间
*/
public static String getDateNowString() {
return convertDateToString(getDateNow(), DATE_TIME_PATTERN);
}
public static String date2LongStr(Date dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
/**
* 获取现在时间字符串
*
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getNowStrLong() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 将日期转换为字符串
*
* @param date 日期
* @param format 字符串格式
* @return 日期字符串
*/
public static String convertDateToString(Date date, String format) {
SimpleDateFormat df = null;
String returnValue = "";
if (null != date) {
df = new SimpleDateFormat(format);
returnValue = df.format(date);
}
return returnValue;
}
/**
* 获取当前时间任意
*
* @return
*/
public static String get(int field) {
return String.valueOf(getCalendar().get(field));
}
/**
* 当前日历,这里用中国时间表示
*
* @return 以当地时区表示的系统当前日历
*/
public static Calendar getCalendar() {
return Calendar.getInstance();
}
/**
* 日期相加减天数
*
* @param date 如果为Null,则为当前时间
* @param days 加减天数
* @param includeTime 是否包括时分秒,true表示包含
* @return
* @throws ParseException
*/
public static Date dateAdd(Date date, int days, boolean includeTime) throws ParseException {
if (date == null) {
date = new Date();
}
if (!includeTime) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_PATTERN);
date = sdf.parse(sdf.format(date));
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, days);
return cal.getTime();
}
/**
* 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
*
* @param strDate
* @return
*/
public static Date longStr2Date(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/**
* 时间格式化成字符串
*
* @param date Date
* @param pattern StrUtils.DATE_TIME_PATTERN || StrUtils.DATE_PATTERN, 如果为空,则为yyyy-MM-dd
* @return
* @throws ParseException
*/
public static String dateFormat(Date date, String pattern) throws ParseException {
if (StringUtils.isNotEmpty(pattern)) {
pattern = DateUtils.DATE_PATTERN;
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
/**
* 暂时不操作原生截取做下转换
*
* @param str
* @return
* @throws ParseException
*/
public static String dateToString(String str) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date parse = null;
String content = null;
try {
parse = sdf.parse(str);
content = DateUtils.dateFormat(parse, DateUtils.DATE_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
return content;
}
/*
* 将时间戳转换为时间
*/
public static String stampToDate(Long s, String format) {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = new Date(s);
res = simpleDateFormat.format(date);
return res;
}
/**
* 字符串解析成时间对象
*
* @param dateTimeString String
* @param pattern StrUtils.DATE_TIME_PATTERN || StrUtils.DATE_PATTERN,如果为空,则为yyyy-MM-dd
* @return
* @throws ParseException
*/
public static Date dateParse(String dateTimeString, String pattern) throws ParseException {
if (StringUtils.isNotEmpty(pattern)) {
pattern = DateUtils.DATE_PATTERN;
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.parse(dateTimeString);
}
/**
* 将日期时间格式成只有日期的字符串(可以直接使用dateFormat,Pattern为Null进行格式化)
*
* @param dateTime Date
* @return
* @throws ParseException
*/
public static String dateTimeToDateString(Date dateTime) throws ParseException {
String dateTimeString = DateUtils.dateFormat(dateTime, DateUtils.DATE_TIME_PATTERN);
return dateTimeString.substring(0, 10);
}
/**
* 当时、分、秒为00:00:00时,将日期时间格式成只有日期的字符串,
* 当时、分、秒不为00:00:00时,直接返回
*
* @param dateTime Date
* @return
* @throws ParseException
*/
public static String dateTimeToDateStringIfTimeEndZero(Date dateTime) throws ParseException {
String dateTimeString = DateUtils.dateFormat(dateTime, DateUtils.DATE_TIME_PATTERN);
if (dateTimeString.endsWith("00:00:00")) {
return dateTimeString.substring(0, 10);
} else {
return dateTimeString;
}
}
/**
* 将日期时间格式成日期对象,和dateParse互用
*
* @param dateTime Date
* @return Date
* @throws ParseException
*/
public static Date dateTimeToDate(Date dateTime) throws ParseException {
Calendar cal = Calendar.getInstance();
cal.setTime(dateTime);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 时间加减小时
*
* @param startDate 要处理的时间,Null则为当前时间
* @param hours 加减的小时
* @return Date
*/
public static Date dateAddHours(Date startDate, int hours) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.HOUR, c.get(Calendar.HOUR) + hours);
return c.getTime();
}
/**
* 时间加减分钟
*
* @param startDate 要处理的时间,Null则为当前时间
* @param minutes 加减的分钟
* @return
*/
public static Date dateAddMinutes(Date startDate, int minutes) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + minutes);
return c.getTime();
}
/**
* 时间加减秒数
*
* @param startDate 要处理的时间,Null则为当前时间
* @param
* @return
*/
public static Date dateAddSeconds(Date startDate, int seconds) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.SECOND, c.get(Calendar.SECOND) + seconds);
return c.getTime();
}
/**
* 时间加减天数
*
* @param startDate 要处理的时间,Null则为当前时间
* @param days 加减的天数
* @return Date
*/
public static Date dateAddDays(Date startDate, int days) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.DATE, c.get(Calendar.DATE) + days);
return c.getTime();
}
/**
* 时间加减月数
*
* @param startDate 要处理的时间,Null则为当前时间
* @param months 加减的月数
* @return Date
*/
public static Date dateAddMonths(Date startDate, int months) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.MONTH, c.get(Calendar.MONTH) + months);
return c.getTime();
}
/**
* 时间加减年数
*
* @param startDate 要处理的时间,Null则为当前时间
* @param years 加减的年数
* @return Date
*/
public static Date dateAddYears(Date startDate, int years) {
if (startDate == null) {
startDate = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(startDate);
c.set(Calendar.YEAR, c.get(Calendar.YEAR) + years);
return c.getTime();
}
/**
* 时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0)
*
* @param myDate 时间
* @param compareDate 要比较的时间
* @return int
*/
public static int dateCompare(Date myDate, Date compareDate) {
Calendar myCal = Calendar.getInstance();
Calendar compareCal = Calendar.getInstance();
myCal.setTime(myDate);
compareCal.setTime(compareDate);
return myCal.compareTo(compareCal);
}
/**
* 获取两个时间中最小的一个时间
*
* @param date
* @param compareDate
* @return
*/
public static Date dateMin(Date date, Date compareDate) {
if (date == null) {
return compareDate;
}
if (compareDate == null) {
return date;
}
if (1 == dateCompare(date, compareDate)) {
return compareDate;
} else if (-1 == dateCompare(date, compareDate)) {
return date;
}
return date;
}
/**
* 获取两个时间中最大的一个时间
*
* @param date
* @param compareDate
* @return
*/
public static Date dateMax(Date date, Date compareDate) {
if (date == null) {
return compareDate;
}
if (compareDate == null) {
return date;
}
if (1 == dateCompare(date, compareDate)) {
return date;
} else if (-1 == dateCompare(date, compareDate)) {
return compareDate;
}
return date;
}
/**
* 获取两个日期(不含时分秒)相差的天数,不包含今天
*
* @param startDate
* @param endDate
* @return
* @throws ParseException
*/
public static int dateBetween(Date startDate, Date endDate) throws ParseException {
Date dateStart = dateParse(dateFormat(startDate, DATE_PATTERN), DATE_PATTERN);
Date dateEnd = dateParse(dateFormat(endDate, DATE_PATTERN), DATE_PATTERN);
return (int) ((dateEnd.getTime() - dateStart.getTime()) / 1000 / 60 / 60 / 24);
}
/**
* 获取两个日期(不含时分秒)相差的天数,包含今天
*
* @param startDate
* @param endDate
* @return
* @throws ParseException
*/
public static int dateBetweenIncludeToday(Date startDate, Date endDate) throws ParseException {
return dateBetween(startDate, endDate) + 1;
}
/**
* 获取日期时间的年份,如2017-02-13,返回2017
*
* @param date
* @return
*/
public static int getYear(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.YEAR);
}
/**
* 获取日期时间的月份,如2017年2月13日,返回2
*
* @param date
* @return
*/
public static int getMonth(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.MONTH) + 1;
}
/**
* 获取日期时间的第几天(即返回日期的dd),如2017-02-13,返回13
*
* @param date
* @return
*/
public static int getDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DATE);
}
/**
* 获取日期时间当月的总天数,如2017-02-13,返回28
*
* @param date
* @return
*/
public static int getDaysOfMonth(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getActualMaximum(Calendar.DATE);
}
/**
* 获取日期时间当年的总天数,如2017-02-13,返回2017年的总天数
*
* @param date
* @return
*/
public static int getDaysOfYear(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getActualMaximum(Calendar.DAY_OF_YEAR);
}
/**
* 根据时间获取当月最大的日期
* <li>2017-02-13,返回2017-02-28</li>
* <li>2016-02-13,返回2016-02-29</li>
* <li>2016-01-11,返回2016-01-31</li>
*
* @param date Date
* @return
* @throws Exception
*/
public static Date maxDateOfMonth(Date date) throws Exception {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int value = cal.getActualMaximum(Calendar.DATE);
return dateParse(dateFormat(date, MONTH_PATTERN) + "-" + value, null);
}
/**
* 根据时间获取当月最小的日期,也就是返回当月的1号日期对象
*
* @param date Date
* @return
* @throws Exception
*/
public static Date minDateOfMonth(Date date) throws Exception {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int value = cal.getActualMinimum(Calendar.DATE);
return dateParse(dateFormat(date, MONTH_PATTERN) + "-" + value, null);
}
public static void main(String[] args) throws Exception {
/*System.out.println(dateTimeToDate(new Date()));
System.out.println(dateParse("2017-02-04 14:58:20", null));
System.out.println(dateTimeToDateStringIfTimeEndZero(new Date()));
System.out.println(dateTimeToDateStringIfTimeEndZero(dateTimeToDate(new Date())));*/
//System.out.println(dateBetween(dateParse("2017-01-30", null), dateParse("2017-02-01", null)));
//System.out.println(dateBetweenIncludeToday(dateParse("2017-01-30", null), dateParse("2017-02-01", null)));
System.out.println(getDate(dateParse("2017-01-17", null)));
/*
System.out.println(getDaysOfMonth(dateParse("2017-02-01", null)));
System.out.println(getDaysOfYear(dateParse("2017-01-30", null)));*/
//System.out.println(dateFormat(dateAddMonths(dateParse("2017-02-07", StrUtils.MONTH_PATTERN), -12), StrUtils.MONTH_PATTERN));
/*System.out.println(dateFormat(maxDateOfMonth(dateParse("2016-02", "yyyy-MM")), null));
System.out.println(dateFormat(minDateOfMonth(dateParse("2016-03-31", null)), null));*/
}
}
package org.amos.boot.biz.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author DELL
*/
public class RedisUtils {
@Autowired
private RedisTemplate redisTemplate;
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public boolean expire(String key, long time) {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
return true;
} else {
throw new RuntimeException("超时时间小于0");
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public long getExpire(String key) {
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
@SuppressWarnings("unchecked")
public void del(String... key) {
if (key != null && key.length > 0) {
if (key.length == 1) {
redisTemplate.delete(key[0]);
} else {
redisTemplate.delete(CollectionUtils.arrayToList(key));
}
}
}
// ============================String=============================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public Object get(String key) {
Object object = redisTemplate.opsForValue().get(key);
return key == null ? null : object;
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean set(String key, Object value) {
redisTemplate.opsForValue().set(key, value);
return true;
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public boolean set(String key, Object value, long time) {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
this.set(key, value);
}
return true;
}
/**
* 递增
*
* @param key 键
* @param by 要增加几(大于0)
* @return
*/
public long incr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递增因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, delta);
}
/**
* 递减
*
* @param key 键
* @param by 要减少几(小于0)
* @return
*/
public long decr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递减因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, -delta);
}
// ================================Map=================================
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public Object hget(String key, String item) {
return redisTemplate.opsForHash().get(key, item);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public Map<Object, Object> hmget(String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public boolean hmset(String key, Map<String, Object> map) {
redisTemplate.opsForHash().putAll(key, map);
return true;
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
redisTemplate.opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value) {
redisTemplate.opsForHash().put(key, item, value);
return true;
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value, long time) {
redisTemplate.opsForHash().put(key, item, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public void hdel(String key, Object... item) {
redisTemplate.opsForHash().delete(key, item);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public boolean hHasKey(String key, String item) {
return redisTemplate.opsForHash().hasKey(key, item);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public double hincr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, by);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public double hdecr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, -by);
}
// ============================set=============================
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public Set<Object> sGet(String key) {
return redisTemplate.opsForSet().members(key);
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public boolean sHasKey(String key, Object value) {
return redisTemplate.opsForSet().isMember(key, value);
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSet(String key, Object... values) {
return redisTemplate.opsForSet().add(key, values);
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSetAndTime(String key, long time, Object... values) {
final Long count = redisTemplate.opsForSet().add(key, values);
if (time > 0) {
expire(key, time);
}
return count;
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public long sGetSetSize(String key) {
return redisTemplate.opsForSet().size(key);
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public long setRemove(String key, Object... values) {
final Long count = redisTemplate.opsForSet().remove(key, values);
return count;
}
// ===============================list=================================
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public List<Object> lGet(String key, long start, long end) {
return redisTemplate.opsForList().range(key, start, end);
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public long lGetListSize(String key) {
return redisTemplate.opsForList().size(key);
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public Object lGetIndex(String key, long index) {
return redisTemplate.opsForList().index(key, index);
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, Object value) {
redisTemplate.opsForList().rightPush(key, value);
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, Object value, long time) {
redisTemplate.opsForList().rightPush(key, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, List<Object> value) {
redisTemplate.opsForList().rightPushAll(key, value);
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, List<Object> value, long time) {
redisTemplate.opsForList().rightPushAll(key, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public boolean lUpdateIndex(String key, long index, Object value) {
redisTemplate.opsForList().set(key, index, value);
return true;
}
}
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
<artifactId>amos-boot-module-tzs-api</artifactId> <artifactId>amos-boot-module-tzs-api</artifactId>
<version>${amos-biz-boot.version}</version> <version>${amos-biz-boot.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-biz-common</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
package org.amos.boot.module.tzs.biz;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package org.amos.boot.module.tzs.biz.controller;
import org.amos.boot.biz.common.controller.BaseController;
import org.amos.boot.biz.common.utils.CommonResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RestController
@RequestMapping("/test")
public class TestController extends BaseController {
public ResponseModel test() {
return CommonResponseUtil.success();
}
}
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
</dependencies> </dependencies>
<modules> <modules>
<module>amos-boot-module-jcs-api</module>
<module>amos-boot-module-tzs-biz</module>
<module>amos-boot-module-api</module> <module>amos-boot-module-api</module>
<module>amos-boot-module-biz</module> <module>amos-boot-module-biz</module>
<module>amos-boot-cloud-gateway</module> <module>amos-boot-cloud-gateway</module>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-tzs-system</artifactId>
<name>SpecialEquipmentServiceStart</name>
<packaging>jar</packaging>
<parent> <parent>
<artifactId>amos-biz-boot</artifactId> <artifactId>amos-biz-boot</artifactId>
<groupId>com.amosframework.boot</groupId> <groupId>com.amosframework.boot</groupId>
<version>1.0.0</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>amos-boot-tzs-system</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.amosframework.boot</groupId> <groupId>com.amosframework.boot</groupId>
......
package com.yeejoin.amos; package com.yeejoin.amos;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
...@@ -23,6 +22,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -23,6 +22,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
* 特种设备服务启动类 * 特种设备服务启动类
* </pre> * </pre>
* *
* @author DELL
*/ */
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
...@@ -34,13 +34,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -34,13 +34,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableAsync @EnableAsync
@EnableEurekaClient @EnableEurekaClient
@ComponentScan({"org.typroject","com.yeejoin.amos"}) @ComponentScan({"org.typroject","com.yeejoin.amos"})
//@MapperScan(basePackages = {"com.yeejoin.amos.patrol.service.business.dao.mapper"}) public class AmosTzsApplication {
public class AmosTzsApplication
{
private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class); private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class);
public static void main( String[] args ) public static void main(String[] args) {
{
ConfigurableApplicationContext context = SpringApplication.run(AmosTzsApplication.class, args); ConfigurableApplicationContext context = SpringApplication.run(AmosTzsApplication.class, args);
Environment environment = context.getEnvironment(); Environment environment = context.getEnvironment();
......
#DB properties:
spring.datasource.url=jdbc:mysql://172.16.10.66:3306/safety-business-3.0.0?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root_123
\ No newline at end of file
#DB properties:
spring.datasource.url=jdbc:mysql://172.16.10.66:3306/safety-business-3.0.0?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root_123
\ No newline at end of file
spring.application.name=SPECIAL-EQUIPMENT
server.servlet.context-path=/specialEquip
server.port=10000
spring.profiles.active=dev
\ No newline at end of file
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<url>http://172.16.1.6:8081/nexus/content/repositories/maven-public/</url> <url>http://172.16.1.6:8081/nexus/content/repositories/maven-public/</url>
</repository> </repository>
<repository> <repository>
<id>maven-public</id> <id>maven-public1</id>
<name>maven-public</name> <name>maven-public</name>
<url>http://repo.typroject.org:8081/repository/maven-public/</url> <url>http://repo.typroject.org:8081/repository/maven-public/</url>
</repository> </repository>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment