Browse Source

2023年12月5日17:57:06

纪新园 2 years ago
parent
commit
b5da6cf7b0

+ 10 - 0
blade-service-api/blade-los-api/src/main/java/org/springblade/los/finance/invoices/entity/FinInvoices.java

@@ -503,5 +503,15 @@ public class FinInvoices implements Serializable {
 	@ApiModelProperty(value = "发表类型")
 	private String type;
 
+	//跳转对应页面的路由
+	@TableField(exist = false)
+	private String url;
+	//页面枚举
+	@TableField(exist = false)
+	private String pageStatus;
+	//页面名字
+	@TableField(exist = false)
+	private String pageLabel;
+
 
 }

+ 2 - 0
blade-service/blade-los/src/main/java/org/springblade/los/check/controller/AuditProecessController.java

@@ -228,6 +228,8 @@ public class AuditProecessController extends BladeController {
 			auditProecessService.losBillsCheck(auditProecess);
 		}else if ("HYCK-FFSQ".equals(proecess.getCheckType())) {
 			auditProecessService.losStlBillsCheck(auditProecess);
+		}else if ("HYCK-FPSQ".equals(proecess.getCheckType())) {
+			auditProecessService.losFinInvoicesCheck(auditProecess);
 		}
 		return R.data(auditProecess);
 	}

+ 2 - 0
blade-service/blade-los/src/main/java/org/springblade/los/check/service/IAuditProecessService.java

@@ -58,4 +58,6 @@ public interface IAuditProecessService extends IService<LosAuditProecess> {
 	 * @param auditProecess
 	 */
 	void losStlBillsCheck(LosAuditProecess auditProecess);
+
+	void losFinInvoicesCheck(LosAuditProecess auditProecess);
 }

+ 200 - 0
blade-service/blade-los/src/main/java/org/springblade/los/check/service/impl/AuditProecessServiceImpl.java

@@ -39,6 +39,8 @@ import org.springblade.los.check.mapper.AuditPathsActsMapper;
 import org.springblade.los.check.mapper.AuditProecessMapper;
 import org.springblade.los.check.service.IAuditProecessService;
 import org.springblade.los.check.vo.LosAuditProecessVO;
+import org.springblade.los.finance.invoices.entity.FinInvoices;
+import org.springblade.los.finance.invoices.mapper.FinInvoicesMapper;
 import org.springblade.los.finance.stl.entity.FinStlBills;
 import org.springblade.los.finance.stl.mapper.FinStlBillsMapper;
 import org.springframework.stereotype.Service;
@@ -69,6 +71,8 @@ public class AuditProecessServiceImpl extends ServiceImpl<AuditProecessMapper, L
 
 	private final FinStlBillsMapper finStlBillsMapper;
 
+	private final FinInvoicesMapper finInvoicesMapper;
+
 	private final IBCorpsService bCorpsService;
 
 
@@ -611,6 +615,202 @@ public class AuditProecessServiceImpl extends ServiceImpl<AuditProecessMapper, L
 	}
 
 	@Override
+	public void losFinInvoicesCheck(LosAuditProecess auditProecess) {
+		//查看最新操作记录,防止重复提交
+		LosAuditProecess proecessTemp = baseMapper.selectById(auditProecess.getId());
+		if (proecessTemp == null) {
+			throw new SecurityException("未查到此审批记录,禁止操作");
+		}
+		if ("A".equals(proecessTemp.getAuditStatus()) || "B".equals(proecessTemp.getAuditStatus())) {
+			throw new SecurityException("当前记录已经完成审批,禁止重复操作");
+		}
+
+		if (auditProecess.getAuditStatus() == null || !"S".equals(auditProecess.getAuditStatus())) {
+			throw new SecurityException("审批状态非待审,禁止操作");
+		}
+		//信息
+		Message sendMessage = new Message();
+		sendMessage.setParameter(String.valueOf(auditProecess.getBillId()));
+		sendMessage.setUserName(AuthUtil.getUserName());
+		sendMessage.setUserId(AuthUtil.getUserId());
+		sendMessage.setToUserId(auditProecess.getSendUserId());
+		sendMessage.setToUserName(auditProecess.getSendName());
+		sendMessage.setMessageType(1);
+		sendMessage.setTenantId(AuthUtil.getTenantId());
+		sendMessage.setCreateUser(AuthUtil.getUserId());
+		sendMessage.setCreateTime(new Date());
+		sendMessage.setUrl(auditProecess.getUrl());
+		sendMessage.setPageLabel(auditProecess.getPageLabel());
+		sendMessage.setPageStatus(auditProecess.getPageStatus());
+
+		//用户操作 1.通过  2.驳回
+		Integer operate = auditProecess.getOperate();
+		//查看当前审批是否为最后一级
+		String iffinalItem = auditProecess.getIffinalItem();
+		//审批人
+		auditProecess.setAuditUserId(String.valueOf(AuthUtil.getUserId()));
+		//审批时间
+		auditProecess.setAuditOpTime(new Date());
+
+		FinInvoices bills = finInvoicesMapper.selectById(proecessTemp.getBillId());
+
+		//不是最后一级
+		if ("F".equals(iffinalItem)) {
+
+			//通过
+			if (operate == 1) {
+				//如果是第一级, 则修改状态为审批中
+				if (auditProecess.getLevelId() == 1) {
+					FinInvoices detail = finInvoicesMapper.selectById(auditProecess.getSrcBillId());
+					if (detail == null) {
+						throw new SecurityException("审批通过失败");
+					}
+					detail.setStatus(2);
+					int count = finInvoicesMapper.updateById(detail);
+					if (count == 0) {
+						throw new SecurityException("审批开始修改审核状态失败");
+					}
+				}
+
+				auditProecess.setAuditStatus("A");
+				//查询下一级,开启待审
+				LambdaQueryWrapper<LosAuditProecess> auditProecessLambdaQueryWrapper = new LambdaQueryWrapper<>();
+				auditProecessLambdaQueryWrapper
+					.eq(LosAuditProecess::getBatchNo, auditProecess.getBatchNo())
+					.eq(LosAuditProecess::getSrcBillId, auditProecess.getSrcBillId())
+					.eq(LosAuditProecess::getIsDelete, 0)
+					.eq(LosAuditProecess::getActId, auditProecess.getActId())
+					.eq(LosAuditProecess::getBillId, auditProecess.getBillId())
+					.eq(LosAuditProecess::getBillNo, auditProecess.getBillNo())
+					.eq(LosAuditProecess::getTenantId, AuthUtil.getTenantId())
+					.eq(LosAuditProecess::getLevelId, auditProecess.getLevelId() + 1);
+				Integer count = baseMapper.selectCount(auditProecessLambdaQueryWrapper);
+				if (count != null && count > 1) {
+					throw new SecurityException("审核失败,获取下一级信息失败");
+				}
+				LosAuditProecess proecess = baseMapper.selectOne(auditProecessLambdaQueryWrapper);
+				if (proecess == null) {
+					throw new SecurityException("审批通过=>获取下一级信息失败");
+				}
+				proecess.setAuditStatus("S");
+				baseMapper.updateById(proecess);
+
+				SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
+
+				//获得订单创建日期
+				String billsDate = null;
+				if (proecessTemp.getBillId() != null) {
+					if (bills != null) {
+						billsDate = simpleDateFormat.format(bills.getCreateTime());
+					}
+				}
+
+				Message message = new Message();
+				message.setUserName(AuthUtil.getUserName());
+				message.setUserId(AuthUtil.getUserId());
+				message.setParameter(String.valueOf(auditProecess.getBillId()));
+				message.setMessageType(1);
+				message.setTenantId(AuthUtil.getTenantId());
+				if ("海运出口审核".equals(auditProecess.getProcessType())) {
+					message.setMessageBody("您有新的海运出口审核,业务单号:" + "" + proecessTemp.getBillNo() + ","
+						+ "单据日期:" + billsDate + ",请审核。"
+						+ "提交人:" + proecessTemp.getSendName() + "  " + "提交时间" + simpleDateFormat.format(proecessTemp.getSendTime())
+					);
+					message.setUrl("/iosBasicData/SeafreightExportF/bills/index");
+				}else if ("付费申请".equals(auditProecess.getProcessType())){
+					message.setMessageBody("您有新的付费申请,申请单号:" + "" + proecessTemp.getBillNo() + ","
+						+ "单据日期:" + billsDate + ",请审核。"
+						+ "提交人:" + proecessTemp.getSendName() + "  " + "提交时间" + simpleDateFormat.format(proecessTemp.getSendTime())
+					);
+					message.setUrl("/iosBasicData/PaymentApplication/index");
+				}else if ("发票申请".equals(auditProecess.getProcessType())){
+					message.setMessageBody("您有新的发票申请,申请单号:" + "" + proecessTemp.getBillNo() + ","
+						+ "单据日期:" + billsDate + ",请审核。"
+						+ "提交人:" + proecessTemp.getSendName() + "  " + "提交时间" + simpleDateFormat.format(proecessTemp.getSendTime())
+					);
+					message.setUrl("/iosBasicData/fininvoicesApplyfor/index");
+				}
+
+				message.setCreateUser(AuthUtil.getUserId());
+				message.setCreateTime(new Date());
+
+				// 消息批量通知下一级
+				sendMsgToGroup(message, proecess.getAuditUserId());
+			}
+			//不通过
+			else if (operate == 2) {
+				auditProecess.setAuditStatus("B");
+				FinInvoices detail = finInvoicesMapper.selectById(auditProecess.getSrcBillId());
+				if (detail == null) {
+					throw new SecurityException("审批通过失败");
+				}
+				detail.setStatus(4);
+				int count = finInvoicesMapper.updateById(detail);
+				if (count == 0) {
+					throw new SecurityException("修改订单数据失败");
+				}
+
+				sendMessage.setMessageBody("您的审核未通过" + ",业务单号:" + proecessTemp.getBillNo() + ",驳回原因:" + auditProecess.getAuditMsg());
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+
+		}
+		//是最后一级
+		else if ("T".equals(iffinalItem)) {
+			//通过
+			if (operate == 1) {
+				auditProecess.setAuditStatus("A");
+				FinInvoices detail = finInvoicesMapper.selectById(auditProecess.getSrcBillId());
+				if (bills == null) {
+					throw new SecurityException("审批通过失败");
+				}
+				detail.setStatus(3);
+				int count = finInvoicesMapper.updateById(detail);
+				if (count == 0) {
+					throw new SecurityException("修改订单数据失败");
+				}
+
+				sendMessage.setMessageBody("您的审核已通过" + ",业务单号:" + proecessTemp.getBillNo() + ",请继续操作");
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+			//不通过
+			else if (operate == 2) {
+				//todo 调用feign取消
+				auditProecess.setAuditStatus("B");
+				FinInvoices detail = finInvoicesMapper.selectById(auditProecess.getSrcBillId());
+				if (detail == null) {
+					throw new SecurityException("审批通过失败");
+				}
+				detail.setStatus(4);
+				int count = finInvoicesMapper.updateById(detail);
+				if (count == 0) {
+					throw new SecurityException("修改订单数据失败");
+				}
+				sendMessage.setMessageBody("您的审核未通过" + ",业务单号:" + proecessTemp.getBillNo() + ",驳回原因:" + auditProecess.getAuditMsg());
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+		} else {
+			throw new SecurityException("审批异常,请联系管理员");
+		}
+
+		cleanMsg(proecessTemp.getAuditUserId(), AuthUtil.getUserId(), proecessTemp.getSrcBillId());
+
+		//保存操作记录
+		auditProecess.setAuditMsg(auditProecess.getAuditMsg());
+		auditProecess.setAuditItem(new Date());
+		baseMapper.updateById(auditProecess);
+	}
+
+	@Override
 	public R deteleByBillId(Long billId) {
 		baseMapper.deteleByBillId(billId);
 		return R.data("操作成功");

+ 66 - 2
blade-service/blade-los/src/main/java/org/springblade/los/finance/invoices/controller/FinInvoicesController.java

@@ -23,6 +23,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
 import javax.validation.Valid;
 
+import org.springblade.common.annotation.RepeatSubmit;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
@@ -124,13 +125,44 @@ public class FinInvoicesController extends BladeController {
 	}
 
 	/**
+	 * 发票 申请
+	 */
+	@PostMapping("/finInvoicesApprove")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "确认", notes = "传入finStlBills")
+	public R settlementApprove(@Valid @RequestBody FinInvoices finInvoices) {
+		return finInvoicesService.finInvoicesApprove(finInvoices);
+	}
+
+	/**
+	 * 发票 申请 撤销
+	 */
+	@PostMapping("/revokeFinInvoicesApprove")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "撤销", notes = "传入finStlBills")
+	public R revokeSettlementApprove(@Valid @RequestBody FinInvoices finInvoices) {
+		return finInvoicesService.revokeFinInvoicesApprove(finInvoices);
+	}
+
+	/**
+	 * 业务-发票申请明细
+	 */
+	@GetMapping("/approveDetail")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "详情", notes = "传入finStlBills")
+	public R<FinInvoices> approveDetail(FinInvoices finInvoices) {
+		FinInvoices detail = finInvoicesService.approveDetail(finInvoices);
+		return R.data(detail);
+	}
+
+	/**
 	 * 业务-发票 确认
 	 */
 	@PostMapping("/confirmFinInvoices")
 	@ApiOperationSupport(order = 6)
 	@ApiOperation(value = "确认", notes = "传入finInvoices")
-	public R confirmSettlement(@Valid @RequestBody FinInvoices finInvoices) {
-		return finInvoicesService.confirmfinInvoices(finInvoices);
+	public R confirmSettlement(@Valid @RequestBody FinInvoices finStlBills) {
+		return finInvoicesService.confirmfinInvoices(finStlBills);
 	}
 
 	/**
@@ -144,5 +176,37 @@ public class FinInvoicesController extends BladeController {
 	}
 
 
+	/**
+	 * 审核通过
+	 */
+	@PostMapping("/passCheck")
+	@ApiOperationSupport(order = 14)
+	@RepeatSubmit
+	public R passCheck(@ApiParam(value = "主表id", required = true) @RequestParam Long id) {
+		return finInvoicesService.passCheck(id);
+	}
+
+	/**
+	 * 审核中
+	 */
+	@PostMapping("/underReview")
+	@ApiOperationSupport(order = 15)
+	@RepeatSubmit
+	public R underReview(@ApiParam(value = "主表id", required = true) @RequestParam Long id) {
+		return finInvoicesService.underReview(id);
+	}
+
+	/**
+	 * 审核不通过
+	 */
+	@PostMapping("/passCancel")
+	@ApiOperationSupport(order = 16)
+	@RepeatSubmit
+	public R passCancel(@ApiParam(value = "财务主表id", required = true) @RequestParam Long id) {
+		finInvoicesService.passCancel(id);
+		return R.success("操作成功");
+	}
+
+
 
 }

+ 23 - 0
blade-service/blade-los/src/main/java/org/springblade/los/finance/invoices/service/IFinInvoicesService.java

@@ -21,6 +21,7 @@ import org.springblade.los.finance.invoices.entity.FinInvoices;
 import org.springblade.los.finance.invoices.vo.FinInvoicesVO;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.los.finance.stl.entity.FinStlBills;
 
 /**
  * 业务-发票主表 服务类
@@ -62,4 +63,26 @@ public interface IFinInvoicesService extends IService<FinInvoices> {
 	 * 业务-发票 撤销
 	 */
 	R revokeFinInvoices(FinInvoices finInvoices);
+
+	/**
+	 * 发票 申请
+	 * @param finInvoices
+	 * @return
+	 */
+    R finInvoicesApprove(FinInvoices finInvoices);
+
+	/**
+	 * 发票 申请 撤销
+	 * @param finInvoices
+	 * @return
+	 */
+	R revokeFinInvoicesApprove(FinInvoices finInvoices);
+
+	R passCheck(Long id);
+
+	R underReview(Long id);
+
+	void passCancel(Long id);
+
+	FinInvoices approveDetail(FinInvoices finInvoices);
 }

+ 159 - 0
blade-service/blade-los/src/main/java/org/springblade/los/finance/invoices/service/impl/FinInvoicesServiceImpl.java

@@ -18,6 +18,7 @@ package org.springblade.los.finance.invoices.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.AllArgsConstructor;
@@ -30,6 +31,12 @@ import org.springblade.los.billno.entity.BusinessBillNo;
 import org.springblade.los.billno.service.IBusinessBillNoService;
 import org.springblade.los.business.sea.entity.Bills;
 import org.springblade.los.business.sea.mapper.BillsMapper;
+import org.springblade.los.check.dto.LosAuditProecessDTO;
+import org.springblade.los.check.entity.LosAuditPathsActs;
+import org.springblade.los.check.entity.LosAuditPathsLevels;
+import org.springblade.los.check.service.IAuditPathsActsService;
+import org.springblade.los.check.service.IAuditPathsLevelsService;
+import org.springblade.los.check.service.IAuditProecessService;
 import org.springblade.los.finance.fee.entity.FeeCenter;
 import org.springblade.los.finance.fee.entity.FinAccBills;
 import org.springblade.los.finance.fee.service.IFeeCenterService;
@@ -78,6 +85,12 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
 
 	private final BillsMapper billsMapper;
 
+	private final IAuditPathsActsService auditPathsActsService;
+
+	private final IAuditPathsLevelsService auditPathsLevelsService;
+
+	private final IAuditProecessService auditProecessService;
+
 	@Override
 	public IPage<FinInvoicesVO> selectFinInvoicesPage(IPage<FinInvoicesVO> page, FinInvoicesVO finInvoices) {
 		return page.setRecords(baseMapper.selectFinInvoicesPage(page, finInvoices));
@@ -457,4 +470,150 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
 		return R.data(detail);
 	}
 
+	@Override
+	public R finInvoicesApprove(FinInvoices finInvoices) {
+		if (finInvoices.getId() == null) {
+			throw new RuntimeException("缺少必要参数");
+		}
+		FinInvoices detail = baseMapper.selectById(finInvoices.getId());
+		if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
+			//审批数据
+			LosAuditProecessDTO auditProecessDTO = new LosAuditProecessDTO();
+			//获取审批级次
+			List<LosAuditPathsLevels> auditPathsLevels;
+			// 判断是否有审批流,如果审批流已开启就进入审批流,否则直接走申请通过
+			LosAuditPathsActs pathsActs;
+			//是否开启流程
+			LambdaQueryWrapper<LosAuditPathsActs> auditPathsActsLambdaQueryWrapper = new LambdaQueryWrapper<>();
+			auditPathsActsLambdaQueryWrapper
+				.eq(LosAuditPathsActs::getIsEnable, 1)
+				.eq(LosAuditPathsActs::getFidStatus, "status")
+				.eq(LosAuditPathsActs::getTenantId, AuthUtil.getTenantId())
+				.eq(LosAuditPathsActs::getSalesCompanyId, AuthUtil.getDeptId())
+				.eq(LosAuditPathsActs::getActId, 1110);
+			pathsActs = auditPathsActsService.getOne(auditPathsActsLambdaQueryWrapper);
+			//获取审批信息
+			LosAuditPathsActs losAuditPathsActs = auditPathsActsService.getOne(new LambdaQueryWrapper<LosAuditPathsActs>()
+				.eq(LosAuditPathsActs::getActId, 1110)
+				.eq(LosAuditPathsActs::getFidStatus, "status")
+				.eq(LosAuditPathsActs::getSalesCompanyId, AuthUtil.getDeptId())
+				.eq(LosAuditPathsActs::getTenantId, AuthUtil.getTenantId()));
+			Long pathId = losAuditPathsActs.getPathId();
+			auditPathsLevels = auditPathsLevelsService.list(new LambdaQueryWrapper<LosAuditPathsLevels>()
+				.eq(LosAuditPathsLevels::getTenantId, AuthUtil.getTenantId()).eq(LosAuditPathsLevels::getPathId, pathId));
+			auditProecessDTO.setTimes(1);
+			auditProecessDTO.setProcessType("发票申请");
+
+			// 没开启审批流直接走 通过流程
+			if (pathsActs == null || pathsActs.getIsEnable() == 2) {
+				throw new SecurityException("当前租户未查询到审批流配置");
+			} else {
+
+				if (CollectionUtils.isEmpty(auditPathsLevels)) {
+					throw new SecurityException("开启审批失败:未查询到审批信息");
+				}
+				// 绑定审核类型
+				auditProecessDTO.setCheckType("HYCK-FPSQ");
+				// 追加跳转路由url
+				auditProecessDTO.setUrl(finInvoices.getUrl());
+				auditProecessDTO.setPageStatus(finInvoices.getPageStatus());
+				auditProecessDTO.setPageLabel(finInvoices.getPageLabel());
+				auditProecessDTO.setOrderRemark(detail.getRemarks());
+				auditProecessDTO.setPathsLevelsList(auditPathsLevels);
+				auditProecessDTO.setActId(1);
+				auditProecessDTO.setSrcBillId(detail.getId());
+				auditProecessDTO.setBillId(detail.getId());
+				auditProecessDTO.setBillNo(detail.getBillNo());
+				auditProecessDTO.setSendUserId(AuthUtil.getUserId());
+				auditProecessDTO.setSendName(AuthUtil.getUserName());
+				auditProecessDTO.setSendTime(new Date());
+				auditProecessDTO.setBillTime(detail.getCreateTime());
+				auditProecessDTO.setTenantId(AuthUtil.getTenantId());
+				auditProecessDTO.setCorpId(detail.getCorpId());
+				auditProecessDTO.setSalesCompanyId(Long.parseLong(detail.getCreateDept()));
+				auditProecessDTO.setSalesCompanyName(detail.getCreateDeptName());
+				R financeProcess = auditProecessService.createFinanceProcess(auditProecessDTO);
+				if (!financeProcess.isSuccess()) {
+					throw new SecurityException("操作失败,请联系管理员");
+				}
+			}
+			detail.setStatus(1);
+		}
+		baseMapper.updateById(detail);
+		return R.data(detail);
+	}
+
+	@Override
+	public R revokeFinInvoicesApprove(FinInvoices finInvoices) {
+		if (finInvoices.getId() == null) {
+			throw new RuntimeException("缺少必要参数");
+		}
+		FinInvoices detail = baseMapper.selectById(finInvoices.getId());
+		if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
+			if (detail.getStatus() > 1) {
+				throw new RuntimeException("正在审核中,撤销失败");
+			}
+			R financeProcess = auditProecessService.deteleByBillId(detail.getId());
+			if (!financeProcess.isSuccess()) {
+				throw new SecurityException("操作失败,请联系管理员");
+			}
+			detail.setStatus(0);
+		}
+		baseMapper.updateById(detail);
+		return R.data(detail);
+	}
+
+	@Override
+	public R passCheck(Long id) {
+		FinInvoices bills = baseMapper.selectById(id);
+		if (bills == null) {
+			throw new SecurityException("审批通过失败");
+		}
+		bills.setStatus(3);
+		baseMapper.updateById(bills);
+		return R.success("操作成功");
+	}
+
+	@Override
+	public R underReview(Long id) {
+		FinInvoices bills = baseMapper.selectById(id);
+		if (bills == null) {
+			throw new SecurityException("审批通过失败");
+		}
+		bills.setStatus(2);
+		baseMapper.updateById(bills);
+
+		return R.success("操作成功");
+	}
+
+	@Override
+	public void passCancel(Long id) {
+		FinInvoices bills = baseMapper.selectById(id);
+		if (bills == null) {
+			throw new SecurityException("审批通过失败");
+		}
+		bills.setStatus(4);
+		baseMapper.updateById(bills);
+	}
+
+	@Override
+	public FinInvoices approveDetail(FinInvoices finInvoices) {
+		if (finInvoices.getBillNo() == null) {
+			throw new RuntimeException("缺少必要参数");
+		}
+		FinInvoices detail = baseMapper.selectOne(new LambdaQueryWrapper<FinInvoices>()
+			.eq(FinInvoices::getIsDeleted, 0)
+			.eq(FinInvoices::getTenantId, AuthUtil.getTenantId())
+			.eq(FinInvoices::getBillNo, finInvoices.getBillNo())
+			.eq(FinInvoices::getStatus, 3));
+		if (detail != null) {
+			detail.setFinInvoicesItemsList(finInvoicesItemsService.list(new LambdaQueryWrapper<FinInvoicesItems>()
+				.eq(FinInvoicesItems::getIsDeleted, 0)
+				.eq(FinInvoicesItems::getTenantId, AuthUtil.getTenantId())
+				.eq(FinInvoicesItems::getPid, detail.getId())
+			));
+		}
+		return detail;
+	}
+
 }

+ 16 - 19
blade-service/blade-sales-part/src/main/java/org/springblade/salesPart/order/service/impl/OrderServiceImpl.java

@@ -886,23 +886,22 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
 					.eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
 					.eq(PjStockDesc::getIsDeleted, 0)
 					.in(PjStockDesc::getGoodsId, goodsId));
-				BigDecimal balanceQuantity = new BigDecimal("0.00");
-				BigDecimal inventoryAmount = new BigDecimal("0.00");
-				if (pjStockDescList.size() > 0) {
-					balanceQuantity = pjStockDescList.stream().map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull)
-						.reduce(BigDecimal.ZERO, BigDecimal::add);
-					inventoryAmount = pjStockDescList.stream().map(PjStockDesc::getInventoryAmount).filter(Objects::nonNull)
-						.reduce(BigDecimal.ZERO, BigDecimal::add);
-				}
-				BigDecimal inventoryCostPrice = new BigDecimal("0.00");
-				if (balanceQuantity.compareTo(new BigDecimal("0.00")) == 0 ||
-					inventoryAmount.compareTo(new BigDecimal("0.00")) == 0) {
-					inventoryCostPrice = new BigDecimal("0.00");
-				} else {
-					inventoryCostPrice = inventoryAmount.divide(balanceQuantity, 2, BigDecimal.ROUND_HALF_UP);
-				}
-
 				for (PjOrderItems item : order.getOrderItemsList()) {
+					BigDecimal balanceQuantity = new BigDecimal("0.00");
+					BigDecimal inventoryAmount = new BigDecimal("0.00");
+					if (pjStockDescList.size() > 0) {
+						balanceQuantity = pjStockDescList.stream().filter(e-> e.getGoodsId().equals(item.getGoodsId())).map(PjStockDesc::getBalanceQuantity).filter(Objects::nonNull)
+							.reduce(BigDecimal.ZERO, BigDecimal::add);
+						inventoryAmount = pjStockDescList.stream().filter(e-> e.getGoodsId().equals(item.getGoodsId())).map(PjStockDesc::getInventoryAmount).filter(Objects::nonNull)
+							.reduce(BigDecimal.ZERO, BigDecimal::add);
+					}
+					BigDecimal inventoryCostPrice = new BigDecimal("0.00");
+					if (balanceQuantity.compareTo(new BigDecimal("0.00")) == 0 ||
+						inventoryAmount.compareTo(new BigDecimal("0.00")) == 0) {
+						inventoryCostPrice = new BigDecimal("0.00");
+					} else {
+						inventoryCostPrice = inventoryAmount.divide(balanceQuantity, 2, BigDecimal.ROUND_HALF_UP);
+					}
 					item.setBizType(order.getBsType());
 					item.setBillNo(order.getOrdNo());
 					if (item.getId() == null) {
@@ -911,12 +910,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
 						item.setCreateUser(AuthUtil.getUserId());
 						item.setPid(order.getId());
 						item.setTenantId(AuthUtil.getTenantId());
-						orderItemsService.save(item);
 					} else {
 						item.setUpdateTime(new Date());
 						item.setUpdateUser(AuthUtil.getUserId());
 						item.setPid(order.getId());
-						orderItemsService.updateById(item);
 					}
 
 					//计算小计
@@ -951,7 +948,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
 					}
 					//计算毛利
 					item.setGrossProfit(item.getSubTotalMoney().subtract(item.getCostprie()));
-					orderItemsService.updateById(item);
+					orderItemsService.saveOrUpdate(item);
 
 				}
 				if (goodsName.length() > 0) {