From 7a960076cef97209d96e2b1246f81dbdf70de5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E5=87=AF?= <371894675@qq.com> Date: Wed, 22 Nov 2023 14:25:10 +0800 Subject: [PATCH] add remote firmInfo --- .../vehicle/firm/domain/common/FirmInfo.java | 41 ++++++--- .../firm/domain/req/FirmRegisterReq.java | 91 +++++++++++++++++++ .../server/controller/FirmInfoController.java | 31 +++++-- .../firm/server/service/FirmInfoService.java | 9 ++ .../service/impl/FirmInfoServiceImpl.java | 10 ++ 5 files changed, 159 insertions(+), 23 deletions(-) create mode 100644 vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/req/FirmRegisterReq.java diff --git a/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/common/FirmInfo.java b/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/common/FirmInfo.java index 970a65d..ec79129 100644 --- a/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/common/FirmInfo.java +++ b/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/common/FirmInfo.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.dragon.common.core.annotation.Excel; +import com.dragon.vehicle.firm.domain.req.FirmRegisterReq; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -22,69 +23,83 @@ import lombok.NoArgsConstructor; @TableName("firm_info") public class FirmInfo { /** - *编号 + * 编号 */ @TableId(type = IdType.AUTO) @Excel(name = "编号") private String firmId; /** - *企业名称 + * 企业名称 */ @Excel(name = "企业名称") private String firmName; /** - *企业联系方式 + * 企业联系方式 */ @Excel(name = "企业联系方式") private String firmTel; /** - *企业联系地址 + * 企业联系地址 */ @Excel(name = "企业联系地址") private String firmAddress; /** - *法定代表人 + * 法定代表人 */ @Excel(name = "法定代表人") private String firmRepresentative; /** - *法人联系方式 + * 法人联系方式 */ @Excel(name = "法人联系方式") private String firmRepresentativePhone; /** - *法人身份证号 + * 法人身份证号 */ @Excel(name = "法人身份证号") private String firmRepresentativeId; /** - *公司开户银行 + * 公司开户银行 */ @Excel(name = "公司开户银行") private String firmBank; /** - *开户行支行 + * 开户行支行 */ @Excel(name = "开户行支行") private String firmBankBranch; /** - *银行账户 + * 银行账户 */ @Excel(name = "银行账户") private String firmBankAccount; /** - *企业营业执照号 + * 企业营业执照号 */ @Excel(name = "企业营业执照号") private String firmBusinessLicense; /** - *统一社会信用代码 + * 统一社会信用代码 */ @Excel(name = "统一社会信用代码") private String firmSocialCredit; /** - *创建人id + * 创建人id */ private Long createBy; + + + public static FirmInfo registry(FirmRegisterReq firmRegisterReq) { + return FirmInfo.builder() + .firmName(firmRegisterReq.getFirmName()) + .firmTel(firmRegisterReq.getFirmTel()) + .firmAddress(firmRegisterReq.getFirmAddress()) + .firmBank(firmRegisterReq.getFirmBank()) + .firmBankAccount(firmRegisterReq.getFirmBankAccount()) + .firmBusinessLicense(firmRegisterReq.getFirmBusinessLicense()) + .firmRepresentative(firmRegisterReq.getFirmRepresentative()) + .firmRepresentativeId(firmRegisterReq.getFirmRepresentativeId()). + build(); + } } diff --git a/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/req/FirmRegisterReq.java b/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/req/FirmRegisterReq.java new file mode 100644 index 0000000..3dc5d6d --- /dev/null +++ b/vehicle-firm-common/src/main/java/com/dragon/vehicle/firm/domain/req/FirmRegisterReq.java @@ -0,0 +1,91 @@ +package com.dragon.vehicle.firm.domain.req; + +import com.dragon.common.core.annotation.Excel; +import com.dragon.vehicle.firm.domain.cache.FirmInfoCache; +import com.dragon.vehicle.firm.domain.common.FirmInfo; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.validator.constraints.UniqueElements; + +import javax.validation.constraints.NotNull; + +/** + * @author 冯凯 + * @version 1.0 + * @description: 公司注册实体类 + * @date 2023/11/22 14:05 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class FirmRegisterReq { + /** + * 编号 + */ + private String firmId; + /** + * 企业名称 + */ + @NotNull(message = "企业名称不能为空") + private String firmName; + /** + * 企业联系方式 + */ + @NotNull(message = "企业联系方式不能为空") + private String firmTel; + /** + * 企业联系地址 + */ + @NotNull(message = "企业地址不能为空") + private String firmAddress; + /** + * 法定代表人 + */ + @NotNull(message = "法定代表人不能为空") + private String firmRepresentative; + /** + * 法人联系方式 + */ + @NotNull(message = "法定代表人联系方式不能为空") + private String firmRepresentativePhone; + /** + * 法人身份证号 + */ + @NotNull(message = "法人身份证不能为空") + private String firmRepresentativeId; + /** + * 公司开户银行 + */ + @NotNull(message = "开户银行不能为空") + private String firmBank; + /** + * 开户行支行 + */ + private String firmBankBranch; + /** + * 银行账户 + */ + @NotNull(message = "银行账户不能为空") + private String firmBankAccount; + /** + * 企业营业执照号 + */ + @NotNull(message = "企业营业执照号不能为空") + private String firmBusinessLicense; + /** + * 统一社会信用代码 + */ + @NotNull(message = "统一社会信用代码不能为空") + private String firmSocialCredit; + + /** + * 创建人id + */ + private Long createBy; + + + +} diff --git a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/controller/FirmInfoController.java b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/controller/FirmInfoController.java index 824dd34..60734d0 100644 --- a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/controller/FirmInfoController.java +++ b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/controller/FirmInfoController.java @@ -1,16 +1,17 @@ package com.dragon.vehicle.firm.server.controller; import com.dragon.common.core.domain.Result; +import com.dragon.common.core.utils.StringUtils; import com.dragon.common.redis.service.RedisService; import com.dragon.common.security.utils.SecurityUtils; import com.dragon.vehicle.firm.domain.cache.FirmInfoCache; +import com.dragon.vehicle.firm.domain.common.FirmInfo; +import com.dragon.vehicle.firm.domain.req.FirmRegisterReq; import com.dragon.vehicle.firm.server.service.FirmInfoService; import lombok.extern.log4j.Log4j2; -import org.apache.catalina.security.SecurityUtil; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; /** * @author 冯凯 @@ -26,25 +27,35 @@ public class FirmInfoController { @Autowired private RedisService redisService; /** - *注入公司service + * 注入公司service */ @Autowired private FirmInfoService firmService; /*** - * @description: 通过userId获取用户的公司 + * @description: 通过userId获取用户的公司 * @param: * @param userId * @return: Result * @author 冯凯 * @date: 2023/11/21 13:55 */ @GetMapping("/by/userId") - public Result getFirmInfoByUserId(){ + public Result getFirmInfoByUserId() { Long userId = SecurityUtils.getUserId();//获取当前登录人的userId - log.info("当前登录人是:"+userId); - - FirmInfoCache firmInfoCache=firmService.getFirmInfoByUserId(1L); + log.info("当前登录人是:" + userId); + FirmInfoCache firmInfoCache = firmService.getFirmInfoByUserId(1L); return Result.success(firmInfoCache); } + + @PostMapping("/register/company") + public Result registerCompany(@RequestBody @Validated FirmRegisterReq firmRegisterReq) { + if (firmService.checkFirmNameUnique(firmRegisterReq.getFirmName())) { + //返回true证明已经有同名企业入驻了 + return Result.error(StringUtils.format("入驻失败,企业 【{}】已经存在", firmRegisterReq.getFirmName())); + } + //企业入驻 + firmService.save(FirmInfo.registry(firmRegisterReq)); + return Result.success("", "入驻成功!!!"); + } } diff --git a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/FirmInfoService.java b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/FirmInfoService.java index acfef0b..db6aa1a 100644 --- a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/FirmInfoService.java +++ b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/FirmInfoService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.dragon.vehicle.firm.domain.cache.FirmInfoCache; import com.dragon.vehicle.firm.domain.common.FirmInfo; +import javax.validation.constraints.NotNull; + /** * @author 冯凯 * @version 1.0 @@ -21,4 +23,11 @@ public interface FirmInfoService extends IService{ * @date: 2023/11/21 13:55 */ FirmInfoCache getFirmInfoByUserId(Long userId); + + /** + *利用企业名称验证企业唯一性 + */ + boolean checkFirmNameUnique(@NotNull String firmName); + + } diff --git a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/impl/FirmInfoServiceImpl.java b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/impl/FirmInfoServiceImpl.java index c11be30..8d5cca6 100644 --- a/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/impl/FirmInfoServiceImpl.java +++ b/vehicle-firm-server/src/main/java/com/dragon/vehicle/firm/server/service/impl/FirmInfoServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import javax.validation.constraints.NotNull; + /** * @author 冯凯 * @version 1.0 @@ -51,4 +53,12 @@ public class FirmInfoServiceImpl extends ServiceImpl i log.info(firmInfoCache); return firmInfoCache; } + + @Override + public boolean checkFirmNameUnique(@NotNull String firmName) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(FirmInfo::getFirmName,firmName); + return firmInfoMapper.selectCount(queryWrapper)>0; + } + }