| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletContext; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | */ |
| | | |
| | | @Transactional |
| | | public Response submit(WorkflowMain main){ |
| | | public Response submit(WorkflowMain main, List<MultipartFile> fileList, List<MultipartFile> picList) throws IOException { |
| | | //1.提交到单据审批流程 |
| | | //如果存在关联单据id,首先校验提交的数量 |
| | | Date now = new Date(); |
| | |
| | | deviceList.get(i).setQuantityUnprocessed(deviceList.get(i).getQuantity()); |
| | | } |
| | | } |
| | | //如果存在附件和图片,则存入对应字段 |
| | | //对存储路径进行定义 |
| | | String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now); |
| | | String dirMonth = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM, now); |
| | | String fileDirPath = CommonUtil.getRootFile() + "workflow" + File.separator + dirMonth; |
| | | File fileDir = new File(fileDirPath); |
| | | //如果文件夹不存在则创建 |
| | | if (!fileDir.exists()) { |
| | | fileDir.mkdirs(); |
| | | } |
| | | StringBuilder fileUrlSb = new StringBuilder(); |
| | | StringBuilder fileNameSb = new StringBuilder(); |
| | | if (fileList != null && fileList.size() > 0) { |
| | | for (int i = 0; i < fileList.size(); i++) { |
| | | MultipartFile multipartFile = fileList.get(i); |
| | | String fileName = multipartFile.getOriginalFilename(); |
| | | //将fileName中可能存在的,去掉 |
| | | fileName = fileName.replace(",",""); |
| | | String filePath = fileDirPath + File.separator + timeFormat+"_"+fileName; |
| | | |
| | | multipartFile.transferTo(new File(filePath)); |
| | | String split = "pis_file"+File.separator+"workflow"; |
| | | String fileUrl = File.separator + filePath.substring(filePath.indexOf(split)); |
| | | if(i == fileList.size()-1) { |
| | | fileUrlSb.append(fileUrl); |
| | | fileNameSb.append(fileName); |
| | | }else { |
| | | fileUrlSb.append(fileUrl).append(","); |
| | | fileNameSb.append(fileName).append(","); |
| | | } |
| | | } |
| | | } |
| | | main.setFileUrl(fileUrlSb.toString()); |
| | | main.setFileName(fileNameSb.toString()); |
| | | |
| | | StringBuilder picUrlSb = new StringBuilder(); |
| | | StringBuilder picNameSb = new StringBuilder(); |
| | | if (picList != null && picList.size() > 0) { |
| | | for (int i = 0; i < picList.size(); i++) { |
| | | MultipartFile multipartFile = picList.get(i); |
| | | String picName = multipartFile.getOriginalFilename(); |
| | | //将picName中可能存在的,去掉 |
| | | picName = picName.replace(",",""); |
| | | String picPath = fileDirPath + File.separator + picName; |
| | | multipartFile.transferTo(new File(picPath)); |
| | | String split = "pis_file"+File.separator+"workflow"; |
| | | String picUrl = File.separator + picPath.substring(picPath.indexOf(split)); |
| | | if(i == picList.size()-1) { |
| | | picUrlSb.append(picUrl); |
| | | picNameSb.append(picName); |
| | | }else { |
| | | picUrlSb.append(picUrl).append(","); |
| | | picNameSb.append(picName).append(","); |
| | | } |
| | | } |
| | | } |
| | | main.setPicUrl(picUrlSb.toString()); |
| | | main.setPicName(picNameSb.toString()); |
| | | add(main); |
| | | //主表关联的物料插入 |
| | | for (WorkflowDevice device : deviceList) { |