public string PostSelectorBomOrderBom(string OrderNo) { if (string.IsNullOrEmpty(OrderNo)) { return _OrderNo; } _OrderNo=OrderNo; return _OrderNo; }改成无返回值
时间: 2024-02-11 11:08:24 浏览: 37
将方法的返回类型从 `string` 改为 `void`,并删除最后一行的 `return` 语句即可:
```
public void PostSelectorBomOrderBom(string OrderNo)
{
if (string.IsNullOrEmpty(OrderNo))
{
_OrderNo = null;
}
else
{
_OrderNo = OrderNo;
}
}
```
在上述代码中,当 `OrderNo` 为空或 null 时,将 `_OrderNo` 置为 null;否则将 `_OrderNo` 赋值为 `OrderNo`。由于方法返回值为 `void`,不需要返回任何值。
相关问题
优化一下这句sql ,SELECT c.Contract AS ItemContract , ISNULL(c.ProductCode, '') AS ProductCode , ISNULL(c.ProductCodeDesc, '') AS ProductCodeDesc , a.OrderBomID , a.OrderNo , a.ItemID , b.ItemCode , a.PerNum , QtyPerAssembly , a.SourceBillNo , a.DopID , a.ManufDopId , b.ItemName , b.ItemSpec , b.Units , b.IsIndivisible , b.IsJITMaterial , ISNULL('', 'A01-03-08') AS cBarCode , ISNULL('', 'A') AS CWhCode , ISNULL('', '三楼电子仓') AS CWhName , a.LineItemNo , a.Contract , a.VartualPart , a.Qty , a.ProductLineNo , a.ProductLineDesc , ISNULL(0, 0) AS IsNotGrn , ISNULL(a.[QtySumassembly], 0) AS QtySumassembly , c.PartType FROM ( SELECT OrderNO ,Status FROM dbo.Prod_Order myq WHERE Status <> 7 ) AS a1 INNER JOIN dbo.Prod_OrderBom AS a ON a1.OrderNO = a.OrderNo INNER JOIN dbo.Basal_Item AS b ON b.ItemID = a.ItemID INNER JOIN dbo.Basal_ItemContract AS c ON c.ItemCode = b.ItemCode AND a.Contract = c.Contract WHERE 1=1 AND EXISTS( SELECT 1 FROM Prod_ShopOrder ps WHERE ps.OrderNo=a.SourceBillNo AND (ps.Status='Released' OR ps.Status='Started' OR ps.Status='Reserved')--230211 排除顶层BOM里面关闭的车间订单BOM ) AND EXISTS( SELECT 1 FROM dbo.Prod_ShopOrder ps WHERE ps.MesOrderNo=a1.OrderNo AND ps.IsMesOrder = 'TRUE' AND (ps.Status='Released' OR ps.Status='Started' OR ps.Status='Reserved')--Released Started Reserved )
答:根据您所提供的SQL语句,我建议您优化SQL语句如下:SELECT c.Contract AS ItemContract, ISNULL(c.ProductCode, '') AS ProductCode, ISNULL(c.ProductCodeDesc, '') AS ProductCodeDesc, a.OrderBomID, a.OrderNo, a.ItemID, b.ItemCode, a.PerNum, QtyPerAssembly, a.SourceBillNo, a.DopID, a.ManufDopId, b.ItemName, b.ItemSpec, b.Units, b.IsIndivisible, b.IsJITMaterial, ISNULL('A01-03-08', '') AS cBarCode, ISNULL('A', '') AS CWhCode, ISNULL('三楼电子仓', '') AS CWhName, a.LineItemNo, a.Contract, a.VartualPart, a.Qty, a.ProductLineNo, a.ProductLineDesc, ISNULL(0, 0) AS IsNotGrn, ISNULL(a.[QtySumassembly], 0) AS QtySumassembly, c.PartType FROM Prod_Order AS a1 INNER JOIN Prod_OrderBom AS a ON a1.OrderNO = a.OrderNo INNER JOIN Basal_Item AS b ON b.ItemID = a.ItemID INNER JOIN Basal_ItemContract AS c ON c.ItemCode = b.ItemCode AND a.Contract = c.Contract WHERE EXISTS( SELECT 1 FROM Prod_ShopOrder ps WHERE ps.OrderNo=a.SourceBillNo AND (ps.Status=Released OR ps.Status=Started OR ps.Status=Reserved) AND EXISTS( SELECT 1 FROM dbo.Prod_ShopOrder ps WHERE ps.MesOrderNo=a1.OrderNo AND ps.IsMesOrder = TRUE AND (ps.Status=Released OR ps.Status=Started OR ps.Status=Reserved) );
public String asyncNotify(String notifyData) { //1.签名校验 PayResponse payResponse = bestPayService.asyncNotify(notifyData); log.info("异步通知 : notifyData={}", payResponse); //2.金额校验(从数据库查订单) //较为严重(正常情况下是不会发生的)发出警告:钉钉,短信 PayInfoDAO payInfo = payInfoMapper.selectByOrderNo(Long.parseLong(payResponse.getOrderId())); if (payInfo == null) { throw new RuntimeException("通过orderNo查询到的结果为null"); } //如果订单支付状态不是"已支付" if (!payInfo.getPlatformStatus().equals(OrderStatusEnum.SUCCESS.name())) { //Double类型比较大小,精度。1.00 1.0 if (payInfo.getPayAmount().compareTo(BigDecimal.valueOf(payResponse.getOrderAmount())) != 0) { //告警 // throw new RuntimeException("异步通知中的金额和数据库里的不一致,orderNo=" + payResponse.getOrderId()); try { throw new Exception("异步通知中的金额和数据库里的不一致,orderNo=" + payResponse.getOrderId()); } catch (Exception e) { e.printStackTrace(); } } //3. 修改订单支付状态 payInfo.setPlatformStatus(OrderStatusEnum.SUCCESS.name()); payInfo.setPlatformNumber(payResponse.getOutTradeNo()); payInfoMapper.updateByPrimaryKeySelective(payInfo); } //TODO pay发送MQ消息,mall接受MQ int i = sysUserService.updateSysUserByUsername(payInfo.getUserId()); if (i <= 0) { //throw new RuntimeException("更改状态错误"); try { throw new Exception("更改状态错误"); } catch (Exception e) { e.printStackTrace(); } } if (payResponse.getPayPlatformEnum() == BestPayPlatformEnum.WX) { //4.告诉微信不要再通知 return "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + "</xml>"; } else if (payResponse.getPayPlatformEnum() == BestPayPlatformEnum.ALIPAY) { //return "success"; return "SUCCESS"; } throw new RuntimeException("异步通知中错误的平台"); } 这个代码有没有什么错误
这段代码存在一些问题:
1. 在发生金额校验不一致时,使用了`try-catch`语句,但是在`catch`块中只是打印了异常堆栈信息,没有进行任何处理,这可能会导致问题被忽略。
2. 在订单支付状态不为"已支付"时,如果金额校验一致,也会更新订单状态,这可能会导致订单状态被错误地修改为"已支付"。
针对这些问题,可以进行以下改进:
1. 在发生金额校验不一致时,不应该使用`try-catch`语句,而是应该直接抛出异常,以便及时发现并处理问题。
2. 在订单支付状态不为"已支付"时,应该只有在金额校验一致的情况下才能更新订单状态。
下面是修改后的代码:
```java
public String asyncNotify(String notifyData) {
//1.签名校验
PayResponse payResponse = bestPayService.asyncNotify(notifyData);
log.info("异步通知 : notifyData={}", payResponse);
//2.金额校验(从数据库查订单)
PayInfoDAO payInfo = payInfoMapper.selectByOrderNo(Long.parseLong(payResponse.getOrderId()));
if (payInfo == null) {
throw new RuntimeException("通过orderNo查询到的结果为null");
}
//如果订单支付状态不是"已支付"
if (!payInfo.getPlatformStatus().equals(OrderStatusEnum.SUCCESS.name())) {
//Double类型比较大小,精度。1.00 1.0
if (payInfo.getPayAmount().compareTo(BigDecimal.valueOf(payResponse.getOrderAmount())) != 0) {
//告警
throw new RuntimeException("异步通知中的金额和数据库里的不一致,orderNo=" + payResponse.getOrderId());
}
//3. 修改订单支付状态
payInfo.setPlatformStatus(OrderStatusEnum.SUCCESS.name());
payInfo.setPlatformNumber(payResponse.getOutTradeNo());
payInfoMapper.updateByPrimaryKeySelective(payInfo);
//TODO pay发送MQ消息,mall接受MQ
int i = sysUserService.updateSysUserByUsername(payInfo.getUserId());
if (i <= 0) {
throw new RuntimeException("更改状态错误");
}
}
if (payResponse.getPayPlatformEnum() == BestPayPlatformEnum.WX) {
//4.告诉微信不要再通知
return "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + "</xml>";
} else if (payResponse.getPayPlatformEnum() == BestPayPlatformEnum.ALIPAY) {
return "SUCCESS";
}
throw new RuntimeException("异步通知中错误的平台");
}
```