| | |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.MdmDept; |
| | | import org.springblade.mdm.gkw.programnode.entity.MachineFile; |
| | | import org.springblade.mdm.gkw.programnode.entity.MachineFileChangeHis; |
| | | import org.springblade.mdm.gkw.programnode.mapper.MachineFileMapper; |
| | | import org.springblade.mdm.gkw.programnode.vo.MachineFileQueryVO; |
| | | import org.springblade.mdm.machineback.vo.MachineBackFileHandleQueryVO; |
| | | import org.springblade.mdm.machineback.vo.MachineBackFileQueryVO; |
| | | import org.springblade.mdm.machineback.vo.MachineBackFileVO; |
| | |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 机床文件 |
| | |
| | | @AllArgsConstructor |
| | | public class MachineFileService extends BizServiceImpl<MachineFileMapper, MachineFile> { |
| | | private final MachineService machineService; |
| | | private final MachineFileChangeHisService machineFileChangeHisService; |
| | | private final OssTemplate ossTemplate; |
| | | /** |
| | | * 检测文件是否存在 |
| | | * @param name 文件名 |
| | |
| | | |
| | | String filePathStr = getBasePath(machine,machineFile.getDirType())+ File.separator+machineFile.getName(); |
| | | Path filePath = Paths.get(filePathStr); |
| | | |
| | | BladeFile bfile; |
| | | try (InputStream inputStream = Files.newInputStream(filePath)) { |
| | | bfile = ossTemplate.putFile(machineFile.getName(), inputStream); |
| | | } |
| | | String charsetName = "UTF-8"; |
| | | try (InputStream inputStream = Files.newInputStream(filePath)) { |
| | | // 使用输入流读取文件内容 |
| | | charsetName = FileContentUtil.detectFromInputStream(inputStream); |
| | | |
| | | //保存历史记录 |
| | | MachineFileChangeHis his = new MachineFileChangeHis(); |
| | | his.setMachineFileId(id); |
| | | his.setOssName(bfile.getName()); |
| | | |
| | | this.machineFileChangeHisService.save(his); |
| | | } catch (IOException e) { |
| | | log.error("读取文件编码失败",e); |
| | | throw new ServiceException("获取文件编码失败"); |
| | |
| | | IPage<MachineBackFileVO> page = this.getBaseMapper().handlePageQuery(Condition.getPage(query),query); |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 机床文件分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | public IPage<MachineFile> pageQuery(MachineFileQueryVO query) { |
| | | return baseMapper.pageQuery(Condition.getPage(query),query); |
| | | } |
| | | } |