skyouc
2025-03-19 a65ca60179efb2bd6e1c8907a42285463512d3e2
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/MatnrController.java
@@ -12,15 +12,21 @@
import com.vincent.rsf.server.common.domain.KeyValVo;
import com.vincent.rsf.server.common.domain.PageParam;
import com.vincent.rsf.server.manager.entity.Matnr;
import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate;
import com.vincent.rsf.server.manager.service.MatnrService;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.*;
@RestController
@@ -106,8 +112,8 @@
        return R.ok().add(vos);
    }
    @SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
    @PreAuthorize("hasAuthority('manager:matnr:list')")
    @ApiOperation(value = "获取分类物料明细列表")
    @PostMapping("/matnr/group")
    public R getGroupMatnrs(@RequestBody  Map<String, Object> map) {
        BaseParam baseParam = buildParam(map, BaseParam.class);
@@ -124,12 +130,35 @@
        return R.ok(new PageResult().setRecords(matnrPage.getRecords()).setTotal(matnrPage.getTotal()));
    }
    @PreAuthorize("hasAuthority('manager:matnr:list')")
    @ApiOperation("导出物料信息")
    @PostMapping("/matnr/export")
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        ExcelUtil.build(ExcelUtil.create(matnrService.list(), Matnr.class), response);
        List<Matnr> matnrs = new ArrayList<>();
        if (!Objects.isNull(map.get("ids"))) {
            matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().in(Matnr::getId, map.get("ids")).eq(Matnr::getStatus, 1));
        } else {
            matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().last("limit 1"));
        }
        ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class, true), response);
    }
    @PreAuthorize("hasAuthority('manager:matnr:list')")
    @ApiOperation("下载物料模板")
    @PostMapping("/matnr/template/download")
    public void download(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class, true), response);
    }
    @PreAuthorize("hasAuthority('manager:matnr:update')")
    @ApiOperation(value = "excel表格导入物料信息")
    @PostMapping("/matnr/import")
    public R listImport(MultipartFile file) throws Exception {
        if (Objects.isNull(file)) {
            throw new CoolException("文件不能为空!!");
        }
       return matnrService.importExcels(file);
    }
}