forked from I3-YF/i3plus-mes-yfai
基础属性新增
parent
aa619aa98c
commit
f73f5e4b11
@ -0,0 +1,63 @@
|
||||
package cn.estsh.i3plus.ext.mes.api.base;
|
||||
|
||||
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
|
||||
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 io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @CreateDate 2021/10/20 10:27
|
||||
* @Author 尹肖
|
||||
*/
|
||||
public interface IBaseMesService<T extends BaseBean> {
|
||||
|
||||
/**
|
||||
* 获取当前服务Class
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<T> getMesClass();
|
||||
|
||||
@ApiOperation(value = "查询列表", notes = "组合查询,外带分页功能")
|
||||
ListPager<T> queryPager(T bean, Pager pager);
|
||||
|
||||
@ApiOperation(value = "查询列表", notes = "组合查询,外带分页功能")
|
||||
ListPager<T> queryPagerWhere(Pager pager, DdlPackBean packBean);
|
||||
|
||||
@ApiOperation(value = "查询列表", notes = "查询所有数据")
|
||||
List<T> findAll(DdlPackBean packBean);
|
||||
|
||||
@ApiOperation(value = "查询数据", notes = "根据ID查询信息")
|
||||
T get(Long id);
|
||||
|
||||
@ApiOperation(value = "新增信息", notes = "新增信息")
|
||||
T insert(T bean);
|
||||
|
||||
@ApiOperation(value = "批量新增数据", notes = "批量新增数据")
|
||||
List<T> insertBatch(List<T> bean);
|
||||
|
||||
@ApiOperation(value = "修改信息", notes = "修改信息")
|
||||
T update(T bean);
|
||||
|
||||
@ApiOperation(value = "批量修改信息", notes = "批量修改信息")
|
||||
void updates(Iterable<T> beans);
|
||||
|
||||
@ApiOperation(value = "删除数据", notes = "根据ID软删除信息")
|
||||
void deleteWeaklyById(Long id, String userName);
|
||||
|
||||
@ApiOperation(value = "删除数据", notes = "根据ID批量删除信息")
|
||||
void deleteWeaklyByIds(Long[] ids, String userName);
|
||||
|
||||
@ApiOperation(value = "强删除数据", notes = "根据ID强删除")
|
||||
void deleteById(Long id);
|
||||
|
||||
@ApiOperation(value = "强删除数据", notes = "根据ID批量强删除")
|
||||
void deleteByIds(Long[] ids);
|
||||
|
||||
@ApiOperation(value = "根据id更新启用或禁用", notes = "根据id更新启用或禁用")
|
||||
int updateValid(Long id, int status, String userName);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cn.estsh.i3plus.ext.mes.apiservice.config;
|
||||
|
||||
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @CreateDate: 2022/11/25 13:46
|
||||
* @Author: simon.song
|
||||
*/
|
||||
public class AuthUtilExt {
|
||||
|
||||
public static String getOrganizeCode() {
|
||||
return AuthUtil.getOrganize().getOrganizeCode();
|
||||
// return "22060";
|
||||
}
|
||||
public static String getUserCode() {
|
||||
return AuthUtil.getSessionUser().getUserCode();
|
||||
}
|
||||
public static String getUserName() {
|
||||
return AuthUtil.getSessionUser().getUserName();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,483 @@
|
||||
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.api.base.IBaseMesService;
|
||||
import cn.estsh.i3plus.ext.mes.apiservice.config.AuthUtilExt;
|
||||
import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel.MesExcelTool;
|
||||
import cn.estsh.i3plus.icloud.core.sdk.ICoreMessageCloud;
|
||||
import cn.estsh.i3plus.icloud.core.sdk.ICoreSysFileCloud;
|
||||
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.*;
|
||||
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.impp.framework.base.controller.BaseController;
|
||||
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.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.lang.reflect.ParameterizedType;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : yx
|
||||
* @CreateDate : 2020-05-20 18:16
|
||||
* @Modify:
|
||||
**/
|
||||
public abstract class BaseMesController<T extends BaseBean> extends BaseController {
|
||||
/**
|
||||
* 主数据Service对象
|
||||
*/
|
||||
@Autowired
|
||||
protected IBaseMesService<T> baseService;
|
||||
/**
|
||||
* entityManager 用于导入导出
|
||||
*/
|
||||
@Autowired
|
||||
protected EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* fastDfs客户端
|
||||
*/
|
||||
@Autowired
|
||||
private ImppFileService fileService;
|
||||
|
||||
@Autowired
|
||||
private ICoreSysFileCloud coreSysFileCloud;
|
||||
|
||||
@Autowired
|
||||
private ICoreMessageCloud coreMessageCloud;
|
||||
|
||||
/**
|
||||
* 泛型class对象
|
||||
*/
|
||||
protected final Class<T> mesClass;
|
||||
|
||||
public BaseMesController() {
|
||||
// 通过反射获取泛型的真实类型
|
||||
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
|
||||
mesClass = (Class<T>) pt.getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
//初始化dao
|
||||
public IBaseMesService<T> getBaseService() {
|
||||
return baseService;
|
||||
}
|
||||
|
||||
//插入时验证
|
||||
public void validateInsert(T bean) throws NoSuchFieldException {
|
||||
/* 新增数据校验 */
|
||||
ValidatorBean.beginValid(bean);
|
||||
}
|
||||
|
||||
//插入后执行
|
||||
public void afterInsert(T t) {
|
||||
//子类实现
|
||||
}
|
||||
|
||||
//修改时验证
|
||||
public void validateUpdate(T bean) throws NoSuchFieldException {
|
||||
/* 修改数据检查 */
|
||||
ValidatorBean.beginValid(bean).checkNotZero("id", bean.getId());
|
||||
}
|
||||
|
||||
//修改时验证
|
||||
private void validateUpdateValid(Long id) {
|
||||
if (id == null) throw new ImppBusiException("请选择需要操作的数据");
|
||||
}
|
||||
|
||||
//修改后执行
|
||||
public void afterUpdate(T t) {
|
||||
//子类实现
|
||||
}
|
||||
|
||||
//导入时验证
|
||||
public void validateImport(List<T> beanList) throws NoSuchFieldException {
|
||||
/* 新增数据校验 */
|
||||
ValidatorBean.beginValid(beanList);
|
||||
}
|
||||
|
||||
//导入时验证
|
||||
public void afterImport(List<T> beanList) throws NoSuchFieldException {
|
||||
}
|
||||
|
||||
//查询后执行
|
||||
public void afterGet(T t) {
|
||||
//子类实现
|
||||
}
|
||||
|
||||
//查询后执行
|
||||
public void afterList(List<T> l) {
|
||||
//子类实现
|
||||
}
|
||||
|
||||
//查询所有时的默认条件
|
||||
private DdlPackBean listAllPackBean = null;
|
||||
|
||||
public void setListAllPackBean(DdlPackBean packBean) {
|
||||
this.listAllPackBean = packBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询信息 分页 + 组合
|
||||
*
|
||||
* @param bean
|
||||
* @param pager
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/query")
|
||||
@ApiOperation(value = "查询信息带分页", notes = "组合查询,外带分页功能")
|
||||
public ResultBean<T> queryByPager(T bean, Pager pager) {
|
||||
try {
|
||||
bean.setOrganizeCode(AuthUtilExt.getOrganizeCode());
|
||||
ListPager<T> listPager = getBaseService().queryPager(bean, pager);
|
||||
return ResultBean.success("操作成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
|
||||
.setListPager(listPager);
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/list")
|
||||
@ApiOperation(value = "查询所有信息", notes = "查询所有数据")
|
||||
public ResultBean<T> list() {
|
||||
try {
|
||||
if (listAllPackBean == null) {
|
||||
//默认查询所有
|
||||
listAllPackBean = DdlPackBean.getDdlPackBean(AuthUtil.getOrganizeCode());
|
||||
}
|
||||
List<T> list = getBaseService().findAll(listAllPackBean);
|
||||
afterList(list);
|
||||
|
||||
return ResultBean.success("操作成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
|
||||
.setResultList(list);
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get/{id}")
|
||||
@ApiOperation(value = "根据ID查询信息", notes = "根据ID查询信息")
|
||||
public ResultBean<T> getById(@PathVariable("id") Long id) {
|
||||
try {
|
||||
// 参数校验
|
||||
ValidatorBean.checkIsNumber(id, ImppExceptionEnum.PARAMETER_EXCEPTION.getDescription());
|
||||
T t = (T) getBaseService().get(id);
|
||||
afterGet(t);
|
||||
return ResultBean.success("操作成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
|
||||
.setResultObject(t);
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/insert")
|
||||
@ApiOperation(value = "新增信息")
|
||||
public ResultBean<T> insert(@RequestBody T bean) {
|
||||
try {
|
||||
validateInsert(bean);
|
||||
//新增初始化
|
||||
bean.setOrganizeCode(AuthUtilExt.getOrganizeCode());
|
||||
ConvertBean.serviceModelInitialize(bean, AuthUtil.getSessionUser().getUserName());
|
||||
T t = (T) getBaseService().insert(bean);
|
||||
afterInsert(t);
|
||||
return ResultBean.success("操作成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
|
||||
.setResultObject(t);
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e).build();
|
||||
} catch (Exception e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
@ApiOperation(value = "修改信息", notes = "修改信息")
|
||||
public ResultBean<T> update(@RequestBody T bean) {
|
||||
try {
|
||||
bean.setOrganizeCode(AuthUtilExt.getOrganizeCode());
|
||||
validateUpdate(bean);
|
||||
T t = getBaseService().update(bean);
|
||||
afterUpdate(t);
|
||||
return ResultBean.success("修改成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
} catch (Exception e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update-list")
|
||||
@ApiOperation(value = "批量修改信息", notes = "批量修改信息")
|
||||
public ResultBean<T> updateList(List<T> beans) {
|
||||
try {
|
||||
String organizeCode = AuthUtilExt.getOrganizeCode();
|
||||
for (T bean : beans) {
|
||||
bean.setOrganizeCode(organizeCode);
|
||||
validateUpdate(bean);
|
||||
T t = getBaseService().update(bean);
|
||||
afterUpdate(t);
|
||||
}
|
||||
return ResultBean.success("修改成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
} catch (Exception e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete-weakly-id")
|
||||
@ApiOperation(value = "软删除信息")
|
||||
public ResultBean<T> batchDeleteWeaklyByIds(@PathVariable("ids") Long id) {
|
||||
try {
|
||||
// 数据校验
|
||||
ValidatorBean.checkNotNull(id, "请选择需要删除的信息");
|
||||
getBaseService().deleteWeaklyById(id, AuthUtil.getSessionUser().getUserName());
|
||||
return ResultBean.success("删除信息成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete-weakly")
|
||||
@ApiOperation(value = "批量软删除信息")
|
||||
public ResultBean<T> batchDeleteWeaklyByIds(@RequestBody Long[] ids) {
|
||||
try {
|
||||
// 数据校验
|
||||
ValidatorBean.checkNotNull(ids, "请选择需要删除的信息");
|
||||
getBaseService().deleteWeaklyByIds(ids, AuthUtil.getSessionUser().getUserName());
|
||||
return ResultBean.success("批量删除信息成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete-id/{ids}")
|
||||
@ApiOperation(value = "强删除信息")
|
||||
public ResultBean<T> batchDeleteByIds(@PathVariable("ids") Long id) {
|
||||
try {
|
||||
// 数据校验
|
||||
ValidatorBean.checkNotNull(id, "请选择需要删除的信息");
|
||||
getBaseService().deleteById(id);
|
||||
return ResultBean.success("删除信息成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete")
|
||||
@ApiOperation(value = "批量强删除信息")
|
||||
public ResultBean<T> batchDeleteByIds(@RequestBody Long[] ids) {
|
||||
try {
|
||||
// 数据校验
|
||||
ValidatorBean.checkNotNull(ids, "请选择需要删除的信息");
|
||||
getBaseService().deleteByIds(ids);
|
||||
return ResultBean.success("批量删除信息成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update-valid")
|
||||
@ApiOperation(value = "根据id更新启用或禁用", notes = "根据id更新启用或禁用")
|
||||
public ResultBean<T> updateValid(Long id, int status) {
|
||||
try {
|
||||
validateUpdateValid(id);
|
||||
getBaseService().updateValid(id, status, AuthUtilExt.getUserName());
|
||||
return ResultBean.success("修改状态成功")
|
||||
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
} catch (Exception e) {
|
||||
return ResultBean.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************* 通用导入导出 *************************************/
|
||||
|
||||
@GetMapping(value = "/export")
|
||||
@ApiOperation(value = "导出数据")
|
||||
public ResultBean<T> exportExcel(T bean, String[] colName, int pageSize, boolean needSendMessage) {
|
||||
ListPager<T> listPager;
|
||||
List<SysFile> result = new ArrayList<>();
|
||||
File zipFile = null;
|
||||
File excelDir = null;
|
||||
File excelFile;
|
||||
ExcelTool excelTool;
|
||||
try {
|
||||
bean.setOrganizeCode(AuthUtilExt.getOrganizeCode());
|
||||
Pager pager = new Pager(0);
|
||||
// 判断是否超过excel最大导出数量设定值
|
||||
int maxPageSize = RedisCacheTool.getSysConfigIntVal(PlatformConstWords.EXCEL_EXPORT_MAX_ROW, 20000);
|
||||
if (pageSize == 0 || pageSize >= maxPageSize) {
|
||||
pager.setPageSize(maxPageSize);
|
||||
} else {
|
||||
pager.setPageSize(pageSize);
|
||||
}
|
||||
|
||||
// 数据校验
|
||||
if (colName == null || colName.length == 0) {
|
||||
Map<String, String> colMap = ExcelTool.getColName(mesClass);
|
||||
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 = baseService.queryPager(bean, pager);
|
||||
pager = listPager.getObjectPager();
|
||||
|
||||
// 将excel导出至临时文件夹
|
||||
excelFile = new File(MessageFormat.format("{0}{1}{2}{3}.xls", excelDir, File.separator, mesClass.getSimpleName(), pager.getCurrentPage()));
|
||||
excelFile.createNewFile();
|
||||
excelTool.exportData(excelFile, listPager.getObjectList(), mesClass, 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.MDM.getValue());
|
||||
BaseResultBean<SysFile> baseResultBean = coreSysFileCloud.insertFile(sysFile);
|
||||
if (!baseResultBean.isSuccess()) {
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.MDM.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.CLOUD_CALL_EXCEPTION.getCode())
|
||||
.setErrorDetail(baseResultBean.errorMsg)
|
||||
.build();
|
||||
} else {
|
||||
sysFile = baseResultBean.getResultObject();
|
||||
}
|
||||
|
||||
result.add(sysFile);
|
||||
|
||||
// 是否发送站内信
|
||||
if (needSendMessage) {
|
||||
coreMessageCloud.insertSysMessage(ExcelTool.sendStationLetter(result, getSessionUser().getUser().getId()));
|
||||
}
|
||||
|
||||
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(result);
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
} 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 {
|
||||
MesExcelTool excelTool = new MesExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
||||
List<T> beanList = excelTool.importData(file.getOriginalFilename(), file.getInputStream(), mesClass);
|
||||
|
||||
// 校验导入数据
|
||||
validateImport(beanList);
|
||||
String userName = AuthUtil.getSessionUser().getUserName();
|
||||
String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
|
||||
// 导入数据初始化
|
||||
for (T bean : beanList) {
|
||||
ConvertBean.serviceModelInitialize(bean, userName);
|
||||
bean.setOrganizeCode(organizeCode);
|
||||
}
|
||||
baseService.insertBatch(beanList);
|
||||
|
||||
// 导入后
|
||||
afterImport(beanList);
|
||||
return ResultBean.success("导入成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException e) {
|
||||
return ResultBean.fail(e);
|
||||
} 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 = mesClass.getSimpleName() + "ImportTemplate";
|
||||
|
||||
// 查询服务器中是否存在模板文件
|
||||
SysFile sysFile = null;
|
||||
BaseResultBean<SysFile> baseResultBean = coreSysFileCloud.getSysFileByFileCode(importTemplateCode);
|
||||
if (!baseResultBean.isSuccess()) {
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.MDM.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.CLOUD_CALL_EXCEPTION.getCode())
|
||||
.setErrorDetail(baseResultBean.errorMsg)
|
||||
.build();
|
||||
} else {
|
||||
sysFile = baseResultBean.getResultObject();
|
||||
}
|
||||
if (sysFile == null) {
|
||||
ImppFile fastDFSFile = new ImppFile(mesClass.getSimpleName() + "ImportTemplate.xls",
|
||||
excelTool.importTemplate(mesClass), ".xls");
|
||||
sysFile = fileService.upload(fastDFSFile, CommonEnumUtil.SOFT_TYPE.MES.getValue());
|
||||
sysFile.setFileCode(importTemplateCode);
|
||||
baseResultBean = coreSysFileCloud.insertFile(sysFile);
|
||||
if (!baseResultBean.isSuccess()) {
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.CLOUD_CALL_EXCEPTION.getCode())
|
||||
.setErrorDetail(baseResultBean.errorMsg)
|
||||
.build();
|
||||
} else {
|
||||
sysFile = baseResultBean.getResultObject();
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
||||
|
||||
public class TestBaseController {
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesArea;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestBaseController extends BaseMesController<MesArea>{
|
||||
}
|
||||
|
@ -1,4 +1,10 @@
|
||||
package cn.estsh.i3plus.ext.mes.apiservice.controller.busi;
|
||||
|
||||
public class TestBusiController {
|
||||
import cn.estsh.i3plus.mes.apiservice.controller.CommonController;
|
||||
import cn.estsh.impp.framework.base.controller.BaseCommonController;
|
||||
import cn.estsh.impp.framework.base.controller.MesBaseController;
|
||||
|
||||
public class TestBusiController extends MesBaseController {
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel;
|
||||
|
||||
import cn.estsh.i3plus.mes.apiservice.util.DateUtil;
|
||||
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.util.BaseRedis;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @CreateDate 2022/6/27 17:28
|
||||
* @Author 尹肖
|
||||
*/
|
||||
public class MesExcelTool extends ExcelTool {
|
||||
public MesExcelTool(EntityManager entityManager, BaseRedis redisRes) {
|
||||
super(entityManager, redisRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getCellValue(Cell cell, Class cellClass) {
|
||||
Object value = "";
|
||||
if (cell == null) {
|
||||
return null;
|
||||
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC) && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||
value = this.getDateCellValue(cell, cellClass);
|
||||
return value;
|
||||
} else {
|
||||
cell.setCellType(CellType.STRING);
|
||||
if ("null".equals(cell.getStringCellValue())) {
|
||||
value = "";
|
||||
} else if ((cellClass == Integer.class || cellClass == Long.class || cellClass == Double.class || cellClass == Float.class) && StringUtils.isBlank(cell.getStringCellValue())) {
|
||||
value = null;
|
||||
} else if (cellClass == String.class) {
|
||||
value = cell.getStringCellValue();
|
||||
} else if (cellClass == Integer.class) {
|
||||
value = Integer.parseInt(cell.getStringCellValue());
|
||||
} else if (cellClass == Long.class) {
|
||||
value = Long.parseLong(cell.getStringCellValue());
|
||||
} else if (cellClass == Double.class) {
|
||||
value = Double.parseDouble(cell.getStringCellValue());
|
||||
} else if (cellClass == Float.class) {
|
||||
value = Float.parseFloat(cell.getStringCellValue());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Object getDateCellValue(Cell cell, Class cellClass) {
|
||||
Object value = null;
|
||||
if (cell.getCellTypeEnum().equals(CellType.NUMERIC) && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||
if (cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm:ss")) {
|
||||
value = TimeTool.pareDateToString("HH:mm:ss", cell.getDateCellValue());
|
||||
} else if (cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd")) {
|
||||
value = TimeTool.pareDateToString("yyyy-MM-dd", cell.getDateCellValue());
|
||||
} else if (cell.getCellStyle().getDataFormat() == 58) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
double numericCellValue = cell.getNumericCellValue();
|
||||
Date date = HSSFDateUtil.getJavaDate(numericCellValue);
|
||||
value = sdf.format(date);
|
||||
} else {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.BASE_FORMAT);
|
||||
double numericCellValue = cell.getNumericCellValue();
|
||||
value = simpleDateFormat.format(HSSFDateUtil.getJavaDate(numericCellValue));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#\u5B89\u9053\u62D3\u6570\u636E\u6E90
|
||||
impp.yfas.datasource.isopen=true
|
||||
#WMS\u6570\u636E\u6E90
|
||||
impp.mes.datasource.isopen=true
|
||||
#\u6570\u636E\u6E90\u7684\u522B\u540D
|
||||
impp.mes.datasource.alias=mesDataSource
|
||||
impp.mes.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
impp.mes.datasource.jdbc-url=jdbc:mysql://192.168.1.241:3306/impp_i3_mes_yf?autoReconnect=true&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
#impp.mes.datasource.jdbc-url=jdbc:sqlserver://139.224.200.147:20037;DatabaseName=impp_i3_mes;
|
||||
impp.mes.datasource.username=root
|
||||
#impp.mes.datasource.password=Test123!
|
||||
impp.mes.datasource.password=estsh123
|
||||
#Admin123!
|
||||
|
||||
|
||||
#\u6570\u636E\u6E90\u7684\u522B\u540D
|
||||
impp.yfas.datasource.alias=yfasDataSource
|
||||
impp.yfas.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
impp.yfas.datasource.jdbc-url=jdbc:mysql://192.168.1.241:3306/impp_i3_mes_yf?autoReconnect=true&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
#impp.yfas.datasource.jdbc-url=jdbc:sqlserver://139.224.200.147:20037;DatabaseName=impp_i3_mes;
|
||||
impp.yfas.datasource.username=root
|
||||
impp.yfas.datasource.password=estsh123
|
Loading…
Reference in New Issue