新增主数据与基本配置部分代码
This commit is contained in:
@@ -0,0 +1,636 @@
|
||||
package com.yunzhupaas.mdm.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 com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.mdm.service.*;
|
||||
import com.yunzhupaas.mdm.entity.*;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.mdm.model.crmlead.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import com.yunzhupaas.model.ExcelModel;
|
||||
import com.yunzhupaas.excel.ExcelExportStyler;
|
||||
import com.yunzhupaas.excel.ExcelHelper;
|
||||
import com.yunzhupaas.annotation.YunzhupaasField;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.base.entity.ProvinceEntity;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.visualJson.UploaderTemplateModel;
|
||||
import com.yunzhupaas.base.util.FormExecelUtils;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import com.yunzhupaas.onlinedev.model.ExcelImFieldModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.ImportDataModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.ImportFormCheckUniqueModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.ExcelImportModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.VisualImportModel;
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import lombok.Cleanup;
|
||||
import com.yunzhupaas.model.visualJson.config.HeaderModel;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.util.VisualUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* crm_lead
|
||||
* @版本: V5.2.7
|
||||
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* @作者: 深圳市乐程软件有限公司
|
||||
* @日期: 2026-05-18
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "crm_lead" , description = "bcm")
|
||||
@RequestMapping("/api/bcm/CrmLead")
|
||||
public class CrmLeadController {
|
||||
|
||||
@Autowired
|
||||
private GeneraterSwapUtil generaterSwapUtil;
|
||||
|
||||
@Autowired
|
||||
private UserProvider userProvider;
|
||||
|
||||
@Autowired
|
||||
private CrmLeadService crmLeadService;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param crmLeadPagination
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取列表")
|
||||
@PostMapping("/getList")
|
||||
public ActionResult list(@RequestBody CrmLeadPagination crmLeadPagination)throws Exception{
|
||||
List<CrmLeadEntity> list= crmLeadService.getList(crmLeadPagination);
|
||||
List<Map<String, Object>> realList=new ArrayList<>();
|
||||
for (CrmLeadEntity entity : list) {
|
||||
Map<String, Object> crmLeadMap=JsonUtil.entityToMap(entity);
|
||||
crmLeadMap.put("id", crmLeadMap.get("lead_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
realList.add(crmLeadMap);
|
||||
}
|
||||
//数据转换
|
||||
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
|
||||
realList = generaterSwapUtil.swapDataList(realList, CrmLeadConstant.getFormData(), CrmLeadConstant.getColumnData(), crmLeadPagination.getModuleId(),isPc?false:false);
|
||||
|
||||
//流程状态添加
|
||||
generaterSwapUtil.getFlowStatus(realList);
|
||||
//返回对象
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(realList);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(crmLeadPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param crmLeadForm
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/{id}")
|
||||
@Operation(summary = "创建")
|
||||
public ActionResult create(@PathVariable("id") String id, @RequestBody @Valid CrmLeadForm crmLeadForm) {
|
||||
String b = crmLeadService.checkForm(crmLeadForm,0);
|
||||
if (StringUtil.isNotEmpty(b)){
|
||||
return ActionResult.fail(b );
|
||||
}
|
||||
try{
|
||||
crmLeadService.saveOrUpdate(crmLeadForm, id ,true);
|
||||
}catch(Exception e){
|
||||
return ActionResult.fail(MsgCode.FA028.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出Excel")
|
||||
@PostMapping("/Actions/Export")
|
||||
public ActionResult Export(@RequestBody CrmLeadPagination crmLeadPagination) throws IOException {
|
||||
if (StringUtil.isEmpty(crmLeadPagination.getSelectKey())){
|
||||
return ActionResult.fail(MsgCode.IMP011.get());
|
||||
}
|
||||
List<CrmLeadEntity> list= crmLeadService.getList(crmLeadPagination);
|
||||
List<Map<String, Object>> realList=new ArrayList<>();
|
||||
for (CrmLeadEntity entity : list) {
|
||||
Map<String, Object> crmLeadMap=JsonUtil.entityToMap(entity);
|
||||
crmLeadMap.put("id", crmLeadMap.get("lead_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
realList.add(crmLeadMap);
|
||||
}
|
||||
//数据转换
|
||||
realList = generaterSwapUtil.swapDataList(realList, CrmLeadConstant.getFormData(), CrmLeadConstant.getColumnData(), crmLeadPagination.getModuleId(),false);
|
||||
String[]keys=!StringUtil.isEmpty(crmLeadPagination.getSelectKey())?crmLeadPagination.getSelectKey():new String[0];
|
||||
UserInfo userInfo=userProvider.get();
|
||||
String menuFullName = generaterSwapUtil.getMenuName(crmLeadPagination.getMenuId());
|
||||
|
||||
DownloadVO vo=this.creatModelExcel(configValueUtil.getTemporaryFilePath(),realList,keys,userInfo,menuFullName);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出表格方法
|
||||
*/
|
||||
public DownloadVO creatModelExcel(String path,List<Map<String, Object>>list,String[]keys,UserInfo userInfo,String menuFullName){
|
||||
DownloadVO vo=DownloadVO.builder().build();
|
||||
List<ExcelExportEntity> entitys=new ArrayList<>();
|
||||
if(keys.length>0){
|
||||
for(String key:keys){
|
||||
switch(key){
|
||||
case "lead_name" :
|
||||
entitys.add(new ExcelExportEntity("线索名称" ,"lead_name"));
|
||||
break;
|
||||
case "mobile" :
|
||||
entitys.add(new ExcelExportEntity("手机号" ,"mobile"));
|
||||
break;
|
||||
case "email" :
|
||||
entitys.add(new ExcelExportEntity("邮箱" ,"email"));
|
||||
break;
|
||||
case "lead_status" :
|
||||
entitys.add(new ExcelExportEntity("状态" ,"lead_status"));
|
||||
break;
|
||||
case "sales_id" :
|
||||
entitys.add(new ExcelExportEntity("销售人员" ,"sales_id"));
|
||||
break;
|
||||
case "customer_source" :
|
||||
entitys.add(new ExcelExportEntity("来源" ,"customer_source"));
|
||||
break;
|
||||
case "remark" :
|
||||
entitys.add(new ExcelExportEntity("备注" ,"remark"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
List<ExcelExportEntity> mergerEntitys = new ArrayList<>(entitys);
|
||||
List<Map<String, Object>> mergerList=new ArrayList<>(dataList);
|
||||
//复杂表头-表头和数据处理
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(CrmLeadConstant.getColumnData(), ColumnDataModel.class);
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList, Objects.equals(columnDataModel.getType(), 4));
|
||||
dataList = VisualUtils.complexHeaderDataHandel(dataList, complexHeaderList, Objects.equals(columnDataModel.getType(), 4));
|
||||
}
|
||||
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, dataList);
|
||||
VisualUtils.mergerVertical(workbook, mergerEntitys, mergerList);
|
||||
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CrmLeadConstant.getFormData(),Arrays.asList(keys));
|
||||
ExcelHelper helper = new ExcelHelper();
|
||||
helper.init(workbook, exportParams, entitys, excelModel);
|
||||
helper.doPreHandle();
|
||||
helper.doPostHandle();
|
||||
}
|
||||
String fileName = menuFullName +"_"+ DateUtil.dateNow("yyyyMMddHHmmss") + ".xls";
|
||||
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(MsgCode.FA017.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "模板下载")
|
||||
@GetMapping("/TemplateDownload")
|
||||
public ActionResult<DownloadVO> TemplateDownload(@RequestParam("menuId") String menuId){
|
||||
DownloadVO vo = DownloadVO.builder().build();
|
||||
UserInfo userInfo = userProvider.get();
|
||||
String menuFullName = generaterSwapUtil.getMenuName(menuId);
|
||||
//主表对象
|
||||
List<ExcelExportEntity> entitys = new ArrayList<>();
|
||||
List<String> selectKeys = new ArrayList<>();
|
||||
//以下添加字段
|
||||
entitys.add(new ExcelExportEntity("线索名称(lead_name)" ,"lead_name"));
|
||||
selectKeys.add("lead_name");
|
||||
entitys.add(new ExcelExportEntity("手机号(mobile)" ,"mobile"));
|
||||
selectKeys.add("mobile");
|
||||
entitys.add(new ExcelExportEntity("状态(lead_status)" ,"lead_status"));
|
||||
selectKeys.add("lead_status");
|
||||
entitys.add(new ExcelExportEntity("销售人员(sales_id)" ,"sales_id"));
|
||||
selectKeys.add("sales_id");
|
||||
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
|
||||
selectKeys.add("remark");
|
||||
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
|
||||
selectKeys.add("email");
|
||||
entitys.add(new ExcelExportEntity("来源(customer_source)" ,"customer_source"));
|
||||
selectKeys.add("customer_source");
|
||||
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CrmLeadConstant.getFormData(),selectKeys);
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(excelModel.getDataMap());
|
||||
|
||||
ExportParams exportParams = new ExportParams(null, menuFullName + "模板");
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
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(CrmLeadConstant.getColumnData(), ColumnDataModel.class);
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList, false);
|
||||
list = VisualUtils.complexHeaderDataHandel(list, complexHeaderList, false);
|
||||
}
|
||||
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
|
||||
ExcelHelper helper = new ExcelHelper();
|
||||
helper.init(workbook, exportParams, entitys, excelModel);
|
||||
helper.doPreHandle();
|
||||
helper.doPostHandle();
|
||||
}
|
||||
String fileName = menuFullName + "导入模板.xls";
|
||||
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 = 1;
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(0);
|
||||
params.setHeadRows(headerRowIndex);
|
||||
params.setNeedVerify(true);
|
||||
try {
|
||||
InputStream inputStream = ExcelUtil.solveOrginTitle(temporary, headerRowIndex);
|
||||
List<Map> excelDataList = ExcelUtil.importExcelByInputStream(inputStream, 0, headerRowIndex, Map.class);
|
||||
//数据超过1000条
|
||||
if(excelDataList != null && excelDataList.size() > 1000) {
|
||||
return ActionResult.fail(MsgCode.ETD117.get());
|
||||
}
|
||||
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(CrmLeadConstant.getColumnData(), ColumnDataModel.class);
|
||||
UploaderTemplateModel uploaderTemplateModel = JsonUtil.getJsonToBean(columnDataModel.getUploaderTemplateJson(), UploaderTemplateModel.class);
|
||||
List<String> selectKey = uploaderTemplateModel.getSelectKey();
|
||||
//子表合并
|
||||
List<Map<String, Object>> results = FormExecelUtils.dataMergeChildTable(excelDataList,selectKey);
|
||||
// 导入字段
|
||||
List<ExcelImFieldModel> columns = new ArrayList<>();
|
||||
columns.add(new ExcelImFieldModel("lead_name","线索名称","input"));
|
||||
columns.add(new ExcelImFieldModel("mobile","手机号","input"));
|
||||
columns.add(new ExcelImFieldModel("lead_status","状态","select"));
|
||||
columns.add(new ExcelImFieldModel("sales_id","销售人员","usersSelect"));
|
||||
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
|
||||
columns.add(new ExcelImFieldModel("email","邮箱","input"));
|
||||
columns.add(new ExcelImFieldModel("customer_source","来源","select"));
|
||||
headAndDataMap.put("dataRow" , results);
|
||||
headAndDataMap.put("headerRow" , JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(columns)));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(MsgCode.VS407.get());
|
||||
}
|
||||
return ActionResult.success(headAndDataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导入数据" )
|
||||
@PostMapping("/ImportData")
|
||||
public ActionResult<ExcelImportModel> ImportData(@RequestBody VisualImportModel visualImportModel) throws Exception {
|
||||
List<Map<String, Object>> listData = visualImportModel.getList();
|
||||
ImportFormCheckUniqueModel uniqueModel = new ImportFormCheckUniqueModel();
|
||||
uniqueModel.setDbLinkId(CrmLeadConstant.DBLINKID);
|
||||
uniqueModel.setUpdate(Objects.equals("1", "2"));
|
||||
uniqueModel.setFlowId(visualImportModel.getFlowId());
|
||||
Map<String,String> tablefieldkey = new HashMap<>();
|
||||
for(String key:CrmLeadConstant.TABLEFIELDKEY.keySet()){
|
||||
tablefieldkey.put(key,CrmLeadConstant.TABLERENAMES.get(CrmLeadConstant.TABLEFIELDKEY.get(key)));
|
||||
}
|
||||
ExcelImportModel excelImportModel = generaterSwapUtil.importData(CrmLeadConstant.getFormData(),listData,uniqueModel, tablefieldkey,CrmLeadConstant.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,CrmLeadForm.class), true);
|
||||
}else {
|
||||
create(RandomUtil.uuId(), JsonUtil.getJsonToBean(result,CrmLeadForm.class));
|
||||
}
|
||||
}
|
||||
return ActionResult.success(excelImportModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出异常报告
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出异常报告")
|
||||
@PostMapping("/ImportExceptionData")
|
||||
public ActionResult<DownloadVO> ImportExceptionData(@RequestBody VisualImportModel visualImportModel) {
|
||||
DownloadVO vo = DownloadVO.builder().build();
|
||||
UserInfo userInfo = userProvider.get();
|
||||
String menuFullName = generaterSwapUtil.getMenuName(visualImportModel.getMenuId());
|
||||
//主表对象
|
||||
List<ExcelExportEntity> entitys = new ArrayList<>();
|
||||
entitys.add(new ExcelExportEntity("异常原因", "errorsInfo",30));
|
||||
List<String> selectKeys = new ArrayList<>();
|
||||
//以下添加字段
|
||||
entitys.add(new ExcelExportEntity("线索名称(lead_name)" ,"lead_name"));
|
||||
selectKeys.add("lead_name");
|
||||
entitys.add(new ExcelExportEntity("手机号(mobile)" ,"mobile"));
|
||||
selectKeys.add("mobile");
|
||||
entitys.add(new ExcelExportEntity("状态(lead_status)" ,"lead_status"));
|
||||
selectKeys.add("lead_status");
|
||||
entitys.add(new ExcelExportEntity("销售人员(sales_id)" ,"sales_id"));
|
||||
selectKeys.add("sales_id");
|
||||
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
|
||||
selectKeys.add("remark");
|
||||
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
|
||||
selectKeys.add("email");
|
||||
entitys.add(new ExcelExportEntity("来源(customer_source)" ,"customer_source"));
|
||||
selectKeys.add("customer_source");
|
||||
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CrmLeadConstant.getFormData(),selectKeys);
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.addAll(visualImportModel.getList());
|
||||
|
||||
ExportParams exportParams = new ExportParams(null, menuFullName + "模板");
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
exportParams.setFreezeCol(1);
|
||||
try{
|
||||
@Cleanup Workbook workbook = new HSSFWorkbook();
|
||||
if (entitys.size()>0){
|
||||
if (list.size()==0){
|
||||
list.add(new HashMap<>());
|
||||
}
|
||||
//复杂表头-表头和数据处理
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(CrmLeadConstant.getColumnData(), ColumnDataModel.class);
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList, false);
|
||||
list = VisualUtils.complexHeaderDataHandel(list, complexHeaderList, false);
|
||||
}
|
||||
|
||||
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
|
||||
ExcelHelper helper = new ExcelHelper();
|
||||
helper.init(workbook, exportParams, entitys, excelModel);
|
||||
helper.doPreHandle();
|
||||
helper.doPostHandle();
|
||||
}
|
||||
|
||||
String fileName = menuFullName + "错误报告_" + DateUtil.dateNow("yyyyMMddHHmmss") + ".xls";
|
||||
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 id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id,@RequestParam(name = "forceDel",defaultValue = "false") boolean forceDel) throws Exception{
|
||||
CrmLeadEntity entity= crmLeadService.getInfo(id);
|
||||
if(entity!=null){
|
||||
if(!forceDel){
|
||||
String errMsg = generaterSwapUtil.deleteFlowTask(entity.getFlowTaskId());
|
||||
if (StringUtil.isNotEmpty(errMsg)) {
|
||||
throw new DataException(errMsg);
|
||||
}
|
||||
}
|
||||
//假删除
|
||||
entity.setDeleteMark(1);
|
||||
entity.setDeleteUserId(userProvider.get().getUserId());
|
||||
entity.setDeleteTime(new Date());
|
||||
crmLeadService.setIgnoreLogicDelete().updateById(entity);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
/**
|
||||
* 批量删除
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/batchRemove")
|
||||
@Transactional
|
||||
@Operation(summary = "批量删除")
|
||||
public ActionResult batchRemove(@RequestBody Object obj){
|
||||
Map<String, Object> objectMap = JsonUtil.entityToMap(obj);
|
||||
List<String> idList = JsonUtil.getJsonToList(objectMap.get("ids"), String.class);
|
||||
String errInfo = "";
|
||||
List<String> successList = new ArrayList<>();
|
||||
for (String allId : idList){
|
||||
try {
|
||||
this.delete(allId,false);
|
||||
successList.add(allId);
|
||||
} catch (Exception e) {
|
||||
errInfo = e.getMessage();
|
||||
}
|
||||
}
|
||||
if (successList.size() == 0 && StringUtil.isNotEmpty(errInfo)){
|
||||
return ActionResult.fail(errInfo);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
* @param id
|
||||
* @param crmLeadForm
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "更新")
|
||||
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid CrmLeadForm crmLeadForm,
|
||||
@RequestParam(value = "isImport", required = false) boolean isImport){
|
||||
CrmLeadEntity entity= crmLeadService.getInfo(id);
|
||||
if(entity!=null){
|
||||
crmLeadForm.setLeadId(String.valueOf(entity.getLeadId()));
|
||||
|
||||
if (!isImport) {
|
||||
String b = crmLeadService.checkForm(crmLeadForm,1);
|
||||
if (StringUtil.isNotEmpty(b)){
|
||||
return ActionResult.fail(b );
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
crmLeadService.saveOrUpdate(crmLeadForm,id,false);
|
||||
}catch (DataException e1){
|
||||
return ActionResult.fail(e1.getMessage());
|
||||
}catch(Exception e){
|
||||
return ActionResult.fail(MsgCode.FA029.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}else{
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
* 详情页面使用-转换数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult detailInfo(@PathVariable("id") String id){
|
||||
CrmLeadEntity entity= crmLeadService.getInfo(id);
|
||||
if(entity==null){
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
Map<String, Object> crmLeadMap=JsonUtil.entityToMap(entity);
|
||||
crmLeadMap.put("id", crmLeadMap.get("lead_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
|
||||
crmLeadMap = generaterSwapUtil.swapDataDetail(crmLeadMap,CrmLeadConstant.getFormData(),"807145376418105157",isPc?false:false);
|
||||
//子表数据
|
||||
return ActionResult.success(crmLeadMap);
|
||||
}
|
||||
/**
|
||||
* 获取详情(编辑页)
|
||||
* 编辑页面使用-不转换数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult info(@PathVariable("id") String id){
|
||||
CrmLeadEntity entity= crmLeadService.getInfo(id);
|
||||
if(entity==null){
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
Map<String, Object> crmLeadMap=JsonUtil.entityToMap(entity);
|
||||
crmLeadMap.put("id", crmLeadMap.get("lead_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
crmLeadMap = generaterSwapUtil.swapDataForm(crmLeadMap,CrmLeadConstant.getFormData(),CrmLeadConstant.TABLEFIELDKEY,CrmLeadConstant.TABLERENAMES);
|
||||
return ActionResult.success(crmLeadMap);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
package com.yunzhupaas.mdm.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 com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.mdm.service.*;
|
||||
import com.yunzhupaas.mdm.entity.*;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.mdm.model.projects.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import com.yunzhupaas.model.ExcelModel;
|
||||
import com.yunzhupaas.excel.ExcelExportStyler;
|
||||
import com.yunzhupaas.excel.ExcelHelper;
|
||||
import com.yunzhupaas.annotation.YunzhupaasField;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.base.entity.ProvinceEntity;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
import com.yunzhupaas.flowable.entity.TaskEntity;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.visualJson.UploaderTemplateModel;
|
||||
import com.yunzhupaas.base.util.FormExecelUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 项目信息
|
||||
* @版本: V5.2.7
|
||||
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* @作者: 深圳市乐程软件有限公司
|
||||
* @日期: 2026-05-19
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "项目信息" , description = "2")
|
||||
@RequestMapping("/api/bcm/Projects")
|
||||
public class ProjectsController {
|
||||
|
||||
@Autowired
|
||||
private GeneraterSwapUtil generaterSwapUtil;
|
||||
|
||||
@Autowired
|
||||
private UserProvider userProvider;
|
||||
|
||||
@Autowired
|
||||
private ProjectsService projectsService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param projectsPagination
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取列表")
|
||||
@PostMapping("/getList")
|
||||
public ActionResult list(@RequestBody ProjectsPagination projectsPagination)throws Exception{
|
||||
List<ProjectsEntity> list= projectsService.getList(projectsPagination);
|
||||
List<Map<String, Object>> realList=new ArrayList<>();
|
||||
for (ProjectsEntity entity : list) {
|
||||
Map<String, Object> projectsMap=JsonUtil.entityToMap(entity);
|
||||
projectsMap.put("id", projectsMap.get("project_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
realList.add(projectsMap);
|
||||
}
|
||||
//数据转换
|
||||
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
|
||||
realList = generaterSwapUtil.swapDataList(realList, ProjectsConstant.getFormData(), ProjectsConstant.getColumnData(), projectsPagination.getModuleId(),isPc?false:false);
|
||||
|
||||
if(isPc){
|
||||
//分组和树形的树形数据转换
|
||||
realList = generaterSwapUtil.swapDataList(realList, ProjectsConstant.getColumnData(), "project_id");
|
||||
}
|
||||
for (Map<String, Object> map : realList) {
|
||||
Object object = map.get("children");
|
||||
if (ObjectUtil.isNotNull(object) && object instanceof List) {
|
||||
// ✅ 直接转换为原对象,不创建新对象
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) object;
|
||||
for (Map<String, Object> child : children) {
|
||||
Object pidIdObj = child.get("pid_id");
|
||||
if (pidIdObj != null && !"".equals(pidIdObj.toString())) {
|
||||
ProjectsEntity entity = projectsService.getInfo(pidIdObj.toString());
|
||||
if (ObjectUtil.isNotNull(child.get("project_type_id_yunzhupaasId"))) {
|
||||
String projecttypeNme=projectsService.getProjettype(child.get("project_type_id_yunzhupaasId").toString());
|
||||
child.put("project_type_id", projecttypeNme);
|
||||
}
|
||||
if (entity != null) {
|
||||
child.put("pid", entity.getProjectName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//返回对象
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(realList);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(projectsPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param projectsForm
|
||||
* @return
|
||||
*/
|
||||
@PostMapping()
|
||||
@Operation(summary = "创建")
|
||||
public ActionResult create(@RequestBody @Valid ProjectsForm projectsForm) throws Exception {
|
||||
String b = projectsService.checkForm(projectsForm,0);
|
||||
if (StringUtil.isNotEmpty(b)){
|
||||
return ActionResult.fail(b );
|
||||
}
|
||||
try{
|
||||
projectsService.saveOrUpdate(projectsForm, null ,true);
|
||||
}catch(Exception e){
|
||||
return ActionResult.fail(MsgCode.FA028.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id,@RequestParam(name = "forceDel",defaultValue = "false") boolean forceDel) throws Exception{
|
||||
ProjectsEntity entity= projectsService.getInfo(id);
|
||||
if(entity!=null){
|
||||
//主表数据删除
|
||||
projectsService.delete(entity);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
/**
|
||||
* 批量删除
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/batchRemove")
|
||||
@Transactional
|
||||
@Operation(summary = "批量删除")
|
||||
public ActionResult batchRemove(@RequestBody Object obj){
|
||||
Map<String, Object> objectMap = JsonUtil.entityToMap(obj);
|
||||
List<String> idList = JsonUtil.getJsonToList(objectMap.get("ids"), String.class);
|
||||
String errInfo = "";
|
||||
List<String> successList = new ArrayList<>();
|
||||
for (String allId : idList){
|
||||
try {
|
||||
this.delete(allId,false);
|
||||
successList.add(allId);
|
||||
} catch (Exception e) {
|
||||
errInfo = e.getMessage();
|
||||
}
|
||||
}
|
||||
if (successList.size() == 0 && StringUtil.isNotEmpty(errInfo)){
|
||||
return ActionResult.fail(errInfo);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
* @param id
|
||||
* @param projectsForm
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "更新")
|
||||
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid ProjectsForm projectsForm,
|
||||
@RequestParam(value = "isImport", required = false) boolean isImport){
|
||||
ProjectsEntity entity= projectsService.getInfo(id);
|
||||
if(entity!=null){
|
||||
projectsForm.setProjectId(String.valueOf(entity.getProjectId()));
|
||||
|
||||
if (!isImport) {
|
||||
String b = projectsService.checkForm(projectsForm,1);
|
||||
if (StringUtil.isNotEmpty(b)){
|
||||
return ActionResult.fail(b );
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
projectsService.saveOrUpdate(projectsForm,id,false);
|
||||
}catch (DataException e1){
|
||||
return ActionResult.fail(e1.getMessage());
|
||||
}catch(Exception e){
|
||||
return ActionResult.fail(MsgCode.FA029.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}else{
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
* 详情页面使用-转换数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult detailInfo(@PathVariable("id") String id){
|
||||
ProjectsEntity entity= projectsService.getInfo(id);
|
||||
if(entity==null){
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
Map<String, Object> projectsMap=JsonUtil.entityToMap(entity);
|
||||
projectsMap.put("id", projectsMap.get("project_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
|
||||
projectsMap = generaterSwapUtil.swapDataDetail(projectsMap,ProjectsConstant.getFormData(),"826396413712664325",isPc?false:false);
|
||||
//子表数据
|
||||
if (ObjectUtil.isNotEmpty(projectsMap.get("pid_yunzhupaasId"))){
|
||||
ProjectsEntity entitys= projectsService.getInfo(projectsMap.get("pid_yunzhupaasId").toString());
|
||||
projectsMap.put("pid", entitys.getProjectName());
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(projectsMap.get("project_type_id_yunzhupaasId"))){
|
||||
String entitys= projectsService.getProjettype(projectsMap.get("project_type_id_yunzhupaasId").toString());
|
||||
projectsMap.put("project_type_id", entitys);
|
||||
}
|
||||
return ActionResult.success(projectsMap);
|
||||
}
|
||||
/**
|
||||
* 获取详情(编辑页)
|
||||
* 编辑页面使用-不转换数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult info(@PathVariable("id") String id){
|
||||
ProjectsEntity entity= projectsService.getInfo(id);
|
||||
if(entity==null){
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
Map<String, Object> projectsMap=JsonUtil.entityToMap(entity);
|
||||
projectsMap.put("id", projectsMap.get("project_id"));
|
||||
//副表数据
|
||||
//子表数据
|
||||
projectsMap = generaterSwapUtil.swapDataForm(projectsMap,ProjectsConstant.getFormData(),ProjectsConstant.TABLEFIELDKEY,ProjectsConstant.TABLERENAMES);
|
||||
|
||||
return ActionResult.success(projectsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 树状列表查询
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "树状列表查询")
|
||||
@GetMapping("/getTreeList")
|
||||
public ActionResult getTreeList(){
|
||||
List<Map<String, Object>> treeList= projectsService.getTreeList();
|
||||
return ActionResult.success(treeList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "工种信息" , description = "2")
|
||||
@RequestMapping("/api/2/WorkType")
|
||||
@RequestMapping("/api/bcm/WorkType")
|
||||
public class WorkTypeController {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user