feat(): 企业增删改功能

dev.vehicleGateway
xinzirun 2024-09-26 19:21:39 +08:00
parent 5012e3c895
commit 0febb2cb21
6 changed files with 271 additions and 4 deletions

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -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;
@ -34,9 +38,9 @@ public class SysEntController extends BaseController {
* *
* @return * @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);
} }
@ -53,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);
}
} }

View File

@ -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();
}
}

View File

@ -1,6 +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.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;
@ -15,6 +16,7 @@ import lombok.NoArgsConstructor;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Tag(name = "企业信息列表请求对象", description = "企业列表条件查询")
public class EntListReq { public class EntListReq {
/** /**

View File

@ -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();
}
}