| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.SopDto; |
| | |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | //文件名 |
| | | sop.setFileName(sheet.getRow(2).getCell(2).getStringCellValue()); |
| | | String fileName = sheet.getRow(2).getCell(2).getStringCellValue().trim(); |
| | | sop.setFileName(fileName); |
| | | //下面的row是动态的,因为文件类型的行数是动态拓展的 |
| | | //锚点:文件版本 |
| | | int fileVersionIndex = 0; |
| | |
| | | sop.setFileTypeList(fileTypeList); |
| | | |
| | | sop.setFileType(fileTypeSb.toString()); |
| | | |
| | | sop.setFileVersion(sheet.getRow(fileVersionIndex).getCell(2).getStringCellValue()); |
| | | //校验文件版本是否已经存在 |
| | | String fileVersion = sheet.getRow(fileVersionIndex).getCell(2).getStringCellValue().trim(); |
| | | QueryWrapper<SOP> query = Wrappers.query(); |
| | | query.select("file_version").eq("file_name",fileName); |
| | | List<SOP> sopListExists = mapper.selectList(query); |
| | | for (int i = 0; i < sopListExists.size(); i++) { |
| | | SOP sopExists = sopListExists.get(i); |
| | | if(sopExists.getFileVersion().equals(fileVersion)){ |
| | | return new Response().set(1,false,"文件版本已存在,请确认SOP版本是否正确!"); |
| | | } |
| | | } |
| | | sop.setFileVersion(fileVersion); |
| | | sop.setFileRelatedVersion(sheet.getRow(fileVersionIndex).getCell(7).getStringCellValue()); |
| | | |
| | | sop.setEditor(sheet.getRow(fileVersionIndex+1).getCell(2).getStringCellValue()); |
| | |
| | | |
| | | @Transactional |
| | | public Response add(SOP sop,MultipartFile multipartFile) throws IOException { |
| | | //是否存在旧版本,存在则把所有旧版本状态更新为0 |
| | | QueryWrapper<SOP> query = Wrappers.query(); |
| | | query.eq("file_name",sop.getFileName()).eq("status",1); |
| | | List<SOP> sopListExists = mapper.selectList(query); |
| | | if(sopListExists.size()>0){ |
| | | for (SOP sopExists : sopListExists) { |
| | | sopExists.setStatus(0); |
| | | mapper.updateById(sopExists); |
| | | } |
| | | } |
| | | |
| | | List<SOPProduct> sopProductList = sop.getSopProductList(); |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | String[] fileNameSplit = originalFilename.split("\\."); |
| | |
| | | //String fileUrlTemp = sop.getFileUrl(); |
| | | //fileUrlTemp = fileUrlTemp.replace("sop_submit", "sop"); |
| | | sop.setFileUrl(fileUrlTemp); |
| | | sop.setStatus(1); |
| | | mapper.insert(sop); |
| | | if(sopProductList.size()>0) { |
| | | sopProductList.forEach(product -> product.setSopId(sop.getId())); |
| | |
| | | } |
| | | return new Response().setII(1,"更新sop说明完成"); |
| | | } |
| | | |
| | | public Response updateStatusById(int id, int status) { |
| | | UpdateWrapper<SOP> update = Wrappers.update(); |
| | | update.set("status",status).eq("id",id); |
| | | mapper.update(null,update); |
| | | return new Response().setII(1,"设置完成"); |
| | | } |
| | | } |