Compare commits
3 Commits
de23d2e383
...
2fc56d44c9
Author | SHA1 | Date |
---|---|---|
|
2fc56d44c9 | |
|
0febb2cb21 | |
|
5012e3c895 |
|
@ -0,0 +1,65 @@
|
||||||
|
package com.muyu.common.core.handler;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
|
import com.muyu.common.core.context.SecurityContextHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
/**
|
||||||
|
* @Author: zi run
|
||||||
|
* @Date 2024/9/26 16:43
|
||||||
|
* @Description 填充公共字段
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
|
||||||
|
|
||||||
|
public MyMetaObjectHandler () {
|
||||||
|
log.info("元数据填充初始化成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加时触发
|
||||||
|
* @param metaObject 元数据对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void insertFill(MetaObject metaObject) {
|
||||||
|
String[] setterNames = metaObject.getSetterNames();
|
||||||
|
Set<String> setterNamesSet = Arrays.stream(setterNames).collect(Collectors.toSet());
|
||||||
|
if (setterNamesSet.contains("createBy")){
|
||||||
|
if (metaObject.getValue("createBy") == null) {
|
||||||
|
this.setFieldValByName("createBy", SecurityContextHolder.getUserName(), metaObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (setterNamesSet.contains("createTime")){
|
||||||
|
if (metaObject.getValue("createTime") == null) {
|
||||||
|
this.setFieldValByName("createTime", new Date(), metaObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时触发
|
||||||
|
* @param metaObject 元数据对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateFill(MetaObject metaObject) {
|
||||||
|
String[] setterNames = metaObject.getSetterNames();
|
||||||
|
Set<String> setterNamesSet = Arrays.stream(setterNames).collect(Collectors.toSet());
|
||||||
|
if (setterNamesSet.contains("updateBy")){
|
||||||
|
if (metaObject.getValue("updateBy") == null) {
|
||||||
|
this.setFieldValByName("updateBy", SecurityContextHolder.getUserName(), metaObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (setterNamesSet.contains("updateTime")){
|
||||||
|
if (metaObject.getValue("updateTime") == null) {
|
||||||
|
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SysEnt extends BaseEntity {
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库名称
|
* 企业编码
|
||||||
*/
|
*/
|
||||||
private Long databaseName;
|
private String entCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,17 @@ import com.muyu.common.core.constant.Constants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.system.domain.SysEnt;
|
import com.muyu.system.domain.req.EntAddReq;
|
||||||
import com.muyu.system.domain.req.EntListReq;
|
import com.muyu.system.domain.req.EntListReq;
|
||||||
|
import com.muyu.system.domain.req.EntUpdateReq;
|
||||||
import com.muyu.system.domain.resp.EntResp;
|
import com.muyu.system.domain.resp.EntResp;
|
||||||
import com.muyu.system.service.SysEntService;
|
import com.muyu.system.service.SysEntService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,15 +36,18 @@ public class SysEntController extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取企业信息
|
* 获取企业信息
|
||||||
|
* @return 响应结果
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping(value = "/getInfo")
|
||||||
@Operation(summary = "获取企业信息", description = "现有的基础企业信息")
|
@Operation(summary = "获取企业信息", description = "现有的基础企业信息")
|
||||||
public Result<List<EntResp>> get() {
|
public Result<List<EntResp>> getInfo() {
|
||||||
return Result.success(sysEntService.selectList(new EntListReq()), Constants.SUCCESS_MESSAGE);
|
return Result.success(sysEntService.selectList(new EntListReq()), Constants.SUCCESS_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询企业信息列表
|
* 查询企业信息列表
|
||||||
|
* @param entListReq 企业列表请求对象
|
||||||
|
* @return 响应结果
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/selectList")
|
@PostMapping(value = "/selectList")
|
||||||
@Operation(summary = "查询企业信息列表", description = "分页展示企业信息")
|
@Operation(summary = "查询企业信息列表", description = "分页展示企业信息")
|
||||||
|
@ -50,4 +57,57 @@ public class SysEntController extends BaseController {
|
||||||
return getDataTable(entRespList);
|
return getDataTable(entRespList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取企业信息
|
||||||
|
* @param entId 企业ID
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/{entId}")
|
||||||
|
@Operation(summary = "根据ID获取企业信息", description = "根据企业唯一标识获取单体企业信息")
|
||||||
|
public Result<EntResp> getById(
|
||||||
|
@Schema(title = "企业ID", type = "Long", defaultValue = "1", description = "企业唯一标识")
|
||||||
|
@PathVariable(value = "entId") Long entId) {
|
||||||
|
return Result.success(EntResp.entBuild(sysEntService.getById(entId)), Constants.SUCCESS_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加企业信息
|
||||||
|
* @param entAddReq 企业添加请求对象
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "添加企业信息", description = "将企业信息添加到系统中")
|
||||||
|
public Result<String> save(@Validated @RequestBody EntAddReq entAddReq) {
|
||||||
|
sysEntService.save(EntAddReq.addBuild(entAddReq));
|
||||||
|
return Result.success(null, Constants.SUCCESS_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改企业信息
|
||||||
|
* @param entId 企业ID
|
||||||
|
* @param entUpdateReq 企业修改请求对象
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@PutMapping(value = "/{entId}")
|
||||||
|
@Operation(summary = "修改企业信息", description = "根据企业唯一标识修改企业信息")
|
||||||
|
public Result<String> update(
|
||||||
|
@Schema(title = "企业ID", type = "Long", defaultValue = "1", description = "企业唯一标识")
|
||||||
|
@NotNull(message = "企业ID不能为空") @PathVariable(value = "entId") Long entId,
|
||||||
|
@RequestBody EntUpdateReq entUpdateReq) {
|
||||||
|
sysEntService.updateById(EntUpdateReq.updateBuild(entUpdateReq, () -> entId));
|
||||||
|
return Result.success(null, Constants.SUCCESS_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除企业信息
|
||||||
|
* @param entId 企业ID
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
@DeleteMapping(value = "/{entId}")
|
||||||
|
@Operation(summary = "删除企业信息", description = "根据企业唯一标识删除企业记录")
|
||||||
|
public Result<String> remove(@Schema(title = "企业ID", type = "Long", defaultValue = "1", description = "企业唯一标识")
|
||||||
|
@NotNull(message = "企业ID不能为空") @PathVariable(value = "entId") Long entId) {
|
||||||
|
sysEntService.removeById(entId);
|
||||||
|
return Result.success(null, Constants.SUCCESS_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.muyu.system.domain.req;
|
||||||
|
|
||||||
|
import com.muyu.common.system.domain.SysEnt;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: zi run
|
||||||
|
* @Date 2024/9/26 11:51
|
||||||
|
* @Description 企业添加请求对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "企业添加请求对象", description = "企业信息添加")
|
||||||
|
public class EntAddReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业名称
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "企业名称不能为空")
|
||||||
|
@Schema(title = "企业名称", type = "String", defaultValue = "长安汽车", description = "企业名称")
|
||||||
|
private String entName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负责人
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "负责人不能为空")
|
||||||
|
@Schema(title = "负责人", type = "String", defaultValue = "张三", description = "负责人")
|
||||||
|
private String leader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "手机号码不能为空")
|
||||||
|
@Schema(title = "手机号码", type = "String", defaultValue = "18321974313", description = "手机号码")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "邮箱不能为空")
|
||||||
|
@Schema(title = "邮箱", type = "String", defaultValue = "12123@qq.com", description = "邮箱账号")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业编码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "企业编码不能为空")
|
||||||
|
@Schema(title = "企业编码", type = "String", defaultValue = "db", description = "连接的数据源")
|
||||||
|
private String entCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业添加构建者
|
||||||
|
* @param req 企业添加请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
public static SysEnt addBuild(EntAddReq req) {
|
||||||
|
return SysEnt.builder()
|
||||||
|
.name(req.getEntName())
|
||||||
|
.leader(req.getLeader())
|
||||||
|
.phoneNumber(req.getPhoneNumber())
|
||||||
|
.email(req.getEmail())
|
||||||
|
.entCode(req.getEntCode())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.system.domain.req;
|
package com.muyu.system.domain.req;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -14,30 +16,36 @@ import lombok.NoArgsConstructor;
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "企业信息列表请求对象", description = "企业列表条件查询")
|
||||||
public class EntListReq {
|
public class EntListReq {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业名称
|
* 企业名称
|
||||||
*/
|
*/
|
||||||
|
@Schema(title = "企业名称", type = "String", defaultValue = "长安汽车", description = "企业名称")
|
||||||
private String entName;
|
private String entName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 负责人
|
* 负责人
|
||||||
*/
|
*/
|
||||||
|
@Schema(title = "负责人", type = "String", defaultValue = "张三", description = "负责人")
|
||||||
private String leader;
|
private String leader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
*/
|
*/
|
||||||
|
@Schema(title = "手机号码", type = "String", defaultValue = "18321974313", description = "手机号码")
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱
|
* 邮箱
|
||||||
*/
|
*/
|
||||||
|
@Schema(title = "邮箱", type = "String", defaultValue = "12123@qq.com", description = "邮箱账号")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库名称
|
* 企业编码
|
||||||
*/
|
*/
|
||||||
private String databaseName;
|
@Schema(title = "企业编码", type = "String", defaultValue = "db", description = "连接的数据源")
|
||||||
|
private String entCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.muyu.system.domain.req;
|
||||||
|
|
||||||
|
import com.muyu.common.system.domain.SysEnt;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: zi run
|
||||||
|
* @Date 2024/9/26 14:34
|
||||||
|
* @Description 企业修改请求对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Tag(name = "企业修改请求对象", description = "企业信息修改")
|
||||||
|
public class EntUpdateReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业名称
|
||||||
|
*/
|
||||||
|
@Schema(title = "企业名称", type = "String", defaultValue = "长安汽车", description = "企业名称")
|
||||||
|
private String entName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负责人
|
||||||
|
*/
|
||||||
|
@Schema(title = "负责人", type = "String", defaultValue = "张三", description = "负责人")
|
||||||
|
private String leader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号码
|
||||||
|
*/
|
||||||
|
@Schema(title = "手机号码", type = "String", defaultValue = "18321974313", description = "手机号码")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
@Schema(title = "邮箱", type = "String", defaultValue = "12123@qq.com", description = "邮箱账号")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业编码
|
||||||
|
*/
|
||||||
|
@Schema(title = "企业编码", type = "String", defaultValue = "db", description = "连接的数据源")
|
||||||
|
private String entCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业修改构建者
|
||||||
|
* @param req 企业修改请求对象
|
||||||
|
* @param entId 企业ID
|
||||||
|
* @return 企业管理实体
|
||||||
|
*/
|
||||||
|
public static SysEnt updateBuild(EntUpdateReq req, Supplier<Long> entId) {
|
||||||
|
return SysEnt.builder()
|
||||||
|
.id(entId.get())
|
||||||
|
.name(req.getEntName())
|
||||||
|
.leader(req.getLeader())
|
||||||
|
.phoneNumber(req.getPhoneNumber())
|
||||||
|
.email(req.getEmail())
|
||||||
|
.entCode(req.getEntCode())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,12 +49,15 @@ public class EntResp {
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库名称
|
* 企业编码
|
||||||
*/
|
*/
|
||||||
private Long databaseName;
|
@Schema(title = "企业编码", type = "String", defaultValue = "db", description = "连接的数据源")
|
||||||
|
private String entCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业管理响应对象构建者模式
|
* 企业管理响应对象构建者模式
|
||||||
|
* @param sysEnt 企业管理
|
||||||
|
* @return 企业信息响应对象
|
||||||
*/
|
*/
|
||||||
public static EntResp entBuild(SysEnt sysEnt) {
|
public static EntResp entBuild(SysEnt sysEnt) {
|
||||||
return EntResp.builder()
|
return EntResp.builder()
|
||||||
|
@ -63,7 +66,7 @@ public class EntResp {
|
||||||
.leader(sysEnt.getLeader())
|
.leader(sysEnt.getLeader())
|
||||||
.phoneNumber(sysEnt.getPhoneNumber())
|
.phoneNumber(sysEnt.getPhoneNumber())
|
||||||
.email(sysEnt.getEmail())
|
.email(sysEnt.getEmail())
|
||||||
.databaseName(sysEnt.getDatabaseName())
|
.entCode(sysEnt.getEntCode())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,8 @@ public class SysEntServiceImpl extends ServiceImpl<SysEntMapper, SysEnt> impleme
|
||||||
SysEnt::getEmail, entListReq.getEmail()
|
SysEnt::getEmail, entListReq.getEmail()
|
||||||
);
|
);
|
||||||
queryWrapper.eq(
|
queryWrapper.eq(
|
||||||
StringUtils.isNotEmpty(entListReq.getDatabaseName()),
|
StringUtils.isNotEmpty(entListReq.getEntCode()),
|
||||||
SysEnt::getDatabaseName, entListReq.getDatabaseName()
|
SysEnt::getEntCode, entListReq.getEntCode()
|
||||||
|
|
||||||
);
|
);
|
||||||
List<SysEnt> sysEntList = this.list(queryWrapper);
|
List<SysEnt> sysEntList = this.list(queryWrapper);
|
||||||
|
|
Loading…
Reference in New Issue