优化代码
parent
ec5ac5ac80
commit
45419686df
|
@ -0,0 +1,47 @@
|
||||||
|
package com.dragon.vehicle.common.page;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.dragon.common.core.utils.StringUtils;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询对象
|
||||||
|
*
|
||||||
|
* @author HuZhiYong
|
||||||
|
* @version 2023/11/20 - 15:04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PageQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第几页
|
||||||
|
*/
|
||||||
|
private Integer page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页长度
|
||||||
|
*/
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private String orderBy;
|
||||||
|
|
||||||
|
public <T> Page<T> buildPage(){
|
||||||
|
Page<T> page = new Page<>(this.getPage(), this.getPageSize());
|
||||||
|
if (StringUtils.isNotEmpty(this.getOrderBy())){
|
||||||
|
page.addOrder(OrderItem.asc(this.getOrderBy()));
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.dragon.vehicle.company.common.contsants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则表达式常量
|
||||||
|
*
|
||||||
|
* @author HuZhiYong
|
||||||
|
* @version 2023/11/20 - 14:48
|
||||||
|
*/
|
||||||
|
public class RegexConstants {
|
||||||
|
|
||||||
|
public final static String PHONE = "^(?:(?:\\\\+|00)86)?1(?:(?:3[\\\\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\\\d])|(?:9[1|8|9]))\\\\d{8}$";
|
||||||
|
}
|
|
@ -1,11 +1,20 @@
|
||||||
package com.dragon.vehicle.company.common.domain;
|
package com.dragon.vehicle.company.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.dragon.vehicle.company.common.domain.req.FirmAddReq;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业信息
|
* 企业信息
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName(value = "firm_info")
|
||||||
public class FirmInfo {
|
public class FirmInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,4 +66,12 @@ public class FirmInfo {
|
||||||
*/
|
*/
|
||||||
private String unifiedSocialCredit;
|
private String unifiedSocialCredit;
|
||||||
|
|
||||||
|
public static FirmInfo addReqBuild(FirmAddReq firmAddReq){
|
||||||
|
return FirmInfo.builder()
|
||||||
|
// TODO 把属性都点上
|
||||||
|
.firmAddress(firmAddReq.getFirmAddress())
|
||||||
|
.firmBank(firmAddReq.getFirmBank())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.dragon.vehicle.company.common.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
import static com.dragon.vehicle.company.common.contsants.RegexConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FirmAddReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业名称
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "企业名称不可为空")
|
||||||
|
private String firmName;
|
||||||
|
/**
|
||||||
|
* 企业电话
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "企业电话不可为空")
|
||||||
|
@Pattern(regexp = PHONE)
|
||||||
|
private String firmTel;
|
||||||
|
/**
|
||||||
|
* 企业详细地址
|
||||||
|
*/
|
||||||
|
private String firmAddress;
|
||||||
|
/**
|
||||||
|
* 企业法定代表人
|
||||||
|
*/
|
||||||
|
private String firmRepresentative;
|
||||||
|
/**
|
||||||
|
* 法定代表人电话
|
||||||
|
*/
|
||||||
|
private String firmRepresentativePhone;
|
||||||
|
/**
|
||||||
|
* 法定代表人身份证号
|
||||||
|
*/
|
||||||
|
private String firmRepresentativeId;
|
||||||
|
/**
|
||||||
|
* 开户行名称
|
||||||
|
*/
|
||||||
|
private String firmBank;
|
||||||
|
/**
|
||||||
|
* 开户行支行
|
||||||
|
*/
|
||||||
|
private String firmBankBranch;
|
||||||
|
/**
|
||||||
|
* 银行账号
|
||||||
|
*/
|
||||||
|
private String firmBankAccount;
|
||||||
|
/**
|
||||||
|
* 营业执照号
|
||||||
|
*/
|
||||||
|
private String firmBusinessLicense;
|
||||||
|
/**
|
||||||
|
* 统一社会信用代码
|
||||||
|
*/
|
||||||
|
private String unifiedSocialCredit;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.dragon.vehicle.company.common.domain.req;
|
||||||
|
|
||||||
|
import com.dragon.vehicle.common.page.PageQuery;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
import static com.dragon.vehicle.company.common.contsants.RegexConstants.PHONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询企业列表
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FirmQueryReq extends PageQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业名称
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "企业名称不可为空")
|
||||||
|
private String firmName;
|
||||||
|
/**
|
||||||
|
* 企业电话
|
||||||
|
*/
|
||||||
|
@NotEmpty(message = "企业电话不可为空")
|
||||||
|
@Pattern(regexp = PHONE)
|
||||||
|
private String firmTel;
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import com.dragon.common.core.utils.StringUtils;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static com.dragon.vehicle.company.common.contsants.RegexConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业认真工具类
|
* 企业认真工具类
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +19,7 @@ public class ValidatorUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
//手机号校验规则
|
//手机号校验规则
|
||||||
String regex="^(?:(?:\\+|00)86)?1(?:(?:3[\\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\d])|(?:9[1|8|9]))\\d{8}$";
|
String regex= PHONE;
|
||||||
if (phone.length()!= 11){
|
if (phone.length()!= 11){
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -2,15 +2,15 @@ package com.dragon.vehicle.company.server.controller;
|
||||||
|
|
||||||
|
|
||||||
import com.dragon.common.core.domain.Result;
|
import com.dragon.common.core.domain.Result;
|
||||||
|
import com.dragon.common.core.web.page.TableDataInfo;
|
||||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||||
import com.dragon.vehicle.company.common.utils.BaiDuAiCheck;
|
import com.dragon.vehicle.company.common.domain.req.FirmAddReq;
|
||||||
|
import com.dragon.vehicle.company.common.domain.req.FirmQueryReq;
|
||||||
import com.dragon.vehicle.company.server.service.FirmService;
|
import com.dragon.vehicle.company.server.service.FirmService;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/firm")
|
@RequestMapping("/firm")
|
||||||
public class FirmController {
|
public class FirmController {
|
||||||
|
@ -20,26 +20,14 @@ public class FirmController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业认证
|
* 企业信息录入
|
||||||
* @param firmInfo
|
* @param firmAddReq 企业添加请求对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/firmEnter")
|
@PostMapping()
|
||||||
public Object addFirm(@RequestBody FirmInfo firmInfo){
|
public Result<String> addFirm(@RequestBody @Validated FirmAddReq firmAddReq){
|
||||||
JSONObject jsonObject = new JSONObject();
|
firmService.save(FirmInfo.addReqBuild(firmAddReq));
|
||||||
JSONObject text = BaiDuAiCheck.checkText(firmInfo.getFirmName());
|
return Result.success();
|
||||||
System.out.println(text);
|
|
||||||
if (text.get("conclusion")==null){
|
|
||||||
jsonObject.put("code",2);
|
|
||||||
}else if (text.get("conclusion").equals("合规")){
|
|
||||||
jsonObject.put("code",1);
|
|
||||||
Result result=firmService.addFirm(firmInfo);
|
|
||||||
return result;
|
|
||||||
}else {
|
|
||||||
jsonObject.put("code",3);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,10 +35,10 @@ public class FirmController {
|
||||||
* 查看数据
|
* 查看数据
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/firmList")
|
@GetMapping("/list")
|
||||||
public Result<List<FirmInfo>> selectFirmList(){
|
public Result<TableDataInfo<FirmInfo>> selectFirmList(@RequestBody @Validated FirmQueryReq firmQueryReq){
|
||||||
List<FirmInfo> list=firmService.selectFirmList();
|
TableDataInfo<FirmInfo> tableDataInfo = firmService.selectFirmList(firmQueryReq);
|
||||||
return Result.success(list);
|
return Result.success(tableDataInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,10 +47,10 @@ public class FirmController {
|
||||||
* @param firmId
|
* @param firmId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/logicDeleteFirmList/{firmId}")
|
@PostMapping("/{firmId}")
|
||||||
public Result logicDeleteFirmList(@PathVariable Integer firmId){
|
public Result logicDeleteFirmList(@PathVariable Integer firmId){
|
||||||
Result result=firmService.logicDeleteFirmList(firmId);
|
firmService.removeById(firmId);
|
||||||
return result;
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
package com.dragon.vehicle.company.server.mapper;
|
package com.dragon.vehicle.company.server.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface FirmMapper {
|
public interface FirmMapper extends BaseMapper<FirmInfo> {
|
||||||
void addFirm(FirmInfo firmInfo);
|
|
||||||
|
|
||||||
List<FirmInfo> selectFirmList();
|
|
||||||
|
|
||||||
void logicDeleteFirmList(@Param("firmId") Integer firmId);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package com.dragon.vehicle.company.server.service;
|
package com.dragon.vehicle.company.server.service;
|
||||||
|
|
||||||
import com.dragon.common.core.domain.Result;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.dragon.common.core.web.page.TableDataInfo;
|
||||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||||
|
import com.dragon.vehicle.company.common.domain.req.FirmQueryReq;
|
||||||
|
|
||||||
import java.util.List;
|
public interface FirmService extends IService<FirmInfo> {
|
||||||
|
|
||||||
public interface FirmService {
|
/**
|
||||||
Result addFirm(FirmInfo firmInfo);
|
* 通过条件查询 企业 列表
|
||||||
|
* @param firmQueryReq 查询条件
|
||||||
List<FirmInfo> selectFirmList();
|
* @return 企业分页结果
|
||||||
|
*/
|
||||||
|
TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq);
|
||||||
Result logicDeleteFirmList(Integer firmId);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,72 @@
|
||||||
package com.dragon.vehicle.company.server.service.impl;
|
package com.dragon.vehicle.company.server.service.impl;
|
||||||
|
|
||||||
import com.dragon.common.core.domain.Result;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
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.dragon.common.core.exception.ServiceException;
|
||||||
|
import com.dragon.common.core.utils.StringUtils;
|
||||||
|
import com.dragon.common.core.web.page.TableDataInfo;
|
||||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||||
import com.dragon.vehicle.company.common.utils.ValidatorUtils;
|
import com.dragon.vehicle.company.common.domain.req.FirmQueryReq;
|
||||||
import com.dragon.vehicle.company.server.mapper.FirmMapper;
|
import com.dragon.vehicle.company.server.mapper.FirmMapper;
|
||||||
import com.dragon.vehicle.company.server.service.FirmService;
|
import com.dragon.vehicle.company.server.service.FirmService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
public class FirmServiceImpl implements FirmService {
|
public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implements FirmService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FirmMapper firmMapper;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result addFirm(FirmInfo firmInfo) {
|
public boolean save(FirmInfo entity) {
|
||||||
if (!ValidatorUtils.isPhone(firmInfo.getFirmRepresentativePhone())){
|
boolean save = super.save(entity);
|
||||||
return Result.error();
|
if (!save){
|
||||||
|
log.warn("企业添加失败:[{}] - {}", entity.getFirmName(), JSONObject.toJSONString(entity));
|
||||||
|
throw new ServiceException("企业添加失败");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
if (!ValidatorUtils.validator(firmInfo.getFirmRepresentativeId())){
|
|
||||||
return Result.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ValidatorUtils.isLicense18(firmInfo.getUnifiedSocialCredit())){
|
|
||||||
return Result.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ValidatorUtils.isTel(firmInfo.getFirmTel())){
|
|
||||||
return Result.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
firmMapper.addFirm(firmInfo);
|
|
||||||
return Result.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<FirmInfo> selectFirmList() {
|
public boolean removeById(Serializable id) {
|
||||||
return firmMapper.selectFirmList();
|
boolean remove = super.removeById(id);
|
||||||
|
if (!remove){
|
||||||
|
log.warn("企业添加失败:[{}]", id);
|
||||||
|
throw new ServiceException("企业失败删除");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过条件查询 企业 列表
|
||||||
|
*
|
||||||
|
* @param firmQueryReq 查询条件
|
||||||
|
* @return 企业分页结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result logicDeleteFirmList(Integer firmId) {
|
public TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq) {
|
||||||
firmMapper.logicDeleteFirmList(firmId);
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
LambdaQueryWrapper<FirmInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (StringUtils.isNotEmpty(firmQueryReq.getFirmName())){
|
||||||
|
queryWrapper.like(FirmInfo::getFirmName, firmQueryReq.getFirmName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(firmQueryReq.getFirmTel())){
|
||||||
|
queryWrapper.eq(FirmInfo::getFirmTel, firmQueryReq.getFirmTel());
|
||||||
|
}
|
||||||
|
|
||||||
|
Page<FirmInfo> page = this.page(firmQueryReq.buildPage(), queryWrapper);
|
||||||
|
return TableDataInfo.<FirmInfo>builder()
|
||||||
|
.rows(page.getRecords())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,4 @@
|
||||||
<mapper namespace="com.dragon.vehicle.company.server.mapper.FirmMapper">
|
<mapper namespace="com.dragon.vehicle.company.server.mapper.FirmMapper">
|
||||||
|
|
||||||
|
|
||||||
<insert id="addFirm">
|
|
||||||
insert into firm_info(firm_name,firm_tel,firm_address,firm_representative,firm_representative_phone,firm_representative_id,firm_bank,firm_bank_branch,
|
|
||||||
firm_bank_account,firm_business_license,unified_social_credit)
|
|
||||||
values (#{firmName},#{firmTel},#{firmAddress},#{firmRepresentative},#{firmRepresentativePhone},#{firmRepresentativeId},#{firmBank},
|
|
||||||
#{firmBankAccount},#{firmBusinessLicense},#{unifiedSocialCredit})
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="logicDeleteFirmList">
|
|
||||||
update firm_info set del_status where firm_id=#{firmId}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
|
|
||||||
<select id="selectFirmList" resultType="com.dragon.vehicle.company.common.domain.FirmInfo">
|
|
||||||
select *from firm_info
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue