refactor(mat): 优化物料出入库服务事务管理和代码规范

- 在 MatMaterialOutServiceImpl 中添加 @Transactional 注解确保数据一致性
- 修复 MatPriceHistoryController 中的服务注入变量名错误
- 统一控制器中的服务调用方法,提升代码可读性
- 优化 MatPurchaseInDetailServiceImpl 的事务配置和方法实现
- 规范化代码格式和命名约定,提高代码质量
This commit is contained in:
2026-01-30 17:02:20 +08:00
parent 609e7707db
commit f64db505d9
3 changed files with 31 additions and 25 deletions

View File

@@ -35,14 +35,14 @@ import com.gear.common.core.page.TableDataInfo;
@RequestMapping("/mat/matPriceHistory") @RequestMapping("/mat/matPriceHistory")
public class MatPriceHistoryController extends BaseController { public class MatPriceHistoryController extends BaseController {
private final IMatPriceHistoryService iMatMatPriceHistoryService; private final IMatPriceHistoryService iMatPriceHistoryService;
/** /**
* 查询配料价格/均价变动历史列表 * 查询配料价格/均价变动历史列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo<MatPriceHistoryVo> list(MatPriceHistoryBo bo, PageQuery pageQuery) { public TableDataInfo<MatPriceHistoryVo> list(MatPriceHistoryBo bo, PageQuery pageQuery) {
return iMatMatPriceHistoryService.queryPageList(bo, pageQuery); return iMatPriceHistoryService.queryPageList(bo, pageQuery);
} }
/** /**
@@ -51,7 +51,7 @@ public class MatPriceHistoryController extends BaseController {
@Log(title = "配料价格/均价变动历史", businessType = BusinessType.EXPORT) @Log(title = "配料价格/均价变动历史", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(MatPriceHistoryBo bo, HttpServletResponse response) { public void export(MatPriceHistoryBo bo, HttpServletResponse response) {
List<MatPriceHistoryVo> list = iMatMatPriceHistoryService.queryList(bo); List<MatPriceHistoryVo> list = iMatPriceHistoryService.queryList(bo);
ExcelUtil.exportExcel(list, "配料价格/均价变动历史", MatPriceHistoryVo.class, response); ExcelUtil.exportExcel(list, "配料价格/均价变动历史", MatPriceHistoryVo.class, response);
} }
@@ -63,7 +63,7 @@ public class MatPriceHistoryController extends BaseController {
@GetMapping("/{historyId}") @GetMapping("/{historyId}")
public R<MatPriceHistoryVo> getInfo(@NotNull(message = "主键不能为空") public R<MatPriceHistoryVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long historyId) { @PathVariable Long historyId) {
return R.ok(iMatMatPriceHistoryService.queryById(historyId)); return R.ok(iMatPriceHistoryService.queryById(historyId));
} }
/** /**
@@ -73,7 +73,7 @@ public class MatPriceHistoryController extends BaseController {
@RepeatSubmit() @RepeatSubmit()
@PostMapping() @PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody MatPriceHistoryBo bo) { public R<Void> add(@Validated(AddGroup.class) @RequestBody MatPriceHistoryBo bo) {
return toAjax(iMatMatPriceHistoryService.insertByBo(bo)); return toAjax(iMatPriceHistoryService.insertByBo(bo));
} }
/** /**
@@ -83,7 +83,7 @@ public class MatPriceHistoryController extends BaseController {
@RepeatSubmit() @RepeatSubmit()
@PutMapping() @PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody MatPriceHistoryBo bo) { public R<Void> edit(@Validated(EditGroup.class) @RequestBody MatPriceHistoryBo bo) {
return toAjax(iMatMatPriceHistoryService.updateByBo(bo)); return toAjax(iMatPriceHistoryService.updateByBo(bo));
} }
/** /**
@@ -95,6 +95,6 @@ public class MatPriceHistoryController extends BaseController {
@DeleteMapping("/{historyIds}") @DeleteMapping("/{historyIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] historyIds) { @PathVariable Long[] historyIds) {
return toAjax(iMatMatPriceHistoryService.deleteWithValidByIds(Arrays.asList(historyIds), true)); return toAjax(iMatPriceHistoryService.deleteWithValidByIds(Arrays.asList(historyIds), true));
} }
} }

View File

@@ -18,6 +18,7 @@ import com.gear.mat.service.IMatMaterialOutService;
import com.gear.mat.service.IMatMaterialService; import com.gear.mat.service.IMatMaterialService;
import com.gear.mat.domain.vo.MatMaterialVo; import com.gear.mat.domain.vo.MatMaterialVo;
import com.gear.mat.domain.bo.MatMaterialBo; import com.gear.mat.domain.bo.MatMaterialBo;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -110,6 +111,7 @@ public class MatMaterialOutServiceImpl implements IMatMaterialOutService {
} }
@Override @Override
@Transactional
public Boolean insertByBoWithInventoryAdjustment(MatMaterialOutBo bo) { public Boolean insertByBoWithInventoryAdjustment(MatMaterialOutBo bo) {
boolean success = insertByBo(bo); boolean success = insertByBo(bo);
@@ -122,6 +124,7 @@ public class MatMaterialOutServiceImpl implements IMatMaterialOutService {
} }
@Override @Override
@Transactional
public Boolean deleteWithValidByIdsWithInventoryAdjustment(Collection<Long> ids, Boolean isValid) { public Boolean deleteWithValidByIdsWithInventoryAdjustment(Collection<Long> ids, Boolean isValid) {
// 获取待删除的出库记录信息,以便后续恢复库存 // 获取待删除的出库记录信息,以便后续恢复库存
List<MatMaterialOutVo> recordsToDelete = new ArrayList<>(); List<MatMaterialOutVo> recordsToDelete = new ArrayList<>();

View File

@@ -21,6 +21,7 @@ import com.gear.mat.domain.vo.MatMaterialVo;
import com.gear.mat.domain.vo.MatPriceHistoryVo; import com.gear.mat.domain.vo.MatPriceHistoryVo;
import com.gear.mat.domain.bo.MatMaterialBo; import com.gear.mat.domain.bo.MatMaterialBo;
import com.gear.mat.domain.bo.MatPriceHistoryBo; import com.gear.mat.domain.bo.MatPriceHistoryBo;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
@@ -142,6 +143,7 @@ public class MatPurchaseInDetailServiceImpl implements IMatPurchaseInDetailServi
} }
@Override @Override
@Transactional
public Boolean insertByBoWithInventoryAndPriceHistory(MatPurchaseInDetailBo bo) { public Boolean insertByBoWithInventoryAndPriceHistory(MatPurchaseInDetailBo bo) {
boolean success = insertByBo(bo); boolean success = insertByBo(bo);
@@ -157,6 +159,7 @@ public class MatPurchaseInDetailServiceImpl implements IMatPurchaseInDetailServi
} }
@Override @Override
@Transactional
public Boolean deleteWithValidByIdsWithInventoryAndPriceHistory(Collection<Long> ids, Boolean isValid) { public Boolean deleteWithValidByIdsWithInventoryAndPriceHistory(Collection<Long> ids, Boolean isValid) {
// 获取待删除的入库记录信息,以便后续还原库存和价格历史 // 获取待删除的入库记录信息,以便后续还原库存和价格历史
List<MatPurchaseInDetailVo> recordsToDelete = new ArrayList<>(); List<MatPurchaseInDetailVo> recordsToDelete = new ArrayList<>();