| | |
| | | package org.springblade.mdm.basesetting.machine.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineExcelVO; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineImportService; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineExcel; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineQueryVO; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineSaveVO; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineVO; |
| | | import org.springblade.mdm.program.vo.MdmProgramImportVO; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springblade.mdm.basesetting.producedivision.vo.ImportResult; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | |
| | | @Autowired |
| | | private MachineService service; |
| | | |
| | | @Autowired |
| | | private MachineImportService machineImportService; |
| | | @Autowired |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | /** |
| | | * 新增 |
| | | */ |
| | |
| | | @Operation(summary = "修改", description = "机床信息") |
| | | @PostMapping("/update") |
| | | public R<Boolean> update(@RequestBody MachineSaveVO vo) { |
| | | return R.<Boolean>status(service.updateMachine(vo)); |
| | | try{ |
| | | return R.data(service.updateMachine(vo)); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Operation(summary = "详情", description = "查询机床详情") |
| | |
| | | @PostMapping("import") |
| | | @ApiOperationSupport(order = 1) |
| | | @Operation(summary = "机床导入", description = "机床导入,全部成功返回空串,部分成功返回具体信息") |
| | | public R<String> importMachines(@RequestParam MultipartFile file) { |
| | | public R<ImportResult> importMachines(@RequestParam MultipartFile file) { |
| | | try { |
| | | return R.data(service.importMachines(file)); |
| | | return R.data(machineImportService.importMachines(file)); |
| | | }catch (Exception e){ |
| | | log.error("导入错误",e); |
| | | return R.fail(e.getMessage()); |
| | |
| | | query.setSize(Integer.MAX_VALUE); |
| | | IPage<MachineVO> pages = service.pageQuery(query); |
| | | |
| | | List<MachineExcelVO> list = new ArrayList<>(); |
| | | List<MachineExcel> list = new ArrayList<>(); |
| | | pages.getRecords().forEach(m ->{ |
| | | MachineExcelVO excelVO = new MachineExcelVO(); |
| | | MachineExcel excelVO = new MachineExcel(); |
| | | BeanUtils.copyProperties(m, excelVO); |
| | | list.add(excelVO); |
| | | }); |
| | | |
| | | ExcelUtil.export(response, "机床数据" + DateUtil.time(), "机床数据表", list, MachineExcelVO.class); |
| | | ExcelUtil.export(response, "机床数据" + DateUtil.time(), "机床数据表", list, MachineExcel.class); |
| | | } |
| | | |
| | | @Operation(summary = "产生机床回传结构树", description = "产生机床回传结构树") |
| | | @PostMapping("/gen-fileback-dirs") |
| | | public R<Void> genFileBackDirs(@RequestParam Long id) { |
| | | @Operation(summary = "下载机床导入模板", description = "下载机床导入模板") |
| | | @GetMapping("/download-template") |
| | | public void downloadTemplate(HttpServletResponse response) { |
| | | String PARAMKEY = "MACHINE_TEMPLATE"; |
| | | |
| | | try { |
| | | service.genMachineFileBackDirs(id); |
| | | String filename = "machinetemplate.xlsx"; |
| | | response.setHeader("Content-Disposition", "attachment; filename="+filename); |
| | | response.setContentType("application/octet-stream"); |
| | | String ossName = paramService.getParamValue(PARAMKEY,""); |
| | | try(InputStream ins = ossTemplate.statFileStream(ossName);){ |
| | | IOUtils.copy(ins,response.getOutputStream()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("产生目录异常",e); |
| | | return R.fail(e.getMessage()); |
| | | log.error("导出分机床模板异常", e); |
| | | } |
| | | return R.status(true); |
| | | } |
| | | |
| | | } |