对接企业微信
This commit is contained in:
13
src/main/java/com/rj/common/DictItemConstants.java
Normal file
13
src/main/java/com/rj/common/DictItemConstants.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.rj.common;
|
||||
|
||||
/**
|
||||
* dict_item 相关常量
|
||||
*/
|
||||
public final class DictItemConstants {
|
||||
|
||||
private DictItemConstants() {
|
||||
}
|
||||
|
||||
public static final String QIWEI_CONFIG = "qiwei_config";
|
||||
}
|
||||
|
||||
@@ -2,6 +2,15 @@ package com.rj.common;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 密码工具类
|
||||
*
|
||||
@@ -15,6 +24,13 @@ public class PasswordUtil {
|
||||
*/
|
||||
public static final String DEFAULT_SALT = "rj_system_2025";
|
||||
|
||||
/**
|
||||
* 可逆加密标记,避免重复加密
|
||||
*/
|
||||
private static final String ENC_PREFIX = "ENC$";
|
||||
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
|
||||
/**
|
||||
* MD5加密密码
|
||||
*
|
||||
@@ -47,6 +63,79 @@ public class PasswordUtil {
|
||||
return encryptPassword(password, DEFAULT_SALT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 可逆加密(AES-GCM),输出格式:ENC$base64(iv).base64(cipherText)
|
||||
* <p>
|
||||
* 说明:此方法用于需要可解密的配置值(例如企微配置),不要用于用户密码。
|
||||
*/
|
||||
public static String encryptReversibleWithDefaultSalt(String plainText) {
|
||||
if (plainText == null) {
|
||||
plainText = "";
|
||||
}
|
||||
if (isEncryptedReversible(plainText)) {
|
||||
return plainText;
|
||||
}
|
||||
try {
|
||||
byte[] iv = new byte[12]; // GCM recommended IV length
|
||||
SECURE_RANDOM.nextBytes(iv);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, deriveAesKey(DEFAULT_SALT), spec);
|
||||
|
||||
byte[] cipherBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
|
||||
String ivB64 = Base64.getEncoder().encodeToString(iv);
|
||||
String ctB64 = Base64.getEncoder().encodeToString(cipherBytes);
|
||||
return ENC_PREFIX + ivB64 + "." + ctB64;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("encrypt reversible failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可逆解密(AES-GCM),支持未加密值直接原样返回。
|
||||
*/
|
||||
public static String decryptReversibleWithDefaultSalt(String encryptedOrPlain) {
|
||||
if (encryptedOrPlain == null) {
|
||||
return null;
|
||||
}
|
||||
if (!isEncryptedReversible(encryptedOrPlain)) {
|
||||
return encryptedOrPlain;
|
||||
}
|
||||
try {
|
||||
String payload = encryptedOrPlain.substring(ENC_PREFIX.length());
|
||||
int dot = payload.indexOf('.');
|
||||
if (dot <= 0 || dot >= payload.length() - 1) {
|
||||
throw new IllegalArgumentException("bad encrypted format");
|
||||
}
|
||||
byte[] iv = Base64.getDecoder().decode(payload.substring(0, dot));
|
||||
byte[] cipherBytes = Base64.getDecoder().decode(payload.substring(dot + 1));
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
||||
cipher.init(Cipher.DECRYPT_MODE, deriveAesKey(DEFAULT_SALT), spec);
|
||||
byte[] plain = cipher.doFinal(cipherBytes);
|
||||
return new String(plain, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("decrypt reversible failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEncryptedReversible(String value) {
|
||||
return value != null && value.startsWith(ENC_PREFIX);
|
||||
}
|
||||
|
||||
private static SecretKey deriveAesKey(String salt) {
|
||||
try {
|
||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
||||
byte[] keyBytes = sha256.digest(String.valueOf(salt).getBytes(StandardCharsets.UTF_8));
|
||||
// 256-bit AES key
|
||||
return new SecretKeySpec(keyBytes, "AES");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("derive key failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rj.common.DictItemConstants;
|
||||
import com.rj.dto.QiWeiConfig;
|
||||
import com.rj.entity.DictItem;
|
||||
import com.rj.service.IDictItemService;
|
||||
@@ -26,6 +28,8 @@ public class DictItemController {
|
||||
@Autowired
|
||||
private IDictItemService dictItemService;
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增")
|
||||
public ResponseEntity<Map<String, Object>> add(
|
||||
@@ -90,10 +94,18 @@ public class DictItemController {
|
||||
try {
|
||||
DictItem data = dictItemService.getById(id);
|
||||
if (data == null) {
|
||||
if ("qiwei_config".equals(name)) {
|
||||
if (DictItemConstants.QIWEI_CONFIG.equals(name)) {
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", new QiWeiConfig());
|
||||
data= new DictItem();
|
||||
QiWeiConfig cfg = new QiWeiConfig();
|
||||
cfg.setCorpid("-");
|
||||
cfg.setAppSecret("-");
|
||||
cfg.setContractSecret("-");
|
||||
data.setValue(OBJECT_MAPPER.writeValueAsString(cfg));
|
||||
data.setName(DictItemConstants.QIWEI_CONFIG);
|
||||
data.setDescription("企微的默认配置项");
|
||||
result.put("data", data);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.entity.QweiDepartment;
|
||||
import com.rj.service.IQweiDepartmentService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/qweiDepartment")
|
||||
@Tag(name = "企微部门", description = "qwei_department增删改查与分页")
|
||||
public class QweiDepartmentController {
|
||||
|
||||
@Autowired
|
||||
private IQweiDepartmentService qweiDepartmentService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增")
|
||||
public ResponseEntity<Map<String, Object>> add(
|
||||
@Parameter(description = "实体", required = true) @RequestBody QweiDepartment entity) {
|
||||
Map<String, Object> result = qweiDepartmentService.add(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新")
|
||||
public ResponseEntity<Map<String, Object>> update(
|
||||
@Parameter(description = "实体", required = true) @RequestBody QweiDepartment entity) {
|
||||
Map<String, Object> result = qweiDepartmentService.update(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "删除")
|
||||
public ResponseEntity<Map<String, Object>> delete(
|
||||
@Parameter(description = "主键ID(UUID)", required = true) @PathVariable String id) {
|
||||
Map<String, Object> result = qweiDepartmentService.deleteById(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询")
|
||||
public ResponseEntity<Map<String, Object>> list(
|
||||
@RequestParam(defaultValue = "1") Integer current,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) Long deptId,
|
||||
@RequestParam(required = false) String deptName,
|
||||
@RequestParam(required = false) Long parentDeptId) {
|
||||
Map<String, Object> result = qweiDepartmentService.pageQuery(current, size, deptId, deptName, parentDeptId);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
75
src/main/java/com/rj/controller/QweiUserController.java
Normal file
75
src/main/java/com/rj/controller/QweiUserController.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.entity.QweiUser;
|
||||
import com.rj.service.IQweiUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/qweiUser")
|
||||
@Tag(name = "企微用户", description = "qwei_user增删改查与分页")
|
||||
public class QweiUserController {
|
||||
|
||||
@Autowired
|
||||
private IQweiUserService qweiUserService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增")
|
||||
public ResponseEntity<Map<String, Object>> add(
|
||||
@Parameter(description = "实体", required = true) @RequestBody QweiUser entity) {
|
||||
Map<String, Object> result = qweiUserService.add(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新")
|
||||
public ResponseEntity<Map<String, Object>> update(
|
||||
@Parameter(description = "实体", required = true) @RequestBody QweiUser entity) {
|
||||
Map<String, Object> result = qweiUserService.update(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "删除")
|
||||
public ResponseEntity<Map<String, Object>> delete(
|
||||
@Parameter(description = "主键ID(UUID)", required = true) @PathVariable String id) {
|
||||
Map<String, Object> result = qweiUserService.deleteById(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询")
|
||||
public ResponseEntity<Map<String, Object>> list(
|
||||
@RequestParam(defaultValue = "1") Integer current,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String userid,
|
||||
@RequestParam(required = false) String userName,
|
||||
@RequestParam(required = false) Long mainDepartmentId,
|
||||
@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = qweiUserService.pageQuery(current, size, userid, userName, mainDepartmentId, status);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main/java/com/rj/entity/QweiDepartment.java
Normal file
53
src/main/java/com/rj/entity/QweiDepartment.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.rj.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("qwei_department")
|
||||
@Schema(description = "企微部门表")
|
||||
public class QweiDepartment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@Schema(description = "主键UUID")
|
||||
private String id;
|
||||
|
||||
@TableField("dept_id")
|
||||
@Schema(description = "企微部门ID")
|
||||
private Long deptId;
|
||||
|
||||
@TableField("dept_name")
|
||||
@Schema(description = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
@TableField("parent_dept_id")
|
||||
@Schema(description = "上级部门ID")
|
||||
private Long parentDeptId;
|
||||
|
||||
@TableField("order_num")
|
||||
@Schema(description = "部门排序")
|
||||
private Integer orderNum;
|
||||
|
||||
@TableField("is_deleted")
|
||||
@Schema(description = "是否删除(0否1是)")
|
||||
private Integer isDeleted;
|
||||
|
||||
@TableField("created_at")
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@TableField("updated_at")
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
97
src/main/java/com/rj/entity/QweiUser.java
Normal file
97
src/main/java/com/rj/entity/QweiUser.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package com.rj.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("qwei_user")
|
||||
@Schema(description = "企微用户表")
|
||||
public class QweiUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@Schema(description = "主键UUID")
|
||||
private String id;
|
||||
|
||||
@TableField("userid")
|
||||
@Schema(description = "企微用户ID")
|
||||
private String userid;
|
||||
|
||||
@TableField("user_name")
|
||||
@Schema(description = "姓名")
|
||||
private String userName;
|
||||
|
||||
@TableField("mobile")
|
||||
@Schema(description = "手机号")
|
||||
private String mobile;
|
||||
|
||||
@TableField("email")
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@TableField("biz_email")
|
||||
@Schema(description = "企业邮箱")
|
||||
private String bizEmail;
|
||||
|
||||
@TableField("telephone")
|
||||
@Schema(description = "座机")
|
||||
private String telephone;
|
||||
|
||||
@TableField("position")
|
||||
@Schema(description = "职位")
|
||||
private String position;
|
||||
|
||||
@TableField("gender")
|
||||
@Schema(description = "性别")
|
||||
private Integer gender;
|
||||
|
||||
@TableField("status")
|
||||
@Schema(description = "激活状态")
|
||||
private Integer status;
|
||||
|
||||
@TableField("main_department_id")
|
||||
@Schema(description = "主部门ID")
|
||||
private Long mainDepartmentId;
|
||||
|
||||
@TableField("department_ids_json")
|
||||
@Schema(description = "所属部门ID列表(JSON)")
|
||||
private String departmentIdsJson;
|
||||
|
||||
@TableField("alias_name")
|
||||
@Schema(description = "别名")
|
||||
private String aliasName;
|
||||
|
||||
@TableField("avatar")
|
||||
@Schema(description = "头像URL")
|
||||
private String avatar;
|
||||
|
||||
@TableField("thumb_avatar")
|
||||
@Schema(description = "头像缩略图URL")
|
||||
private String thumbAvatar;
|
||||
|
||||
@TableField("address")
|
||||
@Schema(description = "地址")
|
||||
private String address;
|
||||
|
||||
@TableField("is_deleted")
|
||||
@Schema(description = "是否删除(0否1是)")
|
||||
private Integer isDeleted;
|
||||
|
||||
@TableField("created_at")
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@TableField("updated_at")
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
10
src/main/java/com/rj/mapper/QweiDepartmentMapper.java
Normal file
10
src/main/java/com/rj/mapper/QweiDepartmentMapper.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.rj.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rj.entity.QweiDepartment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface QweiDepartmentMapper extends BaseMapper<QweiDepartment> {
|
||||
}
|
||||
|
||||
10
src/main/java/com/rj/mapper/QweiUserMapper.java
Normal file
10
src/main/java/com/rj/mapper/QweiUserMapper.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.rj.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rj.entity.QweiUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface QweiUserMapper extends BaseMapper<QweiUser> {
|
||||
}
|
||||
|
||||
22
src/main/java/com/rj/service/IQweiDepartmentService.java
Normal file
22
src/main/java/com/rj/service/IQweiDepartmentService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.QweiDepartment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IQweiDepartmentService extends IService<QweiDepartment> {
|
||||
|
||||
Map<String, Object> add(QweiDepartment entity);
|
||||
|
||||
Map<String, Object> update(QweiDepartment entity);
|
||||
|
||||
Map<String, Object> deleteById(String id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
Long deptId,
|
||||
String deptName,
|
||||
Long parentDeptId);
|
||||
}
|
||||
|
||||
23
src/main/java/com/rj/service/IQweiUserService.java
Normal file
23
src/main/java/com/rj/service/IQweiUserService.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.QweiUser;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IQweiUserService extends IService<QweiUser> {
|
||||
|
||||
Map<String, Object> add(QweiUser entity);
|
||||
|
||||
Map<String, Object> update(QweiUser entity);
|
||||
|
||||
Map<String, Object> deleteById(String id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String userid,
|
||||
String userName,
|
||||
Long mainDepartmentId,
|
||||
Integer status);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.rj.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.common.DictItemConstants;
|
||||
import com.rj.common.PasswordUtil;
|
||||
import com.rj.entity.DictItem;
|
||||
import com.rj.mapper.DictItemMapper;
|
||||
import com.rj.service.IDictItemService;
|
||||
@@ -33,6 +35,26 @@ public class DictItemServiceImpl extends ServiceImpl<DictItemMapper, DictItem> i
|
||||
result.put("message", "name不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
String tenantId = entity.getTenantId().trim();
|
||||
String name = entity.getName().trim();
|
||||
LambdaQueryWrapper<DictItem> dupQ = new LambdaQueryWrapper<DictItem>()
|
||||
.eq(DictItem::getName, name);
|
||||
if (this.count(dupQ) > 0) {
|
||||
result.put("success", false);
|
||||
result.put("message", "该租户下name已存在,不能重复添加");
|
||||
return result;
|
||||
}
|
||||
if (DictItemConstants.QIWEI_CONFIG.equals(name)){
|
||||
String rawValue = entity.getValue();
|
||||
if (rawValue == null) {
|
||||
rawValue = "";
|
||||
}
|
||||
entity.setValue(PasswordUtil.encryptReversibleWithDefaultSalt(rawValue));
|
||||
}
|
||||
|
||||
entity.setTenantId(tenantId);
|
||||
entity.setName(name);
|
||||
entity.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
entity.setCreatedTime(now);
|
||||
@@ -60,6 +82,13 @@ public class DictItemServiceImpl extends ServiceImpl<DictItemMapper, DictItem> i
|
||||
result.put("message", "ID不能为空");
|
||||
return result;
|
||||
}
|
||||
if (DictItemConstants.QIWEI_CONFIG.equals(entity.getName())) {
|
||||
String rawValue = entity.getValue();
|
||||
if (rawValue == null) {
|
||||
rawValue = "";
|
||||
}
|
||||
entity.setValue(PasswordUtil.encryptReversibleWithDefaultSalt(rawValue));
|
||||
}
|
||||
entity.setUpdatedTime(LocalDateTime.now());
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
|
||||
142
src/main/java/com/rj/service/impl/QweiDepartmentServiceImpl.java
Normal file
142
src/main/java/com/rj/service/impl/QweiDepartmentServiceImpl.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.QweiDepartment;
|
||||
import com.rj.mapper.QweiDepartmentMapper;
|
||||
import com.rj.service.IQweiDepartmentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class QweiDepartmentServiceImpl extends ServiceImpl<QweiDepartmentMapper, QweiDepartment>
|
||||
implements IQweiDepartmentService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(QweiDepartment entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getDeptId() == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "deptId不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getDeptName() == null || entity.getDeptName().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "deptName不能为空");
|
||||
return result;
|
||||
}
|
||||
LambdaQueryWrapper<QweiDepartment> dup = new LambdaQueryWrapper<QweiDepartment>()
|
||||
.eq(QweiDepartment::getDeptId, entity.getDeptId());
|
||||
if (this.count(dup) > 0) {
|
||||
result.put("success", false);
|
||||
result.put("message", "deptId已存在");
|
||||
return result;
|
||||
}
|
||||
|
||||
entity.setId(UUID.randomUUID().toString());
|
||||
if (entity.getIsDeleted() == null) {
|
||||
entity.setIsDeleted(0);
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
entity.setCreatedAt(now);
|
||||
entity.setUpdatedAt(now);
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "添加成功" : "添加失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "添加异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(QweiDepartment entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "更新成功" : "更新失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "更新异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
boolean ok = this.removeById(id);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current, Integer size, Long deptId, String deptName, Long parentDeptId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
Page<QweiDepartment> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<QweiDepartment> q = new LambdaQueryWrapper<>();
|
||||
if (deptId != null) {
|
||||
q.eq(QweiDepartment::getDeptId, deptId);
|
||||
}
|
||||
if (deptName != null && !deptName.trim().isEmpty()) {
|
||||
q.like(QweiDepartment::getDeptName, deptName.trim());
|
||||
}
|
||||
if (parentDeptId != null) {
|
||||
q.eq(QweiDepartment::getParentDeptId, parentDeptId);
|
||||
}
|
||||
q.orderByAsc(QweiDepartment::getOrderNum).orderByDesc(QweiDepartment::getUpdatedAt);
|
||||
|
||||
Page<QweiDepartment> data = this.page(page, q);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", data.getRecords());
|
||||
result.put("total", data.getTotal());
|
||||
result.put("current", data.getCurrent());
|
||||
result.put("size", data.getSize());
|
||||
result.put("pages", data.getPages());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
148
src/main/java/com/rj/service/impl/QweiUserServiceImpl.java
Normal file
148
src/main/java/com/rj/service/impl/QweiUserServiceImpl.java
Normal file
@@ -0,0 +1,148 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.QweiUser;
|
||||
import com.rj.mapper.QweiUserMapper;
|
||||
import com.rj.service.IQweiUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class QweiUserServiceImpl extends ServiceImpl<QweiUserMapper, QweiUser> implements IQweiUserService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(QweiUser entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getUserid() == null || entity.getUserid().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "userid不能为空");
|
||||
return result;
|
||||
}
|
||||
LambdaQueryWrapper<QweiUser> dup = new LambdaQueryWrapper<QweiUser>()
|
||||
.eq(QweiUser::getUserid, entity.getUserid().trim());
|
||||
if (this.count(dup) > 0) {
|
||||
result.put("success", false);
|
||||
result.put("message", "userid已存在");
|
||||
return result;
|
||||
}
|
||||
|
||||
entity.setId(UUID.randomUUID().toString());
|
||||
entity.setUserid(entity.getUserid().trim());
|
||||
if (entity.getIsDeleted() == null) {
|
||||
entity.setIsDeleted(0);
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
entity.setCreatedAt(now);
|
||||
entity.setUpdatedAt(now);
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "添加成功" : "添加失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "添加异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(QweiUser entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getUserid() != null) {
|
||||
entity.setUserid(entity.getUserid().trim());
|
||||
}
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "更新成功" : "更新失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "更新异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
boolean ok = this.removeById(id);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String userid,
|
||||
String userName,
|
||||
Long mainDepartmentId,
|
||||
Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
Page<QweiUser> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<QweiUser> q = new LambdaQueryWrapper<>();
|
||||
if (userid != null && !userid.trim().isEmpty()) {
|
||||
q.eq(QweiUser::getUserid, userid.trim());
|
||||
}
|
||||
if (userName != null && !userName.trim().isEmpty()) {
|
||||
q.like(QweiUser::getUserName, userName.trim());
|
||||
}
|
||||
if (mainDepartmentId != null) {
|
||||
q.eq(QweiUser::getMainDepartmentId, mainDepartmentId);
|
||||
}
|
||||
if (status != null) {
|
||||
q.eq(QweiUser::getStatus, status);
|
||||
}
|
||||
q.orderByDesc(QweiUser::getUpdatedAt);
|
||||
|
||||
Page<QweiUser> data = this.page(page, q);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", data.getRecords());
|
||||
result.put("total", data.getTotal());
|
||||
result.put("current", data.getCurrent());
|
||||
result.put("size", data.getSize());
|
||||
result.put("pages", data.getPages());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user