优化代码
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;
|
||||
|
||||
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.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 企业信息
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "firm_info")
|
||||
public class FirmInfo {
|
||||
|
||||
/**
|
||||
|
@ -57,4 +66,12 @@ public class FirmInfo {
|
|||
*/
|
||||
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.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){
|
||||
return false;
|
||||
}else{
|
||||
|
|
|
@ -2,15 +2,15 @@ package com.dragon.vehicle.company.server.controller;
|
|||
|
||||
|
||||
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.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 org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/firm")
|
||||
public class FirmController {
|
||||
|
@ -20,26 +20,14 @@ public class FirmController {
|
|||
|
||||
|
||||
/**
|
||||
* 企业认证
|
||||
* @param firmInfo
|
||||
* 企业信息录入
|
||||
* @param firmAddReq 企业添加请求对象
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/firmEnter")
|
||||
public Object addFirm(@RequestBody FirmInfo firmInfo){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONObject text = BaiDuAiCheck.checkText(firmInfo.getFirmName());
|
||||
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;
|
||||
@PostMapping()
|
||||
public Result<String> addFirm(@RequestBody @Validated FirmAddReq firmAddReq){
|
||||
firmService.save(FirmInfo.addReqBuild(firmAddReq));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,10 +35,10 @@ public class FirmController {
|
|||
* 查看数据
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/firmList")
|
||||
public Result<List<FirmInfo>> selectFirmList(){
|
||||
List<FirmInfo> list=firmService.selectFirmList();
|
||||
return Result.success(list);
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<FirmInfo>> selectFirmList(@RequestBody @Validated FirmQueryReq firmQueryReq){
|
||||
TableDataInfo<FirmInfo> tableDataInfo = firmService.selectFirmList(firmQueryReq);
|
||||
return Result.success(tableDataInfo);
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,10 +47,10 @@ public class FirmController {
|
|||
* @param firmId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/logicDeleteFirmList/{firmId}")
|
||||
@PostMapping("/{firmId}")
|
||||
public Result logicDeleteFirmList(@PathVariable Integer firmId){
|
||||
Result result=firmService.logicDeleteFirmList(firmId);
|
||||
return result;
|
||||
firmService.removeById(firmId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
package com.dragon.vehicle.company.server.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.dragon.vehicle.company.common.domain.FirmInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface FirmMapper {
|
||||
void addFirm(FirmInfo firmInfo);
|
||||
public interface FirmMapper extends BaseMapper<FirmInfo> {
|
||||
|
||||
List<FirmInfo> selectFirmList();
|
||||
|
||||
void logicDeleteFirmList(@Param("firmId") Integer firmId);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
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.req.FirmQueryReq;
|
||||
|
||||
import java.util.List;
|
||||
public interface FirmService extends IService<FirmInfo> {
|
||||
|
||||
public interface FirmService {
|
||||
Result addFirm(FirmInfo firmInfo);
|
||||
|
||||
List<FirmInfo> selectFirmList();
|
||||
|
||||
|
||||
Result logicDeleteFirmList(Integer firmId);
|
||||
/**
|
||||
* 通过条件查询 企业 列表
|
||||
* @param firmQueryReq 查询条件
|
||||
* @return 企业分页结果
|
||||
*/
|
||||
TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq);
|
||||
}
|
||||
|
|
|
@ -1,52 +1,72 @@
|
|||
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.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.service.FirmService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class FirmServiceImpl implements FirmService {
|
||||
|
||||
@Autowired
|
||||
private FirmMapper firmMapper;
|
||||
public class FirmServiceImpl extends ServiceImpl<FirmMapper, FirmInfo> implements FirmService {
|
||||
|
||||
@Override
|
||||
public Result addFirm(FirmInfo firmInfo) {
|
||||
if (!ValidatorUtils.isPhone(firmInfo.getFirmRepresentativePhone())){
|
||||
return Result.error();
|
||||
public boolean save(FirmInfo entity) {
|
||||
boolean save = super.save(entity);
|
||||
if (!save){
|
||||
log.warn("企业添加失败:[{}] - {}", entity.getFirmName(), JSONObject.toJSONString(entity));
|
||||
throw new ServiceException("企业添加失败");
|
||||
}
|
||||
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FirmInfo> selectFirmList() {
|
||||
return firmMapper.selectFirmList();
|
||||
public boolean removeById(Serializable id) {
|
||||
boolean remove = super.removeById(id);
|
||||
if (!remove){
|
||||
log.warn("企业添加失败:[{}]", id);
|
||||
throw new ServiceException("企业失败删除");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过条件查询 企业 列表
|
||||
*
|
||||
* @param firmQueryReq 查询条件
|
||||
* @return 企业分页结果
|
||||
*/
|
||||
@Override
|
||||
public Result logicDeleteFirmList(Integer firmId) {
|
||||
firmMapper.logicDeleteFirmList(firmId);
|
||||
return Result.success();
|
||||
}
|
||||
public TableDataInfo<FirmInfo> selectFirmList(FirmQueryReq firmQueryReq) {
|
||||
|
||||
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">
|
||||
|
||||
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue