导入模板管理开发

tags/yfai-mes-ext-v1.0
jun 11 months ago
parent 4bd046e407
commit 3c81d6cf8a

@ -1,33 +0,0 @@
package cn.estsh.i3plus.ext.mes.api.base.file;
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* @Description :
* @Reference :
* @Author : junsheng.li
* @CreateDate 2024/6/17 14:19
* @Modify:
**/
public interface IMesFileService {
/**
*
* @param file
* @return
*/
@ApiOperation(value = "上传文件", notes = "上传文件")
SysFile uploadFile(MultipartFile file);
/**
*
* @param resp
* @param fileUrl url
* @return
*/
void getFileByUrl(HttpServletResponse resp, String fileUrl);
}

@ -47,23 +47,4 @@ public interface IMesModuleExcelService extends IBaseMesService<MesModuleExcel>
*/
@ApiOperation(value = "更新模块EXCEL模板信息", notes = "更新模块EXCEL模板信息")
void updateModuleExcel(MultipartFile file, MesModuleExcel mesModuleExcel);
/**
* EXCEL
*
* @param resp
* @param fileUrl URL
*/
@ApiOperation(value = "下载模块EXCEL模板", notes = "下载模块EXCEL模板")
void doDownLoadModuleExcel(HttpServletResponse resp, String fileUrl);
/**
*
*
* @param organizeCode
* @param templateCode
* @return
*/
@ApiOperation(value = "获取文件", notes = "获取文件")
MesFile getTemplateFile(String organizeCode, String templateCode);
}

@ -5,6 +5,7 @@ import cn.estsh.i3plus.ext.mes.apiservice.controller.base.BaseMesController;
import cn.estsh.i3plus.ext.mes.apiservice.unit.exception.MesException;
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesModuleExcel;
@ -16,15 +17,12 @@ import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* @Description : EXCEL
* @Reference :
@ -67,7 +65,7 @@ public class MesModuleExcelController extends BaseMesController<MesModuleExcel>
.notNull(MesExtConstWords.MODULE_NAME, mesModuleExcel.getModuleName());
mesModuleExcel.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
mesModuleExcel.setCreateUser(AuthUtil.getSessionUser().getUserName());
ConvertBean.serviceModelUpdate(mesModuleExcel, AuthUtil.getSessionUser().getUserName());
moduleExcelService.insertModuleExcel(file, mesModuleExcel);
return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
@ -88,7 +86,7 @@ public class MesModuleExcelController extends BaseMesController<MesModuleExcel>
.notNull(MesExtConstWords.MODULE_NAME, mesModuleExcel.getModuleName());
mesModuleExcel.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
mesModuleExcel.setModifyUser(AuthUtil.getSessionUser().getUserName());
ConvertBean.serviceModelUpdate(mesModuleExcel, AuthUtil.getSessionUser().getUserName());
moduleExcelService.updateModuleExcel(file, mesModuleExcel);
return ResultBean.success("修改成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
@ -98,21 +96,4 @@ public class MesModuleExcelController extends BaseMesController<MesModuleExcel>
}
}
@PostMapping(value = "/down-load")
@ApiOperation(value = "下载模块EXCEL模板")
public ResultBean doDownLoadModuleExcelManage(HttpServletResponse resp, String fileUrl) {
try {
if (StringUtils.isEmpty(fileUrl)) {
MesException.throwMesBusiException("请选择需要操作的资源。");
}
moduleExcelService.doDownLoadModuleExcel(resp, fileUrl);
return ResultBean.success("下载成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
}

@ -107,6 +107,7 @@ public class MesWorkOrderService extends BaseMesService<MesWorkOrder> implements
copyMesWorkOrder.setProduceSeq((long) (produceSeq + 1));
copyMesWorkOrder.setQty(1D);
copyMesWorkOrder.setWorkOrderNo(resultList.get(0));
copyMesWorkOrder.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
ConvertBean.serviceModelInitialize(copyMesWorkOrder, bean.getCreateUser());
MesWorkOrderLog workOrderLog = new MesWorkOrderLog();
@ -136,7 +137,7 @@ public class MesWorkOrderService extends BaseMesService<MesWorkOrder> implements
List<String> resultList = syncFuncService.syncSerialNo(genSerialNoModel, bean.getCreateUser(), bean.getOrganizeCode(), 1).getResultList();
bean.setWorkOrderNo(resultList.get(0));
bean.setQty(bean.getQty());
bean.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
ConvertBean.serviceModelInitialize(bean, bean.getCreateUser());
MesWorkOrderLog workOrderLog = new MesWorkOrderLog();
@ -251,14 +252,15 @@ public class MesWorkOrderService extends BaseMesService<MesWorkOrder> implements
if (bean.getWorkOrderStatus() > 0) {
result.setWorkOrderStatus(bean.getWorkOrderStatus());
}
ConvertBean.serviceModelInitialize(bean, AuthUtil.getSessionUser().getUserName());
result.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
ConvertBean.serviceModelInitialize(result, AuthUtil.getSessionUser().getUserName());
MesWorkOrderLog workOrderLog = new MesWorkOrderLog();
BeanUtils.copyProperties(result, workOrderLog, "id");
workOrderLogService.insert(workOrderLog);
baseRDao.update(result);
return bean;
return result;
}

@ -1,136 +0,0 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.file;
import cn.estsh.i3plus.ext.mes.api.base.file.IMesFileService;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/**
* @Description :
* @Reference :
* @Author : junsheng.li
* @CreateDate 2024/6/17 14:21
* @Modify:
**/
@Slf4j
@Service
public class MesFileServiceImpl implements IMesFileService {
@Autowired
private ImppFileService imppFileService;
@Override
public SysFile uploadFile(MultipartFile file) {
SysFile sysFile;
try {
log.info("文件大小{}", file.getBytes().length);
sysFile = save2FastDfs(file);
log.info("after save2FastDfs {}", sysFile);
} catch (IOException e) {
log.error("FastDFS上传文件出错{}", e.getMessage() + "\r" + e.getStackTrace());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.IO_EXCEPTION_FILE.getCode())
.setErrorDetail("上传文件至文件服务器出错了。信息为:%s", e.getMessage())
.build();
}
if (null == sysFile) {
log.error("FastDFS上传文件出错");
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.IO_EXCEPTION_FILE.getCode())
.setErrorDetail("FastDFS上传文件出错")
.build();
}
if (StringUtils.isEmpty(sysFile.getFileTypeId())) {
log.error("FastDFS上传文件出错{}", "未在字典中定义该文件类型无法上传成功请先添加file_type字典");
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.IO_EXCEPTION_FILE.getCode())
.setErrorDetail("未在字典中定义该文件类型无法上传成功请先添加file_type字典")
.build();
}
return sysFile;
}
/**
* FastDfs
*
* @param multipartFile
* @return URL
* @throws IOException
*/
private SysFile save2FastDfs(MultipartFile multipartFile) throws IOException {
SysFile sysFile = imppFileService.upload(multipartFile, CommonEnumUtil.SOFT_TYPE.MES.getValue());
return sysFile;
}
@Override
public void getFileByUrl(HttpServletResponse resp, String fileUrl) {
InputStream inputStream = getInputStream(fileUrl);
writeFile(resp, inputStream);
}
private static InputStream getInputStream(String urlPath) {
InputStream inputStream = null;
HttpURLConnection httpURLConnection;
try {
URL url = new URL(urlPath);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(3000);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
int responseCode = httpURLConnection.getResponseCode();
System.out.println("responseCode is:" + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = httpURLConnection.getInputStream();
} else {
inputStream = httpURLConnection.getErrorStream();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return inputStream;
}
private static void writeFile(HttpServletResponse resp, InputStream inputStream) {
OutputStream out = null;
try {
out = resp.getOutputStream();
int len;
byte[] b = new byte[1024];
while ((len = inputStream.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -1,10 +1,11 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.file;
import cn.estsh.i3plus.ext.mes.api.base.file.IMesFileService;
import cn.estsh.i3plus.ext.mes.api.base.file.IMesModuleExcelService;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesModuleExcelDao;
import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.BaseMesService;
import cn.estsh.i3plus.ext.mes.apiservice.unit.exception.MesException;
import cn.estsh.i3plus.ext.mes.apiservice.utils.HuaWeiOBSUtil;
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.ext.mes.pojo.sqlpack.MesExtHqlPack;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
@ -12,20 +13,19 @@ import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesFile;
import cn.estsh.i3plus.pojo.mes.bean.MesModuleExcel;
import cn.estsh.i3plus.pojo.mes.model.MesModuleExcelModel;
import cn.estsh.i3plus.pojo.mes.repository.MesFileRepository;
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
import com.obs.services.model.PutObjectResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
@ -43,9 +43,6 @@ public class MesModuleExcelServiceImpl extends BaseMesService<MesModuleExcel> im
private IMesModuleExcelDao mesModuleExcelDao;
@Autowired
private IMesFileService mesFileService;
@Autowired
private MesFileRepository mesFileRDao;
@Override
@ -64,12 +61,6 @@ public class MesModuleExcelServiceImpl extends BaseMesService<MesModuleExcel> im
MesException.throwMesBusiException("模块代码【%s】记录已存在", mesModuleExcel.getModuleCode());
}
SysFile sysFile = mesFileService.uploadFile(file);
if (sysFile.getFileTypeId() == null) {
log.error("FastDFS上传文件出错{}", "未在字典中定义该文件类型无法上传成功请先添加file_type字典");
MesException.throwMesBusiException("未在字典中定义该文件类型无法上传成功请先添加file_type字典");
}
MesFile f = getMesFile(file, mesModuleExcel);
mesModuleExcel.setFileId(mesFileRDao.insert(f).getId());
ConvertBean.serviceModelInitialize(mesModuleExcel, mesModuleExcel.getCreateUser());
@ -83,10 +74,6 @@ public class MesModuleExcelServiceImpl extends BaseMesService<MesModuleExcel> im
MesException.throwMesBusiException("ID【%s】记录不存在", mesModuleExcel.getId());
}
if (file == null && StringUtils.isEmpty(mesModuleExcel.getFileId())) {
MesException.throwMesBusiException("上传的文件为null后台未能接收到");
}
//改变文件时清除fileUrl
if (StringUtils.isEmpty(mesModuleExcel.getFileUrl())) {
MesFile mesFile = getMesFile(file, mesModuleExcel);
@ -97,38 +84,23 @@ public class MesModuleExcelServiceImpl extends BaseMesService<MesModuleExcel> im
baseRDao.update(moduleExcelManageDb);
}
@Override
public void doDownLoadModuleExcel(HttpServletResponse resp, String fileUrl) {
mesFileService.getFileByUrl(resp, fileUrl);
}
@Override
public MesFile getTemplateFile(String organizeCode, String templateCode) {
MesModuleExcel moduleExcelManageDb = baseRDao.getByProperty(
new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.MODULE_CODE},
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), templateCode});
if (null == moduleExcelManageDb || StringUtils.isEmpty(moduleExcelManageDb.getFileId())) {
MesException.throwMesBusiException("模板代码为【%s】数据信息不存在", templateCode);
}
MesFile fileDb = mesFileRDao.getById(moduleExcelManageDb.getFileId());
if (null == fileDb || StringUtils.isEmpty(fileDb.getFileUrl())) {
MesException.throwMesBusiException("模板代码为【%s】对应文件信息不存在", templateCode);
}
return fileDb;
}
private MesFile getMesFile(MultipartFile file, MesModuleExcel mesModuleExcel) {
SysFile sysFile = mesFileService.uploadFile(file);
String fileName = file.getOriginalFilename();
PutObjectResult putObjectResult = null;
try {
putObjectResult = HuaWeiOBSUtil.putObjectByMultipartFile(MesCommonConstant.OBS_BUCKET_NAME, fileName, file);
} catch (IOException e) {
MesException.throwMesBusiException("文件上传失败");
}
MesFile mesFile = new MesFile();
mesFile.setOrganizeCode(mesModuleExcel.getOrganizeCode());
mesFile.setFileName(sysFile.getDfsFileName());
mesFile.setFileUrl(sysFile.getFilePath());
mesFile.setFileSize(String.valueOf(sysFile.getFileSize()));
mesFile.setFileType(String.valueOf(sysFile.getFileTypeName()));
mesFile.setFileOriginName(sysFile.getFileOriginalName());
mesFile.setGroupName(sysFile.getDfsGroupName());
mesFile.setSyncTag(0);
ConvertBean.serviceModelInitialize(mesFile, mesModuleExcel.getModifyUser());
mesFile.setFileName(fileName);
mesFile.setFileUrl(putObjectResult.getObjectUrl());
mesFile.setFileSize(String.valueOf(file.getSize()));
mesFile.setGroupName(putObjectResult.getBucketName());
mesFile.setFileType(fileName != null && fileName.contains(".") ? fileName.substring(fileName.indexOf(".") + 1) : "");
mesFile.setFileOriginName(fileName);
ConvertBean.serviceModelInitialize(mesFile, mesModuleExcel.getCreateUser());
return mesFile;
}

Loading…
Cancel
Save