对接企业微信

This commit is contained in:
2026-04-24 20:10:51 +08:00
parent 03ba0c9090
commit d1ff7bde35
16 changed files with 1097 additions and 3 deletions

View 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;
}
}
}