feat: 报销模块相关功能调整

new
chenqp 1 year ago
parent 7ade59e05e
commit f156183ad4

@ -12,8 +12,6 @@ import cn.iocoder.yudao.module.bpm.service.expenseclaimtrip.ExpenseClaimTripServ
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.*; import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.*;
import cn.iocoder.yudao.module.bs.convert.expenseclaim.ExpenseClaimConvert; import cn.iocoder.yudao.module.bs.convert.expenseclaim.ExpenseClaimConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapply.ExpenseApplyDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseapplytrip.ExpenseApplyTripDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO; import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimdetail.ExpenseClaimDetailDO; import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimdetail.ExpenseClaimDetailDO;
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimtrip.ExpenseClaimTripDO; import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaimtrip.ExpenseClaimTripDO;
@ -152,5 +150,4 @@ public class ExpenseClaimController {
List<ExpenseClaimExcelVO> datas = ExpenseClaimConvert.INSTANCE.convertList02(list); List<ExpenseClaimExcelVO> datas = ExpenseClaimConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "报销单.xls", "数据", ExpenseClaimExcelVO.class, datas); ExcelUtils.write(response, "报销单.xls", "数据", ExpenseClaimExcelVO.class, datas);
} }
} }

@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.bs.enums.BillTypeEnum;
import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum; import cn.iocoder.yudao.module.bs.enums.ExpenseApplyStatusEnum;
import cn.iocoder.yudao.module.bs.enums.ExpenseClaimSettleStatusEnum; import cn.iocoder.yudao.module.bs.enums.ExpenseClaimSettleStatusEnum;
import cn.iocoder.yudao.module.bs.service.budget.BudgetService; import cn.iocoder.yudao.module.bs.service.budget.BudgetService;
import cn.iocoder.yudao.module.bs.service.feemanage.FeeManageService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@ -67,6 +68,9 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
@Resource @Resource
@Lazy @Lazy
private BudgetService budgetService; private BudgetService budgetService;
@Resource
@Lazy
private FeeManageService feeManageService;
@Override @Override
public CommonResult createExpenseClaim(ExpenseClaimCreateReqVO createReqVO) { public CommonResult createExpenseClaim(ExpenseClaimCreateReqVO createReqVO) {
// 插入 // 插入
@ -129,7 +133,10 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
*/ */
private CommonResult<Object> dataValidAndSetFileName(ExpenseClaimCreateReqVO createReqVO, ExpenseClaimDO expenseClaim) { private CommonResult<Object> dataValidAndSetFileName(ExpenseClaimCreateReqVO createReqVO, ExpenseClaimDO expenseClaim) {
boolean isAdd = createReqVO.getId() == null; boolean isAdd = createReqVO.getId() == null;
LoginUser loginUser = getLoginUser();
expenseClaim.setUserId(loginUser.getId());
AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
expenseClaim.setDeptId(user.getDeptId());
if (expenseClaim.getBillType().equals(BillTypeEnum.CLBX.getValue())) { if (expenseClaim.getBillType().equals(BillTypeEnum.CLBX.getValue())) {
List<ExpenseClaimTripCreateReqVO> expenseApplyTrips = createReqVO.getExpenseClaimTrips(); List<ExpenseClaimTripCreateReqVO> expenseApplyTrips = createReqVO.getExpenseClaimTrips();
// if (CollUtil.isEmpty(expenseApplyTrips)) { // if (CollUtil.isEmpty(expenseApplyTrips)) {
@ -138,16 +145,25 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
// // 参数校验 // // 参数校验
// ValidationUtils.validate(validator, expenseApplyTrips); // ValidationUtils.validate(validator, expenseApplyTrips);
BigDecimal amount = BigDecimal.ZERO; BigDecimal amount = BigDecimal.ZERO;
int aa = 1;
for (ExpenseClaimTripCreateReqVO trip : expenseApplyTrips) { for (ExpenseClaimTripCreateReqVO trip : expenseApplyTrips) {
BigDecimal tripAmount = BigDecimal.ZERO; BigDecimal tripAmount = BigDecimal.ZERO;
List<ExpenseClaimDetailCreateReqVO> details = trip.getExpenseClaimDetails(); List<ExpenseClaimDetailCreateReqVO> details = trip.getExpenseClaimDetails();
if (CollUtil.isNotEmpty(details)) { if (CollUtil.isNotEmpty(details)) {
int bb = 1;
for (ExpenseClaimDetailCreateReqVO detail : details) { for (ExpenseClaimDetailCreateReqVO detail : details) {
//校验是否超出费控设置
BigDecimal setAmount = feeManageService.findByClaim(detail.getFeeType(),loginUser.getId(),expenseClaim.getCostDeptId(),trip.getDestinationLocation());
if (setAmount != null && detail.getAmount().compareTo(setAmount) >0) {
return CommonResult.error("第" + aa + "条行程" + ",第" + bb + "条费用明细超出费控设置金额,费控设置金额为:" + setAmount.stripTrailingZeros().toPlainString());
}
tripAmount = tripAmount.add(detail.getAmount()); tripAmount = tripAmount.add(detail.getAmount());
bb = bb + 1;
} }
} }
trip.setAmount(tripAmount); trip.setAmount(tripAmount);
amount = amount.add(tripAmount); amount = amount.add(tripAmount);
aa = aa +1;
} }
expenseClaim.setAmount(amount); expenseClaim.setAmount(amount);
} else { } else {
@ -169,10 +185,6 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
return CommonResult.error("只有未提交单据才能更新"); return CommonResult.error("只有未提交单据才能更新");
} }
} }
LoginUser loginUser = getLoginUser();
expenseClaim.setUserId(loginUser.getId());
AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
expenseClaim.setDeptId(user.getDeptId());
return CommonResult.success(); return CommonResult.success();
} }

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 单据ID Request VO")
@Data
@ToString(callSuper = true)
public class IdentifyReqVO {
@NotBlank(message = "url不能为空")
private String url;
}

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 单据ID Request VO")
@Data
@ToString(callSuper = true)
public class IdentifyResqVO {
/**
*
*/
private String type;
/**
*
*/
private String invoiceType;
/**
*
*/
private String invoiceCode;
/**
*
*/
private String invoiceNum;
/**
*
*/
private LocalDateTime invoiceDate;
/**
*
*/
private String seller;
/**
*
*/
private BigDecimal taxAmount =BigDecimal.ZERO;
/**
*
*/
private BigDecimal excludingTaxAmount=BigDecimal.ZERO;
/**
*
*/
private BigDecimal totalAmount=BigDecimal.ZERO;
}

@ -20,7 +20,7 @@ import java.util.Set;
public class FeeManageBaseVO { public class FeeManageBaseVO {
@Schema(description = "部门ID", example = "29962") @Schema(description = "部门ID", example = "29962")
@NotBlank(message = "部门不能为空") @NotNull(message = "部门不能为空")
private Long deptId; private Long deptId;
@Schema(description = "角色", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "角色", requiredMode = Schema.RequiredMode.REQUIRED)

@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.IdentifyReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.*; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.*;
import cn.iocoder.yudao.module.bs.convert.invoice.InvoiceConvert; import cn.iocoder.yudao.module.bs.convert.invoice.InvoiceConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO; import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO;
@ -19,6 +20,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -95,5 +97,10 @@ public class InvoiceController {
List<InvoiceExcelVO> datas = InvoiceConvert.INSTANCE.convertList02(list); List<InvoiceExcelVO> datas = InvoiceConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "我的发票.xls", "数据", InvoiceExcelVO.class, datas); ExcelUtils.write(response, "我的发票.xls", "数据", InvoiceExcelVO.class, datas);
} }
@PostMapping("/identify")
@Operation(summary = "发票识别")
@PreAuthorize("@ss.hasPermission('bs:expense-claim:query')")
public CommonResult identify(@Valid @RequestBody IdentifyReqVO billIdReqVO) throws Exception {
return invoiceService.identify(billIdReqVO);
}
} }

@ -31,6 +31,10 @@ public class InvoiceDO extends TenantBaseDO {
*/ */
@TableId @TableId
private Long id; private Long id;
/**
*
*/
private String type;
/** /**
* *
*/ */

@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import com.github.yulichang.base.MPJBaseService; import com.github.yulichang.base.MPJBaseService;
import javax.validation.Valid; import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -73,4 +74,5 @@ public interface FeeManageService extends MPJBaseService<FeeManageDO> {
*/ */
List<FeeManageDO> getFeeManageList(FeeManageExportReqVO exportReqVO); List<FeeManageDO> getFeeManageList(FeeManageExportReqVO exportReqVO);
BigDecimal findByClaim(String feeType, Long id, Long costDeptId, String destinationLocation);
} }

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.bs.service.feemanage; package cn.iocoder.yudao.module.bs.service.feemanage;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO; import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageCreateReqVO;
@ -9,13 +11,17 @@ import cn.iocoder.yudao.module.bs.controller.admin.feemanage.vo.FeeManageUpdateR
import cn.iocoder.yudao.module.bs.convert.feemanage.FeeManageConvert; import cn.iocoder.yudao.module.bs.convert.feemanage.FeeManageConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO; import cn.iocoder.yudao.module.bs.dal.dataobject.feemanage.FeeManageDO;
import cn.iocoder.yudao.module.bs.dal.mysql.feemanage.FeeManageMapper; import cn.iocoder.yudao.module.bs.dal.mysql.feemanage.FeeManageMapper;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import com.github.yulichang.base.MPJBaseServiceImpl; import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.FEE_MANAGE_NOT_EXISTS; import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.FEE_MANAGE_NOT_EXISTS;
@ -31,7 +37,9 @@ public class FeeManageServiceImpl extends MPJBaseServiceImpl<FeeManageMapper, Fe
@Resource @Resource
private FeeManageMapper feeManageMapper; private FeeManageMapper feeManageMapper;
@Resource
@Lazy
private PermissionApi permissionApi;
@Override @Override
public Long createFeeManage(FeeManageCreateReqVO createReqVO) { public Long createFeeManage(FeeManageCreateReqVO createReqVO) {
// 插入 // 插入
@ -45,11 +53,7 @@ public class FeeManageServiceImpl extends MPJBaseServiceImpl<FeeManageMapper, Fe
private void checkExisit(FeeManageDO feeManage) { private void checkExisit(FeeManageDO feeManage) {
for (Long roleId : feeManage.getRoleIds()) { for (Long roleId : feeManage.getRoleIds()) {
for (String area : feeManage.getArea()) { for (String area : feeManage.getArea()) {
LambdaQueryWrapperX<FeeManageDO> query = new LambdaQueryWrapperX<>(); LambdaQueryWrapperX<FeeManageDO> query = getFeeManageByUniq(roleId, area, feeManage.getDeptId(), feeManage.getFeeType());
query.eq(FeeManageDO::getDeptId, feeManage.getDeptId());
query.eq(FeeManageDO::getFeeType, feeManage.getFeeType());
query.apply("FIND_IN_SET({0}, role_ids) > 0",roleId);
query.apply("FIND_IN_SET({0}, area) > 0",area);
if (feeManage.getId() != null) { if (feeManage.getId() != null) {
query.ne(FeeManageDO::getId, feeManage.getId()); query.ne(FeeManageDO::getId, feeManage.getId());
} }
@ -61,6 +65,15 @@ public class FeeManageServiceImpl extends MPJBaseServiceImpl<FeeManageMapper, Fe
} }
} }
private LambdaQueryWrapperX<FeeManageDO> getFeeManageByUniq(Long roleId, String area, Long deptId, String feeType) {
LambdaQueryWrapperX<FeeManageDO> query = new LambdaQueryWrapperX<>();
query.eq(FeeManageDO::getDeptId, deptId);
query.eq(FeeManageDO::getFeeType, feeType);
query.apply("JSON_CONTAINS(role_ids, JSON_ARRAY({0}))", roleId);
query.apply("JSON_CONTAINS(area, JSON_ARRAY({0}))", area);
return query;
}
@Override @Override
public void updateFeeManage(FeeManageUpdateReqVO updateReqVO) { public void updateFeeManage(FeeManageUpdateReqVO updateReqVO) {
// 校验存在 // 校验存在
@ -105,4 +118,21 @@ public class FeeManageServiceImpl extends MPJBaseServiceImpl<FeeManageMapper, Fe
return feeManageMapper.selectList(exportReqVO); return feeManageMapper.selectList(exportReqVO);
} }
@Override
public BigDecimal findByClaim(String feeType, Long userId, Long costDeptId, String destinationLocation) {
Set<Long> roleIds = permissionApi.getUserRoleIdListByUserId(userId);
BigDecimal amount = null;
for (Long roleId : roleIds) {
LambdaQueryWrapperX<FeeManageDO> queryWrapperX = getFeeManageByUniq(roleId, destinationLocation, costDeptId, feeType);
FeeManageDO feeManageDO = getOne(queryWrapperX);
if (feeManageDO !=null) {
if (amount == null) {
amount = BigDecimal.ZERO;
}
//如果用户多角色且正好配置了的话取更大的配置
amount = NumberUtil.max(feeManageDO.getAmount(), amount);
}
}
return amount;
}
} }

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.bs.service.invoice; package cn.iocoder.yudao.module.bs.service.invoice;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.IdentifyReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceCreateReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceExportReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoicePageReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoicePageReqVO;
@ -8,6 +10,7 @@ import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceUpdateReqVO
import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO; import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.UnsupportedEncodingException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -72,4 +75,5 @@ public interface InvoiceService {
*/ */
List<InvoiceDO> getInvoiceList(InvoiceExportReqVO exportReqVO); List<InvoiceDO> getInvoiceList(InvoiceExportReqVO exportReqVO);
CommonResult identify(IdentifyReqVO billIdReqVO) throws Exception;
} }

@ -1,6 +1,11 @@
package cn.iocoder.yudao.module.bs.service.invoice; package cn.iocoder.yudao.module.bs.service.invoice;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.IdentifyReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceCreateReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceCreateReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceExportReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceExportReqVO;
import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoicePageReqVO; import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoicePageReqVO;
@ -8,12 +13,17 @@ import cn.iocoder.yudao.module.bs.controller.admin.invoice.vo.InvoiceUpdateReqVO
import cn.iocoder.yudao.module.bs.convert.invoice.InvoiceConvert; import cn.iocoder.yudao.module.bs.convert.invoice.InvoiceConvert;
import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO; import cn.iocoder.yudao.module.bs.dal.dataobject.invoice.InvoiceDO;
import cn.iocoder.yudao.module.bs.dal.mysql.invoice.InvoiceMapper; import cn.iocoder.yudao.module.bs.dal.mysql.invoice.InvoiceMapper;
import cn.iocoder.yudao.module.bs.utils.BaiduOcrConstant;
import cn.iocoder.yudao.module.bs.utils.BaiduOcrHandler;
import cn.iocoder.yudao.module.bs.utils.Base64Util;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.INVOICE_NOT_EXISTS; import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.INVOICE_NOT_EXISTS;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -81,4 +91,15 @@ public class InvoiceServiceImpl implements InvoiceService {
return invoiceMapper.selectList(exportReqVO); return invoiceMapper.selectList(exportReqVO);
} }
@Override
public CommonResult identify(IdentifyReqVO identifyReqVO) throws Exception {
String url = identifyReqVO.getUrl();
HttpRequest get = HttpUtil.createGet(url);
// String base64 = byteArrayToBase64(get.execute().bodyBytes());
String encode = Base64Util.encode(get.execute().bodyBytes());
encode= URLEncoder.encode(encode, BaiduOcrConstant.CHARSET);
boolean isPdf = StrUtil.endWith(url, ".pdf");
BaiduOcrHandler.invoice(encode,isPdf);
return CommonResult.success();
}
} }

@ -14,13 +14,13 @@ public interface BaiduOcrConstant {
* *
* API Key * API Key
*/ */
String CLIENT_ID = "YLQSdO65OZjARM8A8ZN62O11"; String CLIENT_ID = "Aqp2823OP5H5lS7O94UvqXFb";
/** /**
* *
* Secret Key * Secret Key
*/ */
String CLIENT_SECRET = "4fU8odNqBDqNk5W3BS0PDrdk20TGV9sO"; String CLIENT_SECRET = "qN9e4sSVCAcEWdwH3mUV8GMcWg3ujIvr";
/** /**
* OCR * OCR
@ -41,5 +41,8 @@ public interface BaiduOcrConstant {
* OCR accessToken * OCR accessToken
*/ */
String ACCESS_TOKEN_URL = "https://aip.baidubce.com/oauth/2.0/token"; String ACCESS_TOKEN_URL = "https://aip.baidubce.com/oauth/2.0/token";
/**
*
*/
String INVOICEURL = "https://aip.baidubce.com/rest/2.0/ocr/v1/multiple_invoice";
} }

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.bs.utils; package cn.iocoder.yudao.module.bs.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.bs.controller.admin.expenseclaim.vo.IdentifyResqVO;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baidu.aip.auth.DevAuth; import com.baidu.aip.auth.DevAuth;
import com.baidu.aip.util.AipClientConfiguration; import com.baidu.aip.util.AipClientConfiguration;
@ -15,7 +17,6 @@ import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.SUPPLIER_COMPANY_NOT_EXISTS;
import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.SUPPLIER_COMPANY_NOT_EXISTS_Ai; import static cn.iocoder.yudao.module.bs.enums.ErrorCodeConstants.SUPPLIER_COMPANY_NOT_EXISTS_Ai;
/** /**
@ -287,4 +288,49 @@ public class BaiduOcrHandler {
return config; return config;
} }
public static IdentifyResqVO invoice(String baseStr, boolean isPdf) throws Exception {
String accessToken = getAccessToken();
if (StringUtils.isEmpty(accessToken)) {
throw new RuntimeException("获取token失败");
}
String image = "image";
if (isPdf) {
image = "pdf_file";
}
String param = "verify_parameter=false&" + image + "=" +baseStr;
String jsonStr = HttpUtil.post(BaiduOcrConstant.INVOICEURL, accessToken, param);
JSONObject jsonObject = JSON.parseObject(jsonStr);
// log.info("营业执照OCR识别结果=>{}", jsonObject);
if (!jsonObject.containsKey("words_result")) {
log.error(baseStr+",发票识别失败"+jsonObject.toString());
throw exception("发票识别失败");
}
// JSONObject wordsResult = jsonObject.getJSONObject("words_result");
// JSONObject result = wordsResult.getJSONObject("result");
// IdentifyResqVO identifyResqVO = new IdentifyResqVO();
// identifyResqVO.setType(wordsResult.getString("type"));
// if (CollUtil.isNotEmpty(result.getJSONArray("invoice_type"))) {
// identifyResqVO.setInvoiceType(result.getJSONArray("invoice_type").getJSONObject(0).getString("word"));
// }
// if (CollUtil.isNotEmpty(result.getJSONArray("invoice_code"))) {
// identifyResqVO.setInvoiceCode(result.getJSONArray("invoice_code").getJSONObject(0).getString("word"));
// }
// if (CollUtil.isNotEmpty(result.getJSONArray("invoice_num"))) {
// identifyResqVO.setInvoiceNum(result.getJSONArray("invoice_num").getJSONObject(0).getString("word"));
// }
// String invoiceDateStr = result.getJSONArray("invoice_date").getJSONObject(0).getString("word");
// identifyResqVO.setInvoiceDate(DateUtil.parse(invoiceDateStr).toLocalDateTime());
//// identifyResqVO.setSeller();
// if (CollUtil.isNotEmpty(result.getJSONArray("total_tax"))) {
// identifyResqVO.setTaxAmount(result.getJSONArray("total_tax").getJSONObject(0).getBigDecimal("word"));
// }
// identifyResqVO.setTotalAmount(result.getJSONArray("total_amount").getJSONObject(0).getBigDecimal("word"));
//// identifyResqVO.setExcludingTaxAmount();
System.out.println(jsonObject.toString());
return null;
}
} }

@ -45,5 +45,5 @@ public interface PermissionApi {
* @return * @return
*/ */
DeptDataPermissionRespDTO getDeptDataPermission(Long userId); DeptDataPermissionRespDTO getDeptDataPermission(Long userId);
public Set<Long> getUserRoleIdListByUserId(Long userId);
} }

@ -39,4 +39,8 @@ public class PermissionApiImpl implements PermissionApi {
return permissionService.getDeptDataPermission(userId); return permissionService.getDeptDataPermission(userId);
} }
@Override
public Set<Long> getUserRoleIdListByUserId(Long userId) {
return permissionService.getUserRoleIdListByUserId(userId);
}
} }

Loading…
Cancel
Save