|
|
|
@ -1,19 +1,28 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysMessageService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysTaskService;
|
|
|
|
|
import cn.estsh.i3plus.icloud.andon.sdk.IAndonCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.icloud.mes.pcn.sdk.IMesPcnCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.icloud.mes.sdk.IMesCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.icloud.ptl.sdk.IPtlCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.icloud.softswitch.sdk.IBsCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.icloud.wms.sdk.IWmsCommonCloud;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.FileTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ZipTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ImppFile;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysTask;
|
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
|
import cn.estsh.impp.framework.base.service.CommonServiceImpl;
|
|
|
|
@ -21,6 +30,8 @@ import cn.estsh.impp.framework.base.service.ICommonService;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
@ -28,14 +39,17 @@ import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 任务管理服务
|
|
|
|
@ -72,25 +86,41 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IBsCommonCloud bsCommonCloud;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IPtlCommonCloud ptlCommonCloud;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ImppFileService fileService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysFileService sysFileService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysMessageService sysMessageService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取对应软件模块的通用服务
|
|
|
|
|
*
|
|
|
|
|
* @param softType 软件模块
|
|
|
|
|
* @return 通用服务
|
|
|
|
|
*/
|
|
|
|
|
private ICommonService getCommonService(int softType){
|
|
|
|
|
private ICommonService getCommonService(int softType) {
|
|
|
|
|
ICommonService commonService = coreCommonService;
|
|
|
|
|
|
|
|
|
|
// 平台
|
|
|
|
|
if(softType == CommonEnumUtil.SOFT_TYPE.CORE.getValue()){
|
|
|
|
|
if (softType == CommonEnumUtil.SOFT_TYPE.CORE.getValue()) {
|
|
|
|
|
commonService = coreCommonService;
|
|
|
|
|
// WMS
|
|
|
|
|
} else if(softType == CommonEnumUtil.SOFT_TYPE.WMS.getValue()){
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.WMS.getValue()) {
|
|
|
|
|
commonService = wmsCommonCloud;
|
|
|
|
|
// MES
|
|
|
|
|
} else if(softType == CommonEnumUtil.SOFT_TYPE.MES.getValue()){
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.MES.getValue()) {
|
|
|
|
|
commonService = mesCommonCloud;
|
|
|
|
|
// MES_PCN
|
|
|
|
|
} else if(softType == CommonEnumUtil.SOFT_TYPE.MES_PCN.getValue()){
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.MES_PCN.getValue()) {
|
|
|
|
|
commonService = mesPcnCommonCloud;
|
|
|
|
|
// ANDON
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.ANDON.getValue()) {
|
|
|
|
@ -98,12 +128,16 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
// SoftSwitch
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.SOFTSWITCH.getValue()) {
|
|
|
|
|
commonService = bsCommonCloud;
|
|
|
|
|
// Ptl
|
|
|
|
|
} else if (softType == CommonEnumUtil.SOFT_TYPE.PTL.getValue()) {
|
|
|
|
|
commonService = ptlCommonCloud;
|
|
|
|
|
}
|
|
|
|
|
return commonService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加任务
|
|
|
|
|
*
|
|
|
|
|
* @param sysTask 任务
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
@ -120,7 +154,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
// 类校验
|
|
|
|
|
BaseResultBean resultBean = getCommonService(sysTask.getTaskSoftType()).isExistClass(sysTask.getTaskPackage(), sysTask.getTaskClass());
|
|
|
|
|
if(!resultBean.isSuccess()){
|
|
|
|
|
if (!resultBean.isSuccess()) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
|
|
|
|
@ -128,6 +162,15 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sysTaskService.checkSysTaskOnly(sysTask)) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("任务名称【%s】必须唯一", sysTask.getName())
|
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置组织代码
|
|
|
|
|
sysTask.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
|
|
|
|
|
|
|
|
|
@ -142,6 +185,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改任务
|
|
|
|
|
*
|
|
|
|
|
* @param sysTask 任务
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
@ -156,6 +200,25 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
.notNull("taskPackage", sysTask.getTaskPackage())
|
|
|
|
|
.notNull("taskClass", sysTask.getTaskClass());
|
|
|
|
|
|
|
|
|
|
// 类校验
|
|
|
|
|
BaseResultBean resultBean = getCommonService(sysTask.getTaskSoftType()).isExistClass(sysTask.getTaskPackage(), sysTask.getTaskClass());
|
|
|
|
|
if (!resultBean.isSuccess()) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
|
|
|
|
|
.setErrorDetail(resultBean.errorMsg)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sysTaskService.checkSysTaskOnly(sysTask)) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("任务名称【%s】必须唯一", sysTask.getName())
|
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sysTaskService.updateSysTask(sysTask);
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
@ -167,6 +230,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除任务
|
|
|
|
|
*
|
|
|
|
|
* @param idStr 任务id
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
@ -198,6 +262,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有任务
|
|
|
|
|
*
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
@ -216,6 +281,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 任务复杂查询
|
|
|
|
|
*
|
|
|
|
|
* @param sysTask 查询条件
|
|
|
|
|
* @param pager 分页信息
|
|
|
|
|
* @return 处理结果
|
|
|
|
@ -235,6 +301,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据id批量删除任务
|
|
|
|
|
*
|
|
|
|
|
* @param idsStr 任务id
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
@ -260,6 +327,7 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据code查询任务
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/get-code/{code}")
|
|
|
|
@ -278,4 +346,129 @@ public class SysTaskController extends CoreBaseController {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************** 数据导入导出 ***********************************************/
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/export")
|
|
|
|
|
@ApiOperation(value = "导出数据")
|
|
|
|
|
public ResultBean<SysTask> exportExcel(SysTask bean, boolean needSendMessage) {
|
|
|
|
|
ListPager<SysTask> listPager;
|
|
|
|
|
List<SysFile> result = new ArrayList<>();
|
|
|
|
|
File zipFile = null;
|
|
|
|
|
File excelDir = null;
|
|
|
|
|
File excelFile;
|
|
|
|
|
ExcelTool excelTool;
|
|
|
|
|
try {
|
|
|
|
|
Pager pager = new Pager(0);
|
|
|
|
|
// 判断是否超过excel最大导出数量设定值
|
|
|
|
|
pager.setPageSize(RedisCacheTool.getSysConfigIntVal(PlatformConstWords.EXCEL_EXPORT_MAX_ROW, 20000));
|
|
|
|
|
|
|
|
|
|
// 数据校验
|
|
|
|
|
Map<String, String> colMap = ExcelTool.getColName(SysTask.class);
|
|
|
|
|
String[] colName = new String[colMap.size()];
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (String key : colMap.keySet()) {
|
|
|
|
|
colName[i++] = key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
excelTool = new ExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
|
|
|
|
excelDir = new File(System.getProperty("java.io.tmpdir") + File.separator + new Date().getTime());
|
|
|
|
|
excelDir.mkdir();
|
|
|
|
|
do {
|
|
|
|
|
listPager = sysTaskService.querySysTaskByPager(bean, pager);
|
|
|
|
|
pager = listPager.getObjectPager();
|
|
|
|
|
|
|
|
|
|
// 将excel导出至临时文件夹
|
|
|
|
|
excelFile = new File(MessageFormat.format("{0}{1}{2}{3}.xls", excelDir, File.separator, SysTask.class.getSimpleName(),
|
|
|
|
|
pager.getCurrentPage()));
|
|
|
|
|
excelFile.createNewFile();
|
|
|
|
|
excelTool.exportData(excelFile, listPager.getObjectList(), SysTask.class, colName);
|
|
|
|
|
|
|
|
|
|
pager.setCurrentPage(pager.getCurrentPage() + 1);
|
|
|
|
|
} while (pager.getCurrentPage() <= pager.getTotalPages());
|
|
|
|
|
|
|
|
|
|
// 将所有excel文件打包上传
|
|
|
|
|
zipFile = ZipTool.zipFile(null, excelDir);
|
|
|
|
|
SysFile sysFile = fileService.upload(new FileInputStream(zipFile), zipFile.getName(),
|
|
|
|
|
StringTool.getStringFileSuffix(zipFile.getName(), true), CommonEnumUtil.SOFT_TYPE.CORE.getValue());
|
|
|
|
|
|
|
|
|
|
result.add(sysFileService.insertSysFile(sysFile));
|
|
|
|
|
|
|
|
|
|
// 是否发送站内信
|
|
|
|
|
if (needSendMessage) {
|
|
|
|
|
sysMessageService.insertSysMessage(ExcelTool.sendStationLetter(result, getSessionUser().getUser().getId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(result);
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
} finally {
|
|
|
|
|
// 清理临时文件文件
|
|
|
|
|
if (zipFile != null) {
|
|
|
|
|
FileTool.deleteFile(zipFile.getPath());
|
|
|
|
|
}
|
|
|
|
|
if (excelDir != null) {
|
|
|
|
|
FileTool.deleteFile(excelDir.getPath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/import")
|
|
|
|
|
@ApiOperation(value = "导入数据")
|
|
|
|
|
public ResultBean importExcel(@RequestParam("file") MultipartFile file) {
|
|
|
|
|
try {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
|
|
|
|
List<SysTask> beanList = excelTool.importData(file.getOriginalFilename(), file.getInputStream(), SysTask.class);
|
|
|
|
|
|
|
|
|
|
// 校验导入数据并初始化
|
|
|
|
|
for (SysTask sysTask : beanList) {
|
|
|
|
|
if (!sysTaskService.checkSysTaskOnly(sysTask)) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("任务名称【%s】必须唯一", sysTask.getName())
|
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConvertBean.modelInitialize(sysTask, AuthUtil.getSessionUser());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sysTaskService.insertBatchSysTask(beanList);
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("导入成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/down-template")
|
|
|
|
|
@ApiOperation(value = "下载导入模板")
|
|
|
|
|
public ResultBean downExcelTemplate() {
|
|
|
|
|
try {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
|
|
|
|
String importTemplateCode = "SysTaskImportTemplate";
|
|
|
|
|
|
|
|
|
|
// 查询服务器中是否存在模板文件
|
|
|
|
|
ImppFile fastDFSFile = new ImppFile("SysTaskImportTemplate.xls",
|
|
|
|
|
excelTool.importTemplate(SysTask.class), ".xls");
|
|
|
|
|
|
|
|
|
|
SysFile sysFile = sysFileService.getSysFileByFileCode(importTemplateCode);
|
|
|
|
|
if (sysFile == null) {
|
|
|
|
|
sysFile = fileService.upload(fastDFSFile, CommonEnumUtil.SOFT_TYPE.CORE.getValue());
|
|
|
|
|
sysFile.setFileCode(importTemplateCode);
|
|
|
|
|
sysFile = sysFileService.insertSysFile(sysFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(sysFile);
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|