zss
2 天以前 7ea939485f815ba613c7e45b9e299473e75c1167
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.ruoyi.production.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.BomImportDto;
import com.ruoyi.production.dto.ProductBomDto;
import com.ruoyi.production.pojo.ProcessRoute;
import com.ruoyi.production.pojo.ProductBom;
import com.ruoyi.production.pojo.ProductProcessRoute;
import com.ruoyi.production.pojo.ProductStructure;
import com.ruoyi.production.service.ProcessRouteService;
import com.ruoyi.production.service.ProductBomService;
import com.ruoyi.production.service.ProductProcessRouteService;
import com.ruoyi.production.service.ProductStructureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * <p>
 * BOM主表 前端控制器
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-01-15 09:59:27
 */
@RestController
@RequestMapping("/productBom")
@Api(tags = "BOM")
public class ProductBomController {
 
    @Autowired
    private ProductBomService productBomService;
 
    @Autowired
    private ProcessRouteService processRouteService;
 
    @Autowired
    private ProductProcessRouteService productProcessRouteService;
 
    @Autowired
    private ProductStructureService productStructureService;
 
    @GetMapping("/listPage")
    @Log(title = "BOM-分页查询", businessType = BusinessType.OTHER)
    @ApiOperation("BOM-分页查询")
    public AjaxResult listPage(Page page, ProductBomDto productBomDto) {
        IPage<ProductBomDto> listPage = productBomService.listPage(page, productBomDto);
        return AjaxResult.success(listPage);
    }
 
    @ApiModelProperty("新增BOM")
    @PostMapping("/add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody ProductBom productBom) {
        return productBomService.add(productBom);
    }
 
    @ApiOperation("更新BOM")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody ProductBom productBom) {
        return AjaxResult.success(productBomService.updateById(productBom));
    }
 
    @ApiOperation("删除BOM")
    @DeleteMapping("/batchDelete")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    public AjaxResult batchDelete(@RequestBody List<Integer> ids) {
        List<ProcessRoute> list = processRouteService.list(Wrappers.<ProcessRoute>lambdaQuery().in(ProcessRoute::getBomId, ids));
        List<ProductProcessRoute> list2 = productProcessRouteService.list(Wrappers.<ProductProcessRoute>lambdaQuery().in(ProductProcessRoute::getBomId, ids));
        if (list.size() > 0 || list2.size() > 0) {
            return AjaxResult.error("该BOM已经存在对应的工艺路线,无法进行删除");
        }
        if (CollectionUtils.isEmpty(ids)) {
            return AjaxResult.error("请选择至少一条数据");
        }
        //删除bom子表
        productStructureService.remove(Wrappers.<ProductStructure>lambdaQuery().in(ProductStructure::getBomId, ids));
        return AjaxResult.success(productBomService.removeBatchByIds(ids));
    }
 
    @GetMapping("/getByModel")
    @Log(title = "BOM-根据选择的规格型号id查询存在的bom", businessType = BusinessType.OTHER)
    @ApiOperation("BOM-根据选择的规格型号id查询存在的bom")
    public AjaxResult getByModel(Long productModelId) {
        List<ProductBom> productBoms = productBomService.list(Wrappers.<ProductBom>lambdaQuery().eq(ProductBom::getProductModelId, productModelId));
        return AjaxResult.success(productBoms);
    }
 
    @PostMapping("uploadBom")
    @PreAuthorize("@ss.hasPermi('product:bom:import')")
    @Log(title = "根据Excel导入BOM", businessType = BusinessType.IMPORT)
    @ApiOperation("根据Excel导入BOM")
    public AjaxResult uploadBom(@RequestParam("file") MultipartFile file) {
        return productBomService.uploadBom(file);
    }
 
    @PostMapping("exportBom")
    @PreAuthorize("@ss.hasPermi('product:bom:export')")
    @ApiOperation("导出BOM文件")
    @Log(title = "导出BOM文件", businessType = BusinessType.EXPORT)
    public void exportBom(HttpServletResponse response, @RequestParam Integer bomId) {
        productBomService.exportBom(response, bomId);
    }
 
    @GetMapping("/downloadTemplate")
    @Log(title = "下载BOM导入模板", businessType = BusinessType.EXPORT)
    @ApiOperation("下载BOM导入模板")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BomImportDto> excelUtil = new ExcelUtil<>(BomImportDto.class);
        excelUtil.importTemplateExcel(response, "BOM导入模板");
    }
 
}