From bdf115fc3eec4f95fed6def5f3350b600e1b2b53 Mon Sep 17 00:00:00 2001
From: liyanqi <15181887205@163.com>
Date: 星期四, 08 九月 2022 16:16:57 +0800
Subject: [PATCH] 基本设置
---
ycl-common/src/main/java/com/ycl/entity/depart/SccgDepart.java | 61 +
ycl-platform/src/main/java/com/ycl/controller/user/UmsAdminController.java | 26
ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java | 159 +++
ycl-common/src/main/resources/mapper/depart/SccgDepartMapper.xml | 18
ycl-common/src/main/java/com/ycl/mapper/depart/SccgDepartMapper.java | 16
ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java | 104 +
ycl-common/src/main/resources/mapper/user/UmsAdminMapper.xml | 38
ycl-platform/src/main/java/com/ycl/controller/user/UmsRoleController.java | 2
ycl-common/src/main/java/com/ycl/config/MetaObjectConfig.java | 48 +
ycl-common/src/main/java/com/ycl/vo/user/UserVO.java | 28
ycl-common/src/main/java/com/ycl/utils/common/ThreadDateUtil.java | 79 +
ycl-common/src/main/java/com/ycl/api/BaseEntity.java | 25
ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java | 9
ycl-common/src/main/java/com/ycl/utils/common/DatePattern.java | 30
ycl-common/src/main/java/com/ycl/enums/common/ResultCode.java | 11
ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java | 1
ycl-common/src/main/java/com/ycl/api/BasePageVO.java | 23
ycl-common/src/main/java/com/ycl/service/depart/SccgDepartService.java | 66 +
ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java | 58 +
ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceCategoryController.java | 2
ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceController.java | 2
ycl-platform/src/main/java/com/ycl/controller/depart/DepartController.java | 71 +
ycl-common/src/main/java/com/ycl/enums/common/DelType.java | 48 +
ycl-common/src/main/java/com/ycl/utils/common/DateUtil.java | 1389 +++++++++++++++++++++++++++++++++
ycl-common/src/main/java/com/ycl/vo/depart/DepartVO.java | 80 +
ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java | 3
ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java | 9
ycl-platform/src/main/java/com/ycl/controller/user/UmsMenuController.java | 2
28 files changed, 2,339 insertions(+), 69 deletions(-)
diff --git a/ycl-common/src/main/java/com/ycl/api/BaseEntity.java b/ycl-common/src/main/java/com/ycl/api/BaseEntity.java
new file mode 100644
index 0000000..9a2eff6
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/api/BaseEntity.java
@@ -0,0 +1,25 @@
+package com.ycl.api;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.Date;
+
+/**
+ * @author Lyq
+ * @version 1.0
+ * @date 2022/9/7
+ */
+public class BaseEntity {
+ @ApiModelProperty("鍒涘缓鏃堕棿")
+ @TableField(fill = FieldFill.INSERT)
+ private Date createTime;
+ /**
+ * 涓婁竴娆′慨鏀规椂闂�
+ */
+ @ApiModelProperty("淇敼鏃堕棿")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Date updateTime;
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/api/BasePageVO.java b/ycl-common/src/main/java/com/ycl/api/BasePageVO.java
new file mode 100644
index 0000000..b73b3d8
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/api/BasePageVO.java
@@ -0,0 +1,23 @@
+package com.ycl.api;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import java.io.Serializable;
+
+@Data
+@ApiModel
+public class BasePageVO implements Serializable {
+
+ @ApiModelProperty(value = "褰撳墠椤�",example = "1")
+ @Min(value = 1, message = "鏈�灏忛〉鏁�1")
+ private int current = 1;
+
+ @ApiModelProperty(value = "鏉℃暟",example = "1~100")
+ @Min(value = 1, message = "鏈�灏忔潯鏁�1")
+ @Max(value = 100, message = "鏈�澶ф潯鏁�100")
+ private int pageSize = 20;
+}
diff --git a/ycl-common/src/main/java/com/ycl/config/MetaObjectConfig.java b/ycl-common/src/main/java/com/ycl/config/MetaObjectConfig.java
new file mode 100644
index 0000000..89f544d
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/config/MetaObjectConfig.java
@@ -0,0 +1,48 @@
+package com.ycl.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.ycl.enums.common.DelType;
+import com.ycl.utils.common.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Date;
+
+/**
+ * 鑷姩濉厖 createTime 鍜� updateTime 鏁版嵁
+ *
+ * @author lyq
+ * @since 2022/9/7
+ */
+@Slf4j
+@Configuration
+public class MetaObjectConfig implements MetaObjectHandler {
+ /**
+ * 鑷姩鎻掑叆鏁版嵁
+ *
+ * @param metaObject
+ */
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ log.info("start insert fill ....");
+ // 璧峰鐗堟湰 3.3.0(鎺ㄨ崘浣跨敤)
+ this.setFieldValByName("createTime", new Date(), metaObject);
+ this.setFieldValByName("updateTime", new Date(), metaObject);
+ this.setFieldValByName("isDeleted", DelType.NORMAL.getCode(), metaObject);
+
+ }
+
+
+ /**
+ * 鑷姩鏇存柊鏁版嵁
+ *
+ * @param metaObject
+ */
+ @Override
+ public void updateFill(MetaObject metaObject) {
+ log.info("start update fill ....");
+ // 璧峰鐗堟湰 3.3.0(鎺ㄨ崘浣跨敤)
+ this.setFieldValByName("updateTime", new Date(), metaObject);
+ }
+}
diff --git a/ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java b/ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java
index eee1adb..718b238 100644
--- a/ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java
+++ b/ycl-common/src/main/java/com/ycl/dto/UmsAdminParam.java
@@ -37,13 +37,14 @@
@ApiModelProperty(value = "澶囨敞")
private String note;
- @ApiModelProperty(value = "鏄惁鍏氬憳,0:鍚︼紝1锛氭槸")
+ @ApiModelProperty(value = "鏄惁鍏氬憳,0:鍚︼紝1锛氭槸",example = "0")
private byte isDy;
@ApiModelProperty(value = "鑱屽姟")
private String jobTitle;
@ApiModelProperty(value = "閮ㄩ棬id")
+ @NotNull(message = "閮ㄩ棬涓嶈兘涓虹┖")
private Long departmentId;
@ApiModelProperty(value = "鐢ㄦ埛绫诲瀷")
diff --git a/ycl-common/src/main/java/com/ycl/entity/depart/SccgDepart.java b/ycl-common/src/main/java/com/ycl/entity/depart/SccgDepart.java
new file mode 100644
index 0000000..635d4ac
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/entity/depart/SccgDepart.java
@@ -0,0 +1,61 @@
+package com.ycl.entity.depart;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.ycl.api.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 閮ㄩ棬琛�
+ * </p>
+ *
+ * @author lyq
+ * @since 2022-09-07
+ */
+@Getter
+@Setter
+@TableName("sccg_depart")
+@ApiModel(value = "SccgDepart瀵硅薄", description = "閮ㄩ棬琛�")
+public class SccgDepart extends BaseEntity implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @ApiModelProperty("涓婚敭")
+ @TableId(value = "id", type = IdType.AUTO)
+ private Long id;
+
+ @ApiModelProperty("閮ㄩ棬鍚嶇О")
+ private String departName;
+
+ @ApiModelProperty("閮ㄩ棬鎻忚堪")
+ private String departDes;
+
+ @ApiModelProperty("閮ㄩ棬绫诲瀷")
+ private byte departType;
+
+ @ApiModelProperty("鐖剁骇id,榛樿0")
+ private Long parentId;
+
+ @ApiModelProperty("鍋滅敤鐘舵�侊紝0->false,1->true,榛樿鍋滅敤")
+ private byte status;
+
+ /**
+ * 閫昏緫鍒犻櫎 0:false 1:true 榛樿0
+ */
+ @ApiModelProperty(value = "鏄惁鍒犻櫎", hidden = true)
+ @TableField(select = false)
+ @TableLogic()
+ private byte isDeleted;
+
+ @TableField(exist = false)
+ private List<SccgDepart> children;
+
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java b/ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java
index 67edecf..9b8376d 100644
--- a/ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java
+++ b/ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java
@@ -1,6 +1,7 @@
package com.ycl.entity.user;
import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
@@ -30,6 +31,7 @@
@TableId(value = "id", type = IdType.AUTO)
private Long id;
+ @ApiModelProperty(value = "鐢ㄦ埛濮撳悕")
private String username;
private String password;
@@ -70,14 +72,15 @@
@ApiModelProperty(value = "閮ㄩ棬id")
private Long departmentId;
+ @ApiModelProperty(value = "閮ㄩ棬鍚嶇О")
+ @TableField(exist = false)
+ private String departName;
+
@ApiModelProperty(value = "鐢ㄦ埛绫诲瀷")
private byte userType;
@ApiModelProperty(value = "搴ф満/鍒嗘満")
private String zj;
-
- @ApiModelProperty(value = "鐢ㄦ埛鍚�")
- private String realName;
@ApiModelProperty(value = "鎵嬫満鍙风爜")
private String mobile;
diff --git a/ycl-common/src/main/java/com/ycl/enums/common/DelType.java b/ycl-common/src/main/java/com/ycl/enums/common/DelType.java
new file mode 100644
index 0000000..f591c72
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/enums/common/DelType.java
@@ -0,0 +1,48 @@
+package com.ycl.enums.common;
+
+/**
+ * 浼垹闄�
+ * @author lyq
+ * @since 2022-09-07
+ * @Description
+ */
+public enum DelType {
+
+ /***/
+ NORMAL((byte) 0, "姝e父鐘舵��"),
+
+ IS_DEL((byte) 1, "浼垹闄ょ姸鎬�");
+
+ private byte code;
+ private String name;
+
+ DelType(byte code, String name) {
+ this.code = code;
+ this.name = name;
+ }
+
+ public static String getName(byte code) {
+ for (DelType del : DelType.values()) {
+ if (del.code == code) {
+ return del.name;
+ }
+ }
+ return null;
+ }
+
+ public byte getCode() {
+ return code;
+ }
+
+ public void setCode(byte code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/ycl-common/src/main/java/com/ycl/enums/common/ResultCode.java b/ycl-common/src/main/java/com/ycl/enums/common/ResultCode.java
index 0b280e8..8e9c1b5 100644
--- a/ycl-common/src/main/java/com/ycl/enums/common/ResultCode.java
+++ b/ycl-common/src/main/java/com/ycl/enums/common/ResultCode.java
@@ -4,13 +4,22 @@
/**
* 鏋氫妇浜嗕竴浜涘父鐢ˋPI鎿嶄綔鐮�
+ *
+ * @author lyq
+ * @since 2022-09-06
*/
public enum ResultCode implements IErrorCode {
SUCCESS(200, "鎿嶄綔鎴愬姛"),
FAILED(500, "鎿嶄綔澶辫触"),
VALIDATE_FAILED(404, "鍙傛暟妫�楠屽け璐�"),
UNAUTHORIZED(401, "鏆傛湭鐧诲綍鎴杢oken宸茬粡杩囨湡"),
- FORBIDDEN(403, "娌℃湁鐩稿叧鏉冮檺");
+ FORBIDDEN(403, "娌℃湁鐩稿叧鏉冮檺"),
+
+ RECORD_ALREADY_EXISTS(2001, "璁板綍宸插瓨鍦�"),
+ RECORD_SAVE_FAIL(2002, "璁板綍淇濆瓨澶辫触"),
+ RECORD_UPDATE_FAIL(2003, "璁板綍鏇存柊澶辫触"),
+ RECORD_DELETE_FAIL(2004, "璁板綍鍒犻櫎澶辫触"),
+ RECORD_NOT_EXISTS(2005, "璁板綍涓嶅瓨鍦�");
private long code;
private String message;
diff --git a/ycl-common/src/main/java/com/ycl/mapper/depart/SccgDepartMapper.java b/ycl-common/src/main/java/com/ycl/mapper/depart/SccgDepartMapper.java
new file mode 100644
index 0000000..52b501b
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/mapper/depart/SccgDepartMapper.java
@@ -0,0 +1,16 @@
+package com.ycl.mapper.depart;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ycl.entity.depart.SccgDepart;
+
+/**
+ * <p>
+ * 閮ㄩ棬琛� Mapper 鎺ュ彛
+ * </p>
+ *
+ * @author lyq
+ * @since 2022-09-07
+ */
+public interface SccgDepartMapper extends BaseMapper<SccgDepart> {
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/service/depart/SccgDepartService.java b/ycl-common/src/main/java/com/ycl/service/depart/SccgDepartService.java
new file mode 100644
index 0000000..a24b41b
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/service/depart/SccgDepartService.java
@@ -0,0 +1,66 @@
+package com.ycl.service.depart;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ycl.entity.depart.SccgDepart;
+import com.ycl.vo.depart.DepartVO;
+import org.apache.catalina.LifecycleState;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 閮ㄩ棬琛� 鏈嶅姟绫�
+ * </p>
+ *
+ * @author lyq
+ * @since 2022-09-07
+ */
+public interface SccgDepartService extends IService<SccgDepart> {
+ /**
+ * 鏂板
+ *
+ * @param addDepartVO
+ */
+ void create(DepartVO.AddDepartVO addDepartVO);
+
+ /**
+ * 璇︽儏
+ *
+ * @param id
+ * @return
+ */
+ SccgDepart loadDepartById(long id);
+
+ /**
+ * 淇敼
+ *
+ * @param updateDepartVO
+ */
+ void update(DepartVO.UpdateDepartVO updateDepartVO);
+
+ /**
+ * 鍒犻櫎
+ * @param id
+ */
+ void delete(long id);
+
+ /**
+ * 鏍戝舰
+ * @return
+ */
+ List<SccgDepart> tree();
+
+ /**
+ * 鍒嗛〉
+ * @param params
+ * @return
+ */
+ IPage<SccgDepart> pageDepart(DepartVO.PageDepartVO params);
+
+ /**
+ * 淇敼鐘舵��
+ * @param params
+ */
+ void updateStatus(DepartVO.StatusDepartVO params);
+}
diff --git a/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java
new file mode 100644
index 0000000..7243c24
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/service/depart/impl/SccgDepartServiceImpl.java
@@ -0,0 +1,159 @@
+package com.ycl.service.depart.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ycl.api.CommonResult;
+import com.ycl.entity.depart.SccgDepart;
+import com.ycl.enums.common.ResultCode;
+import com.ycl.exception.ApiException;
+import com.ycl.mapper.depart.SccgDepartMapper;
+import com.ycl.service.depart.SccgDepartService;
+import com.ycl.vo.depart.DepartVO;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import javax.xml.transform.Result;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 閮ㄩ棬琛� 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author lyq
+ * @since 2022-09-07
+ */
+@Service
+public class SccgDepartServiceImpl extends ServiceImpl<SccgDepartMapper, SccgDepart> implements SccgDepartService {
+ @Resource
+ private SccgDepartMapper sccgDepartMapper;
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void create(DepartVO.AddDepartVO addDepartVO) {
+ SccgDepart sccgDepart = this.queryByName(addDepartVO.getDepartName());
+ if (null != sccgDepart) {
+ throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS);
+ }
+ SccgDepart depart = new SccgDepart();
+ BeanUtils.copyProperties(addDepartVO, depart);
+ if (sccgDepartMapper.insert(depart) <= 0) {
+ throw new ApiException(ResultCode.RECORD_SAVE_FAIL);
+ }
+ }
+
+ @Override
+ public SccgDepart loadDepartById(long id) {
+ SccgDepart sccgDepart = sccgDepartMapper.selectById(id);
+ if (null == sccgDepart) {
+ throw new ApiException(ResultCode.RECORD_NOT_EXISTS);
+ }
+ return sccgDepart;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(DepartVO.UpdateDepartVO updateDepartVO) {
+ SccgDepart sccgDepart = this.queryByName(updateDepartVO.getDepartName());
+ if (null != sccgDepart && sccgDepart.getId() != updateDepartVO.getId()) {
+ throw new ApiException(ResultCode.RECORD_ALREADY_EXISTS);
+ }
+ BeanUtils.copyProperties(updateDepartVO, sccgDepart);
+ if (sccgDepartMapper.updateById(sccgDepart) <= 0) {
+ throw new ApiException(ResultCode.RECORD_UPDATE_FAIL);
+ }
+ }
+
+ @Override
+ public void delete(long id) {
+ if (sccgDepartMapper.deleteById(id) <= 0) {
+ throw new ApiException(ResultCode.RECORD_DELETE_FAIL);
+ }
+ }
+
+ @Override
+ public List<SccgDepart> tree() {
+ // 1.鏌ュ嚭鎵�鏈夌綉鏍�
+ List<SccgDepart> list = list();
+
+ // 2.缁勮鎴愮埗瀛愮殑鏍戝瀷缁撴瀯
+ // 2.1銆佹壘鍒版墍鏈夌殑涓�绾х綉鏍�:浣跨敤jdk8鐨剆tream娴佽繘琛岃繃婊�
+ List<SccgDepart> collect = list.stream().filter(griddingEntity -> {
+ //鍒嗙被鐖秈d涓�0灏辫〃绀鸿缃戞牸涓� 涓�绾х綉鏍�
+ return griddingEntity.getParentId() == 0;
+ }).map(item -> {
+ // 鎵惧埌瀛愮綉鏍� set杩沜hildren灞炴�т腑
+ item.setChildren(getChildrens(item, list));
+ return item;
+ }).collect(Collectors.toList());
+ List<SccgDepart> treeData = getTreeData(collect);
+ return treeData;
+ }
+
+ @Override
+ public IPage<SccgDepart> pageDepart(DepartVO.PageDepartVO params) {
+ return null;
+ }
+
+ @Override
+ public void updateStatus(DepartVO.StatusDepartVO params) {
+ SccgDepart sccgDepart = this.loadDepartById(params.getId());
+ BeanUtils.copyProperties(params, sccgDepart);
+ if (sccgDepartMapper.updateById(sccgDepart) <= 0) {
+ throw new ApiException(ResultCode.RECORD_UPDATE_FAIL);
+ }
+ }
+
+ /**
+ * 鍒╃敤閫掑綊灏嗘渶鍚庝竴绾х┖闆嗗悎鍙樹负null锛屽墠绔仈绾ч�夋嫨鍣ㄦ渶鍚庢墠涓嶄細鍑虹幇 鏆傛棤鏁版嵁鐨刡ug
+ *
+ * @return
+ */
+ public List<SccgDepart> getTreeData(List<SccgDepart> griddingEntities) {
+ for (int i = 0; i < griddingEntities.size(); i++) {
+ //濡傛灉Children鐨剆ize灏忎簬1灏辫鏄庝负绌猴紝璁剧疆涓簄ull
+ if (griddingEntities.get(i).getChildren().size() < 1) {
+ griddingEntities.get(i).setChildren(null);
+ } else {
+ //瀛愮綉鏍兼湁鏁版嵁灏遍�掑綊
+ getTreeData(griddingEntities.get(i).getChildren());
+ }
+ }
+ return griddingEntities;
+ }
+
+ /**
+ * 閫掑綊鏌ユ壘鎵�鏈夌綉鏍肩殑瀛愮綉鏍�
+ *
+ * @param root 褰撳墠缃戞牸
+ * @param all 鎵�鏈夌綉鏍�
+ * @return
+ */
+ public List<SccgDepart> getChildrens(SccgDepart root, List<SccgDepart> all) {
+ List<SccgDepart> collect = all.stream().filter(griddingEntity -> {
+ return griddingEntity.getParentId().equals(root.getId());
+ }).map(item -> {
+ item.setChildren(getChildrens(item, all));
+ return item;
+ }).collect(Collectors.toList());
+ return collect;
+ }
+
+
+ /**
+ * 鏍规嵁鍚嶅瓧鏌ヨ
+ *
+ * @param name
+ * @return
+ */
+ private SccgDepart queryByName(String name) {
+ LambdaQueryWrapper<SccgDepart> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(SccgDepart::getDepartName, name);
+ SccgDepart sccgDepart = this.sccgDepartMapper.selectOne(queryWrapper);
+ return sccgDepart;
+ }
+}
diff --git a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
index 3366c8b..765ab4e 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
@@ -1,5 +1,6 @@
package com.ycl.service.user;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ycl.dto.UmsAdminParam;
@@ -7,6 +8,7 @@
import com.ycl.entity.user.UmsAdmin;
import com.ycl.entity.user.UmsResource;
import com.ycl.entity.user.UmsRole;
+import com.ycl.vo.user.UserVO;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.transaction.annotation.Transactional;
@@ -86,4 +88,11 @@
* 鑾峰彇缂撳瓨鏈嶅姟
*/
UmsAdminCacheService getCacheService();
+
+ /**
+ * 鍒嗛〉
+ * @param pageUserVO
+ * @return
+ */
+ IPage<UmsAdmin> pageUser(UserVO.PageUserVO pageUserVO);
}
diff --git a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
index 59a0545..366c696 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
@@ -4,22 +4,30 @@
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.bo.AdminUserDetails;
import com.ycl.dto.UmsAdminParam;
import com.ycl.dto.UpdateAdminPasswordParam;
+import com.ycl.entity.depart.SccgDepart;
import com.ycl.entity.user.*;
import com.ycl.exception.Asserts;
import com.ycl.mapper.user.UmsAdminLoginLogMapper;
import com.ycl.mapper.user.UmsAdminMapper;
import com.ycl.mapper.user.UmsResourceMapper;
import com.ycl.mapper.user.UmsRoleMapper;
+import com.ycl.service.depart.SccgDepartService;
import com.ycl.service.user.UmsAdminCacheService;
import com.ycl.service.user.UmsAdminRoleRelationService;
import com.ycl.service.user.UmsAdminService;
import com.ycl.utils.JwtTokenUtil;
import com.ycl.utils.SpringUtil;
+import com.ycl.utils.common.MacUtils;
+import com.ycl.utils.common.PojoUtils;
+import com.ycl.utils.common.RandomUtils;
+import com.ycl.vo.user.UserVO;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -31,6 +39,7 @@
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -60,13 +69,15 @@
private UmsRoleMapper umsRoleMapper;
@Resource
private UmsResourceMapper umsResourceMapper;
+ @Resource
+ private SccgDepartService sccgDepartService;
@Override
public UmsAdmin getAdminByUsername(String username) {
UmsAdmin admin = getCacheService().getAdmin(username);
- if(admin!=null) return admin;
+ if (admin != null) return admin;
QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(UmsAdmin::getUsername,username);
+ wrapper.lambda().eq(UmsAdmin::getUsername, username);
List<UmsAdmin> adminList = list(wrapper);
if (adminList != null && adminList.size() > 0) {
admin = adminList.get(0);
@@ -77,15 +88,17 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public UmsAdmin register(UmsAdminParam umsAdminParam) {
UmsAdmin umsAdmin = new UmsAdmin();
//TODO mac,ip,鑱屽姟锛岀敤鎴风被鍨�
BeanUtils.copyProperties(umsAdminParam, umsAdmin);
umsAdmin.setCreateTime(new Date());
umsAdmin.setStatus(1);
+ umsAdmin.setMacAddress(MacUtils.getMac());
//鏌ヨ鏄惁鏈夌浉鍚岀敤鎴峰悕鐨勭敤鎴�
QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(UmsAdmin::getUsername,umsAdmin.getUsername());
+ wrapper.lambda().eq(UmsAdmin::getUsername, umsAdmin.getUsername());
List<UmsAdmin> umsAdminList = list(wrapper);
if (umsAdminList.size() > 0) {
return null;
@@ -94,6 +107,8 @@
String encodePassword = passwordEncoder.encode(umsAdmin.getPassword());
umsAdmin.setPassword(encodePassword);
baseMapper.insert(umsAdmin);
+ umsAdmin.setNickName(RandomUtils.getUserId(umsAdmin.getId()));
+ baseMapper.updateById(umsAdmin);
return umsAdmin;
}
@@ -103,10 +118,10 @@
//瀵嗙爜闇�瑕佸鎴风鍔犲瘑鍚庝紶閫�
try {
UserDetails userDetails = loadUserByUsername(username);
- if(!passwordEncoder.matches(password,userDetails.getPassword())){
+ if (!passwordEncoder.matches(password, userDetails.getPassword())) {
Asserts.fail("瀵嗙爜涓嶆纭�");
}
- if(!userDetails.isEnabled()){
+ if (!userDetails.isEnabled()) {
Asserts.fail("甯愬彿宸茶绂佺敤");
}
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
@@ -122,11 +137,12 @@
/**
* 娣诲姞鐧诲綍璁板綍
+ *
* @param username 鐢ㄦ埛鍚�
*/
private void insertLoginLog(String username) {
UmsAdmin admin = getAdminByUsername(username);
- if(admin==null) return;
+ if (admin == null) return;
UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
loginLog.setAdminId(admin.getId());
loginLog.setCreateTime(new Date());
@@ -143,8 +159,8 @@
UmsAdmin record = new UmsAdmin();
record.setLoginTime(new Date());
QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(UmsAdmin::getUsername,username);
- update(record,wrapper);
+ wrapper.lambda().eq(UmsAdmin::getUsername, username);
+ update(record, wrapper);
}
@Override
@@ -154,28 +170,28 @@
@Override
public Page<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum) {
- Page<UmsAdmin> page = new Page<>(pageNum,pageSize);
+ Page<UmsAdmin> page = new Page<>(pageNum, pageSize);
QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
LambdaQueryWrapper<UmsAdmin> lambda = wrapper.lambda();
- if(StrUtil.isNotEmpty(keyword)){
- lambda.like(UmsAdmin::getUsername,keyword);
- lambda.or().like(UmsAdmin::getNickName,keyword);
+ if (StrUtil.isNotEmpty(keyword)) {
+ lambda.like(UmsAdmin::getUsername, keyword);
+ lambda.or().like(UmsAdmin::getNickName, keyword);
}
- return page(page,wrapper);
+ return page(page, wrapper);
}
@Override
public boolean update(Long id, UmsAdmin admin) {
admin.setId(id);
UmsAdmin rawAdmin = getById(id);
- if(rawAdmin.getPassword().equals(admin.getPassword())){
+ if (rawAdmin.getPassword().equals(admin.getPassword())) {
//涓庡師鍔犲瘑瀵嗙爜鐩稿悓鐨勪笉闇�瑕佷慨鏀�
admin.setPassword(null);
- }else{
+ } else {
//涓庡師鍔犲瘑瀵嗙爜涓嶅悓鐨勯渶瑕佸姞瀵嗕慨鏀�
- if(StrUtil.isEmpty(admin.getPassword())){
+ if (StrUtil.isEmpty(admin.getPassword())) {
admin.setPassword(null);
- }else{
+ } else {
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
}
}
@@ -197,7 +213,7 @@
int count = roleIds == null ? 0 : roleIds.size();
//鍏堝垹闄ゅ師鏉ョ殑鍏崇郴
QueryWrapper<UmsAdminRoleRelation> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(UmsAdminRoleRelation::getAdminId,adminId);
+ wrapper.lambda().eq(UmsAdminRoleRelation::getAdminId, adminId);
umsAdminRoleRelationService.remove(wrapper);
//寤虹珛鏂板叧绯�
if (!CollectionUtils.isEmpty(roleIds)) {
@@ -222,31 +238,31 @@
@Override
public List<UmsResource> getResourceList(Long adminId) {
List<UmsResource> resourceList = getCacheService().getResourceList(adminId);
- if(CollUtil.isNotEmpty(resourceList)){
- return resourceList;
+ if (CollUtil.isNotEmpty(resourceList)) {
+ return resourceList;
}
resourceList = umsResourceMapper.getResourceList(adminId);
- if(CollUtil.isNotEmpty(resourceList)){
- getCacheService().setResourceList(adminId,resourceList);
+ if (CollUtil.isNotEmpty(resourceList)) {
+ getCacheService().setResourceList(adminId, resourceList);
}
return resourceList;
}
@Override
public int updatePassword(UpdateAdminPasswordParam param) {
- if(StrUtil.isEmpty(param.getUsername())
- ||StrUtil.isEmpty(param.getOldPassword())
- ||StrUtil.isEmpty(param.getNewPassword())){
+ if (StrUtil.isEmpty(param.getUsername())
+ || StrUtil.isEmpty(param.getOldPassword())
+ || StrUtil.isEmpty(param.getNewPassword())) {
return -1;
}
QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(UmsAdmin::getUsername,param.getUsername());
+ wrapper.lambda().eq(UmsAdmin::getUsername, param.getUsername());
List<UmsAdmin> adminList = list(wrapper);
- if(CollUtil.isEmpty(adminList)){
+ if (CollUtil.isEmpty(adminList)) {
return -2;
}
UmsAdmin umsAdmin = adminList.get(0);
- if(!passwordEncoder.matches(param.getOldPassword(),umsAdmin.getPassword())){
+ if (!passwordEncoder.matches(param.getOldPassword(), umsAdmin.getPassword())) {
return -3;
}
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
@@ -256,12 +272,12 @@
}
@Override
- public UserDetails loadUserByUsername(String username){
+ public UserDetails loadUserByUsername(String username) {
//鑾峰彇鐢ㄦ埛淇℃伅
UmsAdmin admin = getAdminByUsername(username);
if (admin != null) {
List<UmsResource> resourceList = getResourceList(admin.getId());
- return new AdminUserDetails(admin,resourceList);
+ return new AdminUserDetails(admin, resourceList);
}
throw new UsernameNotFoundException("鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒");
}
@@ -270,4 +286,32 @@
public UmsAdminCacheService getCacheService() {
return SpringUtil.getBean(UmsAdminCacheService.class);
}
+
+ @Override
+ public IPage<UmsAdmin> pageUser(UserVO.PageUserVO pageUserVO) {
+ int pageSize = pageUserVO.getPageSize();
+ int current = pageUserVO.getCurrent();
+ Page<UmsAdmin> page = new Page<>(current, pageSize);
+ LambdaQueryWrapper<UmsAdmin> queryWrapper = new LambdaQueryWrapper<>();
+ if (StringUtils.isNotBlank(pageUserVO.getJobTitle())) {
+ queryWrapper.eq(UmsAdmin::getJobTitle, pageUserVO.getJobTitle());
+ }
+ if (PojoUtils.Vo.isUsefulSearchParam(pageUserVO.getUserType())) {
+ queryWrapper.eq(UmsAdmin::getUserType, pageUserVO.getUserType());
+ }
+ if (PojoUtils.Vo.isUsefulSearchParam(pageUserVO.getDepartmentId())) {
+ queryWrapper.eq(UmsAdmin::getDepartmentId, pageUserVO.getDepartmentId());
+ }
+ Page<UmsAdmin> page1 = baseMapper.selectPage(page, queryWrapper);
+ List<UmsAdmin> records = page1.getRecords();
+ if (CollUtil.isNotEmpty(records)) {
+ records.forEach(e -> {
+ SccgDepart sccgDepart = sccgDepartService.getById(e.getDepartmentId());
+ if (null != sccgDepart) {
+ e.setDepartName(sccgDepart.getDepartName());
+ }
+ });
+ }
+ return page1;
+ }
}
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/DatePattern.java b/ycl-common/src/main/java/com/ycl/utils/common/DatePattern.java
new file mode 100644
index 0000000..6c41e32
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/utils/common/DatePattern.java
@@ -0,0 +1,30 @@
+package com.ycl.utils.common;
+
+/**
+ * 甯哥敤鏃ユ湡鏍煎紡
+ */
+public enum DatePattern {
+
+ /** yyyy-MM */
+ YYYY_MM("yyyyMM"),
+
+ YYYY_MM_DD("yyyy-MM-dd"),
+ YYMMDD("yyMMdd"),
+ /**YYYYMMDD*/
+ YYYYMMDD("yyyyMMdd"),
+ /** yyyy-MM-dd HH:mm */
+ YYYY_MM_DD_HHmm("yyyy-MM-dd HH:mm"),
+ /** yyyy-MM-dd HH:mm:ss */
+ YYYY_MM_DD_HHmmss("yyyy-MM-dd HH:mm:ss"),
+ /** yyyy-MM-dd HH:mm:sss */
+ YYYY_MM_DD_HHmmsss("yyyy-MM-dd HH:mm:sss"),
+ /** yyyyMMddHHmmss */
+ YYYYMMDDHHmmss("yyyyMMddHHmmss");
+
+ public String pattern;
+
+ DatePattern(String pattern) {
+ this.pattern = pattern;
+ }
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/DateUtil.java b/ycl-common/src/main/java/com/ycl/utils/common/DateUtil.java
new file mode 100644
index 0000000..820ee6e
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/utils/common/DateUtil.java
@@ -0,0 +1,1389 @@
+package com.ycl.utils.common;
+
+import com.ycl.api.CommonResult;
+import com.ycl.exception.ApiException;
+import io.netty.util.internal.StringUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.prefs.BackingStoreException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 鏃堕棿宸ュ叿
+ */
+public final class DateUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DateUtil.class);
+
+ /**
+ * 鏃ユ湡鏃跺垎绉�
+ */
+
+ public static final String SF = "\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{2}:\\d{2}:\\d{2}";
+
+ /**
+ * 鏃ユ湡鏃跺垎
+ */
+ public static final String SFM = "\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{2}:\\d{2}";
+
+ //ThreadDateUtil
+ /**
+ * yyyy-MM-dd
+ */
+ public static final String sf1 = "yyyy-MM-dd"; // new SimpleDateFormat("");
+ /**
+ * yyyy-MM-dd HH:mm
+ */
+ public static final String sfm = "yyyy-MM-dd HH:mm"; //new SimpleDateFormat("");
+ /**
+ * yyyy-MM-dd HH:mm:ss
+ */
+ public static final String sf = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * yyyyMMdd 鐢ㄤ簬甯︽棩鏈熺殑SN鐢熸垚
+ */
+ public static final String sfPreSn = "yyyyMMdd";
+
+ /**
+ * HH:mm:ss
+ */
+ public static final String sfH = "HH:mm:ss";
+
+ /**
+ * HH:mm
+ */
+ public static final String sf2 = "HH:mm";
+
+
+ public DateUtil() {
+ }
+
+ public static String getNow() {
+ return ThreadDateUtil.getDateFormat(sf).format(new Date());
+ }
+
+ public static String getNowDate() {
+ return ThreadDateUtil.getDateFormat(sf1).format(new Date());
+ }
+
+ public static String getNowDateForPreSn() {
+ return ThreadDateUtil.getDateFormat(sfPreSn).format(new Date());
+ }
+
+ /**
+ * 鏍规嵁鏃堕棿绫诲瀷姣旇緝鏃堕棿澶у皬
+ *
+ * @param source
+ * @param traget
+ * @param "YYYY-MM-DD" "yyyyMMdd HH:mm:ss" 绫诲瀷鍙嚜瀹氫箟
+ * @param
+ * @return 0 锛歴ource鍜宼raget鏃堕棿鐩稿悓
+ * 1 锛歴ource姣攖raget鏃堕棿澶�
+ * -1锛歴ource姣攖raget鏃堕棿灏�
+ * @throws Exception
+ */
+ public static int DateCompare(long source, long traget) throws Exception {
+ if (source == traget)
+ return 0;
+ else if (source > traget) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * 鏂规硶鍚�: getTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠鏃堕棿鏃跺垎
+ * 淇敼鏃堕棿锛�2016骞�12鏈�2鏃� 涓婂崍10:12:46
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getTime(long time) {
+ return ThreadDateUtil.getDateFormat("HH:mm").format(time);
+ }
+
+ /**
+ * 鏂规硶鍚�: getTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠鏃堕棿鏃跺垎
+ * 淇敼鏃堕棿锛�2016骞�12鏈�2鏃� 涓婂崍10:12:46
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getTime() {
+ return ThreadDateUtil.getDateFormat("HH:mm").format(getNowTime());
+ }
+
+ /**
+ * 鏂规硶鍚�: getEndTime
+ * 鏂规硶鎻忚堪: (杩欓噷鐢ㄤ竴鍙ヨ瘽鎻忚堪杩欎釜鏂规硶鐨勪綔鐢�)
+ * 淇敼鏃堕棿锛�2016骞�11鏈�24鏃� 涓嬪崍9:17:18
+ * 鍙傛暟 @param date
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Date 杩斿洖绫诲瀷
+ */
+ public static Date getEndTime(Date date) {
+ if (date == null) {
+ return null;
+ }
+ 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 calendar.getTime();
+ }
+
+ public static void main(String[] args) throws ParseException {
+ String date = "2021-08";
+ System.out.println(getDate(date));
+ }
+
+ /**
+ * 鏂规硶鍚�: getDate
+ * 鏂规硶鎻忚堪: 灏唋ong鍨嬬殑鏃堕棿 瀛楃涓� 杞崲涓簓yyy-MM-dd鏍煎紡鐨勬棩鏈熷瓧绗︿覆
+ * 淇敼鏃堕棿锛�2017骞�6鏈�19鏃� 涓嬪崍3:24:45
+ * 鍙傛暟 @param str
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getDate(String str) {
+ Date d = new Date(parseLong(str));
+ return ThreadDateUtil.getDateFormat(sf1).format(d);
+ }
+
+ /**
+ * 灏嗗瓧绗︿覆绫诲瀷杞崲涓烘暣鍨�
+ *
+ * @param s
+ * @return
+ */
+ public static Long parseLong(String s) {
+ if (s != null && s.trim().matches("^(-)?[0-9]+$"))
+ return Long.parseLong(s.trim());
+ return 0L;
+ }
+
+ public static Date getSfDate(String str) {
+ Date date;
+ try {
+ if (str.matches(SF)) {
+ date = ThreadDateUtil.getDateFormat(sf).parse(str);
+ } else if (str.matches(SFM)) {
+ date = ThreadDateUtil.getDateFormat(sfm).parse(str);
+ } else
+ date = ThreadDateUtil.getDateFormat(sf1).parse(str);
+ return date;
+ } catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 鏂规硶鍚�: getDate
+ * 鏂规硶鎻忚堪: long 杞琩ate
+ * 淇敼鏃堕棿锛�2017骞�6鏈�13鏃� 涓婂崍10:50:34
+ * 鍙傛暟 @param dateTime
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Date 杩斿洖绫诲瀷
+ */
+ public static Date getDate(long dateTime) {
+ String date = getDateTime(dateTime);
+ Date d = null;
+ try {
+ d = ThreadDateUtil.getDateFormat(sf).parse(date);
+ return d;
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 鏂规硶鍚�: getDateByLong
+ * 鏂规硶鎻忚堪: long 杞垚String YYYY-MM-dd
+ * 淇敼鏃堕棿锛�2017骞�6鏈�13鏃� 涓婂崍11:41:43
+ * 鍙傛暟 @param dateTime
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ *
+ * @return
+ */
+ public static String getDateByLong(long dateTime) {
+ Date date = getDate(dateTime);
+ return ThreadDateUtil.getDateFormat(sf1).format(date);
+ }
+
+ public static String getDateTime(Long date) {
+ if (null == date) {
+ return "";
+ }
+ try {
+ Date d = new Date(date);
+ return ThreadDateUtil.getDateFormat(sf).format(d);
+ } catch (Exception e) {
+ LOGGER.error(" getTime E: {}", date, e);
+ }
+ return "";
+ }
+
+ public static String getTime(Long date) {
+ if (null == date) {
+ return "";
+ }
+ try {
+ Date d = new Date(date);
+ return ThreadDateUtil.getDateFormat(sf).format(d);
+ } catch (Exception e) {
+ LOGGER.error(" getTime E: {}", date, e);
+ }
+ return "";
+ }
+
+ /**
+ * 鏂规硶鍚�: getStartTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠0鐐�
+ * 淇敼鏃堕棿锛�2017骞�5鏈�8鏃� 涓嬪崍5:03:49
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Long 杩斿洖绫诲瀷
+ */
+ public static long getStartTime() {
+ Calendar todayStart = Calendar.getInstance();
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
+ todayStart.set(Calendar.MINUTE, 0);
+ todayStart.set(Calendar.SECOND, 0);
+ todayStart.set(Calendar.MILLISECOND, 0);
+ return todayStart.getTime().getTime();
+ }
+
+ /**
+ * 鏂规硶鍚�: getEndTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳ぉ缁撴潫鏃堕棿
+ * 淇敼鏃堕棿锛�2017骞�5鏈�8鏃� 涓嬪崍5:04:12
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 long 杩斿洖绫诲瀷
+ */
+ public static long getEndTime() {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTime().getTime();
+ }
+
+ /**
+ * 鑾峰彇鏌愬ぉ鏈�澶ф椂闂�
+ *
+ * @param date
+ * @return
+ */
+ public static Date getEndOfDay(Date date) {
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
+ ;
+ LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
+ return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ /**
+ * 鑾峰彇鏌愬ぉ鏈�灏忔椂闂�
+ *
+ * @param date
+ * @return
+ */
+ public static Date getStartOfDay(Date date) {
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
+ LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
+ return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ /**
+ * 鏂规硶鍚�: getStartTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠0鐐�
+ * 淇敼鏃堕棿锛�2017骞�5鏈�8鏃� 涓嬪崍5:03:49
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Long 杩斿洖绫诲瀷
+ *
+ * @throws ParseException
+ */
+ public static long getStartTime(String dateStr) throws ParseException {
+ if (StringUtils.isBlank(dateStr)) {
+ return 0;
+ } else {
+ Date date = ThreadDateUtil.getDateFormat(sf1).parse(dateStr);
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ 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().getTime();
+ }
+
+ }
+
+ /**
+ * 鏂规硶鍚�: getEndTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳ぉ缁撴潫鏃堕棿
+ * 淇敼鏃堕棿锛�2017骞�5鏈�8鏃� 涓嬪崍5:04:12
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 long 杩斿洖绫诲瀷
+ *
+ * @throws ParseException
+ */
+ public static long getEndTime(String dateStr) throws ParseException {
+ if (StringUtils.isBlank(dateStr)) {
+ return 0;
+ } else {
+ Date date = ThreadDateUtil.getDateFormat(sf1).parse(dateStr);
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.setTime(date);
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTime().getTime();
+ }
+ }
+
+ /**
+ * 鑾峰彇 鎸囧畾鏃堕棿姣鏁扮殑0鐐�
+ *
+ * @param time
+ * @return
+ */
+ public static long getStartTime(long time) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(time);
+ 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().getTime();
+ }
+
+ /**
+ * 鑾峰彇 鎸囧畾鏃堕棿姣鏁扮殑23鐐�59鍒�59绉�999姣
+ *
+ * @param time
+ * @return
+ */
+ public static long getEndTime(long time) {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.setTimeInMillis(time);
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTime().getTime();
+ }
+
+ public static String getDatem(Long date) {
+ try {
+ Date d = new Date(date);
+ return ThreadDateUtil.getDateFormat(sfm).format(d);
+ } catch (Exception e) {
+ LOGGER.error(" getDatem E: {}", date, e);
+ }
+ return "";
+ }
+
+ public static Long getNowTime() {
+ return System.currentTimeMillis();
+
+ }
+
+ /**
+ * 鏂规硶鍚�: getTodayEndTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳ぉ缁撴潫鏃堕棿
+ * 淇敼鏃堕棿锛�2016骞�11鏈�2鏃� 涓嬪崍6:53:23
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Long 杩斿洖绫诲瀷
+ */
+ public static int getDiffTodayEndTime() {
+ return (int) ((getTodayEndTime() - getNowTime()) / 1000);
+ }
+
+ /**
+ * 鏂规硶鍚�: getStartDateTime
+ * 鏂规硶鎻忚堪: 鑾峰彇涓�澶╁紑濮媡ime
+ * 淇敼鏃堕棿锛�2016骞�12鏈�5鏃� 涓婂崍11:57:01
+ * 鍙傛暟 @param time
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getStartDateTime(long time) {
+ Date d = new Date(time);
+ return ThreadDateUtil.getDateFormat(sf).format(d);
+ }
+
+ /**
+ * 鏂规硶鍚�: getTodayEndTime
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳ぉ鏃堕棿宸�
+ * 淇敼鏃堕棿锛�2016骞�11鏈�2鏃� 涓嬪崍6:53:23
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 Long 杩斿洖绫诲瀷
+ */
+ public static Long getTodayEndTime() {
+ Calendar todayEnd = Calendar.getInstance();
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+ todayEnd.set(Calendar.MINUTE, 59);
+ todayEnd.set(Calendar.SECOND, 59);
+ todayEnd.set(Calendar.MILLISECOND, 999);
+ return todayEnd.getTime().getTime();
+ }
+
+ /**
+ * 鑾峰彇鍙傛暟鏃堕棿鐨勫紑濮嬫椂闂�
+ *
+ * @param time
+ * @return
+ */
+ public static Date getBeginTimeByDate(long time) {
+ Date d = new Date(time);
+ Calendar todayBegin = Calendar.getInstance();
+ todayBegin.setTime(d);
+ todayBegin.set(Calendar.HOUR_OF_DAY, 00);
+ todayBegin.set(Calendar.MINUTE, 00);
+ todayBegin.set(Calendar.SECOND, 00);
+ todayBegin.set(Calendar.MILLISECOND, 000);
+ return todayBegin.getTime();
+
+ }
+
+ /**
+ * 鑾峰彇鍙傛暟鏃堕棿鐨勭粨鏉熸椂闂�
+ *
+ * @param time
+ * @return
+ */
+ public static Date getEndTimeByDate(long time) {
+ Date d = new Date(time);
+ Calendar todayBegin = Calendar.getInstance();
+ todayBegin.setTime(d);
+ todayBegin.set(Calendar.HOUR_OF_DAY, 23);
+ todayBegin.set(Calendar.MINUTE, 59);
+ todayBegin.set(Calendar.SECOND, 59);
+ todayBegin.set(Calendar.MILLISECOND, 999);
+ return todayBegin.getTime();
+ }
+
+
+ /**
+ * 鍒ゆ柇褰撳墠鏃堕棿鏄惁鍦╗startTime, endTime]鍖洪棿锛屾敞鎰忔椂闂存牸寮忚涓�鑷�
+ *
+ * @param nowTime 褰撳墠鏃堕棿
+ * @param startTime 寮�濮嬫椂闂�
+ * @param endTime 缁撴潫鏃堕棿
+ * @return
+ */
+ public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
+ if (nowTime.getTime() == startTime.getTime()
+ || nowTime.getTime() == endTime.getTime()) {
+ return true;
+ }
+ Calendar date = Calendar.getInstance();
+ date.setTime(nowTime);
+ Calendar begin = Calendar.getInstance();
+ begin.setTime(startTime);
+ Calendar end = Calendar.getInstance();
+ end.setTime(endTime);
+ if (date.after(begin) && date.before(end)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static Long getLongTime(String str) {
+ if (StringUtils.isBlank(str)) {
+ return getNowTime();
+ }
+ Date date = null;
+ try {
+ if (str.matches(SF)) {
+ date = ThreadDateUtil.getDateFormat(sf).parse(str);
+ } else if (str.matches(SFM)) {
+ date = ThreadDateUtil.getDateFormat(sfm).parse(str);
+ } else {
+ date = ThreadDateUtil.getDateFormat(sf1).parse(str);
+ }
+ } catch (ParseException e) {
+ LOGGER.error(" getLongTime E: {}", str, e);
+ }
+ if (null == date) {
+ return 0L;
+ }
+ return date.getTime();
+
+ }
+
+ /**
+ * 鎶婃椂闂村弬鏁� 杞崲涓� long
+ *
+ * @param dateStr
+ * @return
+ * @throws BackingStoreException
+ */
+ public static long getTime(String dateStr) throws ApiException {
+ try {
+ Date date = ThreadDateUtil.getDateFormat(sf).parse(dateStr);
+ return date.getTime();
+ } catch (ParseException e) {
+ LOGGER.error(" getTime E: {}", dateStr, e);
+ throw new ApiException(" time parese error: " + dateStr);
+ }
+ }
+
+ /**
+ * 鎶婃椂闂村弬鏁� 杞崲涓� long
+ *
+ * @param dateStr yyyy-MM-dd
+ * @return
+ * @throws BackingStoreException
+ */
+ public static long getTimeByStringDate(String dateStr) throws ApiException {
+ try {
+ Date date = ThreadDateUtil.getDateFormat(sf1).parse(dateStr);
+ return date.getTime();
+ } catch (ParseException e) {
+ LOGGER.error(" getTime E: {}", dateStr, e);
+ throw new ApiException(" time parese error: " + dateStr);
+ }
+ }
+
+ /**
+ * 鏂规硶鍚�: getNowYear
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠骞翠唤
+ * 淇敼鏃堕棿锛�2016骞�6鏈�22鏃� 涓嬪崍6:52:24
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getNowYear() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
+ Date date = new Date();
+ return sdf.format(date);
+ }
+
+ /**
+ * 鏂规硶鍚�: getNowMonth
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠骞存湀yyyy/MM
+ * 淇敼鏃堕棿锛�2016骞�6鏈�22鏃� 涓嬪崍6:52:24
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getNowMonth() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM");
+ Date date = new Date();
+ return sdf.format(date);
+ }
+
+ /**
+ * 鏂规硶鍚�: getNowMonthDaySn
+ * 鏂规硶鎻忚堪: 鑾峰彇褰撳墠骞存湀yyyyMMdd
+ * 淇敼鏃堕棿锛�2017骞�6鏈�28鏃� 涓婂崍10:52:24
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 String 杩斿洖绫诲瀷
+ */
+ public static String getNowMonthDay() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+ Date date = new Date();
+ return sdf.format(date);
+ }
+
+
+ /**
+ * 鑾峰彇鏄庡ぉ鐨勬棩鏈熷瓧绗︿覆
+ *
+ * @return
+ */
+ public static String tomorrowDateStr(int day) {
+ Date date = new Date();//鍙栨椂闂�
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ //鎶婃棩鏈熷線鍚庡鍔犱竴澶�.鏁存暟寰�鍚庢帹,璐熸暟寰�鍓嶇Щ鍔�
+ calendar.add(calendar.DATE, day);
+ //杩欎釜鏃堕棿灏辨槸鏃ユ湡寰�鍚庢帹涓�澶╃殑缁撴灉
+ date = calendar.getTime();
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+ String tomorrowStr = formatter.format(date);
+ return tomorrowStr;
+ }
+
+ /**
+ * dq
+ * 鑾峰彇鎸囧畾骞存湀yyyyMMddHHmmss
+ *
+ * @param dateTime
+ * @return
+ */
+ public static String getNowMonthDay(long dateTime) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+ Date date = new Date(dateTime);
+ return sdf.format(date);
+ }
+
+ public static String getAge(String birthDate) {
+ if (null == birthDate) {
+ throw new RuntimeException("鍑虹敓鏃ユ湡涓嶈兘涓簄ull");
+ }
+
+ int age = 0;
+ String[] str = birthDate.split("-");
+ if (str.length == 3) {
+ Date now = new Date();
+ SimpleDateFormat format_y = new SimpleDateFormat("yyyy");
+ SimpleDateFormat format_M = new SimpleDateFormat("MM");
+ String birth_year = str[0];
+ String this_year = format_y.format(now);
+ String birth_month = str[1];
+ String this_month = format_M.format(now);
+ // 鍒濇锛屼及绠�
+ age = Integer.parseInt(this_year) - Integer.parseInt(birth_year);
+
+ // 濡傛灉鏈埌鍑虹敓鏈堜唤锛屽垯age - 1
+
+ if (this_month.compareTo(birth_month) < 0) {
+ age -= 1;
+ }
+ if (age < 0) {
+ age = 0;
+ }
+ return age + "." + (parseInt(this_month) - parseInt(this_month));
+ }
+
+ return "0";
+ }
+
+ /**
+ * 灏嗗瓧绗︿覆绫诲瀷杞崲涓烘暣鍨�
+ *
+ * @param s
+ * @return
+ */
+ public static Integer parseInt(String s) {
+ if (s != null && s.trim().matches("^(-)?[0-9]+$"))
+ return Integer.parseInt(s.trim());
+ return 0;
+ }
+
+ /**
+ * 鏌ヨ鍓嶄竴澶�
+ *
+ * @param date
+ * @return
+ */
+ public static String getPreDay(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ date = calendar.getTime();
+ return ThreadDateUtil.getDateFormat(sf1).format(date);
+ }
+
+ /**
+ * 鏂规硶鍚�: isBirthday
+ * 鏂规硶鎻忚堪: 鍒ゆ柇杈撳叆鐨勫瓧绗︿覆鏄惁鏄悎娉曠殑鐢熸棩 鐢熸棩涓嶈兘澶т簬褰撳墠鏃ユ湡
+ * 淇敼鏃堕棿锛�2017骞�3鏈�22鏃� 涓婂崍9:16:09
+ * 鍙傛暟 @param birthday
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 boolean 杩斿洖绫诲瀷
+ */
+ public static boolean isBirthday(String birthday) {
+ if (StringUtils.isBlank(birthday)) {
+ return false;
+ }
+ if (birthday.length() != 10) {
+ return false;
+ }
+ Pattern pattern = Pattern
+ .compile("^[1,2]\\d{3}(-){1}(0[1-9]||1[0-2])(-){1}(0[1-9]||[1,2][0-9]||3[0,1])$");
+ Matcher matcher = pattern.matcher(birthday);
+ if (!matcher.matches()) {
+ return false;
+ }
+ Date birth = null;
+ try {
+ birth = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ if (!new SimpleDateFormat("yyyy-MM-dd").format(birth).equals(birthday)) {
+ return false;
+ }
+ // 鑾峰彇褰撳墠鏃ユ湡鐨勬绉掓暟
+ long currentTime = System.currentTimeMillis();
+ // 鑾峰彇鐢熸棩鐨勬绉掓暟
+ long birthTime = birth.getTime();
+ // 濡傛灉褰撳墠鏃堕棿灏忎簬鐢熸棩锛岀敓鏃ヤ笉鍚堟硶銆傚弽涔嬪悎娉�
+ if (birthTime > currentTime) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * 鏂规硶鍚�: isAfterHour
+ * 鏂规硶鎻忚堪: 褰撳墠鏃堕棿7鐐逛箣鍚庡彲浠ユ樉绀�
+ * 淇敼鏃堕棿锛�2017骞�5鏈�11鏃� 涓嬪崍3:39:34
+ * 鍙傛暟 @return 鍙傛暟璇存槑
+ * 杩斿洖绫诲瀷 boolean 杩斿洖绫诲瀷
+ */
+ public static boolean isAfterHour() {
+ Calendar todayStart = Calendar.getInstance();
+ //鐢╠.getHour()鍙互鑾峰彇褰撳墠灏忔椂鏁般��
+ int hour = todayStart.get(Calendar.HOUR_OF_DAY);
+ return hour >= 7;
+ }
+
+ /**
+ * wye
+ * 鑾峰彇鏌愬ぉ寮�濮嬫椂闂�0:0:0:0
+ *
+ * @param date
+ * @param addDay
+ * @return
+ */
+ public static long getStartTime(Date date, int addDay) {
+ Calendar dayTimeStart = Calendar.getInstance();
+ dayTimeStart.setTime(date);
+ if (addDay != 0) {
+ dayTimeStart.add(Calendar.DATE, addDay);
+ }
+ dayTimeStart.set(Calendar.HOUR_OF_DAY, 0);
+ dayTimeStart.set(Calendar.MINUTE, 0);
+ dayTimeStart.set(Calendar.SECOND, 0);
+ dayTimeStart.set(Calendar.MILLISECOND, 0);
+ return dayTimeStart.getTime().getTime();
+
+ }
+
+ /**
+ * wye
+ * 鑾峰彇鏌愬ぉ缁撴潫鏃堕棿23:59:59:999
+ *
+ * @param date
+ * @param addDay
+ * @return
+ */
+ public static long getEndTime(Date date, int addDay) {
+ Calendar dayTimeEnd = Calendar.getInstance();
+ dayTimeEnd.setTime(date);
+ if (addDay != 0) {
+ dayTimeEnd.add(Calendar.DATE, addDay);
+ }
+ dayTimeEnd.set(Calendar.HOUR_OF_DAY, 23);
+ dayTimeEnd.set(Calendar.MINUTE, 59);
+ dayTimeEnd.set(Calendar.SECOND, 59);
+ dayTimeEnd.set(Calendar.MILLISECOND, 999);
+ return dayTimeEnd.getTime().getTime();
+ }
+
+ /**
+ * wye
+ * 鑾峰彇褰撳墠鏃堕棿 涔嬪悗鎴栦箣鍓嶇殑鍑犲ぉ
+ *
+ * @param
+ * @return
+ * @throws ParseException
+ */
+ public static long getLongTimeByDay(long dateTime, int day) {
+ Calendar start = Calendar.getInstance();
+ start.setTimeInMillis(dateTime);
+ start.add(Calendar.DAY_OF_MONTH, day);
+ return start.getTime().getTime();
+ }
+
+
+ /**
+ * 鏃ユ湡鏍煎紡鍖栧瓧绗︿覆
+ * 榛樿鏍煎紡 yyyy-MM-dd HH:mm:ss
+ */
+ public static String format(Date date) {
+ if (date == null) {
+ return null;
+ }
+ return format(date, DatePattern.YYYY_MM_DD_HHmmss);
+ }
+
+ /**
+ * 鏃ユ湡鏍煎紡鍖栧瓧绗︿覆
+ */
+ public static String format(Date date, DatePattern datePattern) {
+ if (date == null || datePattern == null) {
+ return null;
+ }
+ return format(date, datePattern.pattern);
+ }
+
+ /**
+ * 鏃ユ湡鏍煎紡鍖栧瓧绗︿覆
+ *
+ * @param date 鏃ユ湡瀵硅薄
+ * @param pattern 鏃ユ湡鏍煎紡
+ * @return
+ */
+ public static String format(Date date, String pattern) {
+ if (date == null) {
+ return null;
+ }
+ return ThreadDateUtil.getDateFormat(pattern).format(date);
+ }
+
+ /**
+ * 鏃ユ湡瀛楃涓� 杞崲涓烘棩鏈�
+ * 榛樿鏍煎紡 yyyy-MM-dd HH:mm:ss
+ *
+ * @throws ParseException
+ */
+ public static Date parse(String source) throws ParseException {
+ return parse(source, DatePattern.YYYY_MM_DD_HHmmss);
+ }
+
+ /**
+ * 鏃ユ湡鏍煎紡鍖栧瓧绗︿覆
+ *
+ * @param source 鏃堕棿瀛楃涓�
+ * @param datePattern 鏃ユ湡鏍煎紡
+ * @return
+ * @throws ParseException
+ */
+ public static Date parse(String source, DatePattern datePattern) throws ParseException {
+ return parse(source, datePattern.pattern);
+ }
+
+ /**
+ * 鏃ユ湡瀛楃涓� 杞崲涓烘棩鏈�
+ *
+ * @param source 鏃堕棿瀛楃涓�
+ * @param pattern 鏃ユ湡鏍煎紡
+ * @return
+ * @throws ParseException
+ */
+ public static Date parse(String source, String pattern) throws ParseException {
+ return ThreadDateUtil.getDateFormat(pattern).parse(source);
+ }
+
+ /**
+ * 鏃ユ湡瀛楃涓� 杞崲涓烘棩鏈熸绉掓暟
+ * 榛樿鏍煎紡 yyyy-MM-dd HH:mm:ss
+ *
+ * @throws ParseException
+ */
+ public static Long parseToLong(String source) throws ParseException {
+ return parse(source, DatePattern.YYYY_MM_DD_HHmmss).getTime();
+ }
+
+ /**
+ * 鏃ユ湡瀛楃涓� 杞崲涓烘棩鏈熸绉掓暟
+ *
+ * @param source 鏃堕棿瀛楃涓�
+ * @param datePattern 鏃ユ湡鏍煎紡
+ * @return
+ * @throws ParseException
+ */
+ public static Long parseToLong(String source, DatePattern datePattern) throws ParseException {
+ return parse(source, datePattern.pattern).getTime();
+ }
+
+ /**
+ * 鏃ユ湡瀛楃涓� 杞崲涓烘棩鏈熸绉掓暟
+ *
+ * @param source 鏃堕棿瀛楃涓�
+ * @param pattern 鏃ユ湡鏍煎紡
+ * @return
+ * @throws ParseException
+ */
+ public static Long parseToLong(String source, String pattern) throws ParseException {
+ return ThreadDateUtil.getDateFormat(pattern).parse(source).getTime();
+ }
+
+
+ /**
+ * 鑾峰彇鏃ユ湡骞翠唤
+ *
+ * @param date 鏃ユ湡
+ * @return
+ */
+ public static String getYear(Date date) {
+ return format(date).substring(0, 4);
+ }
+
+ /**
+ * 鍔熻兘鎻忚堪锛氳繑鍥炴湀
+ *
+ * @param date Date 鏃ユ湡
+ * @return 杩斿洖鏈堜唤
+ */
+ public static int getMonth(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.get(Calendar.MONTH) + 1;
+ }
+
+ /**
+ * 鍔熻兘鎻忚堪锛氳繑鍥炴棩
+ *
+ * @param date Date 鏃ユ湡
+ * @return 杩斿洖鏃ヤ唤
+ */
+ public static int getDay(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.get(Calendar.DAY_OF_MONTH);
+ }
+
+ /**
+ * 鍔熻兘鎻忚堪锛氳繑鍥炲皬
+ *
+ * @param date 鏃ユ湡
+ * @return 杩斿洖灏忔椂
+ */
+ public static int getHour(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.get(Calendar.HOUR_OF_DAY);
+ }
+
+ /**
+ * 鍔熻兘鎻忚堪锛氳繑鍥炲垎
+ *
+ * @param date 鏃ユ湡
+ * @return 杩斿洖鍒嗛挓
+ */
+ public static int getMinute(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.get(Calendar.MINUTE);
+ }
+
+ /**
+ * 杩斿洖绉掗挓
+ *
+ * @param date Date 鏃ユ湡
+ * @return 杩斿洖绉掗挓
+ */
+ public static int getSecond(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.get(Calendar.SECOND);
+ }
+
+ /**
+ * 鍔熻兘鎻忚堪锛氳繑鍥炴
+ *
+ * @param date 鏃ユ湡
+ * @return 杩斿洖姣�
+ */
+ public static long getMillis(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar.getTimeInMillis();
+ }
+
+
+ /**
+ * 楠岃瘉璇锋眰鏄惁鍦ㄥ悎娉曟椂闂村唴
+ *
+ * @param timestamp
+ * @return
+ */
+ public static boolean verifyRequestTime(long timestamp) {
+ long now = System.currentTimeMillis();
+ long time = now - timestamp;
+ System.out.println(now);
+ System.out.println(time);
+ System.out.println(time / 1000);
+ if (time / 1000 > 60) {
+ return false;
+ }
+ return true;
+ }
+
+ public static String formatDate(String format) {
+ return formatDate(new Date(), format);
+ }
+
+ public static String formatDate(Date date, String format) {
+ if ((null == date) || (StringUtils.isEmpty(format))) {
+ return null;
+ }
+ return new SimpleDateFormat(format).format(date);
+ }
+
+ public static long getYesterDay() {
+ Date date = new Date();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(calendar.DATE, -1);
+ date = calendar.getTime();
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
+ String dateString = format.format(date);
+ long time = 0;
+ try {
+ time = format.parse(dateString).getTime();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return time;
+ }
+
+ public static long get1MonthByNow() {
+ Calendar c = Calendar.getInstance();
+ //杩囧幓涓�鏈�
+ c.setTime(new Date());
+ c.add(Calendar.MONTH, -1);
+ Date m = c.getTime();
+ long time = m.getTime();
+// String mon = format.format(m);
+ return time;
+ }
+
+ public static int dateDiff(Date date1, Date date2) {
+ int days = (int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24));
+ return days;
+ }
+
+ public static int dateDiff(Long date1, Long date2) {
+ int days = (int) ((date2 - date1) / (1000 * 3600 * 24));
+ return days;
+ }
+
+
+ public static List te() {
+ List<String> list = new LinkedList<>();
+ Calendar calendar = Calendar.getInstance();
+ int month = calendar.get(Calendar.MONTH) + 1;
+ int year = calendar.get(Calendar.YEAR);
+ for (int i = 1; i <= 12; i++) {
+ if (month == 1) {
+ list.add(year + "-" + month);
+ break;
+ }
+ list.add(year + "-" + month);
+ month--;
+ }
+ return list;
+ }
+
+ /**
+ * 鑾峰彇涓婁釜鏈堢殑绗竴澶�
+ *
+ * @return
+ */
+ public static long getLastMonthStart() {
+ //鑾峰彇鍓嶆湀鐨勭涓�澶�
+ Calendar start = Calendar.getInstance();
+ //鑾峰彇褰撳墠鏃ユ湡
+ start.add(Calendar.MONTH, -1);
+ //璁剧疆涓�1鍙�,褰撳墠鏃ユ湡鏃负鏈湀绗竴澶�
+ start.set(Calendar.DAY_OF_MONTH, 1);
+ return DateUtil.getStartTime(start.getTimeInMillis());
+ }
+
+ /**
+ * 鑾峰彇鏈湀绗竴澶�
+ *
+ * @return
+ */
+ public static long getCurrentMonthStart() {
+ //鑾峰彇鍓嶆湀鐨勭涓�澶�
+ Calendar start = Calendar.getInstance();
+ //璁剧疆涓�1鍙�,褰撳墠鏃ユ湡鏃负鏈湀绗竴澶�
+ start.set(Calendar.DAY_OF_MONTH, 1);
+ return DateUtil.getStartTime(start.getTimeInMillis());
+ }
+
+ /**
+ * 鑾峰彇鏈堜唤寮�濮嬫椂闂�
+ *
+ * @param date
+ * @return
+ */
+ public static long getMonthStart(Date date) {
+ //鑾峰彇鍓嶆湀鐨勭涓�澶�
+ Calendar start = Calendar.getInstance();
+ start.setTime(date);
+ //璁剧疆涓�1鍙�,褰撳墠鏃ユ湡鏃负鏈湀绗竴澶�
+ start.set(Calendar.DAY_OF_MONTH, 1);
+ return DateUtil.getStartTime(start.getTimeInMillis());
+ }
+
+ /**
+ * 鑾峰彇鏈堜唤缁撴潫鏃堕棿
+ *
+ * @param date
+ * @return
+ */
+ public static long getMonthEnd(Date date) {
+ Calendar end = Calendar.getInstance();
+ end.setTime(date);
+ end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH));
+ return DateUtil.getEndTime(end.getTimeInMillis());
+ }
+
+ /**
+ * 鑾峰彇涓婁釜鏈堢殑鏈�鍚庝竴澶�
+ *
+ * @return
+ */
+ public static long getLastMonthEnd() {
+ Calendar cale = Calendar.getInstance();
+ cale.set(Calendar.DAY_OF_MONTH, 0);
+ return DateUtil.getEndTime(cale.getTimeInMillis());
+ }
+
+ /**
+ * 涓婁釜鏈�
+ *
+ * @return
+ */
+ public static String getLastMonth() {
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
+ Date date = new Date();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date); // 璁剧疆涓哄綋鍓嶆椂闂�
+ calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 璁剧疆涓轰笂涓�涓湀
+ date = calendar.getTime();
+ String accDate = format.format(date);
+ return accDate;
+ }
+
+ /**
+ * 鍓�2涓湀
+ *
+ * @return
+ */
+ public static String getLast2Month() {
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
+ Date date = new Date();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date); // 璁剧疆涓哄綋鍓嶆椂闂�
+ calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 2); // 璁剧疆涓轰笂涓�涓湀
+ date = calendar.getTime();
+ String accDate = format.format(date);
+ return accDate;
+ }
+
+ public static String getYearMoney(Date date) {
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
+ String format1 = format.format(date);
+ return format1;
+ }
+
+ /**
+ * 鑾峰彇绮剧‘鍒扮鐨勬椂闂存埑
+ *
+ * @param date
+ * @return
+ */
+ public static int getSecondTimestamp(Date date) {
+ if (null == date) {
+ return 0;
+ }
+ String timestamp = String.valueOf(date.getTime() / 1000);
+ return Integer.valueOf(timestamp);
+ }
+
+ /**
+ * 鑾峰彇闂ㄥ簵钀ヤ笟鏃堕棿
+ *
+ * @param storeLocalTime 闂ㄥ簵鏃堕棿
+ * @param date
+ * @return
+ */
+ public static Date getStoreDate(Long storeLocalTime, Date date) {
+ Date storeDate = getDate(storeLocalTime);
+ String format = ThreadDateUtil.getDateFormat(sfH).format(storeDate);
+ String dateStr = ThreadDateUtil.getDateFormat(sf1).format(date);
+// Date userDate = getDate(receiveTime);
+// String nowDate = ThreadDateUtil.getDateFormat(sf1).format(userDate);
+ String concat = dateStr.concat(" ").concat(format);
+ Date newDate = null;
+ try {
+ newDate = ThreadDateUtil.getDateFormat(sf).parse(concat);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return newDate;
+ }
+
+ /**
+ * 鑾峰彇鎸囧畾骞存湀鐨勭涓�澶�
+ *
+ * @param year
+ * @param month
+ * @return
+ */
+ public static String getFirstDayOfMonth(int year, int month) {
+ Calendar cal = Calendar.getInstance();
+ //璁剧疆骞翠唤
+ cal.set(Calendar.YEAR, year);
+ //璁剧疆鏈堜唤
+ cal.set(Calendar.MONTH, month - 1);
+ //鑾峰彇鏌愭湀鏈�灏忓ぉ鏁�
+ int firstDay = cal.getMinimum(Calendar.DATE);
+ //璁剧疆鏃ュ巻涓湀浠界殑鏈�灏忓ぉ鏁�
+ cal.set(Calendar.DAY_OF_MONTH, firstDay);
+ //鏍煎紡鍖栨棩鏈�
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ return sdf.format(cal.getTime());
+ }
+
+ /**
+ * 鑾峰彇鎸囧畾骞存湀鐨勬渶鍚庝竴澶�
+ *
+ * @param year
+ * @param month
+ * @return
+ */
+ public static String getLastDayOfMonth(int year, int month) {
+ Calendar cal = Calendar.getInstance();
+ //璁剧疆骞翠唤
+ cal.set(Calendar.YEAR, year);
+ //璁剧疆鏈堜唤
+ cal.set(Calendar.MONTH, month - 1);
+ //鑾峰彇鏌愭湀鏈�澶уぉ鏁�
+ int lastDay = cal.getActualMaximum(Calendar.DATE);
+ //璁剧疆鏃ュ巻涓湀浠界殑鏈�澶уぉ鏁�
+ cal.set(Calendar.DAY_OF_MONTH, lastDay);
+ //鏍煎紡鍖栨棩鏈�
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
+ return sdf.format(cal.getTime());
+ }
+
+ /**
+ * 璁$畻鏃堕棿鐩稿樊澶氬皯澶�
+ *
+ * @param startDate
+ * @param endDate
+ * @return
+ * @throws ParseException
+ */
+ public static int getDayDiffer(Date startDate, Date endDate) throws ParseException {
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ long startDateTime = dateFormat.parse(dateFormat.format(startDate)).getTime();
+ long endDateTime = dateFormat.parse(dateFormat.format(endDate)).getTime();
+ return (int) ((endDateTime - startDateTime) / (1000 * 3600 * 24));
+ }
+
+ /**
+ * 璁$畻鏃堕棿宸�
+ *
+ * @param startDate
+ * @param endDate
+ * @return
+ */
+ public static int getOrderDayDiffer(Date startDate, Date endDate) {
+ int dayDiffer = 0;
+ try {
+ dayDiffer = getDayDiffer(startDate, endDate);
+ if (dayDiffer < 0) {
+ throw new ApiException(CommonResult.failed().getMessage());
+ }
+ if (dayDiffer == 0) {
+ dayDiffer = 1;
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ throw new ApiException(e);
+ }
+ return dayDiffer;
+ }
+
+ /**
+ * 鑾峰彇鏃跺垎
+ *
+ * @param date
+ * @return
+ */
+ public static String getHm(Date date) {
+ DateFormat dateFormat = ThreadDateUtil.getDateFormat(sf2);
+ return dateFormat.format(date);
+ }
+
+ /**
+ * 鑾峰彇骞存湀鏃�
+ *
+ * @param date
+ * @return
+ */
+ public static String getYmd(Date date) {
+ DateFormat dateFormat = ThreadDateUtil.getDateFormat(sf1);
+ return dateFormat.format(date);
+ }
+
+ public static long swapYmd(Long localTime, Long receiveTime) {
+ Date localDate = DateUtil.getDate(localTime);
+ String hms = ThreadDateUtil.getDateFormat(sfH).format(localDate);
+ Date receiveDate = DateUtil.getDate(receiveTime);
+ String ymd = ThreadDateUtil.getDateFormat(sf1).format(receiveDate);
+ String concat = ymd.concat(" ").concat(hms);
+ Date newDate = null;
+ try {
+ newDate = ThreadDateUtil.getDateFormat(sf).parse(concat);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return newDate.getTime();
+
+ }
+
+ /**
+ * 聽 聽 * 鑾峰彇鎸囧畾鏃ユ湡鎵�鍦ㄥ懆鐨勫懆涓�
+ * <p>
+ * 聽 聽 *
+ * <p>
+ * 聽 聽 * @param date聽 聽 聽 鏃ユ湡
+ * <p>
+ * 聽 聽
+ */
+ public static Date getFirstDayOfWeek(Date date) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ if (c.get(Calendar.DAY_OF_WEEK) == 1) {
+ c.add(Calendar.DAY_OF_MONTH, -1);
+ }
+ c.add(Calendar.DATE, c.getFirstDayOfWeek() - c.get(Calendar.DAY_OF_WEEK) + 1);
+ return c.getTime();
+ }
+
+ /**
+ * 聽 聽 * 鑾峰彇鎸囧畾鏃ユ湡鎵�鍦ㄥ懆鐨勫懆鏃�
+ * <p>
+ * 聽 聽 *
+ * <p>
+ * 聽 聽 * @param date聽 聽 聽 鏃ユ湡
+ * <p>
+ * 聽 聽
+ */
+ public static Date getLastDayOfWeek(Date date) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);// 濡傛灉鏄懆鏃ョ洿鎺ヨ繑鍥�
+ if (c.get(Calendar.DAY_OF_WEEK) == 1) {
+ return date;
+ }
+ System.out.println(c.get(Calendar.DAY_OF_WEEK));
+ c.add(Calendar.DATE, 7 - c.get(Calendar.DAY_OF_WEEK) + 1);
+ return c.getTime();
+ }
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java b/ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java
index 2cd3a40..336e6a9 100644
--- a/ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java
+++ b/ycl-common/src/main/java/com/ycl/utils/common/PojoUtils.java
@@ -31,5 +31,4 @@
return n != null && n.intValue() != SysConst.COMBOBOX_ALL;
}
}
-
}
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java b/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
index 34c3268..22a574e 100644
--- a/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
+++ b/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
@@ -6,4 +6,62 @@
* @date 2022/9/7
*/
public class RandomUtils {
+ /**
+ * 鐢ㄦ埛鍚�
+ */
+ private static final String NICK_NAME = "NK";
+
+ /**
+ * 鏍囪闀垮害
+ */
+ public static final int SIGN_LENGTH = 6;
+
+ /**
+ * 鏍囪鏍煎紡鍖栨牸寮忓寲瀛楃涓�
+ */
+ private static final String FORMT_STRING = "888888";
+
+ /**
+ * 鑾峰彇鐢ㄦ埛鍚�
+ *
+ * @param userId
+ * @return
+ */
+ public static String getUserId(long userId) {
+ return NICK_NAME + formatSign(userId)
+ + generateRandomInt(SIGN_LENGTH);
+
+ }
+
+ /**
+ * 鏍煎紡鍖栨爣璁�
+ *
+ * @return4
+ */
+ private static String formatSign(long param) {
+ String str = Long.toString(param);
+ int length = str.length() - SIGN_LENGTH;
+ if (length == 0) {
+ return str;
+ } else if (length < 0) {
+ str = "0" + str;
+ return FORMT_STRING.substring(0, Math.abs(length) - 1) + str;
+ } else {
+ return str.substring(length);
+ }
+ }
+
+ /**
+ * 鑾峰彇鎸囧畾闀垮害(1浣嶅埌9浣�)鐨勯殢鏈烘暟瀛楀瓧绗︿覆
+ *
+ * @param length 澶т簬1 灏忎簬9
+ * @return
+ */
+ public static String generateRandomInt(int length) {
+ length = length < 1 ? 1 : length;
+ length = length > 9 ? 9 : length;
+ int max = ((int) Math.pow(10, length)) - 1;
+ int min = (int) Math.pow(10, length - 1);
+ return String.valueOf((int) (Math.random() * (max - min) + min));
+ }
}
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/ThreadDateUtil.java b/ycl-common/src/main/java/com/ycl/utils/common/ThreadDateUtil.java
new file mode 100644
index 0000000..ec9c245
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/utils/common/ThreadDateUtil.java
@@ -0,0 +1,79 @@
+package com.ycl.utils.common;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 鏃ユ湡绾跨▼绫�
+ */
+public final class ThreadDateUtil {
+
+ /**
+ * 鏃ユ湡鏍煎紡1
+ */
+ public static final String yyyyMMddHHmmsss = "yyyyMMddHHmmsss";
+ /**
+ * 鏃ユ湡鏍煎紡2
+ */
+ public static final String yyMMddHHmmsss = "yyMMddHHmmsss";
+
+ /**
+ * 榛樿鏍煎紡
+ */
+ private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * 鏍煎紡鍖� 绾跨▼闆�
+ */
+ private static Map<String, ThreadLocal<DateFormat>> threadLocalMap = new HashMap<>();
+
+ /**
+ * 鑾峰彇鏃ユ湡鏍煎紡鍖栧伐鍏峰璞�
+ * 绾跨▼瀹夊叏
+ * @return
+ */
+ public static DateFormat getDateFormat() {
+ return getDateFormat(DEFAULT_FORMAT);
+ }
+
+ /**
+ * 鑾峰彇鏃ユ湡鏍煎紡鍖栧伐鍏峰璞�
+ * 绾跨▼瀹夊叏
+ * @param format 鏍煎紡 鍙彇浜涘伐鍏风被涓殑甯搁噺鏍煎紡锛岄粯璁や负yyyy-MM-dd HH:mm:ss
+ * @return
+ */
+ public static DateFormat getDateFormat(String format) {
+ ThreadLocal<DateFormat> threadLocal = threadLocalMap.get(format);
+ DateFormat df = null;
+ if (threadLocal == null) {
+ threadLocal = new ThreadLocal<DateFormat>();
+ df = new SimpleDateFormat(format);
+ threadLocal.set(df);
+ threadLocalMap.put(format, threadLocal);
+ } else {
+ df = threadLocal.get();
+ if (df == null) {
+ df = new SimpleDateFormat(format);
+ threadLocal.set(df);
+ threadLocalMap.put(format, threadLocal);
+ }
+ }
+ return df;
+ }
+
+ public static String formatDate(Date date) throws ParseException {
+ return getDateFormat().format(date);
+ }
+
+ public static Date parse(String strDate) throws ParseException {
+ return getDateFormat().parse(strDate);
+ }
+
+
+
+
+}
diff --git a/ycl-common/src/main/java/com/ycl/vo/depart/DepartVO.java b/ycl-common/src/main/java/com/ycl/vo/depart/DepartVO.java
new file mode 100644
index 0000000..66489d2
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/vo/depart/DepartVO.java
@@ -0,0 +1,80 @@
+package com.ycl.vo.depart;
+
+import com.ycl.api.BasePageVO;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Lyq
+ * @version 1.0
+ * @date 2022/9/7
+ */
+public class DepartVO {
+ @Data
+ @ApiModel
+ public static class AddDepartVO {
+ @ApiModelProperty("閮ㄩ棬鍚嶇О")
+ private String departName;
+
+ @ApiModelProperty("閮ㄩ棬鎻忚堪")
+ private String departDes;
+
+ @ApiModelProperty("閮ㄩ棬绫诲瀷")
+ private Integer departType;
+
+ @ApiModelProperty("鐖剁骇id,榛樿0")
+ private Long parentId;
+
+ @ApiModelProperty("鍋滅敤鐘舵�侊紝0->false,1->true,榛樿鍋滅敤")
+ private byte status;
+ }
+
+ @ApiModel
+ @Data
+ public static class IdDepartVO {
+ @ApiModelProperty(value = "閮ㄩ棬id")
+ @NotNull(message = "閮ㄩ棬id涓嶈兘涓虹┖")
+ private Long id;
+ }
+
+ @ApiModel
+ @Data
+ public static class StatusDepartVO {
+ @ApiModelProperty(value = "閮ㄩ棬id")
+ @NotNull(message = "閮ㄩ棬id涓嶈兘涓虹┖")
+ private Long id;
+ @ApiModelProperty("鍋滅敤鐘舵�侊紝0->false,1->true,榛樿鍋滅敤")
+ private byte status;
+ }
+
+ @ApiModel
+ @Data
+ public static class UpdateDepartVO {
+ @ApiModelProperty(value = "閮ㄩ棬id")
+ @NotNull(message = "閮ㄩ棬id涓嶈兘涓虹┖")
+ private Long id;
+ @ApiModelProperty("閮ㄩ棬鍚嶇О")
+ private String departName;
+
+ @ApiModelProperty("閮ㄩ棬鎻忚堪")
+ private String departDes;
+
+ @ApiModelProperty("閮ㄩ棬绫诲瀷")
+ private Integer departType;
+
+ @ApiModelProperty("鐖剁骇id,榛樿0")
+ private Long parentId;
+
+ @ApiModelProperty("鍋滅敤鐘舵�侊紝0->false,1->true,榛樿鍋滅敤")
+ private byte status;
+ }
+
+ @ApiModel
+ @Data
+ public static class PageDepartVO extends BasePageVO {
+
+ }
+}
diff --git a/ycl-common/src/main/java/com/ycl/vo/user/UserVO.java b/ycl-common/src/main/java/com/ycl/vo/user/UserVO.java
new file mode 100644
index 0000000..fbfce15
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/vo/user/UserVO.java
@@ -0,0 +1,28 @@
+package com.ycl.vo.user;
+
+import com.ycl.api.BasePageVO;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author Lyq
+ * @version 1.0
+ * @date 2022/9/7
+ */
+public class UserVO {
+
+ @Data
+ @ApiModel
+ public static class PageUserVO extends BasePageVO {
+ @ApiModelProperty(value = "閮ㄩ棬id,0鍗充负鏌ヨ鍏ㄩ儴锛岄粯璁�0",example = "0")
+ private Long departmentId;
+
+ @ApiModelProperty(value = "鐢ㄦ埛绫诲瀷,0鍗充负鏌ヨ鍏ㄩ儴锛岄粯璁�0",example = "0")
+ private byte userType;
+
+ @ApiModelProperty(value = "鑱屽姟")
+ private String jobTitle;
+ }
+
+}
diff --git a/ycl-common/src/main/resources/mapper/depart/SccgDepartMapper.xml b/ycl-common/src/main/resources/mapper/depart/SccgDepartMapper.xml
new file mode 100644
index 0000000..965b5f5
--- /dev/null
+++ b/ycl-common/src/main/resources/mapper/depart/SccgDepartMapper.xml
@@ -0,0 +1,18 @@
+<?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="com.ycl.depart.mapper.SccgDepartMapper">
+
+ <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+ <resultMap id="BaseResultMap" type="com.ycl.entity.depart.SccgDepart">
+ <id column="id" property="id" />
+ <result column="depart_name" property="departName" />
+ <result column="depart_des" property="departDes" />
+ <result column="depart_type" property="departType" />
+ <result column="parent_id" property="parentId" />
+ <result column="status" property="status" />
+ <result column="create_time" property="createTime" />
+ <result column="update_time" property="updateTime" />
+ <result column="is_deleted" property="isDeleted" />
+ </resultMap>
+
+</mapper>
diff --git a/ycl-common/src/main/resources/mapper/user/UmsAdminMapper.xml b/ycl-common/src/main/resources/mapper/user/UmsAdminMapper.xml
index 50b91ba..5ae33ba 100644
--- a/ycl-common/src/main/resources/mapper/user/UmsAdminMapper.xml
+++ b/ycl-common/src/main/resources/mapper/user/UmsAdminMapper.xml
@@ -4,25 +4,31 @@
<!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
<resultMap id="BaseResultMap" type="com.ycl.entity.user.UmsAdmin">
- <id column="id" property="id" />
- <result column="username" property="username" />
- <result column="password" property="password" />
- <result column="icon" property="icon" />
- <result column="email" property="email" />
- <result column="nick_name" property="nickName" />
- <result column="note" property="note" />
- <result column="create_time" property="createTime" />
- <result column="login_time" property="loginTime" />
- <result column="status" property="status" />
+ <id column="id" property="id"/>
+ <result column="username" property="username"/>
+ <result column="password" property="password"/>
+ <result column="icon" property="icon"/>
+ <result column="email" property="email"/>
+ <result column="nick_name" property="nickName"/>
+ <result column="note" property="note"/>
+ <result column="create_time" property="createTime"/>
+ <result column="login_time" property="loginTime"/>
+ <result column="status" property="status"/>
+ <result column="mac_address" property="macAddress"/>
+ <result column="ip_address" property="ipAddress"/>
+ <result column="is_dy" property="isDy"/>
+ <result column="job_title" property="jobTitle"/>
+ <result column="department_id" property="departmentId"/>
+ <result column="user_type" property="userType"/>
+ <result column="zj" property="zj"/>
+ <result column="mobile" property="mobile"/>
</resultMap>
<select id="getAdminIdList" resultType="java.lang.Long">
- SELECT
- DISTINCT ar.admin_id
- FROM
- ums_role_resource_relation rr
- LEFT JOIN ums_admin_role_relation ar ON rr.role_id = ar.role_id
- WHERE rr.resource_id=#{resourceId}
+ SELECT DISTINCT ar.admin_id
+ FROM ums_role_resource_relation rr
+ LEFT JOIN ums_admin_role_relation ar ON rr.role_id = ar.role_id
+ WHERE rr.resource_id = #{resourceId}
</select>
</mapper>
diff --git a/ycl-platform/src/main/java/com/ycl/controller/depart/DepartController.java b/ycl-platform/src/main/java/com/ycl/controller/depart/DepartController.java
new file mode 100644
index 0000000..4c8303e
--- /dev/null
+++ b/ycl-platform/src/main/java/com/ycl/controller/depart/DepartController.java
@@ -0,0 +1,71 @@
+package com.ycl.controller.depart;
+
+
+import com.ycl.api.CommonResult;
+import com.ycl.entity.depart.SccgDepart;
+import com.ycl.entity.user.UmsMenu;
+import com.ycl.service.depart.SccgDepartService;
+import com.ycl.service.user.UmsMenuService;
+import com.ycl.vo.depart.DepartVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * <p>
+ * 閮ㄩ棬琛� 鍓嶇鎺у埗鍣�
+ * </p>
+ *
+ * @author lyq
+ * @since 2022-09-07
+ */
+@RestController
+@Api(tags = "閮ㄩ棬绠$悊妯″潡")
+@RequestMapping("/depart")
+public class DepartController {
+
+ @Autowired
+ private SccgDepartService departService;
+
+ @ApiOperation("娣诲姞閮ㄩ棬")
+ @PostMapping(value = "/create")
+ public CommonResult<Void> create(@Validated @RequestBody DepartVO.AddDepartVO addDepartVO) {
+ departService.create(addDepartVO);
+ return CommonResult.success(null);
+ }
+
+ @ApiOperation("鍒犻櫎")
+ @PostMapping(value = "/delete")
+ public CommonResult<Void> delete(@Validated @RequestBody DepartVO.IdDepartVO params) {
+ departService.delete(params.getId());
+ return CommonResult.success(null);
+ }
+
+ @ApiOperation("璇︽儏")
+ @PostMapping(value = "/detail")
+ public CommonResult<SccgDepart> detail(@Validated @RequestBody DepartVO.IdDepartVO params) {
+ SccgDepart sccgDepart = departService.loadDepartById(params.getId());
+ return CommonResult.success(sccgDepart);
+ }
+
+ @ApiOperation("鏍戠粨鏋�")
+ @GetMapping(value = "/tree")
+ public CommonResult<List<SccgDepart>> tree() {
+ List<SccgDepart> tree = departService.tree();
+ return CommonResult.success(tree);
+ }
+
+ @ApiOperation("淇敼閮ㄩ棬鐘舵��")
+ @PostMapping(value = "/status")
+ public CommonResult<Void> status(@Validated @RequestBody DepartVO.StatusDepartVO params) {
+ departService.updateStatus(params);
+ return CommonResult.success(null);
+ }
+
+}
+
diff --git a/ycl-platform/src/main/java/com/ycl/controller/UmsAdminController.java b/ycl-platform/src/main/java/com/ycl/controller/user/UmsAdminController.java
similarity index 88%
rename from ycl-platform/src/main/java/com/ycl/controller/UmsAdminController.java
rename to ycl-platform/src/main/java/com/ycl/controller/user/UmsAdminController.java
index 135d517..277425d 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/UmsAdminController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/user/UmsAdminController.java
@@ -1,6 +1,7 @@
-package com.ycl.controller;
+package com.ycl.controller.user;
import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonPage;
import com.ycl.api.CommonResult;
@@ -11,6 +12,7 @@
import com.ycl.entity.user.UmsRole;
import com.ycl.service.user.UmsAdminService;
import com.ycl.service.user.UmsRoleService;
+import com.ycl.vo.user.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -87,7 +89,7 @@
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public CommonResult getAdminInfo(Principal principal) {
- if(principal==null){
+ if (principal == null) {
return CommonResult.unauthorized(null);
}
String username = principal.getName();
@@ -97,9 +99,9 @@
data.put("menus", roleService.getMenuList(umsAdmin.getId()));
data.put("icon", umsAdmin.getIcon());
List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId());
- if(CollUtil.isNotEmpty(roleList)){
+ if (CollUtil.isNotEmpty(roleList)) {
List<String> roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList());
- data.put("roles",roles);
+ data.put("roles", roles);
}
return CommonResult.success(data);
}
@@ -111,14 +113,12 @@
return CommonResult.success(null);
}
- @ApiOperation("鏍规嵁鐢ㄦ埛鍚嶆垨濮撳悕鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃")
- @RequestMapping(value = "/list", method = RequestMethod.GET)
+ @ApiOperation("鍒嗛〉")
+ @RequestMapping(value = "/page", method = RequestMethod.GET)
@ResponseBody
- public CommonResult<CommonPage<UmsAdmin>> list(@RequestParam(value = "keyword", required = false) String keyword,
- @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
- @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
- Page<UmsAdmin> adminList = adminService.list(keyword, pageSize, pageNum);
- return CommonResult.success(CommonPage.restPage(adminList));
+ public CommonResult<IPage<UmsAdmin>> list(@Validated UserVO.PageUserVO pageUserVO) {
+ IPage<UmsAdmin> page = adminService.pageUser(pageUserVO);
+ return CommonResult.success(page);
}
@ApiOperation("鑾峰彇鎸囧畾鐢ㄦ埛淇℃伅")
@@ -172,10 +172,10 @@
@ApiOperation("淇敼甯愬彿鐘舵��")
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
@ResponseBody
- public CommonResult updateStatus(@PathVariable Long id,@RequestParam(value = "status") Integer status) {
+ public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
UmsAdmin umsAdmin = new UmsAdmin();
umsAdmin.setStatus(status);
- boolean success = adminService.update(id,umsAdmin);
+ boolean success = adminService.update(id, umsAdmin);
if (success) {
return CommonResult.success(null);
}
diff --git a/ycl-platform/src/main/java/com/ycl/controller/UmsMenuController.java b/ycl-platform/src/main/java/com/ycl/controller/user/UmsMenuController.java
similarity index 98%
rename from ycl-platform/src/main/java/com/ycl/controller/UmsMenuController.java
rename to ycl-platform/src/main/java/com/ycl/controller/user/UmsMenuController.java
index d8811a7..fad1cdd 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/UmsMenuController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/user/UmsMenuController.java
@@ -1,4 +1,4 @@
-package com.ycl.controller;
+package com.ycl.controller.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonPage;
diff --git a/ycl-platform/src/main/java/com/ycl/controller/UmsResourceCategoryController.java b/ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceCategoryController.java
similarity index 98%
rename from ycl-platform/src/main/java/com/ycl/controller/UmsResourceCategoryController.java
rename to ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceCategoryController.java
index 90e2408..93dbede 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/UmsResourceCategoryController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceCategoryController.java
@@ -1,4 +1,4 @@
-package com.ycl.controller;
+package com.ycl.controller.user;
import com.ycl.api.CommonResult;
import com.ycl.entity.user.UmsResourceCategory;
diff --git a/ycl-platform/src/main/java/com/ycl/controller/UmsResourceController.java b/ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceController.java
similarity index 98%
rename from ycl-platform/src/main/java/com/ycl/controller/UmsResourceController.java
rename to ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceController.java
index 12a6fee..eb3c9e4 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/UmsResourceController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/user/UmsResourceController.java
@@ -1,4 +1,4 @@
-package com.ycl.controller;
+package com.ycl.controller.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonPage;
diff --git a/ycl-platform/src/main/java/com/ycl/controller/UmsRoleController.java b/ycl-platform/src/main/java/com/ycl/controller/user/UmsRoleController.java
similarity index 99%
rename from ycl-platform/src/main/java/com/ycl/controller/UmsRoleController.java
rename to ycl-platform/src/main/java/com/ycl/controller/user/UmsRoleController.java
index 68d5519..c395768 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/UmsRoleController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/user/UmsRoleController.java
@@ -1,4 +1,4 @@
-package com.ycl.controller;
+package com.ycl.controller.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonPage;
--
Gitblit v1.8.0