Merge remote-tracking branch 'origin/dev.saas' into dev

dev.vehicleGateway
xinzirun 2024-09-26 19:22:22 +08:00
commit 2fc56d44c9
9 changed files with 292 additions and 13 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

@ -50,7 +50,7 @@ public class SysEnt extends BaseEntity {
private String email; private String email;
/** /**
* *
*/ */
private Long databaseName; private String entCode;
} }

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

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

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

View File

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

View File

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