@ -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,73 +141,82 @@ 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 ( ) ) ) {
for ( PurchaseOrderChild child : purchaseOrder . getPurchaseOrderChildList ( ) ) {
supplierNum = purchaseOrder . getPurchaseOrderChildList ( ) . size ( ) ;
child . setPurchaseOrderCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
}
// 累加物料数量和金额
if ( purchaseOrder . getPurchaseOrderChildList ( ) ! = null ) {
for ( PurchaseQuoteChild quote : child . getPurchaseQuoteChildList ( ) ) {
for ( PurchaseOrderChild child : purchaseOrder . getPurchaseOrderChildList ( ) ) {
//获取物料供应商采购价格
if ( child . getCorrelationCode ( ) . contains ( "," ) ) {
BigDecimal suplierMaterialNoRmb = quote . getMaterialNoRmb ( ) ;
String [ ] correlationCodes = child . getCorrelationCode ( ) . split ( "," ) ;
// 获取物料供应商采购价格
for ( int i = 0 ; i < correlationCodes . length ; i + + ) {
BigDecimal suplierMaterialRmb = quote . getMaterialRmb ( ) ;
String correlationCode = correlationCodes [ i ] ;
// 获取物料数量
String planCode = child . getPurchasePlanCode ( ) . split ( "," ) [ i ] ;
Long suplierMaterialNum = quote . getMaterialNum ( ) ;
if ( correlationCode ! = null ) {
// 累加物料数量
PurchaseOrderChild material = new PurchaseOrderChild ( ) ;
materialNum + = suplierMaterialNum ;
child . setPurchaseOrderCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
// 累加不含税物料价格
// 累加物料数量和金额
materialNoRmb = materialNoRmb . add ( suplierMaterialNoRmb ) ;
//获取物料供应商采购价格
// 累加含税物料价格
BigDecimal suplierMaterialNoRmb = child . getMaterialNoRmb ( ) ;
materialRmb = materialRmb . add ( suplierMaterialRmb ) ;
// 获取物料供应商采购价格
BigDecimal suplierMaterialRmb = child . getMaterialRmb ( ) ;
child . setPurchasePlanCode ( quote . getPurchasePlanCode ( ) ) ;
// 获取物料数量
// 计算不含税物料总价
Long suplierMaterialNum = child . getMaterialNum ( ) ;
BigDecimal suplierMaterialNoRmbSumLocal = suplierMaterialNoRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
// 累加物料数量
// 计算物料含税总价
materialNum + = suplierMaterialNum ;
BigDecimal suplierMaterialRmbSumLocal = suplierMaterialRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
// 累加不含税物料价格
// 累加物料总价
materialNoRmb = materialNoRmb . add ( suplierMaterialNoRmb ) ;
materialNoRmbSum = materialNoRmbSum . add ( suplierMaterialNoRmbSumLocal ) ;
// 累加含税物料价格
// 累加物料含税总价
materialRmb = materialRmb . add ( suplierMaterialRmb ) ;
materialRmbSum = materialRmbSum . add ( suplierMaterialRmbSumLocal ) ;
// 计算不含税物料总价
BigDecimal suplierMaterialNoRmbSumLocal = suplierMaterialNoRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
// 设置采购报价单编号和供应商信息到QuoteChild
// 计算物料含税总价
quote . setPurchaseQuoteCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
BigDecimal suplierMaterialRmbSumLocal = suplierMaterialRmb . multiply ( BigDecimal . valueOf ( suplierMaterialNum ) ) ;
child . setSupplierCode ( quote . getSupplierCode ( ) ) ;
// 累加物料总价
child . setSupplierName ( quote . getSupplierName ( ) ) ;
materialNoRmbSum = materialNoRmbSum . add ( suplierMaterialNoRmbSumLocal ) ;
// 累加物料含税总价
materialRmbSum = materialRmbSum . add ( suplierMaterialRmbSumLocal ) ;
// 设置采购报价单编号和供应商信息到QuoteChild
material . setPurchaseQuoteCode ( purchaseOrder . getPurchaseOrderCode ( ) ) ;
material . setSupplierCode ( child . getSupplierCode ( ) ) ;
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 ;