diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java index a329fb17..86adc1cd 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.date; import cn.hutool.core.date.LocalDateTimeUtil; +import java.text.SimpleDateFormat; import java.time.*; import java.util.Calendar; import java.util.Date; @@ -26,6 +27,7 @@ public class DateUtils { public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; public static final String FORMAT_HOUR_MINUTE_SECOND = "HH:mm:ss"; + public static final String FORMAT_HOUR_MINUT = "HHmmss"; /** * 将 LocalDateTime 转换成 Date @@ -170,4 +172,13 @@ public class DateUtils { return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now()); } + /** + * 获取当前时间转换成字符串 + * @param pattern + * @return + */ + public static String dateToStr(String pattern,Date date){ + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return sdf.format(date); + } } diff --git a/yudao-module-bs/pom.xml b/yudao-module-bs/pom.xml index 072be292..6cd6f43d 100644 --- a/yudao-module-bs/pom.xml +++ b/yudao-module-bs/pom.xml @@ -19,5 +19,25 @@ 报销系统业务模块 + + + com.baidu.aip + java-sdk + 4.8.0 + + + commons-io + commons-io + 2.6 + + + + com.alibaba + fastjson + 1.2.80 + + + + diff --git a/yudao-module-bs/yudao-module-bs-api/src/main/java/cn/iocoder/yudao/module/bs/enums/ErrorCodeConstants.java b/yudao-module-bs/yudao-module-bs-api/src/main/java/cn/iocoder/yudao/module/bs/enums/ErrorCodeConstants.java index 5bde1a33..98b27b8c 100644 --- a/yudao-module-bs/yudao-module-bs-api/src/main/java/cn/iocoder/yudao/module/bs/enums/ErrorCodeConstants.java +++ b/yudao-module-bs/yudao-module-bs-api/src/main/java/cn/iocoder/yudao/module/bs/enums/ErrorCodeConstants.java @@ -15,4 +15,5 @@ public interface ErrorCodeConstants { ErrorCode FEE_MANAGE_NOT_EXISTS = new ErrorCode(200500, "费用控制不存在"); ErrorCode CUSTOMER_COMPANY_NOT_EXISTS = new ErrorCode(200600, "客户公司不存在"); ErrorCode EXPENSE_CLAIM_NOT_EXISTS = new ErrorCode(200700, "报销单不存在"); + ErrorCode SUPPLIER_COMPANY_NOT_EXISTS = new ErrorCode(202300, "供应商信息不存在"); } diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/SupplierCompanyController.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/SupplierCompanyController.java new file mode 100644 index 00000000..a435a519 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/SupplierCompanyController.java @@ -0,0 +1,116 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany; + +import cn.iocoder.yudao.module.bs.utils.BusinessLicense; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; +import static cn.iocoder.yudao.module.bs.utils.BaiduOcrHandler.handleBusinessLicense; + +import cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo.*; +import cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany.SupplierCompanyDO; +import cn.iocoder.yudao.module.bs.convert.suppliercompany.SupplierCompanyConvert; +import cn.iocoder.yudao.module.bs.service.suppliercompany.SupplierCompanyService; +import org.springframework.web.multipart.MultipartFile; + +@Tag(name = "管理后台 - 供应商信息") +@RestController +@RequestMapping("/bs/supplier-company") +@Validated +public class SupplierCompanyController { + + @Resource + private SupplierCompanyService supplierCompanyService; + + @PostMapping("/buildBusinessLicense") + @Operation(summary = "百度云营业执照识别") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:create')") + public CommonResult buildBusinessLicense(MultipartFile file) { + try { + return success(handleBusinessLicense(file)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @PostMapping("/create") + @Operation(summary = "创建供应商信息") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:create')") + public CommonResult createSupplierCompany(@Valid @RequestBody SupplierCompanyCreateReqVO createReqVO) { + return success(supplierCompanyService.createSupplierCompany(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新供应商信息") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:update')") + public CommonResult updateSupplierCompany(@Valid @RequestBody SupplierCompanyUpdateReqVO updateReqVO) { + supplierCompanyService.updateSupplierCompany(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除供应商信息") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('bs:supplier-company:delete')") + public CommonResult deleteSupplierCompany(@RequestParam("id") Long id) { + supplierCompanyService.deleteSupplierCompany(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得供应商信息") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:query')") + public CommonResult getSupplierCompany(@RequestParam("id") Long id) { + SupplierCompanyDO supplierCompany = supplierCompanyService.getSupplierCompany(id); + return success(SupplierCompanyConvert.INSTANCE.convert(supplierCompany)); + } + + @GetMapping("/list") + @Operation(summary = "获得供应商信息列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:query')") + public CommonResult> getSupplierCompanyList(@RequestParam("ids") Collection ids) { + List list = supplierCompanyService.getSupplierCompanyList(ids); + return success(SupplierCompanyConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得供应商信息分页") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:query')") + public CommonResult> getSupplierCompanyPage(@Valid SupplierCompanyPageReqVO pageVO) { + PageResult pageResult = supplierCompanyService.getSupplierCompanyPage(pageVO); + return success(SupplierCompanyConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出供应商信息 Excel") + @PreAuthorize("@ss.hasPermission('bs:supplier-company:export')") + @OperateLog(type = EXPORT) + public void exportSupplierCompanyExcel(@Valid SupplierCompanyExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = supplierCompanyService.getSupplierCompanyList(exportReqVO); + // 导出 Excel + List datas = SupplierCompanyConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "供应商信息.xls", "数据", SupplierCompanyExcelVO.class, datas); + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyBaseVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyBaseVO.java new file mode 100644 index 00000000..fec01a42 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyBaseVO.java @@ -0,0 +1,90 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 供应商信息 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class SupplierCompanyBaseVO { + + @Schema(description = "供应商企业名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "供应商企业名称不能为空") + private String companyAme; + + @Schema(description = "供应商编码", requiredMode = Schema.RequiredMode.REQUIRED) +// @NotNull(message = "供应商编码不能为空") + private String companyNumber; + + @Schema(description = "企业性质", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "企业性质不能为空") + private Integer companyType; + + @Schema(description = "法人代表", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "法人代表不能为空") + private String legalPerson; + + @Schema(description = "联系方式", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "联系方式不能为空") + private String phone; + + @Schema(description = "统一社会信用代码", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "统一社会信用代码不能为空") + private String creditCode; + + @Schema(description = "企业地址", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "企业地址不能为空") + private String address; + + @Schema(description = "营业期限(起)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "营业期限(起)不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime businessStratDate; + + @Schema(description = "营业期限(止)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "营业期限(止)不能为空") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime businessEndDate; + + @Schema(description = "注册资本(w)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "注册资本(w)不能为空") + private Integer capital; + + @Schema(description = "银行户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @NotNull(message = "银行户名不能为空") + private String bankName; + + @Schema(description = "银行账号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "银行账号不能为空") + private String bankNumber; + + @Schema(description = "开户行名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "开户行名称不能为空") + private String bankOfDeposit; + + @Schema(description = "是否注册", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "是否注册不能为空") + private Byte isRegister; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "状态不能为空") + private Integer status; + + @Schema(description = "备注", example = "随便") + private String remark; + + @Schema(description = "附件") + private String files; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyCreateReqVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyCreateReqVO.java new file mode 100644 index 00000000..aac51b05 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 供应商信息创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SupplierCompanyCreateReqVO extends SupplierCompanyBaseVO { + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExcelVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExcelVO.java new file mode 100644 index 00000000..04c84e83 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExcelVO.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 供应商信息 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SupplierCompanyExcelVO { + + @ExcelProperty("主键") + private Long id; + + @ExcelProperty("供应商企业名称") + private String companyAme; + + @ExcelProperty("供应商编码") + private String companyNumber; + + @ExcelProperty("企业性质") + private Integer companyType; + + @ExcelProperty("法人代表") + private String legalPerson; + + @ExcelProperty("联系方式") + private String phone; + + @ExcelProperty("统一社会信用代码") + private String creditCode; + + @ExcelProperty("企业地址") + private String address; + + @ExcelProperty("营业期限(起)") + private LocalDateTime businessStratDate; + + @ExcelProperty("营业期限(止)") + private LocalDateTime businessEndDate; + + @ExcelProperty("注册资本(w)") + private Integer capital; + + @ExcelProperty("银行户名") + private String bankName; + + @ExcelProperty("银行账号") + private String bankNumber; + + @ExcelProperty("开户行名称") + private String bankOfDeposit; + + @ExcelProperty("是否注册") + private Byte isRegister; + + @ExcelProperty("状态") + private Integer status; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("附件") + private String files; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExportReqVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExportReqVO.java new file mode 100644 index 00000000..607b922a --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyExportReqVO.java @@ -0,0 +1,73 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.time.LocalDateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 供应商信息 Excel 导出 Request VO,参数和 SupplierCompanyPageReqVO 是一致的") +@Data +public class SupplierCompanyExportReqVO { + + @Schema(description = "供应商企业名称") + private String companyAme; + + @Schema(description = "供应商编码") + private String companyNumber; + + @Schema(description = "企业性质", example = "2") + private Integer companyType; + + @Schema(description = "法人代表") + private String legalPerson; + + @Schema(description = "联系方式") + private String phone; + + @Schema(description = "统一社会信用代码") + private String creditCode; + + @Schema(description = "企业地址") + private String address; + + @Schema(description = "营业期限(起)") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] businessStratDate; + + @Schema(description = "营业期限(止)") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] businessEndDate; + + @Schema(description = "注册资本(w)") + private Integer capital; + + @Schema(description = "银行户名", example = "李四") + private String bankName; + + @Schema(description = "银行账号") + private String bankNumber; + + @Schema(description = "开户行名称") + private String bankOfDeposit; + + @Schema(description = "是否注册") + private Byte isRegister; + + @Schema(description = "状态", example = "1") + private Integer status; + + @Schema(description = "备注", example = "随便") + private String remark; + + @Schema(description = "附件") + private String files; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyPageReqVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyPageReqVO.java new file mode 100644 index 00000000..d9169159 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyPageReqVO.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 供应商信息分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SupplierCompanyPageReqVO extends PageParam { + + @Schema(description = "供应商企业名称") + private String companyAme; + + @Schema(description = "供应商编码") + private String companyNumber; + + @Schema(description = "企业性质", example = "2") + private Integer companyType; + + @Schema(description = "法人代表") + private String legalPerson; + + @Schema(description = "联系方式") + private String phone; + + @Schema(description = "统一社会信用代码") + private String creditCode; + + @Schema(description = "企业地址") + private String address; + + @Schema(description = "营业期限(起)") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] businessStratDate; + + @Schema(description = "营业期限(止)") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] businessEndDate; + + @Schema(description = "注册资本(w)") + private Integer capital; + + @Schema(description = "银行户名", example = "李四") + private String bankName; + + @Schema(description = "银行账号") + private String bankNumber; + + @Schema(description = "开户行名称") + private String bankOfDeposit; + + @Schema(description = "是否注册") + private Byte isRegister; + + @Schema(description = "状态", example = "1") + private Integer status; + + @Schema(description = "备注", example = "随便") + private String remark; + + @Schema(description = "附件") + private String files; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyRespVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyRespVO.java new file mode 100644 index 00000000..96226482 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 供应商信息 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SupplierCompanyRespVO extends SupplierCompanyBaseVO { + + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14420") + private Long id; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyUpdateReqVO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyUpdateReqVO.java new file mode 100644 index 00000000..e5a99fcf --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/controller/admin/suppliercompany/vo/SupplierCompanyUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 供应商信息更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SupplierCompanyUpdateReqVO extends SupplierCompanyBaseVO { + + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14420") + @NotNull(message = "主键不能为空") + private Long id; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/convert/suppliercompany/SupplierCompanyConvert.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/convert/suppliercompany/SupplierCompanyConvert.java new file mode 100644 index 00000000..087165dc --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/convert/suppliercompany/SupplierCompanyConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.bs.convert.suppliercompany; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo.*; +import cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany.SupplierCompanyDO; + +/** + * 供应商信息 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface SupplierCompanyConvert { + + SupplierCompanyConvert INSTANCE = Mappers.getMapper(SupplierCompanyConvert.class); + + SupplierCompanyDO convert(SupplierCompanyCreateReqVO bean); + + SupplierCompanyDO convert(SupplierCompanyUpdateReqVO bean); + + SupplierCompanyRespVO convert(SupplierCompanyDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/dataobject/suppliercompany/SupplierCompanyDO.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/dataobject/suppliercompany/SupplierCompanyDO.java new file mode 100644 index 00000000..37092e42 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/dataobject/suppliercompany/SupplierCompanyDO.java @@ -0,0 +1,101 @@ +package cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 供应商信息 DO + * + * @author 芋道源码 + */ +@TableName("bs_supplier_company") +@KeySequence("bs_supplier_company_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SupplierCompanyDO extends BaseDO { + + /** + * 主键 + */ + @TableId + private Long id; + /** + * 供应商企业名称 + */ + private String companyAme; + /** + * 供应商编码 + */ + private String companyNumber; + /** + * 企业性质 + */ + private Integer companyType; + /** + * 法人代表 + */ + private String legalPerson; + /** + * 联系方式 + */ + private String phone; + /** + * 统一社会信用代码 + */ + private String creditCode; + /** + * 企业地址 + */ + private String address; + /** + * 营业期限(起) + */ + private LocalDateTime businessStratDate; + /** + * 营业期限(止) + */ + private LocalDateTime businessEndDate; + /** + * 注册资本(w) + */ + private Integer capital; + /** + * 银行户名 + */ + private String bankName; + /** + * 银行账号 + */ + private String bankNumber; + /** + * 开户行名称 + */ + private String bankOfDeposit; + /** + * 是否注册 + */ + private Byte isRegister; + /** + * 状态 + */ + private Integer status; + /** + * 备注 + */ + private String remark; + /** + * 附件 + */ + private String files; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/mysql/suppliercompany/SupplierCompanyMapper.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/mysql/suppliercompany/SupplierCompanyMapper.java new file mode 100644 index 00000000..084ff074 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/dal/mysql/suppliercompany/SupplierCompanyMapper.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.bs.dal.mysql.suppliercompany; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany.SupplierCompanyDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo.*; + +/** + * 供应商信息 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface SupplierCompanyMapper extends BaseMapperX { + + default PageResult selectPage(SupplierCompanyPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(SupplierCompanyDO::getCompanyAme, reqVO.getCompanyAme()) + .eqIfPresent(SupplierCompanyDO::getCompanyNumber, reqVO.getCompanyNumber()) + .eqIfPresent(SupplierCompanyDO::getCompanyType, reqVO.getCompanyType()) + .eqIfPresent(SupplierCompanyDO::getLegalPerson, reqVO.getLegalPerson()) + .eqIfPresent(SupplierCompanyDO::getPhone, reqVO.getPhone()) + .eqIfPresent(SupplierCompanyDO::getCreditCode, reqVO.getCreditCode()) + .eqIfPresent(SupplierCompanyDO::getAddress, reqVO.getAddress()) + .betweenIfPresent(SupplierCompanyDO::getBusinessStratDate, reqVO.getBusinessStratDate()) + .betweenIfPresent(SupplierCompanyDO::getBusinessEndDate, reqVO.getBusinessEndDate()) + .eqIfPresent(SupplierCompanyDO::getCapital, reqVO.getCapital()) + .likeIfPresent(SupplierCompanyDO::getBankName, reqVO.getBankName()) + .eqIfPresent(SupplierCompanyDO::getBankNumber, reqVO.getBankNumber()) + .eqIfPresent(SupplierCompanyDO::getBankOfDeposit, reqVO.getBankOfDeposit()) + .eqIfPresent(SupplierCompanyDO::getIsRegister, reqVO.getIsRegister()) + .eqIfPresent(SupplierCompanyDO::getStatus, reqVO.getStatus()) + .eqIfPresent(SupplierCompanyDO::getRemark, reqVO.getRemark()) + .eqIfPresent(SupplierCompanyDO::getFiles, reqVO.getFiles()) + .betweenIfPresent(SupplierCompanyDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SupplierCompanyDO::getId)); + } + + default List selectList(SupplierCompanyExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(SupplierCompanyDO::getCompanyAme, reqVO.getCompanyAme()) + .eqIfPresent(SupplierCompanyDO::getCompanyNumber, reqVO.getCompanyNumber()) + .eqIfPresent(SupplierCompanyDO::getCompanyType, reqVO.getCompanyType()) + .eqIfPresent(SupplierCompanyDO::getLegalPerson, reqVO.getLegalPerson()) + .eqIfPresent(SupplierCompanyDO::getPhone, reqVO.getPhone()) + .eqIfPresent(SupplierCompanyDO::getCreditCode, reqVO.getCreditCode()) + .eqIfPresent(SupplierCompanyDO::getAddress, reqVO.getAddress()) + .betweenIfPresent(SupplierCompanyDO::getBusinessStratDate, reqVO.getBusinessStratDate()) + .betweenIfPresent(SupplierCompanyDO::getBusinessEndDate, reqVO.getBusinessEndDate()) + .eqIfPresent(SupplierCompanyDO::getCapital, reqVO.getCapital()) + .likeIfPresent(SupplierCompanyDO::getBankName, reqVO.getBankName()) + .eqIfPresent(SupplierCompanyDO::getBankNumber, reqVO.getBankNumber()) + .eqIfPresent(SupplierCompanyDO::getBankOfDeposit, reqVO.getBankOfDeposit()) + .eqIfPresent(SupplierCompanyDO::getIsRegister, reqVO.getIsRegister()) + .eqIfPresent(SupplierCompanyDO::getStatus, reqVO.getStatus()) + .eqIfPresent(SupplierCompanyDO::getRemark, reqVO.getRemark()) + .eqIfPresent(SupplierCompanyDO::getFiles, reqVO.getFiles()) + .betweenIfPresent(SupplierCompanyDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SupplierCompanyDO::getId)); + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyService.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyService.java new file mode 100644 index 00000000..4dfc5f50 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.bs.service.suppliercompany; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo.*; +import cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany.SupplierCompanyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 供应商信息 Service 接口 + * + * @author 芋道源码 + */ +public interface SupplierCompanyService { + + /** + * 创建供应商信息 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createSupplierCompany(@Valid SupplierCompanyCreateReqVO createReqVO); + + /** + * 更新供应商信息 + * + * @param updateReqVO 更新信息 + */ + void updateSupplierCompany(@Valid SupplierCompanyUpdateReqVO updateReqVO); + + /** + * 删除供应商信息 + * + * @param id 编号 + */ + void deleteSupplierCompany(Long id); + + /** + * 获得供应商信息 + * + * @param id 编号 + * @return 供应商信息 + */ + SupplierCompanyDO getSupplierCompany(Long id); + + /** + * 获得供应商信息列表 + * + * @param ids 编号 + * @return 供应商信息列表 + */ + List getSupplierCompanyList(Collection ids); + + /** + * 获得供应商信息分页 + * + * @param pageReqVO 分页查询 + * @return 供应商信息分页 + */ + PageResult getSupplierCompanyPage(SupplierCompanyPageReqVO pageReqVO); + + /** + * 获得供应商信息列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 供应商信息列表 + */ + List getSupplierCompanyList(SupplierCompanyExportReqVO exportReqVO); + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyServiceImpl.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyServiceImpl.java new file mode 100644 index 00000000..ecf522e3 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/service/suppliercompany/SupplierCompanyServiceImpl.java @@ -0,0 +1,134 @@ +package cn.iocoder.yudao.module.bs.service.suppliercompany; + +import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.bs.controller.admin.suppliercompany.vo.*; +import cn.iocoder.yudao.module.bs.dal.dataobject.suppliercompany.SupplierCompanyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.bs.convert.suppliercompany.SupplierCompanyConvert; +import cn.iocoder.yudao.module.bs.dal.mysql.suppliercompany.SupplierCompanyMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.*; + +/** + * 供应商信息 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SupplierCompanyServiceImpl implements SupplierCompanyService { + + @Resource + private SupplierCompanyMapper supplierCompanyMapper; + + + @Override + public Long createSupplierCompany(SupplierCompanyCreateReqVO createReqVO) { + // 插入 + SupplierCompanyDO supplierCompany = SupplierCompanyConvert.INSTANCE.convert(createReqVO); + String companyNumber = numberCreate(); + supplierCompany.setCompanyNumber(companyNumber); + supplierCompanyMapper.insert(supplierCompany); + // 返回 + return supplierCompany.getId(); + } + + @Override + public void updateSupplierCompany(SupplierCompanyUpdateReqVO updateReqVO) { + // 校验存在 + validateSupplierCompanyExists(updateReqVO.getId()); + // 更新 + SupplierCompanyDO updateObj = SupplierCompanyConvert.INSTANCE.convert(updateReqVO); + supplierCompanyMapper.updateById(updateObj); + } + + @Override + public void deleteSupplierCompany(Long id) { + // 校验存在 + validateSupplierCompanyExists(id); + // 删除 + supplierCompanyMapper.deleteById(id); + } + + private void validateSupplierCompanyExists(Long id) { + if (supplierCompanyMapper.selectById(id) == null) { + throw exception(SUPPLIER_COMPANY_NOT_EXISTS); + } + } + + @Override + public SupplierCompanyDO getSupplierCompany(Long id) { + return supplierCompanyMapper.selectById(id); + } + + @Override + public List getSupplierCompanyList(Collection ids) { + return supplierCompanyMapper.selectBatchIds(ids); + } + + @Override + public PageResult getSupplierCompanyPage(SupplierCompanyPageReqVO pageReqVO) { + return supplierCompanyMapper.selectPage(pageReqVO); + } + + @Override + public List getSupplierCompanyList(SupplierCompanyExportReqVO exportReqVO) { + return supplierCompanyMapper.selectList(exportReqVO); + } + /** + * 编号生成方法 + * @return + */ + private String numberCreate(){ + long currentTime = System.currentTimeMillis(); + Date date = new Date(currentTime); + String companyNumber="gys"+ DateUtils.dateToStr(DateUtils.FORMAT_HOUR_MINUT,date); + Long companyNumberSize = supplierCompanyMapper.selectCount(new QueryWrapper().likeLeft("company_number", companyNumber)); + Long l = companyNumberSize + 1L; + int length = String.valueOf(companyNumberSize + 1L).length(); + if ((4-length) !=0){ + String gys = fillStr("", (4-length), true, "0"); + companyNumber=companyNumber+gys+l.intValue(); + }else { + companyNumber=companyNumber+l; + } + return companyNumber; + } + + private String fillStr(String value, int count, boolean frontORback, String fillChar) { + String rtvalue = value; + if (rtvalue == null) { + rtvalue = ""; + for (int i = 0; i < count; i++) + if (frontORback) + rtvalue = String.valueOf(rtvalue) + + String.valueOf(fillChar); + else + rtvalue = String.valueOf(fillChar) + + String.valueOf(rtvalue); + } else { + int len = rtvalue.length(); + if (len > count) { + rtvalue = rtvalue.substring(0, count); + } else { + int a = count - len; + for (int i = 0; i < a; i++) + if (frontORback) + rtvalue = String.valueOf(rtvalue) + + String.valueOf(fillChar); + else + rtvalue = String.valueOf(fillChar) + + String.valueOf(rtvalue); + } + } + return rtvalue; + } +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrConstant.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrConstant.java new file mode 100644 index 00000000..ab8c34be --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrConstant.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.bs.utils; + +/** + * @author MrFang + * @date 2023年08月15日 11:36 + */ +public interface BaiduOcrConstant { + /** + * 编码 + */ + String CHARSET = "UTF-8"; + + /** + * 百度智能云注册的应用程序API Key + */ + String CLIENT_ID = "YLQSdO65OZjARM8A8ZN62O11"; + + /** + * 百度智能云注册的应用程序Secret Key + */ + String CLIENT_SECRET = "4fU8odNqBDqNk5W3BS0PDrdk20TGV9sO"; + + /** + * 身份证正面识别OCR接口地址 + */ + String ID_CARD_FRONT_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard"; + + /** + * 身份证混贴识别OCR接口地址 + */ + String ID_CARD_MULTI_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/multi_idcard"; + + /** + * 营业执照识别OCR接口地址 + */ + String BUSINESS_LICENSE_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license"; + + /** + * OCR accessToken获取接口地址 + */ + String ACCESS_TOKEN_URL = "https://aip.baidubce.com/oauth/2.0/token"; + +} \ No newline at end of file diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrHandler.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrHandler.java new file mode 100644 index 00000000..117358a4 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BaiduOcrHandler.java @@ -0,0 +1,281 @@ +package cn.iocoder.yudao.module.bs.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baidu.aip.auth.DevAuth; +import com.baidu.aip.util.AipClientConfiguration; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.multipart.MultipartFile; + + +import java.io.File; +import java.net.URLEncoder; +import java.util.Map; + +/** + * @author MrFang + * @date 2023年08月15日 11:36 + */ +@Slf4j +public class BaiduOcrHandler { + + /** + * 身份证正面OCR识别 + * + * @param idCardFrontImage 身份证正面照片(支持:{@linkplain File}及{@linkplain MultipartFile}) + * @return IdCard + */ + /* public static IdCard handleFrontIdCard(Object idCardFrontImage) throws Exception { + String accessToken = getAccessToken(); + if (StringUtils.isEmpty(accessToken)) { + throw new RuntimeException("获取token失败"); + } + String base64ImgParam = getImageBase64Param(idCardFrontImage); + String param = "id_card_side=front&image=" + base64ImgParam; + String jsonStr = HttpUtil.post(BaiduOcrConstant.ID_CARD_FRONT_URL, accessToken, param); + JSONObject jsonObject = JSON.parseObject(jsonStr); + log.info("身份证正面OCR识别结果=>{}", jsonObject); + + // 解析身份证正面数据 + String status = jsonObject.getString("image_status"); + if (!"normal".equals(status)) { + throw new RuntimeException("身份证图片识别失败:"+status ); + } + JSONObject wordsResult = jsonObject.getJSONObject("words_result"); + if (wordsResult.isEmpty()) { + throw new RuntimeException("没有解析到任何数据"); + } + IdCard idCard = new IdCard(); + buildIdCard(idCard, wordsResult); + return idCard; + }*/ + + /** + * 身份证正反面OCR识别 + * + * @param idCardFrontImage 身份证正面照片(支持:{@linkplain File}及{@linkplain MultipartFile}) + * @return IdCard + */ + /* public static IdCard handleMultiIdCard(Object idCardFrontImage) throws Exception { + String accessToken = getAccessToken(); + if (StringUtils.isEmpty(accessToken)) { + throw new RuntimeException("获取token失败"); + } + String base64ImgParam = getImageBase64Param(idCardFrontImage); + String param = "image=" + base64ImgParam; + String jsonStr = HttpUtil.post(BaiduOcrConstant.ID_CARD_MULTI_URL, accessToken, param); + JSONObject jsonObject = JSON.parseObject(jsonStr); + log.info("身份证正反面OCR识别结果=>{}", jsonObject); + + // 解析正反面 + JSONArray wordsResult = jsonObject.getJSONArray("words_result"); + if (wordsResult.isEmpty()) { + throw new RuntimeException("没有解析到任何数据"); + } + IdCard idCard = new IdCard(); + for (Object o : wordsResult) { + JSONObject obj = (JSONObject) o; + JSONObject cardResult = obj.getJSONObject("card_result"); + if (cardResult == null) { + continue; + } + buildIdCard(idCard, cardResult); + } + return idCard; + }*/ + + /** + * 营业执照OCR识别 + * + * @param businessLicenseImage 营业执照照片(支持:{@linkplain File}及{@linkplain MultipartFile}) + * @return IdCard + */ + public static BusinessLicense handleBusinessLicense(Object businessLicenseImage) throws Exception { + String accessToken = getAccessToken(); + if (StringUtils.isEmpty(accessToken)) { + throw new RuntimeException("获取token失败"); + } + String base64ImgParam = getImageBase64Param(businessLicenseImage); + String param = "detect_direction=true&" + "image=" + base64ImgParam; + String jsonStr = HttpUtil.post(BaiduOcrConstant.BUSINESS_LICENSE_URL, accessToken, param); + JSONObject jsonObject = JSON.parseObject(jsonStr); + // log.info("营业执照OCR识别结果=>{}", jsonObject); + if (!jsonObject.containsKey("words_result")) { + throw new RuntimeException("识别营业执照接口返回信息状态失败"); + } + BusinessLicense license = new BusinessLicense(); + JSONObject wordsResult = jsonObject.getJSONObject("words_result"); + buildBusinessLicense(license, wordsResult); + return license; + } + + + + /** + * 构建身份证信息实体对象 + * + * @param idCard 身份证对象 + * @param meta 接口返回身份证元数据 + *//* + private static void buildIdCard(IdCard idCard, JSONObject meta) { + for (Map.Entry entry : meta.entrySet()) { + String key = entry.getKey(); + String resultStr = entry.getValue().toString(); + JSONObject result = JSON.parseObject(resultStr); + String value = result.getString("words"); + switch (key) { + case IDCardKeywords.FRONT_NAME: + idCard.setName(value); + break; + case IDCardKeywords.FRONT_SEX: + idCard.setSex(value); + break; + case IDCardKeywords.FRONT_NATION: + idCard.setNation(value); + break; + case IDCardKeywords.FRONT_BIRTH: + idCard.setBirthDate(value); + break; + case IDCardKeywords.FRONT_ADDRESS: + idCard.setAddress(value); + break; + case IDCardKeywords.FRONT_ID: + idCard.setCardNumber(value); + break; + case IDCardKeywords.BACK_SIGN_ORG: + idCard.setSignOrg(value); + break; + case IDCardKeywords.BACK_SIGN_DATE: + idCard.setSignDate(value); + break; + case IDCardKeywords.BACK_EXPIRE: + idCard.setExpiredDate(value); + break; + default: + } + } + } +*/ + /** + * 构建营业执照信息实体对象 + * + * @param license 营业执照对象 + * @param meta 接口返回营业执照元数据 + */ + private static void buildBusinessLicense(BusinessLicense license, JSONObject meta) { + for (Map.Entry entry : meta.entrySet()) { + String key = entry.getKey(); + String resultStr = entry.getValue().toString(); + JSONObject result = JSON.parseObject(resultStr); + String value = result.getString("words"); + switch (key) { + case LicenseKeywords.UNIT_NAME: + license.setUnitName(value); + break; + case LicenseKeywords.UNIT_TYPE: + license.setUnitType(value); + break; + case LicenseKeywords.LEGAL_PERSON: + license.setLegalPerson(value); + break; + case LicenseKeywords.ADDRESS: + license.setAddress(value); + break; + case LicenseKeywords.CODE: + license.setCode(value); + break; + case LicenseKeywords.ID_NUMBER: + license.setIdNumber(value); + break; + case LicenseKeywords.VALIDITY: + license.setValidity(value); + break; + case LicenseKeywords.REGISTERED_CAPITAL: + license.setRegisteredCapital(value); + break; + case LicenseKeywords.COMPANY_CREATE_DATE: + license.setCompanyCreateDate(value); + break; + case LicenseKeywords.LAYOUT: + license.setLayout(value); + break; + case LicenseKeywords.BUSINESS_SCOPE: + license.setBusinessScope(value); + break; + default: + } + } + } + + /** + * 获取目标文件类型的返回结果 + * + * @param file File或MultipartFile类型 + * @return + * @throws Exception + */ + private static File transferToFile(Object file) throws Exception { + File img; + if (file instanceof File) { + img = (File) file; + } else if (file instanceof MultipartFile) { + img = FileUtils.multipartFileToFile((MultipartFile) file); + } else { + throw new UnsupportedOperationException("仅支持File或MultipartFile类型的参数"); + } + return img; + } + + /** + * 获取接口请求参数的base64编码格式的图片参数 + * + * @param file + * @return + * @throws Exception + */ + private static String getImageBase64Param(Object file) throws Exception { + File img; + if (file instanceof File) { + img = (File) file; + } else if (file instanceof MultipartFile) { + img = FileUtils.multipartFileToFile((MultipartFile) file); + } else { + throw new UnsupportedOperationException("仅支持File或MultipartFile类型的参数"); + } + byte[] bytes = FileUtil.readFileByBytes(img); + String encode = Base64Util.encode(bytes); + return URLEncoder.encode(encode, BaiduOcrConstant.CHARSET); + } + + /** + * 获取百度云API的access_token + * 所需参数:grant_type - 固定值:client_credentials + * client_id - 百度智能云注册的应用程序API Key + * client_secret - 百度智能云注册的应用程序Secret Key + * + * @return access_token + */ + public static String getAccessToken() { + try { + org.json.JSONObject jsonObject = DevAuth.oauth(BaiduOcrConstant.CLIENT_ID, BaiduOcrConstant.CLIENT_SECRET, config()); + return jsonObject.getString("access_token"); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return null; + } + + /** + * 请求额外参数配置 + * + */ + private static AipClientConfiguration config() { + AipClientConfiguration config = new AipClientConfiguration(); + config.setConnectionTimeoutMillis(60000); + config.setSocketTimeoutMillis(60000); + return config; + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/Base64Util.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/Base64Util.java new file mode 100644 index 00000000..f5a99b5c --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/Base64Util.java @@ -0,0 +1,67 @@ +package cn.iocoder.yudao.module.bs.utils; + +/** + * @author MrFang + * @date 2023年08月15日 11:38 + */ +public class Base64Util { + private static final char last2byte = (char) Integer.parseInt("00000011", 2); + private static final char last4byte = (char) Integer.parseInt("00001111", 2); + private static final char last6byte = (char) Integer.parseInt("00111111", 2); + private static final char lead6byte = (char) Integer.parseInt("11111100", 2); + private static final char lead4byte = (char) Integer.parseInt("11110000", 2); + private static final char lead2byte = (char) Integer.parseInt("11000000", 2); + private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + + public Base64Util() { + } + + public static String encode(byte[] from) { + StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3); + int num = 0; + char currentByte = 0; + + int i; + for (i = 0; i < from.length; ++i) { + for (num %= 8; num < 8; num += 6) { + switch (num) { + case 0: + currentByte = (char) (from[i] & lead6byte); + currentByte = (char) (currentByte >>> 2); + case 1: + case 3: + case 5: + default: + break; + case 2: + currentByte = (char) (from[i] & last6byte); + break; + case 4: + currentByte = (char) (from[i] & last4byte); + currentByte = (char) (currentByte << 2); + if (i + 1 < from.length) { + currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6); + } + break; + case 6: + currentByte = (char) (from[i] & last2byte); + currentByte = (char) (currentByte << 4); + if (i + 1 < from.length) { + currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4); + } + } + + to.append(encodeTable[currentByte]); + } + } + + if (to.length() % 4 != 0) { + for (i = 4 - to.length() % 4; i > 0; --i) { + to.append("="); + } + } + + return to.toString(); + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BusinessLicense.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BusinessLicense.java new file mode 100644 index 00000000..2982dcb7 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/BusinessLicense.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.bs.utils; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author MrFang + * @date 2023年08月15日 11:37 + */ +@Data +public class BusinessLicense { + + @Schema(description = "单位名称") + private String unitName; + + @Schema(description = "类型") + private String unitType; + + @Schema(description = "公司法人") + private String legalPerson; + + @Schema(description = "地址") + private String address; + + @Schema(description = "有效期") + private String validity; + + @Schema(description = "证件编号") + private String idNumber; + + @Schema(description = "社会信用代码") + private String code; + + @Schema(description = "注册资本") + private String registeredCapital; + + @Schema(description = "成立日期") + private String companyCreateDate; + + @Schema(description = "组成形式") + private String layout; + + @Schema(description = "经营范围") + private String businessScope; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtil.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtil.java new file mode 100644 index 00000000..558ac277 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtil.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.bs.utils; + +import java.io.*; + +/** + * @author MrFang + * @date 2023年08月15日 11:39 + */ +public class FileUtil { + /** + * 读取文件内容,作为字符串返回 + */ + public static String readFileAsString(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + + if (file.length() > 1024 * 1024 * 1024) { + throw new IOException("File is too large"); + } + + StringBuilder sb = new StringBuilder((int) (file.length())); + // 创建字节输入流 + FileInputStream fis = new FileInputStream(filePath); + // 创建一个长度为10240的Buffer + byte[] bbuf = new byte[10240]; + // 用于保存实际读取的字节数 + int hasRead = 0; + while ((hasRead = fis.read(bbuf)) > 0) { + sb.append(new String(bbuf, 0, hasRead)); + } + fis.close(); + return sb.toString(); + } + + /** + * 根据文件路径读取byte[] 数组 + */ + public static byte[] readFileByBytes(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + return readFileByBytes(file); + } + + /** + * 根据文件读取byte[] 数组 + */ + public static byte[] readFileByBytes(File file) throws IOException { + try (ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length())) { + BufferedInputStream in = null; + in = new BufferedInputStream(new FileInputStream(file)); + short bufSize = 1024; + byte[] buffer = new byte[bufSize]; + int len1; + while (-1 != (len1 = in.read(buffer, 0, bufSize))) { + bos.write(buffer, 0, len1); + } + byte[] var7 = bos.toByteArray(); + return var7; + } + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtils.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtils.java new file mode 100644 index 00000000..fb6532e0 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/FileUtils.java @@ -0,0 +1,127 @@ +package cn.iocoder.yudao.module.bs.utils; + +import org.springframework.core.io.ClassPathResource; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Objects; + +/** + * @author MrFang + * @date 2023年08月15日 11:38 + */ +public class FileUtils { + /** + * 读取classpath下的文件数据 + * + * @param fileClassPath classpath下的文件 + * @return + */ + public static InputStream readFileStreamWithClassPath(String fileClassPath) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileClassPath); + } + + /** + * 读取classpath下的文件数据 + * + * @param fileClassPath classpath下的文件 + * @return + */ + public static File readFileWithClassPath(String fileClassPath) throws IOException { + return new ClassPathResource(fileClassPath).getFile(); + } + + /** + * 读取classpath下的文件数据 + * + * @param absoluteFilePath 文件绝对路径 + * @return + */ + public static InputStream readFile(String absoluteFilePath) throws IOException { + return Files.newInputStream(Paths.get(absoluteFilePath)); + } + + /** + * 复制文件到目标路径 + * + * @param sourceFilePath + * @param targetFilePath + * @throws IOException + */ + public static void copy(String sourceFilePath, String targetFilePath) throws IOException { + Files.copy(Paths.get(sourceFilePath), Paths.get(targetFilePath)); + } + + /** + * MultipartFile转File + *

+ * 选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。 + * + * @param multipartFile + * @return + */ + public static File transferToFile(MultipartFile multipartFile) { + File file = null; + try { + String originalFilename = multipartFile.getOriginalFilename(); + String[] filename = originalFilename.split("\\."); + file = File.createTempFile(filename[0], filename[1]); + multipartFile.transferTo(file); + file.deleteOnExit(); + } catch (IOException e) { + e.printStackTrace(); + } + return file; + } + + /** + * MultipartFile 转 File + * + * @param file + * @throws Exception + */ + public static File multipartFileToFile(MultipartFile file) throws Exception { + File toFile = null; + InputStream ins; + ins = file.getInputStream(); + toFile = new File(Objects.requireNonNull(file.getOriginalFilename())); + inputStreamToFile(ins, toFile); + ins.close(); + return toFile; + } + + /** + * 获取流文件 + * @param ins + * @param file + */ + private static void inputStreamToFile(InputStream ins, File file) { + try { + OutputStream os = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 删除本地临时文件 + * @param file + */ + public static boolean deleteTempFile(File file) { + if (file != null) { + File del = new File(file.toURI()); + return del.delete(); + } + return false; + } + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/HttpUtil.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/HttpUtil.java new file mode 100644 index 00000000..70f9f1e3 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/HttpUtil.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.module.bs.utils; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import java.util.Map; + +/** + * @author MrFang + * @date 2023年08月15日 11:39 + */ +public class HttpUtil { + public static String post(String requestUrl, String accessToken, String params) + throws Exception { + String contentType = "application/x-www-form-urlencoded"; + return HttpUtil.post(requestUrl, accessToken, contentType, params); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params) + throws Exception { + String encoding = "UTF-8"; + if (requestUrl.contains("nlp")) { + encoding = "GBK"; + } + return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) + throws Exception { + String url = requestUrl + "?access_token=" + accessToken; + return HttpUtil.postGeneralUrl(url, contentType, params, encoding); + } + + public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) + throws Exception { + URL url = new URL(generalUrl); + // 打开和URL之间的连接 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + // 设置通用的请求属性 + connection.setRequestProperty("Content-Type", contentType); + connection.setRequestProperty("Connection", "Keep-Alive"); + connection.setUseCaches(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // 得到请求的输出流对象 + DataOutputStream out = new DataOutputStream(connection.getOutputStream()); + out.write(params.getBytes(encoding)); + out.flush(); + out.close(); + + // 建立实际的连接 + connection.connect(); + // 获取所有响应头字段 + Map> headers = connection.getHeaderFields(); + // 遍历所有的响应头字段 + for (String key : headers.keySet()) { + System.err.println(key + "--->" + headers.get(key)); + } + // 定义 BufferedReader输入流来读取URL的响应 + BufferedReader in = null; + in = new BufferedReader( + new InputStreamReader(connection.getInputStream(), encoding)); + String result = ""; + String getLine; + while ((getLine = in.readLine()) != null) { + result += getLine; + } + in.close(); + System.err.println("result:" + result); + return result; + } +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/IdCard.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/IdCard.java new file mode 100644 index 00000000..6abaad97 --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/IdCard.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.bs.utils; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author MrFang + * @date 2023年08月15日 11:37 + */ + +@Data +public class IdCard { + + @Schema(description = "姓名") + private String name; + + @Schema(description = "性别") + private String sex; + + @Schema(description = "民族") + private String nation; + + @Schema(description = "出生日期") + private String birthDate; + + @Schema(description = "住址") + private String address; + + @Schema(description = "公民身份号码") + private String cardNumber; + + @Schema(description = "签发机关") + private String signOrg; + + @Schema(description = "签发日期") + private String signDate; + + @Schema(description = "失效日期") + private String expiredDate; + +} diff --git a/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/LicenseKeywords.java b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/LicenseKeywords.java new file mode 100644 index 00000000..52ef42af --- /dev/null +++ b/yudao-module-bs/yudao-module-bs-biz/src/main/java/cn/iocoder/yudao/module/bs/utils/LicenseKeywords.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.bs.utils; + +/** + * @author MrFang + * @date 2023年08月15日 14:08 + */ +public class LicenseKeywords { + public static final String UNIT_NAME = "单位名称"; + public static final String BUSINESS_SCOPE = "经营范围"; + public static final String LAYOUT = "组成形式"; + public static final String UNIT_TYPE = "类型"; + public static final String LEGAL_PERSON = "法定代表人"; + public static final String ADDRESS = "地址"; + public static final String CODE = "社会信用代码"; + public static final String ID_NUMBER = "证件编号"; + public static final String VALIDITY = "有效期"; + public static final String REGISTERED_CAPITAL = "注册资本"; + public static final String COMPANY_CREATE_DATE = "成立日期"; +}