|
|
|
@ -0,0 +1,634 @@
|
|
|
|
|
package jnpf.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import jnpf.base.ActionResult;
|
|
|
|
|
import jnpf.base.UserInfo;
|
|
|
|
|
import jnpf.exception.DataException;
|
|
|
|
|
import jnpf.permission.entity.UserEntity;
|
|
|
|
|
import jnpf.service.*;
|
|
|
|
|
import jnpf.entity.*;
|
|
|
|
|
import jnpf.util.*;
|
|
|
|
|
import jnpf.model.businessline1.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import jnpf.annotation.JnpfField;
|
|
|
|
|
import jnpf.base.vo.PageListVO;
|
|
|
|
|
import jnpf.base.vo.PaginationVO;
|
|
|
|
|
import jnpf.base.vo.DownloadVO;
|
|
|
|
|
import jnpf.config.ConfigValueUtil;
|
|
|
|
|
import jnpf.base.entity.ProvinceEntity;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import jnpf.engine.entity.FlowTaskEntity;
|
|
|
|
|
import jnpf.exception.WorkFlowException;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import jnpf.onlinedev.model.ExcelImFieldModel;
|
|
|
|
|
import jnpf.onlinedev.model.OnlineImport.ImportDataModel;
|
|
|
|
|
import jnpf.onlinedev.model.OnlineImport.ImportFormCheckUniqueModel;
|
|
|
|
|
import jnpf.onlinedev.model.OnlineImport.ExcelImportModel;
|
|
|
|
|
import jnpf.onlinedev.model.OnlineImport.VisualImportModel;
|
|
|
|
|
import cn.xuyanwu.spring.file.storage.FileInfo;
|
|
|
|
|
import lombok.Cleanup;
|
|
|
|
|
import jnpf.model.visualJson.config.HeaderModel;
|
|
|
|
|
import jnpf.base.model.ColumnDataModel;
|
|
|
|
|
import jnpf.base.util.VisualUtils;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* businessLine1
|
|
|
|
|
* @版本: V3.5
|
|
|
|
|
* @版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
|
|
|
|
|
* @作者: JNPF开发平台组
|
|
|
|
|
* @日期: 2024-02-04
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@Tag(name = "businessLine1" , description = "scm")
|
|
|
|
|
@RequestMapping("/api/scm/BusinessLine1")
|
|
|
|
|
public class BusinessLine1Controller {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private GeneraterSwapUtil generaterSwapUtil;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserProvider userProvider;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BusinessLine1Service businessLine1Service;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BusinessContact1Service businessContact1Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ConfigValueUtil configValueUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表
|
|
|
|
|
*
|
|
|
|
|
* @param businessLine1Pagination
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "获取列表")
|
|
|
|
|
@PostMapping("/getList")
|
|
|
|
|
public ActionResult list(@RequestBody BusinessLine1Pagination businessLine1Pagination)throws IOException{
|
|
|
|
|
List<BusinessLine1Entity> list= businessLine1Service.getList(businessLine1Pagination);
|
|
|
|
|
List<Map<String, Object>> realList=new ArrayList<>();
|
|
|
|
|
for (BusinessLine1Entity entity : list) {
|
|
|
|
|
if (entity.getDifflag().equals("3")||entity.getDifflag().equals("5")){
|
|
|
|
|
Map<String, Object> businessLine1Map=JsonUtil.entityToMap(entity);
|
|
|
|
|
businessLine1Map.put("id", businessLine1Map.get("id"));
|
|
|
|
|
//副表数据
|
|
|
|
|
//子表数据
|
|
|
|
|
List<BusinessContact1Entity> businessContact1List = businessLine1Service.getBusinessContact1List(entity.getId(),businessLine1Pagination);
|
|
|
|
|
businessLine1Map.put("tableField133",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(businessContact1List)));
|
|
|
|
|
realList.add(businessLine1Map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//数据转换
|
|
|
|
|
realList = generaterSwapUtil.swapDataList(realList, BusinessLine1Constant.getFormData(), BusinessLine1Constant.getColumnData(), businessLine1Pagination.getModuleId(),false);
|
|
|
|
|
|
|
|
|
|
//流程状态添加
|
|
|
|
|
for(Map<String, Object> vo:realList){
|
|
|
|
|
FlowTaskEntity flowTaskEntity = generaterSwapUtil.getInfoSubmit(String.valueOf(vo.get("id")), FlowTaskEntity::getStatus);
|
|
|
|
|
if (flowTaskEntity!=null){
|
|
|
|
|
vo.put("flowState",flowTaskEntity.getStatus());
|
|
|
|
|
}else{
|
|
|
|
|
vo.put("flowState",null);
|
|
|
|
|
}
|
|
|
|
|
//添加流程id
|
|
|
|
|
String flowId="";
|
|
|
|
|
if(vo.get("flowid")!=null){
|
|
|
|
|
flowId = String.valueOf(vo.get("flowid"));
|
|
|
|
|
}
|
|
|
|
|
if(vo.get("flowid".toUpperCase())!=null){
|
|
|
|
|
flowId = String.valueOf(vo.get("flowid".toUpperCase()));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtil.isNotEmpty(flowId)){
|
|
|
|
|
vo.put("flowId" ,flowId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//返回对象
|
|
|
|
|
PageListVO vo = new PageListVO();
|
|
|
|
|
vo.setList(realList);
|
|
|
|
|
PaginationVO page = JsonUtil.getJsonToBean(businessLine1Pagination, PaginationVO.class);
|
|
|
|
|
vo.setPagination(page);
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 创建
|
|
|
|
|
*
|
|
|
|
|
* @param businessLine1Form
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/{id}")
|
|
|
|
|
@Operation(summary = "创建")
|
|
|
|
|
public ActionResult create(@PathVariable("id") String id, @RequestBody @Valid BusinessLine1Form businessLine1Form) {
|
|
|
|
|
String b = businessLine1Service.checkForm(businessLine1Form,0);
|
|
|
|
|
if (StringUtil.isNotEmpty(b)){
|
|
|
|
|
return ActionResult.fail(b );
|
|
|
|
|
}
|
|
|
|
|
try{
|
|
|
|
|
businessLine1Service.saveOrUpdate(businessLine1Form, id ,true);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return ActionResult.fail("新增数据失败");
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("创建成功");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 导出Excel
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "导出Excel")
|
|
|
|
|
@PostMapping("/Actions/Export")
|
|
|
|
|
public ActionResult Export(@RequestBody BusinessLine1Pagination businessLine1Pagination) throws IOException {
|
|
|
|
|
if (StringUtil.isEmpty(businessLine1Pagination.getSelectKey())){
|
|
|
|
|
return ActionResult.fail("请选择导出字段");
|
|
|
|
|
}
|
|
|
|
|
List<BusinessLine1Entity> list= businessLine1Service.getList(businessLine1Pagination);
|
|
|
|
|
List<Map<String, Object>> realList=new ArrayList<>();
|
|
|
|
|
for (BusinessLine1Entity entity : list) {
|
|
|
|
|
Map<String, Object> businessLine1Map=JsonUtil.entityToMap(entity);
|
|
|
|
|
businessLine1Map.put("id", businessLine1Map.get("id"));
|
|
|
|
|
//副表数据
|
|
|
|
|
//子表数据
|
|
|
|
|
List<BusinessContact1Entity> businessContact1List = businessLine1Service.getBusinessContact1List(entity.getId(),businessLine1Pagination);
|
|
|
|
|
businessLine1Map.put("tableField133",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(businessContact1List)));
|
|
|
|
|
realList.add(businessLine1Map);
|
|
|
|
|
}
|
|
|
|
|
//数据转换
|
|
|
|
|
realList = generaterSwapUtil.swapDataList(realList, BusinessLine1Constant.getFormData(), BusinessLine1Constant.getColumnData(), businessLine1Pagination.getModuleId(),false);
|
|
|
|
|
String[]keys=!StringUtil.isEmpty(businessLine1Pagination.getSelectKey())?businessLine1Pagination.getSelectKey():new String[0];
|
|
|
|
|
UserInfo userInfo=userProvider.get();
|
|
|
|
|
DownloadVO vo=this.creatModelExcel(configValueUtil.getTemporaryFilePath(),realList,keys,userInfo);
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出表格方法
|
|
|
|
|
*/
|
|
|
|
|
public DownloadVO creatModelExcel(String path,List<Map<String, Object>>list,String[]keys,UserInfo userInfo){
|
|
|
|
|
DownloadVO vo=DownloadVO.builder().build();
|
|
|
|
|
List<ExcelExportEntity> entitys=new ArrayList<>();
|
|
|
|
|
if(keys.length>0){
|
|
|
|
|
ExcelExportEntity tableField133ExcelEntity = new ExcelExportEntity("","tableField133");
|
|
|
|
|
List<ExcelExportEntity> tableField133List = new ArrayList<>();
|
|
|
|
|
for(String key:keys){
|
|
|
|
|
switch(key){
|
|
|
|
|
case "code" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("生产线编号" ,"code"));
|
|
|
|
|
break;
|
|
|
|
|
case "name" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("生产线名称" ,"name"));
|
|
|
|
|
break;
|
|
|
|
|
case "simpleName" :
|
|
|
|
|
entitys.add(new ExcelExportEntity(" 简称/英文名" ,"simpleName"));
|
|
|
|
|
break;
|
|
|
|
|
case "type" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("类型" ,"type"));
|
|
|
|
|
break;
|
|
|
|
|
case "parentId" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("所属工厂" ,"parentId"));
|
|
|
|
|
break;
|
|
|
|
|
case "workshopId" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("所属车间" ,"workshopId"));
|
|
|
|
|
break;
|
|
|
|
|
case "status" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("状态" ,"status"));
|
|
|
|
|
break;
|
|
|
|
|
case "description" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("描述" ,"description"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-contactType":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("类型" ,"contactType"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-name":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("姓名" ,"name"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-phone":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("手机号" ,"phone"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-landline":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("座机" ,"landline"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-email":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("邮箱" ,"email"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-fax":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("传真" ,"fax"));
|
|
|
|
|
break;
|
|
|
|
|
case "tableField133-lastModifyTime":
|
|
|
|
|
tableField133List.add(new ExcelExportEntity("更新时间" ,"lastModifyTime"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(tableField133List.size() > 0){
|
|
|
|
|
tableField133ExcelEntity.setList(tableField133List);
|
|
|
|
|
entitys.add(tableField133ExcelEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExportParams exportParams = new ExportParams(null, "表单信息");
|
|
|
|
|
exportParams.setType(ExcelType.XSSF);
|
|
|
|
|
try{
|
|
|
|
|
@Cleanup Workbook workbook = new HSSFWorkbook();
|
|
|
|
|
if (entitys.size()>0){
|
|
|
|
|
if (list.size()==0){
|
|
|
|
|
list.add(new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
//去除空数据
|
|
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
|
|
for (Map<String, Object> map : list) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (String key : keys) {
|
|
|
|
|
//子表
|
|
|
|
|
if (key.toLowerCase().startsWith("tablefield")) {
|
|
|
|
|
String tableField = key.substring(0, key.indexOf("-" ));
|
|
|
|
|
String field = key.substring(key.indexOf("-" ) + 1);
|
|
|
|
|
Object o = map.get(tableField);
|
|
|
|
|
if (o != null) {
|
|
|
|
|
List<Map<String, Object>> childList = (List<Map<String, Object>>) o;
|
|
|
|
|
for (Map<String, Object> childMap : childList) {
|
|
|
|
|
if (childMap.get(field) != null) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Object o = map.get(key);
|
|
|
|
|
if (o != null) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
dataList.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//复杂表头-表头和数据处理
|
|
|
|
|
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(BusinessLine1Constant.getColumnData(), ColumnDataModel.class);
|
|
|
|
|
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
|
|
|
|
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
|
|
|
|
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList);
|
|
|
|
|
dataList = VisualUtils.complexHeaderDataHandel(dataList, complexHeaderList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, dataList);
|
|
|
|
|
}
|
|
|
|
|
String fileName = "表单信息" + DateUtil.dateNow("yyyyMMdd") + "_" + RandomUtil.uuId() + ".xlsx";
|
|
|
|
|
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
|
|
|
|
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
|
|
|
|
FileInfo fileInfo = FileUploadUtils.uploadFile(multipartFile, temporaryFilePath, fileName);
|
|
|
|
|
vo.setName(fileInfo.getFilename());
|
|
|
|
|
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("信息导出Excel错误:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
@Operation(summary = "上传文件")
|
|
|
|
|
@PostMapping("/Uploader")
|
|
|
|
|
public ActionResult<Object> Uploader() {
|
|
|
|
|
List<MultipartFile> list = UpUtil.getFileAll();
|
|
|
|
|
MultipartFile file = list.get(0);
|
|
|
|
|
if (file.getOriginalFilename().endsWith(".xlsx") || file.getOriginalFilename().endsWith(".xls")) {
|
|
|
|
|
String filePath = XSSEscape.escape(configValueUtil.getTemporaryFilePath());
|
|
|
|
|
String fileName = XSSEscape.escape(RandomUtil.uuId() + "." + UpUtil.getFileType(file));
|
|
|
|
|
//上传文件
|
|
|
|
|
FileInfo fileInfo = FileUploadUtils.uploadFile(file, filePath, fileName);
|
|
|
|
|
DownloadVO vo = DownloadVO.builder().build();
|
|
|
|
|
vo.setName(fileInfo.getFilename());
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.fail("选择文件不符合导入");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 模板下载
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "模板下载")
|
|
|
|
|
@GetMapping("/TemplateDownload")
|
|
|
|
|
public ActionResult<DownloadVO> TemplateDownload(){
|
|
|
|
|
DownloadVO vo = DownloadVO.builder().build();
|
|
|
|
|
UserInfo userInfo = userProvider.get();
|
|
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
|
|
//主表对象
|
|
|
|
|
List<ExcelExportEntity> entitys = new ArrayList<>();
|
|
|
|
|
//以下添加字段
|
|
|
|
|
entitys.add(new ExcelExportEntity("生产线编号" ,"code"));
|
|
|
|
|
dataMap.put("code", "系统自动生成");
|
|
|
|
|
entitys.add(new ExcelExportEntity("生产线名称" ,"name"));
|
|
|
|
|
entitys.add(new ExcelExportEntity("类型" ,"type"));
|
|
|
|
|
entitys.add(new ExcelExportEntity("所属工厂" ,"parentId"));
|
|
|
|
|
entitys.add(new ExcelExportEntity("状态" ,"status"));
|
|
|
|
|
entitys.add(new ExcelExportEntity("所属车间" ,"workshopId"));
|
|
|
|
|
//tableField133子表对象
|
|
|
|
|
ExcelExportEntity tableField133ExcelEntity = new ExcelExportEntity("","tableField133");
|
|
|
|
|
List<ExcelExportEntity> tableField133ExcelEntityList = new ArrayList<>();
|
|
|
|
|
Map<String, Object> tableField133ChildData = new HashMap<>();
|
|
|
|
|
List<Map<String, Object>> tableField133ChildDataList = new ArrayList<>();
|
|
|
|
|
tableField133ExcelEntityList.add(new ExcelExportEntity("类型" ,"contactType"));
|
|
|
|
|
tableField133ExcelEntityList.add(new ExcelExportEntity("姓名" ,"name"));
|
|
|
|
|
tableField133ExcelEntityList.add(new ExcelExportEntity("手机号" ,"phone"));
|
|
|
|
|
tableField133ExcelEntityList.add(new ExcelExportEntity("邮箱" ,"email"));
|
|
|
|
|
tableField133ChildDataList.add(tableField133ChildData);
|
|
|
|
|
dataMap.put("tableField133",tableField133ChildDataList);
|
|
|
|
|
tableField133ExcelEntity.setList(tableField133ExcelEntityList);
|
|
|
|
|
entitys.add(tableField133ExcelEntity);
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
list.add(dataMap);
|
|
|
|
|
|
|
|
|
|
ExportParams exportParams = new ExportParams(null, "加工生产线模板");
|
|
|
|
|
exportParams.setType(ExcelType.XSSF);
|
|
|
|
|
try{
|
|
|
|
|
@Cleanup Workbook workbook = new HSSFWorkbook();
|
|
|
|
|
if (entitys.size()>0){
|
|
|
|
|
if (list.size()==0){
|
|
|
|
|
list.add(new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
//复杂表头-表头和数据处理
|
|
|
|
|
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(BusinessLine1Constant.getColumnData(), ColumnDataModel.class);
|
|
|
|
|
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
|
|
|
|
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
|
|
|
|
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList);
|
|
|
|
|
list = VisualUtils.complexHeaderDataHandel(list, complexHeaderList);
|
|
|
|
|
}
|
|
|
|
|
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
|
|
|
|
|
}
|
|
|
|
|
String fileName = "加工生产线模板" + DateUtil.dateNow("yyyyMMddHHmmss") + ".xlsx";
|
|
|
|
|
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
|
|
|
|
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
|
|
|
|
FileInfo fileInfo = FileUploadUtils.uploadFile(multipartFile, temporaryFilePath, fileName);
|
|
|
|
|
vo.setName(fileInfo.getFilename());
|
|
|
|
|
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("模板信息导出Excel错误:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入预览
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "导入预览" )
|
|
|
|
|
@GetMapping("/ImportPreview")
|
|
|
|
|
public ActionResult<Map<String, Object>> ImportPreview(String fileName) throws Exception {
|
|
|
|
|
Map<String, Object> headAndDataMap = new HashMap<>(2);
|
|
|
|
|
String filePath = FileUploadUtils.getLocalBasePath() + configValueUtil.getTemporaryFilePath();
|
|
|
|
|
FileUploadUtils.downLocal(configValueUtil.getTemporaryFilePath(), filePath, fileName);
|
|
|
|
|
File temporary = new File(XSSEscape.escapePath(filePath + fileName));
|
|
|
|
|
int headerRowIndex = 2;
|
|
|
|
|
ImportParams params = new ImportParams();
|
|
|
|
|
params.setTitleRows(0);
|
|
|
|
|
params.setHeadRows(headerRowIndex);
|
|
|
|
|
params.setNeedVerify(true);
|
|
|
|
|
try {
|
|
|
|
|
List<BusinessLine1ExcelVO> excelDataList = ExcelImportUtil.importExcel(temporary, BusinessLine1ExcelVO.class, params);
|
|
|
|
|
// 导入字段
|
|
|
|
|
List<ExcelImFieldModel> columns = new ArrayList<>();
|
|
|
|
|
columns.add(new ExcelImFieldModel("code","生产线编号"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("name","生产线名称"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("type","类型"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("parentId","所属工厂"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("status","状态"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("workshopId","所属车间"));
|
|
|
|
|
//tableField133子表对象
|
|
|
|
|
List<ExcelImFieldModel> tableField133columns = new ArrayList<>();
|
|
|
|
|
tableField133columns.add(new ExcelImFieldModel("contactType" ,"类型"));
|
|
|
|
|
tableField133columns.add(new ExcelImFieldModel("name" ,"姓名"));
|
|
|
|
|
tableField133columns.add(new ExcelImFieldModel("phone" ,"手机号"));
|
|
|
|
|
tableField133columns.add(new ExcelImFieldModel("email" ,"邮箱"));
|
|
|
|
|
columns.add(new ExcelImFieldModel("tableField133","",tableField133columns));
|
|
|
|
|
headAndDataMap.put("dataRow" , JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(excelDataList)));
|
|
|
|
|
headAndDataMap.put("headerRow" , JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(columns)));
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ActionResult.fail("表头名称不可更改,表头行不能删除");
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success(headAndDataMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入数据
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "导入数据" )
|
|
|
|
|
@PostMapping("/ImportData")
|
|
|
|
|
public ActionResult<ExcelImportModel> ImportData(@RequestBody VisualImportModel visualImportModel) throws Exception {
|
|
|
|
|
List<Map<String, Object>> listData=new ArrayList<>();
|
|
|
|
|
for(Map<String, Object> map : visualImportModel.getList()){
|
|
|
|
|
listData.add(map);
|
|
|
|
|
}
|
|
|
|
|
ImportFormCheckUniqueModel uniqueModel = new ImportFormCheckUniqueModel();
|
|
|
|
|
uniqueModel.setDbLinkId(BusinessLine1Constant.DBLINKID);
|
|
|
|
|
uniqueModel.setUpdate(Objects.equals("1", "2"));
|
|
|
|
|
uniqueModel.setFlowId(visualImportModel.getFlowId()); ExcelImportModel excelImportModel = generaterSwapUtil.importData(BusinessLine1Constant.getFormData(),listData,uniqueModel,
|
|
|
|
|
BusinessLine1Constant.TABLEFIELDKEY,BusinessLine1Constant.getTableList());
|
|
|
|
|
List<ImportDataModel> importDataModel = uniqueModel.getImportDataModel();
|
|
|
|
|
for (ImportDataModel model : importDataModel) {
|
|
|
|
|
String id = model.getId();
|
|
|
|
|
Map<String, Object> result = model.getResultData();
|
|
|
|
|
if(StringUtil.isNotEmpty(id)){
|
|
|
|
|
update(id, JsonUtil.getJsonToBean(result,BusinessLine1Form.class), true);
|
|
|
|
|
}else {
|
|
|
|
|
create(RandomUtil.uuId(), JsonUtil.getJsonToBean(result,BusinessLine1Form.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success(excelImportModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出异常报告
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "导出异常报告")
|
|
|
|
|
@PostMapping("/ImportExceptionData")
|
|
|
|
|
public ActionResult<DownloadVO> ImportExceptionData(@RequestBody VisualImportModel visualImportModel) {
|
|
|
|
|
DownloadVO vo=DownloadVO.builder().build();
|
|
|
|
|
List<BusinessLine1ExcelErrorVO> businessLine1VOList = JsonUtil.getJsonToList(visualImportModel.getList(), BusinessLine1ExcelErrorVO.class);
|
|
|
|
|
UserInfo userInfo = userProvider.get();
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
@Cleanup Workbook workbook = new HSSFWorkbook();
|
|
|
|
|
ExportParams exportParams = new ExportParams(null, "错误报告");
|
|
|
|
|
exportParams.setType(ExcelType.XSSF);
|
|
|
|
|
workbook = ExcelExportUtil.exportExcel(exportParams,
|
|
|
|
|
BusinessLine1ExcelErrorVO.class, businessLine1VOList);
|
|
|
|
|
|
|
|
|
|
String fileName = "错误报告" + DateUtil.dateNow("yyyyMMdd") + "_" + RandomUtil.uuId() + ".xlsx";
|
|
|
|
|
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
|
|
|
|
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
|
|
|
|
FileInfo fileInfo = FileUploadUtils.uploadFile(multipartFile, temporaryFilePath, fileName);
|
|
|
|
|
vo.setName(fileInfo.getFilename());
|
|
|
|
|
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 批量删除
|
|
|
|
|
* @param ids
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/batchRemove")
|
|
|
|
|
@Transactional
|
|
|
|
|
@Operation(summary = "批量删除")
|
|
|
|
|
public ActionResult batchRemove(@RequestBody String ids){
|
|
|
|
|
List<String> idList = JsonUtil.getJsonToList(ids, String.class);
|
|
|
|
|
List<String> columnIdList = new ArrayList<>(20);
|
|
|
|
|
int i =0;
|
|
|
|
|
String errInfo = "";
|
|
|
|
|
for (String allId : idList){
|
|
|
|
|
FlowTaskEntity taskEntity = generaterSwapUtil.getInfoSubmit(allId, FlowTaskEntity::getId, FlowTaskEntity::getStatus);
|
|
|
|
|
if (taskEntity==null){
|
|
|
|
|
columnIdList.add(allId);
|
|
|
|
|
this.delete(allId);
|
|
|
|
|
}else if (taskEntity.getStatus().equals(0) || taskEntity.getStatus().equals(4)){
|
|
|
|
|
try {
|
|
|
|
|
generaterSwapUtil.deleteFlowTask(taskEntity);
|
|
|
|
|
columnIdList.add(allId);
|
|
|
|
|
this.delete(allId);
|
|
|
|
|
i++;
|
|
|
|
|
} catch (WorkFlowException e) {
|
|
|
|
|
errInfo = e.getMessage();
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i == 0 && columnIdList.size()==0){
|
|
|
|
|
return ActionResult.fail("流程已发起,无法删除");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtil.isNotEmpty(errInfo)){
|
|
|
|
|
return ActionResult.fail(errInfo);
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("删除成功");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 编辑
|
|
|
|
|
* @param id
|
|
|
|
|
* @param businessLine1Form
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping("/{id}")
|
|
|
|
|
@Operation(summary = "更新")
|
|
|
|
|
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid BusinessLine1Form businessLine1Form,
|
|
|
|
|
@RequestParam(value = "isImport", required = false) boolean isImport){
|
|
|
|
|
businessLine1Form.setId(id);
|
|
|
|
|
if (!isImport) {
|
|
|
|
|
String b = businessLine1Service.checkForm(businessLine1Form,1);
|
|
|
|
|
if (StringUtil.isNotEmpty(b)){
|
|
|
|
|
return ActionResult.fail(b );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BusinessLine1Entity entity= businessLine1Service.getInfo(id);
|
|
|
|
|
if(entity!=null){
|
|
|
|
|
try{
|
|
|
|
|
businessLine1Service.saveOrUpdate(businessLine1Form,id,false);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return ActionResult.fail("修改数据失败");
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("更新成功");
|
|
|
|
|
}else{
|
|
|
|
|
return ActionResult.fail("更新失败,数据不存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "删除")
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
@Transactional
|
|
|
|
|
public ActionResult delete(@PathVariable("id") String id){
|
|
|
|
|
BusinessLine1Entity entity= businessLine1Service.getInfo(id);
|
|
|
|
|
if(entity!=null){
|
|
|
|
|
FlowTaskEntity taskEntity = generaterSwapUtil.getInfoSubmit(id, FlowTaskEntity::getId, FlowTaskEntity::getStatus);
|
|
|
|
|
if (taskEntity != null) {
|
|
|
|
|
try {
|
|
|
|
|
generaterSwapUtil.deleteFlowTask(taskEntity);
|
|
|
|
|
} catch (WorkFlowException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//假删除
|
|
|
|
|
entity.setDeleteMark(1);
|
|
|
|
|
businessLine1Service.update(id,entity);
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("删除成功");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 表单信息(详情页)
|
|
|
|
|
* 详情页面使用-转换数据
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "表单信息(详情页)")
|
|
|
|
|
@GetMapping("/detail/{id}")
|
|
|
|
|
public ActionResult detailInfo(@PathVariable("id") String id){
|
|
|
|
|
BusinessLine1Entity entity= businessLine1Service.getInfo(id);
|
|
|
|
|
if(entity==null){
|
|
|
|
|
return ActionResult.fail("表单数据不存在!");
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> businessLine1Map=JsonUtil.entityToMap(entity);
|
|
|
|
|
businessLine1Map.put("id", businessLine1Map.get("id"));
|
|
|
|
|
//副表数据
|
|
|
|
|
//子表数据
|
|
|
|
|
List<BusinessContact1Entity> businessContact1List = businessLine1Service.getBusinessContact1List(entity.getId());
|
|
|
|
|
businessLine1Map.put("tableField133",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(businessContact1List)));
|
|
|
|
|
businessLine1Map = generaterSwapUtil.swapDataDetail(businessLine1Map,BusinessLine1Constant.getFormData(),"521949393889270917",false);
|
|
|
|
|
return ActionResult.success(businessLine1Map);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取详情(编辑页)
|
|
|
|
|
* 编辑页面使用-不转换数据
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "信息")
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
public ActionResult info(@PathVariable("id") String id){
|
|
|
|
|
BusinessLine1Entity entity= businessLine1Service.getInfo(id);
|
|
|
|
|
if(entity==null){
|
|
|
|
|
return ActionResult.fail("表单数据不存在!");
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> businessLine1Map=JsonUtil.entityToMap(entity);
|
|
|
|
|
businessLine1Map.put("id", businessLine1Map.get("id"));
|
|
|
|
|
//副表数据
|
|
|
|
|
//子表数据
|
|
|
|
|
List<BusinessContact1Entity> businessContact1List = businessLine1Service.getBusinessContact1List(entity.getId());
|
|
|
|
|
businessLine1Map.put("businessContact1List",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(businessContact1List)));
|
|
|
|
|
businessLine1Map = generaterSwapUtil.swapDataForm(businessLine1Map,BusinessLine1Constant.getFormData(),BusinessLine1Constant.TABLEFIELDKEY,BusinessLine1Constant.TABLERENAMES);
|
|
|
|
|
return ActionResult.success(businessLine1Map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|