@ -15,16 +15,17 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo ;
import com.ruoyi.common.core.page.TableDataInfo ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.enums.BusinessType ;
import com.ruoyi.common.enums.BusinessType ;
import com.ruoyi.common.utils.DateUtils ;
import com.ruoyi.common.utils.ShiroUtils ;
import com.ruoyi.common.utils.poi.ExcelUtil ;
import com.ruoyi.common.utils.poi.ExcelUtil ;
import com.ruoyi.purchase.domain.PurchaseMaterial ;
import com.ruoyi.purchase.domain.* ;
import com.ruoyi.purchase.domain.PurchaseOrder ;
import com.ruoyi.purchase.domain.PurchaseOrderChild ;
import com.ruoyi.purchase.domain.PurchaseQuoteChild ;
import com.ruoyi.purchase.domain.exportDto.PurchaseMaterialDto ;
import com.ruoyi.purchase.domain.exportDto.PurchaseMaterialDto ;
import com.ruoyi.purchase.domain.exportDto.PurchaseOrderDto ;
import com.ruoyi.purchase.domain.exportDto.PurchaseOrderDto ;
import com.ruoyi.purchase.mapper.PurchaseOrderChildMapper ;
import com.ruoyi.purchase.mapper.PurchaseOrderChildMapper ;
import com.ruoyi.purchase.service.IPurchaseMaterialService ;
import com.ruoyi.purchase.service.IPurchaseMaterialService ;
import com.ruoyi.purchase.service.IPurchaseOrderChildService ;
import com.ruoyi.purchase.service.IPurchaseOrderService ;
import com.ruoyi.purchase.service.IPurchaseOrderService ;
import com.ruoyi.purchase.service.IPurchasePlanService ;
import com.ruoyi.quality.domain.QualityOrderDetail ;
import com.ruoyi.quality.domain.QualityOrderDetail ;
import com.ruoyi.storehouse.utils.CustomRowWriteCellHandler ;
import com.ruoyi.storehouse.utils.CustomRowWriteCellHandler ;
import org.apache.poi.ss.usermodel.HorizontalAlignment ;
import org.apache.poi.ss.usermodel.HorizontalAlignment ;
@ -62,7 +63,10 @@ public class PurchaseOrderController extends BaseController
@Autowired
@Autowired
private IPurchaseMaterialService purchaseMaterialService ;
private IPurchaseMaterialService purchaseMaterialService ;
@Autowired
@Autowired
private PurchaseOrderChildMapper purchaseOrderChildService ; ;
private IPurchaseOrderChildService purchaseOrderChildService ; ;
@Autowired
private IPurchasePlanService purchasePlanService ;
@Autowired
@Autowired
private RedisCache redisCache ;
private RedisCache redisCache ;
@ -116,9 +120,18 @@ public class PurchaseOrderController extends BaseController
@Log ( title = "采购订单" , businessType = BusinessType . INSERT )
@Log ( title = "采购订单" , businessType = BusinessType . INSERT )
@PostMapping ( "/add" )
@PostMapping ( "/add" )
@ResponseBody
@ResponseBody
public AjaxResult addSave ( @Valid @RequestBody PurchaseOrder purchaseOrder ) {
public AjaxResult addSave ( @RequestBody PurchaseOrder purchaseOrder ) {
// 数据校验,确保前端传入数据格式正确
// 生成采购订单编号
// 执行主表插入操作
return toAjax ( purchaseOrderService . insertPurchaseOrder ( purchaseOrder ) ) ; // 假设toAjax方法处理成功逻辑
}
@RequiresPermissions ( "purchase:purchaseOrder:add" )
@Log ( title = "采购订单" , businessType = BusinessType . INSERT )
@PostMapping ( "/addPurchaseOrder" )
@ResponseBody
public AjaxResult addPurchasePlantoPuserchaseOrder ( @RequestBody PurchaseOrder purchaseOrder ) {
// 数据校验,确保前端传入数据格式正确
// 数据校验,确保前端传入数据格式正确
validatePurchaseOrder ( purchaseOrder ) ;
// 生成采购订单编号
// 生成采购订单编号
purchaseOrder . setPurchaseOrderCode ( redisCache . generateBillNo ( "CG" ) ) ;
purchaseOrder . setPurchaseOrderCode ( redisCache . generateBillNo ( "CG" ) ) ;
// 初始化累加变量
// 初始化累加变量
@ -128,25 +141,32 @@ public class PurchaseOrderController extends BaseController
BigDecimal materialRmbSum = BigDecimal . ZERO ;
BigDecimal materialRmbSum = BigDecimal . ZERO ;
Long materialNum = 0L ;
Long materialNum = 0L ;
int supplierNum = 0 ;
int supplierNum = 0 ;
// 遍历处理采购订单子表
if ( ! CollectionUtils . isEmpty ( purchaseOrder . getPurchaseOrderChildList ( ) ) ) {
supplierNum = purchaseOrder . getPurchaseOrderChildList ( ) . size ( ) ;
}
if ( purchaseOrder . getPurchaseOrderChildList ( ) ! = null ) {
for ( PurchaseOrderChild child : purchaseOrder . getPurchaseOrderChildList ( ) ) {
for ( PurchaseOrderChild child : purchaseOrder . getPurchaseOrderChildList ( ) ) {
if ( child . getCorrelationCode ( ) . contains ( "," ) ) {
String [ ] correlationCodes = child . getCorrelationCode ( ) . split ( "," ) ;
for ( int i = 0 ; i < correlationCodes . length ; i + + ) {
String correlationCode = correlationCodes [ i ] ;
String planCode = child . getPurchasePlanCode ( ) . split ( "," ) [ i ] ;
if ( correlationCode ! = null ) {
PurchaseOrderChild material = new PurchaseOrderChild ( ) ;
child . setPurchaseOrderCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
child . setPurchaseOrderCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
// 累加物料数量和金额
// 累加物料数量和金额
for ( PurchaseQuoteChild quote : child . getPurchaseQuoteChildList ( ) ) {
//获取物料供应商采购价格
//获取物料供应商采购价格
BigDecimal suplierMaterialNoRmb = quote . getMaterialNoRmb ( ) ;
BigDecimal suplierMaterialNoRmb = child . getMaterialNoRmb ( ) ;
// 获取物料供应商采购价格
// 获取物料供应商采购价格
BigDecimal suplierMaterialRmb = quote . getMaterialRmb ( ) ;
BigDecimal suplierMaterialRmb = child . getMaterialRmb ( ) ;
// 获取物料数量
// 获取物料数量
Long suplierMaterialNum = quote . getMaterialNum ( ) ;
Long suplierMaterialNum = child . getMaterialNum ( ) ;
// 累加物料数量
// 累加物料数量
materialNum + = suplierMaterialNum ;
materialNum + = suplierMaterialNum ;
// 累加不含税物料价格
// 累加不含税物料价格
materialNoRmb = materialNoRmb . add ( suplierMaterialNoRmb ) ;
materialNoRmb = materialNoRmb . add ( suplierMaterialNoRmb ) ;
// 累加含税物料价格
// 累加含税物料价格
materialRmb = materialRmb . add ( suplierMaterialRmb ) ;
materialRmb = materialRmb . add ( suplierMaterialRmb ) ;
child . setPurchasePlanCode ( quote . getPurchasePlanCode ( ) ) ;
// 计算不含税物料总价
// 计算不含税物料总价
BigDecimal suplierMaterialNoRmbSumLocal = suplierMaterialNoRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
BigDecimal suplierMaterialNoRmbSumLocal = suplierMaterialNoRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
// 计算物料含税总价
// 计算物料含税总价
@ -155,46 +175,48 @@ public class PurchaseOrderController extends BaseController
materialNoRmbSum = materialNoRmbSum . add ( suplierMaterialNoRmbSumLocal ) ;
materialNoRmbSum = materialNoRmbSum . add ( suplierMaterialNoRmbSumLocal ) ;
// 累加物料含税总价
// 累加物料含税总价
materialRmbSum = materialRmbSum . add ( suplierMaterialRmbSumLocal ) ;
materialRmbSum = materialRmbSum . add ( suplierMaterialRmbSumLocal ) ;
// 设置采购报价单编号和供应商信息到QuoteChild
// 设置采购报价单编号和供应商信息到QuoteChild
quote . setPurchaseQuoteCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
material . setPurchaseQuoteCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
child . setSupplierCode ( quote . getSupplierCode ( ) ) ;
material . setSupplierCode ( child . getSupplierCode ( ) ) ;
child . setSupplierName ( quote . getSupplierName ( ) ) ;
material . setSupplierName ( child . getSupplierName ( ) ) ;
material . setMaterialNoRmb ( child . getMaterialNoRmb ( ) ) ;
material . setMaterialRmb ( child . getMaterialRmb ( ) ) ;
material . setMaterialNum ( child . getMaterialNum ( ) ) ;
material . setMaterialName ( child . getMaterialName ( ) ) ;
material . setMaterialNoRmbSum ( child . getMaterialNoRmbSum ( ) ) ;
material . setMaterialRmbSum ( child . getMaterialRmbSum ( ) ) ;
material . setMaterialNoRmbSum ( child . getMaterialNoRmbSum ( ) ) ;
material . setCorrelationCode ( correlationCode ) ;
material . setPurchasePlanCode ( planCode ) ;
material . setPurchaseOrderCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
// 执行子表插入操作
purchaseOrderChildService . insertPurchaseOrderChild ( child ) ;
PurchasePlan plan = new PurchasePlan ( ) ;
plan . setPurchasePlanCode ( child . getPurchasePlanCode ( ) ) ;
plan . setPurchasePlanStatus ( "1" ) ;
int result = purchasePlanService . updatePurchasePlan ( plan ) ;
}
}
child . setMaterialNoRmb ( BigDecimal . ZERO ) ;
}
// 确保供应商数量统计准确
// 确保供应商数量统计准确
if ( quote . getSupplierCode ( ) ! = null ) {
if ( child . getSupplierCode ( ) ! = null ) {
supplierNum + + ;
supplierNum + + ;
}
}
}
// 设置累加的物料信息到子表
child . setMaterialNoRmb ( materialNoRmb ) ;
child . setMaterialRmb ( materialRmb ) ;
child . setMaterialNum ( materialNum ) ;
// 执行子表插入操作
purchaseOrderChildService . insertPurchaseOrderChild ( child ) ;
}
}
}
// 遍历处理采购订单子表
// 设置累加的物料信息到子表
purchaseOrder . setMaterialSum ( Math . toIntExact ( materialNum ) ) ;
purchaseOrder . setNoRmbSum ( materialNoRmbSum ) ;
purchaseOrder . setRmbSum ( materialRmbSum ) ;
// 设置主表的供应商数量
// 设置主表的供应商数量
purchaseOrder . setSupplierNum ( supplierNum ) ;
purchaseOrder . setSupplierNum ( supplierNum ) ;
// 执行主表插入操作
// 执行主表插入操作
return toAjax ( purchaseOrderService . insertPurchaseOrder ( purchaseOrder ) ) ; // 假设toAjax方法处理成功逻辑
return toAjax ( purchaseOrderService . insertPurchaseOrder ( purchaseOrder ) ) ; // 假设toAjax方法处理成功逻辑
}
}
// 数据校验逻辑
private void validatePurchaseOrder ( PurchaseOrder purchaseOrder ) {
if ( CollectionUtils . isEmpty ( purchaseOrder . getPurchaseOrderChildList ( ) ) ) {
try {
throw new Exception ( "采购订单子项不能为空" ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
// 可以添加更多校验逻辑
}
/ * *
/ * *
* 修改采购订单
* 修改采购订单
* /
* /
@ -213,6 +235,18 @@ public class PurchaseOrderController extends BaseController
mmap . put ( "purchaseOrderChild" , purchaseOrderChild ) ;
mmap . put ( "purchaseOrderChild" , purchaseOrderChild ) ;
return prefix + "/detail" ;
return prefix + "/detail" ;
}
}
@GetMapping ( "/addPurchaseOrderStorage/{purchaseOrderCode}" )
public String addPurchaseOrderStorage ( @PathVariable ( "purchaseOrderCode" ) String purchaseOrderCode , ModelMap mmap ) {
//purchasePlanCodes去除重复数据,purchasePlanCodeArray作为数组类型去除
//查询相关采购计划数据
PurchaseOrder purchaseOrderList = purchaseOrderService . selectPurchaseOrderByOrderCode ( purchaseOrderCode ) ;
//根据采购计划编号查询对应的采购报价数据
List < PurchaseOrderChild > purchaseOrderChildList = purchaseOrderChildService . selectPurchaseOrderChildByOrderCode ( purchaseOrderCode ) ;
//再根据采购计划编号分组查询对应的采购报价数据分组
mmap . put ( "purchaseOrderList" , purchaseOrderList ) ;
mmap . put ( "purchaseOrderChildList" , purchaseOrderChildList ) ;
return prefix + "/addPurchaseOrderStorage" ;
}
@ResponseBody
@ResponseBody
@RequestMapping ( "/detailListGroupedBySupplier" )
@RequestMapping ( "/detailListGroupedBySupplier" )
public Map < String , List < PurchaseOrderChild > > detailListGroupedBySupplier ( String qualityOrderCode ) {
public Map < String , List < PurchaseOrderChild > > detailListGroupedBySupplier ( String qualityOrderCode ) {
@ -288,7 +322,6 @@ public class PurchaseOrderController extends BaseController
// 创建列合并工具类对象
// 创建列合并工具类对象
// ExcelFillCellMergePrevColUtils mergePrevColUtils = new ExcelFillCellMergePrevColUtils();
// ExcelFillCellMergePrevColUtils mergePrevColUtils = new ExcelFillCellMergePrevColUtils();
List < PurchaseMaterial > purchaseMaterialList = purchaseMaterialService . selectPurchaseMaterialList ( purchaseMaterial ) ;
List < PurchaseMaterial > purchaseMaterialList = purchaseMaterialService . selectPurchaseMaterialList ( purchaseMaterial ) ;
List < PurchaseMaterialDto > purchaseMaterialDtoList = new ArrayList < > ( ) ;
List < PurchaseMaterialDto > purchaseMaterialDtoList = new ArrayList < > ( ) ;
double total = 0 . 00 ;
double total = 0 . 00 ;