| | |
| | | package org.jeecg.modules.base.controller; |
| | | |
| | | import java.io.File; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLDecoder; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.base.entity.Supplier; |
| | | import org.jeecg.modules.base.service.ISupplierService; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | | import org.jeecgframework.poi.excel.entity.ImportParams; |
| | | import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.modules.base.entity.Supplier; |
| | | import org.jeecg.modules.base.entity.SupplierCategory; |
| | | import org.jeecg.modules.base.service.ISupplierCategoryService; |
| | | import org.jeecg.modules.base.service.ISupplierService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import com.alibaba.fastjson.JSON; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: 供应商 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2023-03-10 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Api(tags="供应商") |
| | | /** |
| | | * @Description: 供应商管理 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-06-24 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Api(tags="供应商管理") |
| | | @RestController |
| | | @RequestMapping("/eam/supplier") |
| | | @RequestMapping("/base/supplier") |
| | | @Slf4j |
| | | public class SupplierController extends JeecgController<Supplier, ISupplierService> { |
| | | @Autowired |
| | | private ISupplierService inspectionProjectService; |
| | | @Autowired |
| | | private ISupplierCategoryService inspectionProjectCategoryService; |
| | | |
| | | @Autowired |
| | | private ISupplierService supplierService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | | * @param supplier |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param req |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "供应商管理-分页列表查询") |
| | | @ApiOperation(value="供应商管理-分页列表查询", notes="供应商管理-分页列表查询") |
| | | @GetMapping(value = "/list") |
| | | public Result<IPage<Supplier>> queryPageList(Supplier supplier, |
| | | @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
| | | @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<Supplier> queryWrapper = QueryGenerator.initQueryWrapper(supplier, req.getParameterMap()); |
| | | Page<Supplier> page = new Page<Supplier>(pageNo, pageSize); |
| | | IPage<Supplier> pageList = supplierService.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param supplier |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商管理-添加") |
| | | @ApiOperation(value="供应商管理-添加", notes="供应商管理-添加") |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:add") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody Supplier supplier) { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_1); |
| | | supplierService.save(supplier); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param supplier |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商管理-编辑") |
| | | @ApiOperation(value="供应商管理-编辑", notes="供应商管理-编辑") |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:edit") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| | | public Result<String> edit(@RequestBody Supplier supplier) { |
| | | supplierService.updateById(supplier); |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商管理-通过id删除") |
| | | @ApiOperation(value="供应商管理-通过id删除", notes="供应商管理-通过id删除") |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:delete") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<String> delete(@RequestParam(name="id",required=true) String id) { |
| | | supplierService.removeById(id); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商管理-批量删除") |
| | | @ApiOperation(value="供应商管理-批量删除", notes="供应商管理-批量删除") |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:deleteBatch") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { |
| | | this.supplierService.removeByIds(Arrays.asList(ids.split(","))); |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id查询 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "供应商管理-通过id查询") |
| | | @ApiOperation(value="供应商管理-通过id查询", notes="供应商管理-通过id查询") |
| | | @GetMapping(value = "/queryById") |
| | | public Result<Supplier> queryById(@RequestParam(name="id",required=true) String id) { |
| | | Supplier supplier = supplierService.getById(id); |
| | | if(supplier==null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | return Result.OK(supplier); |
| | | } |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | | * @param inspectionProject |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @ApiOperation(value="供应商-分页列表查询", notes="供应商-分页列表查询") |
| | | @GetMapping(value = "/list") |
| | | public Result<IPage<Supplier>> queryPageList(Supplier inspectionProject, |
| | | @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
| | | @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<Supplier> queryWrapper = QueryGenerator.initQueryWrapper(inspectionProject, req.getParameterMap()); |
| | | Page<Supplier> page = new Page<Supplier>(pageNo, pageSize); |
| | | IPage<Supplier> pageList = inspectionProjectService.page(page, queryWrapper); |
| | | List<Supplier> records = pageList.getRecords(); |
| | | for (Supplier record : records) { |
| | | String inspectionProjectTypeId = record.getSupplierCategoryId(); |
| | | SupplierCategory inspectionProjectCategory = inspectionProjectCategoryService.getById(inspectionProjectTypeId); |
| | | if(inspectionProjectCategory != null ){ |
| | | record.setSupplierCategoryNumName(inspectionProjectCategory.getNum()+"/"+ inspectionProjectCategory.getName()); |
| | | }else{ |
| | | record.setSupplierCategoryNumName("/"); |
| | | } |
| | | |
| | | } |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param inspectionProject |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商-添加") |
| | | @ApiOperation(value="供应商-添加", notes="供应商-添加") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody Supplier inspectionProject) { |
| | | inspectionProjectService.save(inspectionProject); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param inspectionProject |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商-编辑") |
| | | @ApiOperation(value="供应商-编辑", notes="供应商-编辑") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| | | public Result<String> edit(@RequestBody Supplier inspectionProject) { |
| | | inspectionProjectService.updateById(inspectionProject); |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商-通过id删除") |
| | | @ApiOperation(value="供应商-通过id删除", notes="供应商-通过id删除") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<String> delete(@RequestParam(name="id",required=true) String id) { |
| | | Supplier inspectionProject = inspectionProjectService.getById(id); |
| | | inspectionProject.setDelFlag(1); |
| | | inspectionProjectService.updateById(inspectionProject); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "供应商-批量删除") |
| | | @ApiOperation(value="供应商-批量删除", notes="供应商-批量删除") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { |
| | | List<String> idList = Arrays.asList(ids.split(",")); |
| | | for (String id : idList) { |
| | | Supplier inspectionProject = inspectionProjectService.getById(id); |
| | | inspectionProject.setDelFlag(1); |
| | | inspectionProjectService.updateById(inspectionProject); |
| | | } |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id查询 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value="供应商-通过id查询", notes="供应商-通过id查询") |
| | | @GetMapping(value = "/queryById") |
| | | public Result<Supplier> queryById(@RequestParam(name="id",required=true) String id) { |
| | | Supplier inspectionProject = inspectionProjectService.getById(id); |
| | | if(inspectionProject==null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | return Result.OK(inspectionProject); |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param request |
| | | * @param inspectionProject |
| | | */ |
| | | * 导出excel |
| | | * |
| | | * @param request |
| | | * @param supplier |
| | | */ |
| | | //@RequiresPermissions("org.jeecg.modules:base_supplier:exportXls") |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, Supplier inspectionProject) { |
| | | return super.exportXls(request, inspectionProject, Supplier.class, "mom_base_supplier"); |
| | | public ModelAndView exportXls(HttpServletRequest request, Supplier supplier) { |
| | | return super.exportXls(request, supplier, Supplier.class, "供应商管理"); |
| | | } |
| | | |
| | | /** |
| | | * 通过excel导入数据 |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | * 通过excel导入数据 |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | //@RequiresPermissions("base_supplier:importExcel") |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | return super.importExcel(request, response, Supplier.class); |
| | | } |
| | | |
| | | |
| | | @AutoLog(value = "供应商-启用&禁用") |
| | | @ApiOperation(value = "供应商-启用&禁用", notes = "供应商-启用&禁用") |
| | | @PutMapping(value = "/active") |
| | | public Result<?> active(@RequestParam(name = "id", required = true) String id) { |
| | | Supplier supplier = supplierService.getById(id); |
| | | if (CommonConstant.STATUS_1.equals(supplier.getSupplierStatus())) { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_0); |
| | | } else { |
| | | supplier.setSupplierStatus(CommonConstant.STATUS_1); |
| | | } |
| | | supplierService.updateById(supplier); |
| | | return Result.ok("操作成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 导入模板下载 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/loadTemplate") |
| | | public void loadTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | |
| | | Map<String,String[]> req = request.getParameterMap(); |
| | | Workbook workbook = WorkbookFactory.create(new File("D:\\opt\\upFiles\\供应商信息导入模板.xlsx")); |
| | | //导出Workbook |
| | | //设置响应头 |
| | | String fileName = "供应商信息导入模板.xlsx"; |
| | | // 对文件名进行URL编码,防止中文乱码 |
| | | String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName); |
| | | // 将Workbook写入响应输出流 |
| | | try { // try-with-resources自动关闭资源 |
| | | workbook.write(response.getOutputStream()); |
| | | response.flushBuffer(); |
| | | } catch (IOException e) { |
| | | // 异常处理(如记录日志) |
| | | throw new IOException("下载模板失败", e); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |