去除无用代码,新增主数据功能

This commit is contained in:
wangmingwei
2026-05-06 09:32:05 +08:00
parent 540f3973d9
commit 825c45a45a
194 changed files with 12560 additions and 7946 deletions

View File

@@ -1,265 +0,0 @@
package com.yunzhupaas.base.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.base.service.*;
import com.yunzhupaas.base.entity.*;
import com.yunzhupaas.util.*;
import com.yunzhupaas.base.model.bcmprojecttype.*;
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.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-03-26
*/
@Slf4j
@RestController
@Tag(name = "项目类型" , description = "bcm")
@RequestMapping("/api/bcm/BcmProjectType")
public class BcmProjectTypeController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private BcmProjectTypeService bcmProjectTypeService;
/**
* 列表
*
* @param bcmProjectTypePagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody BcmProjectTypePagination bcmProjectTypePagination)throws Exception{
List<BcmProjectTypeEntity> list= bcmProjectTypeService.getList(bcmProjectTypePagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (BcmProjectTypeEntity entity : list) {
Map<String, Object> bcmProjectTypeMap=JsonUtil.entityToMap(entity);
bcmProjectTypeMap.put("id", bcmProjectTypeMap.get("project_type_id"));
//副表数据
//子表数据
realList.add(bcmProjectTypeMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, BcmProjectTypeConstant.getFormData(), BcmProjectTypeConstant.getColumnData(), bcmProjectTypePagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(bcmProjectTypePagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param bcmProjectTypeForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid BcmProjectTypeForm bcmProjectTypeForm) {
String b = bcmProjectTypeService.checkForm(bcmProjectTypeForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
bcmProjectTypeService.saveOrUpdate(bcmProjectTypeForm, null ,true);
}catch(Exception e){
log.error("【项目类型新增接口异常】参数:{}", bcmProjectTypeForm, 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{
BcmProjectTypeEntity entity= bcmProjectTypeService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
bcmProjectTypeService.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 bcmProjectTypeForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid BcmProjectTypeForm bcmProjectTypeForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
BcmProjectTypeEntity entity= bcmProjectTypeService.getInfo(id);
if(entity!=null){
bcmProjectTypeForm.setProjectTypeId(String.valueOf(entity.getProjectTypeId()));
if (!isImport) {
String b = bcmProjectTypeService.checkForm(bcmProjectTypeForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
bcmProjectTypeService.saveOrUpdate(bcmProjectTypeForm,id,false);
}catch (DataException e1){
return ActionResult.fail(e1.getMessage());
}catch(Exception e){
log.error("【项目类型修改接口异常】参数:{}", bcmProjectTypeForm, 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){
BcmProjectTypeEntity entity= bcmProjectTypeService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> bcmProjectTypeMap=JsonUtil.entityToMap(entity);
bcmProjectTypeMap.put("id", bcmProjectTypeMap.get("project_type_id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
bcmProjectTypeMap = generaterSwapUtil.swapDataDetail(bcmProjectTypeMap,BcmProjectTypeConstant.getFormData(),"806852213774222853",isPc?false:false);
//子表数据
return ActionResult.success(bcmProjectTypeMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
BcmProjectTypeEntity entity= bcmProjectTypeService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> bcmProjectTypeMap=JsonUtil.entityToMap(entity);
bcmProjectTypeMap.put("id", bcmProjectTypeMap.get("project_type_id"));
//副表数据
//子表数据
bcmProjectTypeMap = generaterSwapUtil.swapDataForm(bcmProjectTypeMap,BcmProjectTypeConstant.getFormData(),BcmProjectTypeConstant.TABLEFIELDKEY,BcmProjectTypeConstant.TABLERENAMES);
return ActionResult.success(bcmProjectTypeMap);
}
/**
* 获取项目类型列表
*
* @param bcmProjectTypePagination
* @return
*/
@Operation(summary = "获取项目类型列表")
@PostMapping("/getBcmprojecttypeList")
public ActionResult getBcmprojecttypeList(@RequestBody BcmProjectTypePagination bcmProjectTypePagination)throws Exception{
List<BcmProjectTypeEntity> list= bcmProjectTypeService.getList(bcmProjectTypePagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (BcmProjectTypeEntity entity : list) {
Map<String, Object> bcmProjectTypeMap=JsonUtil.entityToMap(entity);
bcmProjectTypeMap.put("id", bcmProjectTypeMap.get("project_type_id"));
//副表数据
//子表数据
realList.add(bcmProjectTypeMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, BcmProjectTypeConstant.getFormData(), BcmProjectTypeConstant.getColumnData(), bcmProjectTypePagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(bcmProjectTypePagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
}

View File

@@ -1,273 +0,0 @@
package com.yunzhupaas.base.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.base.service.*;
import com.yunzhupaas.base.entity.*;
import com.yunzhupaas.util.*;
import com.yunzhupaas.base.model.mdmcompany.*;
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.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;
/**
* mdm_company
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-03-270
*/
@Slf4j
@RestController
@Tag(name = "mdm_company" , description = "bcm")
@RequestMapping("/api/bcm/MdmCompany")
public class MdmCompanyController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private MdmCompanyService mdmCompanyService;
@Autowired
private CrmCustomerService crmCustomerService;
@Autowired
private MdmCompanyContactService mdmCompanyContactService;
@Autowired
private MdmCompanyBankService mdmCompanyBankService;
/**
* 列表
*
* @param mdmCompanyPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody MdmCompanyPagination mdmCompanyPagination)throws Exception{
List<MdmCompanyEntity> list= mdmCompanyService.getList(mdmCompanyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MdmCompanyEntity entity : list) {
Map<String, Object> mdmCompanyMap=JsonUtil.entityToMap(entity);
mdmCompanyMap.put("id", mdmCompanyMap.get("company_id"));
//副表数据
//子表数据
// CrmCustomerEntity crmCustomerList = entity.getCrmCustomer();
// mdmCompanyMap.put("tableField798457",JsonUtil.getJsonToBean(crmCustomerList,CrmCustomerEntity.class));
// mdmCompanyMap.put("crmCustomerList",JsonUtil.getJsonToBean(crmCustomerList,CrmCustomerEntity.class));
List<MdmCompanyContactEntity> mdmCompanyContactList = entity.getMdmCompanyContact();
mdmCompanyMap.put("tableFieldc4fb23",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
mdmCompanyMap.put("mdmCompanyContactList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
List<MdmCompanyBankEntity> mdmCompanyBankList = entity.getMdmCompanyBank();
mdmCompanyMap.put("tableFieldaafa82",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
mdmCompanyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
realList.add(mdmCompanyMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, MdmCompanyConstant.getFormData(), MdmCompanyConstant.getColumnData(), mdmCompanyPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(mdmCompanyPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param mdmCompanyForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid MdmCompanyForm mdmCompanyForm) {
String b = mdmCompanyService.checkForm(mdmCompanyForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
mdmCompanyService.saveOrUpdate(mdmCompanyForm, null ,true);
}catch(Exception e){
log.error("【企业信息(包括:客商与企业内部单位)创建接口异常】参数:{}", mdmCompanyForm, 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{
MdmCompanyEntity entity= mdmCompanyService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
mdmCompanyService.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 mdmCompanyForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MdmCompanyForm mdmCompanyForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
MdmCompanyEntity entity= mdmCompanyService.getInfo(id);
if(entity!=null){
mdmCompanyForm.setCompanyId(String.valueOf(entity.getCompanyId()));
if (!isImport) {
String b = mdmCompanyService.checkForm(mdmCompanyForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
mdmCompanyService.saveOrUpdate(mdmCompanyForm,id,false);
}catch (DataException e1){
return ActionResult.fail(e1.getMessage());
}catch(Exception e){
log.error("【企业信息(包括:客商与企业内部单位)编辑接口异常】参数:{}", mdmCompanyForm, 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){
MdmCompanyEntity entity= mdmCompanyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmCompanyMap=JsonUtil.entityToMap(entity);
mdmCompanyMap.put("id", mdmCompanyMap.get("company_id"));
//副表数据
//子表数据
CrmCustomerEntity crmCustomerList = entity.getCrmCustomer();
mdmCompanyMap.put("tableField798457",JsonUtil.getJsonToBean(crmCustomerList,CrmCustomerEntity.class));
mdmCompanyMap.put("crmCustomerList",JsonUtil.getJsonToBean(crmCustomerList,CrmCustomerEntity.class));
List<MdmCompanyContactEntity> mdmCompanyContactList = entity.getMdmCompanyContact();
mdmCompanyMap.put("tableFieldc4fb23",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
mdmCompanyMap.put("mdmCompanyContactList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
List<MdmCompanyBankEntity> mdmCompanyBankList = entity.getMdmCompanyBank();
mdmCompanyMap.put("tableFieldaafa82",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
mdmCompanyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
mdmCompanyMap = generaterSwapUtil.swapDataDetail(mdmCompanyMap,MdmCompanyConstant.getFormData(),"807175611364673349",isPc?false:false);
//子表数据
mdmCompanyMap.put("crmCustomerList",mdmCompanyMap.get("tableField798457"));
mdmCompanyMap.put("mdmCompanyContactList",mdmCompanyMap.get("tableFieldc4fb23"));
mdmCompanyMap.put("mdmCompanyBankList",mdmCompanyMap.get("tableFieldaafa82"));
return ActionResult.success(mdmCompanyMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
MdmCompanyEntity entity= mdmCompanyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmCompanyMap=JsonUtil.entityToMap(entity);
mdmCompanyMap.put("id", mdmCompanyMap.get("company_id"));
//副表数据
//子表数据
CrmCustomerEntity crmCustomer = entity.getCrmCustomer();
// mdmCompanyMap.put("tableField798457",JsonUtil.getJsonToBean(crmCustomerList,CrmCustomerEntity.class));
mdmCompanyMap.put("crmCustomer",JsonUtil.getJsonToBean(crmCustomer,CrmCustomerEntity.class));
List<MdmCompanyContactEntity> mdmCompanyContactList = entity.getMdmCompanyContact();
mdmCompanyMap.put("tableFieldc4fb23",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
mdmCompanyMap.put("mdmCompanyContactList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyContactList)));
List<MdmCompanyBankEntity> mdmCompanyBankList = entity.getMdmCompanyBank();
mdmCompanyMap.put("tableFieldaafa82",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
mdmCompanyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
mdmCompanyMap = generaterSwapUtil.swapDataForm(mdmCompanyMap,MdmCompanyConstant.getFormData(),MdmCompanyConstant.TABLEFIELDKEY,MdmCompanyConstant.TABLERENAMES);
return ActionResult.success(mdmCompanyMap);
}
}

View File

@@ -1,257 +0,0 @@
package com.yunzhupaas.base.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.base.service.*;
import com.yunzhupaas.base.entity.*;
import com.yunzhupaas.util.*;
import com.yunzhupaas.base.model.mdmcontracttype.*;
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.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;
/**
* mdmContractType
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-03-30
*/
@Slf4j
@RestController
@Tag(name = "mdmContractType" , description = "bcm")
@RequestMapping("/api/bcm/MdmContractType")
public class MdmContractTypeController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private MdmContractTypeService mdmContractTypeService;
/**
* 列表
*
* @param mdmContractTypePagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody MdmContractTypePagination mdmContractTypePagination)throws Exception{
List<MdmContractTypeEntity> list= mdmContractTypeService.getList(mdmContractTypePagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MdmContractTypeEntity entity : list) {
Map<String, Object> mdmContractTypeMap=JsonUtil.entityToMap(entity);
mdmContractTypeMap.put("id", mdmContractTypeMap.get("id"));
//副表数据
//子表数据
realList.add(mdmContractTypeMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, MdmContractTypeConstant.getFormData(), MdmContractTypeConstant.getColumnData(), mdmContractTypePagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(mdmContractTypePagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param mdmContractTypeForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid MdmContractTypeForm mdmContractTypeForm) {
String b = mdmContractTypeService.checkForm(mdmContractTypeForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
mdmContractTypeService.saveOrUpdate(mdmContractTypeForm, null ,true);
}catch(Exception e){
log.error("【合同类型配置创建接口异常】参数:{}", mdmContractTypeForm, 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{
MdmContractTypeEntity entity= mdmContractTypeService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
mdmContractTypeService.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 mdmContractTypeForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MdmContractTypeForm mdmContractTypeForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
MdmContractTypeEntity entity= mdmContractTypeService.getInfo(id);
if(entity!=null){
mdmContractTypeForm.setId(String.valueOf(entity.getId()));
if (!isImport) {
String b = mdmContractTypeService.checkForm(mdmContractTypeForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
mdmContractTypeService.saveOrUpdate(mdmContractTypeForm,id,false);
}catch (DataException e1){
return ActionResult.fail(e1.getMessage());
}catch(Exception e){
log.error("【合同类型配置编辑接口异常】参数:{}", mdmContractTypeForm, 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){
MdmContractTypeEntity entity= mdmContractTypeService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmContractTypeMap=JsonUtil.entityToMap(entity);
mdmContractTypeMap.put("id", mdmContractTypeMap.get("id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
mdmContractTypeMap = generaterSwapUtil.swapDataDetail(mdmContractTypeMap,MdmContractTypeConstant.getFormData(),"808252366691240901",isPc?false:false);
//子表数据
return ActionResult.success(mdmContractTypeMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
MdmContractTypeEntity entity= mdmContractTypeService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmContractTypeMap=JsonUtil.entityToMap(entity);
mdmContractTypeMap.put("id", mdmContractTypeMap.get("id"));
//副表数据
//子表数据
mdmContractTypeMap = generaterSwapUtil.swapDataForm(mdmContractTypeMap,MdmContractTypeConstant.getFormData(),MdmContractTypeConstant.TABLEFIELDKEY,MdmContractTypeConstant.TABLERENAMES);
return ActionResult.success(mdmContractTypeMap);
}
/**
* 根据类型查询
*
* @param mdmContractTypePagination
* @return
*/
@Operation(summary = "根据类型查询")
@PostMapping("/listByContractMode")
public ActionResult listByContractMode(@RequestBody MdmContractTypePagination mdmContractTypePagination)throws Exception{
List<MdmContractTypeEntity> list= mdmContractTypeService.getList(mdmContractTypePagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MdmContractTypeEntity entity : list) {
Map<String, Object> mdmContractTypeMap=JsonUtil.entityToMap(entity);
mdmContractTypeMap.put("id", mdmContractTypeMap.get("id"));
//副表数据
//子表数据
realList.add(mdmContractTypeMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, MdmContractTypeConstant.getFormData(), MdmContractTypeConstant.getColumnData(), mdmContractTypePagination.getModuleId(),isPc?false:false);
return ActionResult.success(realList);
}
}

View File

@@ -1,232 +0,0 @@
package com.yunzhupaas.base.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.base.service.*;
import com.yunzhupaas.base.entity.*;
import com.yunzhupaas.util.*;
import com.yunzhupaas.base.model.mdmproject.*;
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.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-03-26
*/
@Slf4j
@RestController
@Tag(name = "项目结构" , description = "bcm")
@RequestMapping("/api/bcm/MdmProject")
public class MdmProjectController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private MdmProjectService mdmProjectService;
/**
* 列表
*
* @param mdmProjectPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody MdmProjectPagination mdmProjectPagination)throws Exception{
List<MdmProjectEntity> list= mdmProjectService.getList(mdmProjectPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MdmProjectEntity entity : list) {
Map<String, Object> mdmProjectMap=JsonUtil.entityToMap(entity);
mdmProjectMap.put("id", mdmProjectMap.get("project_id"));
//副表数据
//子表数据
realList.add(mdmProjectMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, MdmProjectConstant.getFormData(), MdmProjectConstant.getColumnData(), mdmProjectPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(mdmProjectPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param mdmProjectForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid MdmProjectForm mdmProjectForm) {
String b = mdmProjectService.checkForm(mdmProjectForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
mdmProjectService.saveOrUpdate(mdmProjectForm, null ,true);
}catch(Exception e){
log.error("【项目结构创建项目接口异常】参数:{}", mdmProjectForm, 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{
MdmProjectEntity entity= mdmProjectService.getInfo(id);
if(entity!=null){
//主表数据删除
mdmProjectService.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 mdmProjectForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MdmProjectForm mdmProjectForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
MdmProjectEntity entity= mdmProjectService.getInfo(id);
if(entity!=null){
mdmProjectForm.setProjectId(String.valueOf(entity.getProjectId()));
if (!isImport) {
String b = mdmProjectService.checkForm(mdmProjectForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
mdmProjectService.saveOrUpdate(mdmProjectForm,id,false);
}catch (DataException e1){
return ActionResult.fail(e1.getMessage());
}catch(Exception e){
log.error("【项目结构修改项目接口异常】参数:{}", mdmProjectForm, 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){
MdmProjectEntity entity= mdmProjectService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmProjectMap=JsonUtil.entityToMap(entity);
mdmProjectMap.put("id", mdmProjectMap.get("project_id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
mdmProjectMap = generaterSwapUtil.swapDataDetail(mdmProjectMap,MdmProjectConstant.getFormData(),"806868519370098181",isPc?false:false);
//子表数据
return ActionResult.success(mdmProjectMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
MdmProjectEntity entity= mdmProjectService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> mdmProjectMap=JsonUtil.entityToMap(entity);
mdmProjectMap.put("id", mdmProjectMap.get("project_id"));
//副表数据
//子表数据
mdmProjectMap = generaterSwapUtil.swapDataForm(mdmProjectMap,MdmProjectConstant.getFormData(),MdmProjectConstant.TABLEFIELDKEY,MdmProjectConstant.TABLERENAMES);
return ActionResult.success(mdmProjectMap);
}
}

View File

@@ -0,0 +1,697 @@
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.asset.*;
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;
/**
* 资产信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-28
*/
@Slf4j
@RestController
@Tag(name = "资产信息" , description = "bcm")
@RequestMapping("/api/bcm/Asset")
public class AssetController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private AssetService assetService;
@Autowired
private SuppinfoService companyService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param assetPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody AssetPagination assetPagination)throws Exception{
List<AssetEntity> list= assetService.getList(assetPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (AssetEntity entity : list) {
Map<String, Object> assetMap=JsonUtil.entityToMap(entity);
assetMap.put("id", assetMap.get("asset_id"));
//副表数据
//子表数据
realList.add(assetMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, AssetConstant.getFormData(), AssetConstant.getColumnData(), assetPagination.getModuleId(),isPc?false:false);
for (Map<String, Object> map : realList) {
if(ObjectUtil.isNotEmpty( map.get("supplier_id"))){
map.put("supplier_id", companyService.getInfo(map.get("supplier_id").toString()).getCompanyName());
}
}
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(assetPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param assetForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid AssetForm assetForm) {
String b = assetService.checkForm(assetForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
assetService.saveOrUpdate(assetForm, null ,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 AssetPagination assetPagination) throws IOException {
if (StringUtil.isEmpty(assetPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<AssetEntity> list= assetService.getList(assetPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (AssetEntity entity : list) {
Map<String, Object> assetMap=JsonUtil.entityToMap(entity);
assetMap.put("id", assetMap.get("asset_id"));
//副表数据
//子表数据
realList.add(assetMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, AssetConstant.getFormData(), AssetConstant.getColumnData(), assetPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(assetPagination.getSelectKey())?assetPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(assetPagination.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 "asset_code" :
entitys.add(new ExcelExportEntity("资产编码" ,"asset_code"));
break;
case "asset_name" :
entitys.add(new ExcelExportEntity("资产名称" ,"asset_name"));
break;
case "asset_type" :
entitys.add(new ExcelExportEntity("资产类型" ,"asset_type"));
break;
case "asset_category" :
entitys.add(new ExcelExportEntity("资产分类" ,"asset_category"));
break;
case "asset_status" :
entitys.add(new ExcelExportEntity("资产状态" ,"asset_status"));
break;
case "asset_location" :
entitys.add(new ExcelExportEntity("资产位置" ,"asset_location"));
break;
case "current_org_id" :
entitys.add(new ExcelExportEntity("使用组织" ,"current_org_id"));
break;
case "current_user_id" :
entitys.add(new ExcelExportEntity("保管用户" ,"current_user_id"));
break;
case "asset_ownership" :
entitys.add(new ExcelExportEntity("资产权属" ,"asset_ownership"));
break;
case "measurement_unit" :
entitys.add(new ExcelExportEntity("单位" ,"measurement_unit"));
break;
case "quantity" :
entitys.add(new ExcelExportEntity("数量" ,"quantity"));
break;
case "purchase_date" :
entitys.add(new ExcelExportEntity("购置日期" ,"purchase_date"));
break;
case "commissioning_date" :
entitys.add(new ExcelExportEntity("启用日期" ,"commissioning_date"));
break;
case "expected_life" :
entitys.add(new ExcelExportEntity("预计使用年限" ,"expected_life"));
break;
case "supplier_id" :
entitys.add(new ExcelExportEntity("供应商" ,"supplier_id"));
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(AssetConstant.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(AssetConstant.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("资产名称(asset_name)" ,"asset_name"));
selectKeys.add("asset_name");
entitys.add(new ExcelExportEntity("资产类型(asset_type)" ,"asset_type"));
selectKeys.add("asset_type");
entitys.add(new ExcelExportEntity("资产分类(asset_category)" ,"asset_category"));
selectKeys.add("asset_category");
entitys.add(new ExcelExportEntity("资产状态(asset_status)" ,"asset_status"));
selectKeys.add("asset_status");
entitys.add(new ExcelExportEntity("资产权属(asset_ownership)" ,"asset_ownership"));
selectKeys.add("asset_ownership");
entitys.add(new ExcelExportEntity("资产位置(asset_location)" ,"asset_location"));
selectKeys.add("asset_location");
entitys.add(new ExcelExportEntity("使用组织(current_org_id)" ,"current_org_id"));
selectKeys.add("current_org_id");
entitys.add(new ExcelExportEntity("单位(measurement_unit)" ,"measurement_unit"));
selectKeys.add("measurement_unit");
entitys.add(new ExcelExportEntity("启用日期(commissioning_date)" ,"commissioning_date"));
selectKeys.add("commissioning_date");
entitys.add(new ExcelExportEntity("购置日期(purchase_date)" ,"purchase_date"));
selectKeys.add("purchase_date");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
entitys.add(new ExcelExportEntity("预计使用年限(expected_life)" ,"expected_life"));
selectKeys.add("expected_life");
entitys.add(new ExcelExportEntity("数量(quantity)" ,"quantity"));
selectKeys.add("quantity");
entitys.add(new ExcelExportEntity("保管用户(current_user_id)" ,"current_user_id"));
selectKeys.add("current_user_id");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(AssetConstant.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(AssetConstant.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(AssetConstant.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("asset_name","资产名称","input"));
columns.add(new ExcelImFieldModel("asset_type","资产类型","select"));
columns.add(new ExcelImFieldModel("asset_category","资产分类","select"));
columns.add(new ExcelImFieldModel("asset_status","资产状态","select"));
columns.add(new ExcelImFieldModel("asset_ownership","资产权属","select"));
columns.add(new ExcelImFieldModel("asset_location","资产位置","cascader"));
columns.add(new ExcelImFieldModel("current_org_id","使用组织","organizeSelect"));
columns.add(new ExcelImFieldModel("measurement_unit","单位","input"));
columns.add(new ExcelImFieldModel("commissioning_date","启用日期","datePicker"));
columns.add(new ExcelImFieldModel("purchase_date","购置日期","datePicker"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
columns.add(new ExcelImFieldModel("expected_life","预计使用年限","inputNumber"));
columns.add(new ExcelImFieldModel("quantity","数量","inputNumber"));
columns.add(new ExcelImFieldModel("current_user_id","保管用户","userSelect"));
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(AssetConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("1", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:AssetConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,AssetConstant.TABLERENAMES.get(AssetConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(AssetConstant.getFormData(),listData,uniqueModel, tablefieldkey,AssetConstant.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,AssetForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,AssetForm.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("资产名称(asset_name)" ,"asset_name"));
selectKeys.add("asset_name");
entitys.add(new ExcelExportEntity("资产类型(asset_type)" ,"asset_type"));
selectKeys.add("asset_type");
entitys.add(new ExcelExportEntity("资产分类(asset_category)" ,"asset_category"));
selectKeys.add("asset_category");
entitys.add(new ExcelExportEntity("资产状态(asset_status)" ,"asset_status"));
selectKeys.add("asset_status");
entitys.add(new ExcelExportEntity("资产权属(asset_ownership)" ,"asset_ownership"));
selectKeys.add("asset_ownership");
entitys.add(new ExcelExportEntity("资产位置(asset_location)" ,"asset_location"));
selectKeys.add("asset_location");
entitys.add(new ExcelExportEntity("使用组织(current_org_id)" ,"current_org_id"));
selectKeys.add("current_org_id");
entitys.add(new ExcelExportEntity("单位(measurement_unit)" ,"measurement_unit"));
selectKeys.add("measurement_unit");
entitys.add(new ExcelExportEntity("启用日期(commissioning_date)" ,"commissioning_date"));
selectKeys.add("commissioning_date");
entitys.add(new ExcelExportEntity("购置日期(purchase_date)" ,"purchase_date"));
selectKeys.add("purchase_date");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
entitys.add(new ExcelExportEntity("预计使用年限(expected_life)" ,"expected_life"));
selectKeys.add("expected_life");
entitys.add(new ExcelExportEntity("数量(quantity)" ,"quantity"));
selectKeys.add("quantity");
entitys.add(new ExcelExportEntity("保管用户(current_user_id)" ,"current_user_id"));
selectKeys.add("current_user_id");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(AssetConstant.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(AssetConstant.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{
AssetEntity entity= assetService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
assetService.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 assetForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid AssetForm assetForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
AssetEntity entity= assetService.getInfo(id);
if(entity!=null){
assetForm.setAssetId(String.valueOf(entity.getAssetId()));
if (!isImport) {
String b = assetService.checkForm(assetForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
assetService.saveOrUpdate(assetForm,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){
AssetEntity entity= assetService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> assetMap=JsonUtil.entityToMap(entity);
assetMap.put("id", assetMap.get("asset_id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
assetMap = generaterSwapUtil.swapDataDetail(assetMap,AssetConstant.getFormData(),"818770027560829701",isPc?false:false);
assetMap.put("supplier_id", companyService.getInfo(assetMap.get("supplier_id").toString()).getCompanyName());
//子表数据
return ActionResult.success(assetMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
AssetEntity entity= assetService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> assetMap=JsonUtil.entityToMap(entity);
assetMap.put("id", assetMap.get("asset_id"));
//副表数据
//子表数据
assetMap = generaterSwapUtil.swapDataForm(assetMap,AssetConstant.getFormData(),AssetConstant.TABLEFIELDKEY,AssetConstant.TABLERENAMES);
return ActionResult.success(assetMap);
}
}

View File

@@ -0,0 +1,932 @@
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.company.*;
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;
/**
* 企业信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-24
*/
@Slf4j
@RestController
@Tag(name = "企业信息" , description = "bcm")
@RequestMapping("/api/bcm/Company")
public class CompanyController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private CompanyService companyService;
@Autowired
private CompanyBankService mdmCompanyBankService;
@Autowired
private CompanyInvoiceService companyInvoiceService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param companyPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody CompanyPagination companyPagination)throws Exception{
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
//子表数据
List<CompanyBankEntity> mdmCompanyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
companyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
realList.add(companyMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, CompanyConstant.getFormData(), CompanyConstant.getColumnData(), companyPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(companyPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param companyForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid CompanyForm companyForm) {
String b = companyService.checkForm(companyForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
companyService.saveOrUpdate(companyForm, null ,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 CompanyPagination companyPagination) throws IOException {
if (StringUtil.isEmpty(companyPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
//子表数据
List<CompanyBankEntity> mdmCompanyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
companyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
realList.add(companyMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, CompanyConstant.getFormData(), CompanyConstant.getColumnData(), companyPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(companyPagination.getSelectKey())?companyPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(companyPagination.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){
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92List = new ArrayList<>();
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53List = new ArrayList<>();
for(String key:keys){
switch(key){
case "company_code" :
entitys.add(new ExcelExportEntity("企业编码" ,"company_code"));
break;
case "company_name" :
entitys.add(new ExcelExportEntity("企业名称" ,"company_name"));
break;
case "short_name" :
entitys.add(new ExcelExportEntity("简称/昵称" ,"short_name"));
break;
case "entity_type" :
entitys.add(new ExcelExportEntity("类型" ,"entity_type"));
break;
case "credit_code" :
entitys.add(new ExcelExportEntity("社会信用代码" ,"credit_code"));
break;
case "org_id" :
entitys.add(new ExcelExportEntity("归属组织" ,"org_id"));
break;
case "province_id" :
entitys.add(new ExcelExportEntity("所属地区" ,"province_id"));
break;
case "tax_type" :
entitys.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "enterprise_scale" :
entitys.add(new ExcelExportEntity("企业规模" ,"enterprise_scale"));
break;
case "enterprise_nature" :
entitys.add(new ExcelExportEntity("企业类型" ,"enterprise_nature"));
break;
case "industry_code" :
entitys.add(new ExcelExportEntity("行业代码" ,"industry_code"));
break;
case "registration_date" :
entitys.add(new ExcelExportEntity("成立日期" ,"registration_date"));
break;
case "registered_capital" :
entitys.add(new ExcelExportEntity("注册资本" ,"registered_capital"));
break;
case "legal_representative" :
entitys.add(new ExcelExportEntity("法定代表人" ,"legal_representative"));
break;
case "phone" :
entitys.add(new ExcelExportEntity("联系电话" ,"phone"));
break;
case "email" :
entitys.add(new ExcelExportEntity("邮箱" ,"email"));
break;
case "website" :
entitys.add(new ExcelExportEntity("网站" ,"website"));
break;
case "address" :
entitys.add(new ExcelExportEntity("地址" ,"address"));
break;
case "business_scope" :
entitys.add(new ExcelExportEntity("经营范围" ,"business_scope"));
break;
case "remark" :
entitys.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "tableFieldad9d92-bank_name":
tableFieldad9d92List.add(new ExcelExportEntity("开户行" ,"bank_name"));
break;
case "tableFieldad9d92-bank_account_name":
tableFieldad9d92List.add(new ExcelExportEntity("账户名" ,"bank_account_name"));
break;
case "tableFieldad9d92-bank_account_number":
tableFieldad9d92List.add(new ExcelExportEntity("银行账号" ,"bank_account_number"));
break;
case "tableFieldad9d92-bank_province":
tableFieldad9d92List.add(new ExcelExportEntity("开户行城市" ,"bank_province"));
break;
case "tableFieldad9d92-remark":
tableFieldad9d92List.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "tableField46dc53-title_code":
tableField46dc53List.add(new ExcelExportEntity("发票抬头编码" ,"title_code"));
break;
case "tableField46dc53-title_name":
tableField46dc53List.add(new ExcelExportEntity("发票抬头名称" ,"title_name"));
break;
case "tableField46dc53-credit_code":
tableField46dc53List.add(new ExcelExportEntity("纳税人识别号" ,"credit_code"));
break;
case "tableField46dc53-tax_type":
tableField46dc53List.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "tableField46dc53-address":
tableField46dc53List.add(new ExcelExportEntity("地址" ,"address"));
break;
case "tableField46dc53-phone":
tableField46dc53List.add(new ExcelExportEntity("电话" ,"phone"));
break;
case "tableField46dc53-bank_name":
tableField46dc53List.add(new ExcelExportEntity("开户银行" ,"bank_name"));
break;
case "tableField46dc53-bank_account":
tableField46dc53List.add(new ExcelExportEntity("银行账户" ,"bank_account"));
break;
case "tableField46dc53-is_defalut":
tableField46dc53List.add(new ExcelExportEntity("是否默认" ,"is_defalut"));
break;
case "tableField46dc53-is_valid":
tableField46dc53List.add(new ExcelExportEntity("是否有效" ,"is_valid"));
break;
case "tableField46dc53-remark":
tableField46dc53List.add(new ExcelExportEntity("备注" ,"remark"));
break;
default:
break;
}
}
if(tableFieldad9d92List.size() > 0){
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92List);
entitys.add(tableFieldad9d92ExcelEntity);
}
if(tableField46dc53List.size() > 0){
tableField46dc53ExcelEntity.setList(tableField46dc53List);
entitys.add(tableField46dc53ExcelEntity);
}
}
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(CompanyConstant.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(CompanyConstant.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("企业编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
if(tableFieldad9d92ExcelEntityList.size() > 0){
entitys.add(tableFieldad9d92ExcelEntity);
}
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
if(tableField46dc53ExcelEntityList.size() > 0){
entitys.add(tableField46dc53ExcelEntity);
}
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CompanyConstant.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(CompanyConstant.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 = 2;
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(CompanyConstant.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("company_name","企业名称","input"));
columns.add(new ExcelImFieldModel("credit_code","社会信用代码","input"));
columns.add(new ExcelImFieldModel("org_id","归属组织","organizeSelect"));
columns.add(new ExcelImFieldModel("company_code","企业编码","billRule"));
columns.add(new ExcelImFieldModel("short_name","简称/昵称","input"));
columns.add(new ExcelImFieldModel("entity_type","类型","radio"));
columns.add(new ExcelImFieldModel("tax_type","纳税人类别","select"));
columns.add(new ExcelImFieldModel("enterprise_scale","企业规模","select"));
columns.add(new ExcelImFieldModel("enterprise_nature","企业类型","select"));
columns.add(new ExcelImFieldModel("industry_code","行业代码","select"));
columns.add(new ExcelImFieldModel("registration_date","成立日期","datePicker"));
columns.add(new ExcelImFieldModel("registered_capital","注册资本","inputNumber"));
columns.add(new ExcelImFieldModel("legal_representative","法定代表人","input"));
columns.add(new ExcelImFieldModel("phone","联系电话","input"));
columns.add(new ExcelImFieldModel("email","邮箱","input"));
columns.add(new ExcelImFieldModel("website","网站","input"));
columns.add(new ExcelImFieldModel("address","地址","input"));
columns.add(new ExcelImFieldModel("province_id","所属地区","areaSelect"));
columns.add(new ExcelImFieldModel("business_scope","经营范围","textarea"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
//tableFieldad9d92子表对象
List<ExcelImFieldModel> tableFieldad9d92columns = new ArrayList<>();
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_name" ,"开户行"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_name" ,"账户名"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_number" ,"银行账号"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_province" ,"开户行城市"));
tableFieldad9d92columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableFieldad9d92","设计子表","table",tableFieldad9d92columns));
//tableField46dc53子表对象
List<ExcelImFieldModel> tableField46dc53columns = new ArrayList<>();
tableField46dc53columns.add(new ExcelImFieldModel("title_name" ,"发票抬头名称"));
tableField46dc53columns.add(new ExcelImFieldModel("credit_code" ,"纳税人识别号"));
tableField46dc53columns.add(new ExcelImFieldModel("tax_type" ,"纳税人类别"));
tableField46dc53columns.add(new ExcelImFieldModel("address" ,"地址"));
tableField46dc53columns.add(new ExcelImFieldModel("phone" ,"电话"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_name" ,"开户银行"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_account" ,"银行账户"));
tableField46dc53columns.add(new ExcelImFieldModel("is_defalut" ,"是否默认"));
tableField46dc53columns.add(new ExcelImFieldModel("is_valid" ,"是否有效"));
tableField46dc53columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableField46dc53","设计子表","table",tableField46dc53columns));
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(CompanyConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:CompanyConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,CompanyConstant.TABLERENAMES.get(CompanyConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(CompanyConstant.getFormData(),listData,uniqueModel, tablefieldkey,CompanyConstant.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,CompanyForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,CompanyForm.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("企业编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
entitys.add(tableFieldad9d92ExcelEntity);
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
entitys.add(tableField46dc53ExcelEntity);
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CompanyConstant.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(CompanyConstant.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{
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
//主表数据删除
companyService.delete(entity);
QueryWrapper<CompanyBankEntity> queryWrapperMdmCompanyBank=new QueryWrapper<>();
queryWrapperMdmCompanyBank.lambda().eq(CompanyBankEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
mdmCompanyBankService.remove(queryWrapperMdmCompanyBank);
QueryWrapper<CompanyInvoiceEntity> queryWrapperCompanyInvoice=new QueryWrapper<>();
queryWrapperCompanyInvoice.lambda().eq(CompanyInvoiceEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
companyInvoiceService.remove(queryWrapperCompanyInvoice);
}
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 companyForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid CompanyForm companyForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
companyForm.setCompanyId(String.valueOf(entity.getCompanyId()));
if (!isImport) {
String b = companyService.checkForm(companyForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
companyService.saveOrUpdate(companyForm,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){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
//子表数据
List<CompanyBankEntity> mdmCompanyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
companyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
companyMap = generaterSwapUtil.swapDataDetail(companyMap,CompanyConstant.getFormData(),"806858527036409349",isPc?false:false);
//子表数据
companyMap.put("mdmCompanyBankList",companyMap.get("tableFieldad9d92"));
companyMap.put("companyInvoiceList",companyMap.get("tableField46dc53"));
return ActionResult.success(companyMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
//子表数据
List<CompanyBankEntity> mdmCompanyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
companyMap.put("mdmCompanyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(mdmCompanyBankList)));
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap = generaterSwapUtil.swapDataForm(companyMap,CompanyConstant.getFormData(),CompanyConstant.TABLEFIELDKEY,CompanyConstant.TABLERENAMES);
return ActionResult.success(companyMap);
}
}

View File

@@ -0,0 +1,970 @@
package com.yunzhupaas.mdm.controller;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.mdm.model.custinfo.CustinfoConstant;
import com.yunzhupaas.mdm.model.custinfo.CustinfoForm;
import com.yunzhupaas.mdm.model.custinfo.CustinfoPagination;
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.constant.MsgCode;
import com.yunzhupaas.mdm.service.*;
import com.yunzhupaas.mdm.entity.*;
import com.yunzhupaas.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.base.vo.PageListVO;
import com.yunzhupaas.base.vo.PaginationVO;
import com.yunzhupaas.base.vo.DownloadVO;
import com.yunzhupaas.config.ConfigValueUtil;
import java.io.IOException;
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.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.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;
/**
* 客户信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-24
*/
@Slf4j
@RestController
@Tag(name = "客户信息" , description = "bcm")
@RequestMapping("/api/bcm/Custinfo")
public class CustinfoController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private CustinfoService companyService;
@Autowired
private CompanyInvoiceService companyInvoiceService;
@Autowired
private CompanyBankService companyBankService;
@Autowired
private CustomerService customerService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param companyPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody CustinfoPagination companyPagination)throws Exception{
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CustomerEntity customerEntity = entity.getCustomer();
if(ObjectUtil.isNotEmpty(customerEntity)){
Map<String, Object> customerMap=JsonUtil.entityToMap(customerEntity);
for(String key:customerMap.keySet()){
companyMap.put("yunzhupaas_mdm_customer_yunzhupaas_"+key,customerMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, CustinfoConstant.getFormData(), CustinfoConstant.getColumnData(), companyPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(companyPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param companyForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid CustinfoForm companyForm) {
String b = companyService.checkForm(companyForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
companyService.saveOrUpdate(companyForm, null ,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 CustinfoPagination companyPagination) throws IOException {
if (StringUtil.isEmpty(companyPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CustomerEntity customerEntity = entity.getCustomer();
if(ObjectUtil.isNotEmpty(customerEntity)){
Map<String, Object> customerMap=JsonUtil.entityToMap(customerEntity);
for(String key:customerMap.keySet()){
companyMap.put("yunzhupaas_mdm_customer_yunzhupaas_"+key,customerMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, CustinfoConstant.getFormData(), CustinfoConstant.getColumnData(), companyPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(companyPagination.getSelectKey())?companyPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(companyPagination.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){
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53List = new ArrayList<>();
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92List = new ArrayList<>();
for(String key:keys){
switch(key){
case "company_code" :
entitys.add(new ExcelExportEntity("客户编码" ,"company_code"));
break;
case "company_name" :
entitys.add(new ExcelExportEntity("客户名称" ,"company_name"));
break;
case "short_name" :
entitys.add(new ExcelExportEntity("简称/昵称" ,"short_name"));
break;
case "entity_type" :
entitys.add(new ExcelExportEntity("类型" ,"entity_type"));
break;
case "credit_code" :
entitys.add(new ExcelExportEntity("社会信用代码" ,"credit_code"));
break;
case "org_id" :
entitys.add(new ExcelExportEntity("归属组织" ,"org_id"));
break;
case "province_id" :
entitys.add(new ExcelExportEntity("所属地区" ,"province_id"));
break;
case "tax_type" :
entitys.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "enterprise_scale" :
entitys.add(new ExcelExportEntity("企业规模" ,"enterprise_scale"));
break;
case "enterprise_nature" :
entitys.add(new ExcelExportEntity("企业类型" ,"enterprise_nature"));
break;
case "industry_code" :
entitys.add(new ExcelExportEntity("行业代码" ,"industry_code"));
break;
case "registration_date" :
entitys.add(new ExcelExportEntity("成立日期" ,"registration_date"));
break;
case "registered_capital" :
entitys.add(new ExcelExportEntity("注册资本" ,"registered_capital"));
break;
case "legal_representative" :
entitys.add(new ExcelExportEntity("法定代表人" ,"legal_representative"));
break;
case "phone" :
entitys.add(new ExcelExportEntity("联系电话" ,"phone"));
break;
case "email" :
entitys.add(new ExcelExportEntity("邮箱" ,"email"));
break;
case "website" :
entitys.add(new ExcelExportEntity("网站" ,"website"));
break;
case "address" :
entitys.add(new ExcelExportEntity("地址" ,"address"));
break;
case "business_scope" :
entitys.add(new ExcelExportEntity("经营范围" ,"business_scope"));
break;
case "remark" :
entitys.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "yunzhupaas_mdm_customer_yunzhupaas_major_person_id" :
entitys.add(new ExcelExportEntity("销售责任人" ,"yunzhupaas_mdm_customer_yunzhupaas_major_person_id"));
break;
case "yunzhupaas_mdm_customer_yunzhupaas_customer_level" :
entitys.add(new ExcelExportEntity("客户级别" ,"yunzhupaas_mdm_customer_yunzhupaas_customer_level"));
break;
case "yunzhupaas_mdm_customer_yunzhupaas_customer_source" :
entitys.add(new ExcelExportEntity("客户来源" ,"yunzhupaas_mdm_customer_yunzhupaas_customer_source"));
break;
case "tableField46dc53-title_code":
tableField46dc53List.add(new ExcelExportEntity("发票抬头编码" ,"title_code"));
break;
case "tableField46dc53-title_name":
tableField46dc53List.add(new ExcelExportEntity("发票抬头名称" ,"title_name"));
break;
case "tableField46dc53-credit_code":
tableField46dc53List.add(new ExcelExportEntity("纳税人识别号" ,"credit_code"));
break;
case "tableField46dc53-tax_type":
tableField46dc53List.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "tableField46dc53-address":
tableField46dc53List.add(new ExcelExportEntity("地址" ,"address"));
break;
case "tableField46dc53-phone":
tableField46dc53List.add(new ExcelExportEntity("电话" ,"phone"));
break;
case "tableField46dc53-bank_name":
tableField46dc53List.add(new ExcelExportEntity("开户银行" ,"bank_name"));
break;
case "tableField46dc53-bank_account":
tableField46dc53List.add(new ExcelExportEntity("银行账户" ,"bank_account"));
break;
case "tableField46dc53-is_defalut":
tableField46dc53List.add(new ExcelExportEntity("是否默认" ,"is_defalut"));
break;
case "tableField46dc53-is_valid":
tableField46dc53List.add(new ExcelExportEntity("是否有效" ,"is_valid"));
break;
case "tableField46dc53-remark":
tableField46dc53List.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "tableFieldad9d92-bank_name":
tableFieldad9d92List.add(new ExcelExportEntity("开户行" ,"bank_name"));
break;
case "tableFieldad9d92-bank_account_name":
tableFieldad9d92List.add(new ExcelExportEntity("账户名" ,"bank_account_name"));
break;
case "tableFieldad9d92-bank_account_number":
tableFieldad9d92List.add(new ExcelExportEntity("银行账号" ,"bank_account_number"));
break;
case "tableFieldad9d92-bank_province":
tableFieldad9d92List.add(new ExcelExportEntity("开户行城市" ,"bank_province"));
break;
case "tableFieldad9d92-remark":
tableFieldad9d92List.add(new ExcelExportEntity("备注" ,"remark"));
break;
default:
break;
}
}
if(tableField46dc53List.size() > 0){
tableField46dc53ExcelEntity.setList(tableField46dc53List);
entitys.add(tableField46dc53ExcelEntity);
}
if(tableFieldad9d92List.size() > 0){
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92List);
entitys.add(tableFieldad9d92ExcelEntity);
}
}
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(CustinfoConstant.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(CustinfoConstant.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("客户名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("客户编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
if(tableField46dc53ExcelEntityList.size() > 0){
entitys.add(tableField46dc53ExcelEntity);
}
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
if(tableFieldad9d92ExcelEntityList.size() > 0){
entitys.add(tableFieldad9d92ExcelEntity);
}
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CustinfoConstant.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(CustinfoConstant.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 = 2;
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(CustinfoConstant.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("company_name","客户名称","input"));
columns.add(new ExcelImFieldModel("credit_code","社会信用代码","input"));
columns.add(new ExcelImFieldModel("org_id","归属组织","organizeSelect"));
columns.add(new ExcelImFieldModel("company_code","客户编码","billRule"));
columns.add(new ExcelImFieldModel("short_name","简称/昵称","input"));
columns.add(new ExcelImFieldModel("entity_type","类型","radio"));
columns.add(new ExcelImFieldModel("tax_type","纳税人类别","select"));
columns.add(new ExcelImFieldModel("enterprise_scale","企业规模","select"));
columns.add(new ExcelImFieldModel("enterprise_nature","企业类型","select"));
columns.add(new ExcelImFieldModel("industry_code","行业代码","select"));
columns.add(new ExcelImFieldModel("registration_date","成立日期","datePicker"));
columns.add(new ExcelImFieldModel("registered_capital","注册资本","inputNumber"));
columns.add(new ExcelImFieldModel("legal_representative","法定代表人","input"));
columns.add(new ExcelImFieldModel("phone","联系电话","input"));
columns.add(new ExcelImFieldModel("email","邮箱","input"));
columns.add(new ExcelImFieldModel("website","网站","input"));
columns.add(new ExcelImFieldModel("address","地址","input"));
columns.add(new ExcelImFieldModel("province_id","所属地区","areaSelect"));
columns.add(new ExcelImFieldModel("business_scope","经营范围","textarea"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
//tableField46dc53子表对象
List<ExcelImFieldModel> tableField46dc53columns = new ArrayList<>();
tableField46dc53columns.add(new ExcelImFieldModel("title_name" ,"发票抬头名称"));
tableField46dc53columns.add(new ExcelImFieldModel("credit_code" ,"纳税人识别号"));
tableField46dc53columns.add(new ExcelImFieldModel("tax_type" ,"纳税人类别"));
tableField46dc53columns.add(new ExcelImFieldModel("address" ,"地址"));
tableField46dc53columns.add(new ExcelImFieldModel("phone" ,"电话"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_name" ,"开户银行"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_account" ,"银行账户"));
tableField46dc53columns.add(new ExcelImFieldModel("is_defalut" ,"是否默认"));
tableField46dc53columns.add(new ExcelImFieldModel("is_valid" ,"是否有效"));
tableField46dc53columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableField46dc53","设计子表","table",tableField46dc53columns));
//tableFieldad9d92子表对象
List<ExcelImFieldModel> tableFieldad9d92columns = new ArrayList<>();
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_name" ,"开户行"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_name" ,"账户名"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_number" ,"银行账号"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_province" ,"开户行城市"));
tableFieldad9d92columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableFieldad9d92","设计子表","table",tableFieldad9d92columns));
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(CustinfoConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:CustinfoConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,CustinfoConstant.TABLERENAMES.get(CustinfoConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(CustinfoConstant.getFormData(),listData,uniqueModel, tablefieldkey,CustinfoConstant.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,CustinfoForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,CustinfoForm.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("客户名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("客户编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
entitys.add(tableField46dc53ExcelEntity);
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
entitys.add(tableFieldad9d92ExcelEntity);
ExcelModel excelModel = generaterSwapUtil.getExcelParams(CustinfoConstant.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(CustinfoConstant.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{
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
//主表数据删除
companyService.delete(entity);
QueryWrapper<CustomerEntity> queryWrapperCustomer=new QueryWrapper<>();
queryWrapperCustomer.lambda().eq(CustomerEntity::getCompanyId,entity.getCompanyId());
//副表数据删除
customerService.remove(queryWrapperCustomer);
QueryWrapper<CompanyInvoiceEntity> queryWrapperCompanyInvoice=new QueryWrapper<>();
queryWrapperCompanyInvoice.lambda().eq(CompanyInvoiceEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
companyInvoiceService.remove(queryWrapperCompanyInvoice);
QueryWrapper<CompanyBankEntity> queryWrapperCompanyBank=new QueryWrapper<>();
queryWrapperCompanyBank.lambda().eq(CompanyBankEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
companyBankService.remove(queryWrapperCompanyBank);
}
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 companyForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid CustinfoForm companyForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
companyForm.setCompanyId(String.valueOf(entity.getCompanyId()));
if (!isImport) {
String b = companyService.checkForm(companyForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
companyService.saveOrUpdate(companyForm,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){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CustomerEntity customerEntity = entity.getCustomer();
if(ObjectUtil.isNotEmpty(customerEntity)){
Map<String, Object> customerMap=JsonUtil.entityToMap(customerEntity);
for(String key:customerMap.keySet()){
companyMap.put("yunzhupaas_mdm_customer_yunzhupaas_"+key,customerMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
companyMap = generaterSwapUtil.swapDataDetail(companyMap,CustinfoConstant.getFormData(),"816972827587510981",isPc?false:false);
//子表数据
companyMap.put("companyInvoiceList",companyMap.get("tableField46dc53"));
companyMap.put("companyBankList",companyMap.get("tableFieldad9d92"));
return ActionResult.success(companyMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CustomerEntity customerEntity = entity.getCustomer();
if(ObjectUtil.isNotEmpty(customerEntity)){
Map<String, Object> customerMap=JsonUtil.entityToMap(customerEntity);
for(String key:customerMap.keySet()){
companyMap.put("yunzhupaas_mdm_customer_yunzhupaas_"+key,customerMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> companyInvoiceList = entity.getCompanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
companyMap.put("companyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap = generaterSwapUtil.swapDataForm(companyMap,CustinfoConstant.getFormData(),CustinfoConstant.TABLEFIELDKEY,CustinfoConstant.TABLERENAMES);
return ActionResult.success(companyMap);
}
}

View File

@@ -0,0 +1,947 @@
package com.yunzhupaas.mdm.controller;
import cn.hutool.core.util.ObjectUtil;
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.constant.MsgCode;
import com.yunzhupaas.mdm.service.*;
import com.yunzhupaas.mdm.entity.*;
import com.yunzhupaas.util.*;
import com.yunzhupaas.mdm.model.lpc.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.base.vo.PageListVO;
import com.yunzhupaas.base.vo.PaginationVO;
import com.yunzhupaas.base.vo.DownloadVO;
import com.yunzhupaas.config.ConfigValueUtil;
import java.io.IOException;
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.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.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;
/**
* 法人公司
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-24
*/
@Slf4j
@RestController
@Tag(name = "法人公司" , description = "bcm")
@RequestMapping("/api/bcm/Lpc")
public class LpcController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private LpcService companyService;
@Autowired
private CompanyInvoiceService company_invoiceService;
@Autowired
private CompanyBankService companyBankService;
@Autowired
private CorporationService corporationService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param companyPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody LpcPagination companyPagination)throws Exception{
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CorporationEntity corporationEntity = entity.getCorporation();
if(ObjectUtil.isNotEmpty(corporationEntity)){
Map<String, Object> corporationMap=JsonUtil.entityToMap(corporationEntity);
for(String key:corporationMap.keySet()){
companyMap.put("yunzhupaas_mdm_corporation_yunzhupaas_"+key,corporationMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> company_invoiceList = entity.getCompanyInvoice();
companyMap.put("tableField5ced3a",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
companyMap.put("company_invoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldbd0aa4",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, LpcConstant.getFormData(), LpcConstant.getColumnData(), companyPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(companyPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param companyForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid LpcForm companyForm) throws Exception {
String b = companyService.checkForm(companyForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
// try{
companyService.saveOrUpdate(companyForm, null ,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 LpcPagination companyPagination) throws IOException {
if (StringUtil.isEmpty(companyPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CorporationEntity corporationEntity = entity.getCorporation();
if(ObjectUtil.isNotEmpty(corporationEntity)){
Map<String, Object> corporationMap=JsonUtil.entityToMap(corporationEntity);
for(String key:corporationMap.keySet()){
companyMap.put("yunzhupaas_mdm_corporation_yunzhupaas_"+key,corporationMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> company_invoiceList = entity.getCompanyInvoice();
companyMap.put("tableField5ced3a",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
companyMap.put("company_invoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldbd0aa4",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, LpcConstant.getFormData(),LpcConstant.getColumnData(), companyPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(companyPagination.getSelectKey())?companyPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(companyPagination.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){
ExcelExportEntity tableField5ced3aExcelEntity = new ExcelExportEntity("设计子表(tableField5ced3a)","tableField5ced3a");
List<ExcelExportEntity> tableField5ced3aList = new ArrayList<>();
ExcelExportEntity tableFieldbd0aa4ExcelEntity = new ExcelExportEntity("设计子表(tableFieldbd0aa4)","tableFieldbd0aa4");
List<ExcelExportEntity> tableFieldbd0aa4List = new ArrayList<>();
for(String key:keys){
switch(key){
case "entity_type" :
entitys.add(new ExcelExportEntity("实体类型" ,"entity_type"));
break;
case "company_code" :
entitys.add(new ExcelExportEntity("企业编码" ,"company_code"));
break;
case "company_name" :
entitys.add(new ExcelExportEntity("企业名称" ,"company_name"));
break;
case "short_name" :
entitys.add(new ExcelExportEntity("简称/昵称" ,"short_name"));
break;
case "credit_code" :
entitys.add(new ExcelExportEntity("社会信用代码" ,"credit_code"));
break;
case "tax_type" :
entitys.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "org_id" :
entitys.add(new ExcelExportEntity("归属组织" ,"org_id"));
break;
case "province_id" :
entitys.add(new ExcelExportEntity("所属地区" ,"province_id"));
break;
case "enterprise_nature" :
entitys.add(new ExcelExportEntity("企业类型" ,"enterprise_nature"));
break;
case "industry_code" :
entitys.add(new ExcelExportEntity("行业代码" ,"industry_code"));
break;
case "enterprise_scale" :
entitys.add(new ExcelExportEntity("企业规模" ,"enterprise_scale"));
break;
case "registration_date" :
entitys.add(new ExcelExportEntity("成立日期" ,"registration_date"));
break;
case "registered_capital" :
entitys.add(new ExcelExportEntity("注册资本" ,"registered_capital"));
break;
case "legal_representative" :
entitys.add(new ExcelExportEntity("法定代表人" ,"legal_representative"));
break;
case "phone" :
entitys.add(new ExcelExportEntity("联系电话" ,"phone"));
break;
case "email" :
entitys.add(new ExcelExportEntity("邮箱" ,"email"));
break;
case "website" :
entitys.add(new ExcelExportEntity("网站" ,"website"));
break;
case "address" :
entitys.add(new ExcelExportEntity("地址" ,"address"));
break;
case "business_scope" :
entitys.add(new ExcelExportEntity("经营范围" ,"business_scope"));
break;
case "remark" :
entitys.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "yunzhupaas_mdm_corporation_yunzhupaas_major_person_id" :
entitys.add(new ExcelExportEntity("负责人" ,"yunzhupaas_mdm_corporation_yunzhupaas_major_person_id"));
break;
case "tableField5ced3a-title_code":
tableField5ced3aList.add(new ExcelExportEntity("发票抬头编码" ,"title_code"));
break;
case "tableField5ced3a-title_name":
tableField5ced3aList.add(new ExcelExportEntity("发票抬头名称" ,"title_name"));
break;
case "tableField5ced3a-credit_code":
tableField5ced3aList.add(new ExcelExportEntity("纳税人识别号" ,"credit_code"));
break;
case "tableField5ced3a-tax_type":
tableField5ced3aList.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "tableField5ced3a-address":
tableField5ced3aList.add(new ExcelExportEntity("地址" ,"address"));
break;
case "tableField5ced3a-phone":
tableField5ced3aList.add(new ExcelExportEntity("电话" ,"phone"));
break;
case "tableField5ced3a-bank_name":
tableField5ced3aList.add(new ExcelExportEntity("开户银行" ,"bank_name"));
break;
case "tableField5ced3a-bank_account":
tableField5ced3aList.add(new ExcelExportEntity("银行账户" ,"bank_account"));
break;
case "tableField5ced3a-is_defalut":
tableField5ced3aList.add(new ExcelExportEntity("是否默认抬头" ,"is_defalut"));
break;
case "tableField5ced3a-is_valid":
tableField5ced3aList.add(new ExcelExportEntity("是否有效" ,"is_valid"));
break;
case "tableField5ced3a-remark":
tableField5ced3aList.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "tableFieldbd0aa4-bank_name":
tableFieldbd0aa4List.add(new ExcelExportEntity("开户行" ,"bank_name"));
break;
case "tableFieldbd0aa4-bank_account_name":
tableFieldbd0aa4List.add(new ExcelExportEntity("账户名" ,"bank_account_name"));
break;
case "tableFieldbd0aa4-bank_account_number":
tableFieldbd0aa4List.add(new ExcelExportEntity("银行账号" ,"bank_account_number"));
break;
case "tableFieldbd0aa4-bank_province":
tableFieldbd0aa4List.add(new ExcelExportEntity("开户行城市" ,"bank_province"));
break;
case "tableFieldbd0aa4-remark":
tableFieldbd0aa4List.add(new ExcelExportEntity("备注" ,"remark"));
break;
default:
break;
}
}
if(tableField5ced3aList.size() > 0){
tableField5ced3aExcelEntity.setList(tableField5ced3aList);
entitys.add(tableField5ced3aExcelEntity);
}
if(tableFieldbd0aa4List.size() > 0){
tableFieldbd0aa4ExcelEntity.setList(tableFieldbd0aa4List);
entitys.add(tableFieldbd0aa4ExcelEntity);
}
}
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(LpcConstant.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(LpcConstant.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("负责人(yunzhupaas_mdm_corporation_yunzhupaas_major_person_id)" ,"yunzhupaas_mdm_corporation_yunzhupaas_major_person_id"));
selectKeys.add("yunzhupaas_mdm_corporation_yunzhupaas_major_person_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableField5ced3a子表对象
ExcelExportEntity tableField5ced3aExcelEntity = new ExcelExportEntity("设计子表(tableField5ced3a)","tableField5ced3a");
List<ExcelExportEntity> tableField5ced3aExcelEntityList = new ArrayList<>();
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField5ced3a-title_name)" ,"title_name"));
selectKeys.add("tableField5ced3a-title_name");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField5ced3a-credit_code)" ,"credit_code"));
selectKeys.add("tableField5ced3a-credit_code");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField5ced3a-tax_type)" ,"tax_type"));
selectKeys.add("tableField5ced3a-tax_type");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("地址(tableField5ced3a-address)" ,"address"));
selectKeys.add("tableField5ced3a-address");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("电话(tableField5ced3a-phone)" ,"phone"));
selectKeys.add("tableField5ced3a-phone");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("开户银行(tableField5ced3a-bank_name)" ,"bank_name"));
selectKeys.add("tableField5ced3a-bank_name");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("银行账户(tableField5ced3a-bank_account)" ,"bank_account"));
selectKeys.add("tableField5ced3a-bank_account");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("是否默认抬头(tableField5ced3a-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField5ced3a-is_defalut");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("是否有效(tableField5ced3a-is_valid)" ,"is_valid"));
selectKeys.add("tableField5ced3a-is_valid");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("备注(tableField5ced3a-remark)" ,"remark"));
selectKeys.add("tableField5ced3a-remark");
tableField5ced3aExcelEntity.setList(tableField5ced3aExcelEntityList);
if(tableField5ced3aExcelEntityList.size() > 0){
entitys.add(tableField5ced3aExcelEntity);
}
//tableFieldbd0aa4子表对象
ExcelExportEntity tableFieldbd0aa4ExcelEntity = new ExcelExportEntity("设计子表(tableFieldbd0aa4)","tableFieldbd0aa4");
List<ExcelExportEntity> tableFieldbd0aa4ExcelEntityList = new ArrayList<>();
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldbd0aa4-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldbd0aa4-bank_name");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldbd0aa4-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldbd0aa4-bank_account_name");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldbd0aa4-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldbd0aa4-bank_account_number");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldbd0aa4-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldbd0aa4-bank_province");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldbd0aa4-remark)" ,"remark"));
selectKeys.add("tableFieldbd0aa4-remark");
tableFieldbd0aa4ExcelEntity.setList(tableFieldbd0aa4ExcelEntityList);
if(tableFieldbd0aa4ExcelEntityList.size() > 0){
entitys.add(tableFieldbd0aa4ExcelEntity);
}
ExcelModel excelModel = generaterSwapUtil.getExcelParams(LpcConstant.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(LpcConstant.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 = 2;
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(LpcConstant.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("company_name","企业名称","input"));
columns.add(new ExcelImFieldModel("short_name","简称/昵称","input"));
columns.add(new ExcelImFieldModel("credit_code","社会信用代码","input"));
columns.add(new ExcelImFieldModel("tax_type","纳税人类别","select"));
columns.add(new ExcelImFieldModel("org_id","归属组织","organizeSelect"));
columns.add(new ExcelImFieldModel("province_id","所属地区","areaSelect"));
columns.add(new ExcelImFieldModel("enterprise_nature","企业类型","select"));
columns.add(new ExcelImFieldModel("industry_code","行业代码","select"));
columns.add(new ExcelImFieldModel("enterprise_scale","企业规模","select"));
columns.add(new ExcelImFieldModel("registration_date","成立日期","datePicker"));
columns.add(new ExcelImFieldModel("registered_capital","注册资本","inputNumber"));
columns.add(new ExcelImFieldModel("legal_representative","法定代表人","input"));
columns.add(new ExcelImFieldModel("phone","联系电话","input"));
columns.add(new ExcelImFieldModel("email","邮箱","input"));
columns.add(new ExcelImFieldModel("website","网站","input"));
columns.add(new ExcelImFieldModel("address","地址","input"));
columns.add(new ExcelImFieldModel("yunzhupaas_mdm_corporation_yunzhupaas_major_person_id","负责人","userSelect"));
columns.add(new ExcelImFieldModel("business_scope","经营范围","textarea"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
//tableField5ced3a子表对象
List<ExcelImFieldModel> tableField5ced3acolumns = new ArrayList<>();
tableField5ced3acolumns.add(new ExcelImFieldModel("title_name" ,"*发票抬头名称"));
tableField5ced3acolumns.add(new ExcelImFieldModel("credit_code" ,"*纳税人识别号"));
tableField5ced3acolumns.add(new ExcelImFieldModel("tax_type" ,"*纳税人类别"));
tableField5ced3acolumns.add(new ExcelImFieldModel("address" ,"地址"));
tableField5ced3acolumns.add(new ExcelImFieldModel("phone" ,"电话"));
tableField5ced3acolumns.add(new ExcelImFieldModel("bank_name" ,"开户银行"));
tableField5ced3acolumns.add(new ExcelImFieldModel("bank_account" ,"银行账户"));
tableField5ced3acolumns.add(new ExcelImFieldModel("is_defalut" ,"是否默认抬头"));
tableField5ced3acolumns.add(new ExcelImFieldModel("is_valid" ,"是否有效"));
tableField5ced3acolumns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableField5ced3a","设计子表","table",tableField5ced3acolumns));
//tableFieldbd0aa4子表对象
List<ExcelImFieldModel> tableFieldbd0aa4columns = new ArrayList<>();
tableFieldbd0aa4columns.add(new ExcelImFieldModel("bank_name" ,"开户行"));
tableFieldbd0aa4columns.add(new ExcelImFieldModel("bank_account_name" ,"账户名"));
tableFieldbd0aa4columns.add(new ExcelImFieldModel("bank_account_number" ,"银行账号"));
tableFieldbd0aa4columns.add(new ExcelImFieldModel("bank_province" ,"开户行城市"));
tableFieldbd0aa4columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableFieldbd0aa4","设计子表","table",tableFieldbd0aa4columns));
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(LpcConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:LpcConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,LpcConstant.TABLERENAMES.get(LpcConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(LpcConstant.getFormData(),listData,uniqueModel, tablefieldkey,LpcConstant.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,LpcForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,LpcForm.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("负责人(yunzhupaas_mdm_corporation_yunzhupaas_major_person_id)" ,"yunzhupaas_mdm_corporation_yunzhupaas_major_person_id"));
selectKeys.add("yunzhupaas_mdm_corporation_yunzhupaas_major_person_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
//tableField5ced3a子表对象
ExcelExportEntity tableField5ced3aExcelEntity = new ExcelExportEntity("设计子表(tableField5ced3a)","tableField5ced3a");
List<ExcelExportEntity> tableField5ced3aExcelEntityList = new ArrayList<>();
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField5ced3a-title_name)" ,"title_name"));
selectKeys.add("tableField5ced3a-title_name");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField5ced3a-credit_code)" ,"credit_code"));
selectKeys.add("tableField5ced3a-credit_code");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField5ced3a-tax_type)" ,"tax_type"));
selectKeys.add("tableField5ced3a-tax_type");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("地址(tableField5ced3a-address)" ,"address"));
selectKeys.add("tableField5ced3a-address");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("电话(tableField5ced3a-phone)" ,"phone"));
selectKeys.add("tableField5ced3a-phone");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("开户银行(tableField5ced3a-bank_name)" ,"bank_name"));
selectKeys.add("tableField5ced3a-bank_name");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("银行账户(tableField5ced3a-bank_account)" ,"bank_account"));
selectKeys.add("tableField5ced3a-bank_account");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("是否默认抬头(tableField5ced3a-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField5ced3a-is_defalut");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("是否有效(tableField5ced3a-is_valid)" ,"is_valid"));
selectKeys.add("tableField5ced3a-is_valid");
tableField5ced3aExcelEntityList.add(new ExcelExportEntity("备注(tableField5ced3a-remark)" ,"remark"));
selectKeys.add("tableField5ced3a-remark");
tableField5ced3aExcelEntity.setList(tableField5ced3aExcelEntityList);
entitys.add(tableField5ced3aExcelEntity);
//tableFieldbd0aa4子表对象
ExcelExportEntity tableFieldbd0aa4ExcelEntity = new ExcelExportEntity("设计子表(tableFieldbd0aa4)","tableFieldbd0aa4");
List<ExcelExportEntity> tableFieldbd0aa4ExcelEntityList = new ArrayList<>();
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldbd0aa4-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldbd0aa4-bank_name");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldbd0aa4-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldbd0aa4-bank_account_name");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldbd0aa4-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldbd0aa4-bank_account_number");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldbd0aa4-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldbd0aa4-bank_province");
tableFieldbd0aa4ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldbd0aa4-remark)" ,"remark"));
selectKeys.add("tableFieldbd0aa4-remark");
tableFieldbd0aa4ExcelEntity.setList(tableFieldbd0aa4ExcelEntityList);
entitys.add(tableFieldbd0aa4ExcelEntity);
ExcelModel excelModel = generaterSwapUtil.getExcelParams(LpcConstant.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(LpcConstant.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{
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
companyService.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 companyForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid LpcForm companyForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
companyForm.setCompanyId(String.valueOf(entity.getCompanyId()));
if (!isImport) {
String b = companyService.checkForm(companyForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
companyService.saveOrUpdate(companyForm,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){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CorporationEntity corporationEntity = entity.getCorporation();
if(ObjectUtil.isNotEmpty(corporationEntity)){
Map<String, Object> corporationMap=JsonUtil.entityToMap(corporationEntity);
for(String key:corporationMap.keySet()){
companyMap.put("yunzhupaas_mdm_corporation_yunzhupaas_"+key,corporationMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> company_invoiceList = entity.getCompanyInvoice();
companyMap.put("tableField5ced3a",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
companyMap.put("company_invoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldbd0aa4",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
companyMap = generaterSwapUtil.swapDataDetail(companyMap,LpcConstant.getFormData(),"816296614598542021",isPc?false:false);
//子表数据
companyMap.put("company_invoiceList",companyMap.get("tableField5ced3a"));
companyMap.put("companyBankList",companyMap.get("tableFieldbd0aa4"));
return ActionResult.success(companyMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
CorporationEntity corporationEntity = entity.getCorporation();
if(ObjectUtil.isNotEmpty(corporationEntity)){
Map<String, Object> corporationMap=JsonUtil.entityToMap(corporationEntity);
for(String key:corporationMap.keySet()){
companyMap.put("yunzhupaas_mdm_corporation_yunzhupaas_"+key,corporationMap.get(key));
}
}
//子表数据
List<CompanyInvoiceEntity> company_invoiceList = entity.getCompanyInvoice();
companyMap.put("tableField5ced3a",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
companyMap.put("company_invoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(company_invoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldbd0aa4",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap = generaterSwapUtil.swapDataForm(companyMap,LpcConstant.getFormData(),LpcConstant.TABLEFIELDKEY,LpcConstant.TABLERENAMES);
return ActionResult.success(companyMap);
}
}

View File

@@ -0,0 +1,679 @@
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.material.*;
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;
/**
* 物料信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-27
*/
@Slf4j
@RestController
@Tag(name = "物料信息" , description = "bcm")
@RequestMapping("/api/bcm/Material")
public class MaterialController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private MaterialService materialService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param materialPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody MaterialPagination materialPagination)throws Exception{
List<MaterialEntity> list= materialService.getList(materialPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MaterialEntity entity : list) {
Map<String, Object> materialMap=JsonUtil.entityToMap(entity);
materialMap.put("id", materialMap.get("material_id"));
//副表数据
//子表数据
realList.add(materialMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, MaterialConstant.getFormData(), MaterialConstant.getColumnData(), materialPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(materialPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param materialForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid MaterialForm materialForm) {
String b = materialService.checkForm(materialForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
materialService.saveOrUpdate(materialForm, null ,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 MaterialPagination materialPagination) throws IOException {
if (StringUtil.isEmpty(materialPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<MaterialEntity> list= materialService.getList(materialPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (MaterialEntity entity : list) {
Map<String, Object> materialMap=JsonUtil.entityToMap(entity);
materialMap.put("id", materialMap.get("material_id"));
//副表数据
//子表数据
realList.add(materialMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, MaterialConstant.getFormData(), MaterialConstant.getColumnData(), materialPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(materialPagination.getSelectKey())?materialPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(materialPagination.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 "material_code" :
entitys.add(new ExcelExportEntity("物料编码" ,"material_code"));
break;
case "material_name" :
entitys.add(new ExcelExportEntity("物料名称" ,"material_name"));
break;
case "material_category" :
entitys.add(new ExcelExportEntity("物料分类" ,"material_category"));
break;
case "material_model" :
entitys.add(new ExcelExportEntity("规格型号" ,"material_model"));
break;
case "unit_name" :
entitys.add(new ExcelExportEntity("单位名称" ,"unit_name"));
break;
case "brand" :
entitys.add(new ExcelExportEntity("品牌" ,"brand"));
break;
case "tax_rate" :
entitys.add(new ExcelExportEntity("税率" ,"tax_rate"));
break;
case "tax_code" :
entitys.add(new ExcelExportEntity("税收分类" ,"tax_code"));
break;
case "texture" :
entitys.add(new ExcelExportEntity("材质/纹理" ,"texture"));
break;
case "quality_standard" :
entitys.add(new ExcelExportEntity("质量标准" ,"quality_standard"));
break;
case "technical_standard" :
entitys.add(new ExcelExportEntity("技术标准" ,"technical_standard"));
break;
case "acceptance_criteria" :
entitys.add(new ExcelExportEntity("验收标准" ,"acceptance_criteria"));
break;
case "delivery_requirements" :
entitys.add(new ExcelExportEntity("交付要求" ,"delivery_requirements"));
break;
case "storage_conditions" :
entitys.add(new ExcelExportEntity("储存条件" ,"storage_conditions"));
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(MaterialConstant.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(MaterialConstant.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("物料名称(material_name)" ,"material_name"));
selectKeys.add("material_name");
entitys.add(new ExcelExportEntity("物料分类(material_category)" ,"material_category"));
selectKeys.add("material_category");
entitys.add(new ExcelExportEntity("规格型号(material_model)" ,"material_model"));
selectKeys.add("material_model");
entitys.add(new ExcelExportEntity("单位名称(unit_name)" ,"unit_name"));
selectKeys.add("unit_name");
entitys.add(new ExcelExportEntity("品牌(brand)" ,"brand"));
selectKeys.add("brand");
entitys.add(new ExcelExportEntity("税率(tax_rate)" ,"tax_rate"));
selectKeys.add("tax_rate");
entitys.add(new ExcelExportEntity("税收分类(tax_code)" ,"tax_code"));
selectKeys.add("tax_code");
entitys.add(new ExcelExportEntity("材质/纹理(texture)" ,"texture"));
selectKeys.add("texture");
entitys.add(new ExcelExportEntity("质量标准(quality_standard)" ,"quality_standard"));
selectKeys.add("quality_standard");
entitys.add(new ExcelExportEntity("技术标准(technical_standard)" ,"technical_standard"));
selectKeys.add("technical_standard");
entitys.add(new ExcelExportEntity("验收标准(acceptance_criteria)" ,"acceptance_criteria"));
selectKeys.add("acceptance_criteria");
entitys.add(new ExcelExportEntity("交付要求(delivery_requirements)" ,"delivery_requirements"));
selectKeys.add("delivery_requirements");
entitys.add(new ExcelExportEntity("储存条件(storage_conditions)" ,"storage_conditions"));
selectKeys.add("storage_conditions");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(MaterialConstant.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(MaterialConstant.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(MaterialConstant.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("material_name","物料名称","input"));
columns.add(new ExcelImFieldModel("material_category","物料分类","cascader"));
columns.add(new ExcelImFieldModel("material_model","规格型号","input"));
columns.add(new ExcelImFieldModel("unit_name","单位名称","input"));
columns.add(new ExcelImFieldModel("brand","品牌","input"));
columns.add(new ExcelImFieldModel("tax_rate","税率","select"));
columns.add(new ExcelImFieldModel("tax_code","税收分类","cascader"));
columns.add(new ExcelImFieldModel("texture","材质/纹理","input"));
columns.add(new ExcelImFieldModel("quality_standard","质量标准","input"));
columns.add(new ExcelImFieldModel("technical_standard","技术标准","textarea"));
columns.add(new ExcelImFieldModel("acceptance_criteria","验收标准","textarea"));
columns.add(new ExcelImFieldModel("delivery_requirements","交付要求","textarea"));
columns.add(new ExcelImFieldModel("storage_conditions","储存条件","textarea"));
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(MaterialConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:MaterialConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,MaterialConstant.TABLERENAMES.get(MaterialConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(MaterialConstant.getFormData(),listData,uniqueModel, tablefieldkey,MaterialConstant.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,MaterialForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,MaterialForm.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("物料名称(material_name)" ,"material_name"));
selectKeys.add("material_name");
entitys.add(new ExcelExportEntity("物料分类(material_category)" ,"material_category"));
selectKeys.add("material_category");
entitys.add(new ExcelExportEntity("规格型号(material_model)" ,"material_model"));
selectKeys.add("material_model");
entitys.add(new ExcelExportEntity("单位名称(unit_name)" ,"unit_name"));
selectKeys.add("unit_name");
entitys.add(new ExcelExportEntity("品牌(brand)" ,"brand"));
selectKeys.add("brand");
entitys.add(new ExcelExportEntity("税率(tax_rate)" ,"tax_rate"));
selectKeys.add("tax_rate");
entitys.add(new ExcelExportEntity("税收分类(tax_code)" ,"tax_code"));
selectKeys.add("tax_code");
entitys.add(new ExcelExportEntity("材质/纹理(texture)" ,"texture"));
selectKeys.add("texture");
entitys.add(new ExcelExportEntity("质量标准(quality_standard)" ,"quality_standard"));
selectKeys.add("quality_standard");
entitys.add(new ExcelExportEntity("技术标准(technical_standard)" ,"technical_standard"));
selectKeys.add("technical_standard");
entitys.add(new ExcelExportEntity("验收标准(acceptance_criteria)" ,"acceptance_criteria"));
selectKeys.add("acceptance_criteria");
entitys.add(new ExcelExportEntity("交付要求(delivery_requirements)" ,"delivery_requirements"));
selectKeys.add("delivery_requirements");
entitys.add(new ExcelExportEntity("储存条件(storage_conditions)" ,"storage_conditions"));
selectKeys.add("storage_conditions");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(MaterialConstant.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(MaterialConstant.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{
MaterialEntity entity= materialService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
materialService.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 materialForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MaterialForm materialForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
MaterialEntity entity= materialService.getInfo(id);
if(entity!=null){
materialForm.setMaterialId(String.valueOf(entity.getMaterialId()));
if (!isImport) {
String b = materialService.checkForm(materialForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
materialService.saveOrUpdate(materialForm,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){
MaterialEntity entity= materialService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> materialMap=JsonUtil.entityToMap(entity);
materialMap.put("id", materialMap.get("material_id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
materialMap = generaterSwapUtil.swapDataDetail(materialMap,MaterialConstant.getFormData(),"817350987260887813",isPc?false:false);
//子表数据
return ActionResult.success(materialMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
MaterialEntity entity= materialService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> materialMap=JsonUtil.entityToMap(entity);
materialMap.put("id", materialMap.get("material_id"));
//副表数据
//子表数据
materialMap = generaterSwapUtil.swapDataForm(materialMap,MaterialConstant.getFormData(),MaterialConstant.TABLEFIELDKEY,MaterialConstant.TABLERENAMES);
return ActionResult.success(materialMap);
}
}

View File

@@ -0,0 +1,743 @@
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.product.*;
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;
/**
* 商品信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-27
*/
@Slf4j
@RestController
@Tag(name = "商品信息" , description = "bcm")
@RequestMapping("/api/bcm/Products")
public class ProductsController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private ProductsService productsService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param productPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody ProductPagination productPagination)throws Exception{
List<ProductEntity> list= productsService.getList(productPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (ProductEntity entity : list) {
Map<String, Object> productMap=JsonUtil.entityToMap(entity);
productMap.put("id", productMap.get("product_id"));
//副表数据
//子表数据
realList.add(productMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, ProductsConstant.getFormData(), ProductsConstant.getColumnData(), productPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(productPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param productForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid ProductForm productForm) {
String b = productsService.checkForm(productForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
try{
productsService.saveOrUpdate(productForm, null ,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 ProductPagination productPagination) throws IOException {
if (StringUtil.isEmpty(productPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<ProductEntity> list= productsService.getList(productPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (ProductEntity entity : list) {
Map<String, Object> productMap=JsonUtil.entityToMap(entity);
productMap.put("id", productMap.get("product_id"));
//副表数据
//子表数据
realList.add(productMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, ProductsConstant.getFormData(), ProductsConstant.getColumnData(), productPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(productPagination.getSelectKey())?productPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(productPagination.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 "product_code" :
entitys.add(new ExcelExportEntity("商品编码" ,"product_code"));
break;
case "product_name" :
entitys.add(new ExcelExportEntity("商品名称" ,"product_name"));
break;
case "product_type" :
entitys.add(new ExcelExportEntity("商品类型" ,"product_type"));
break;
case "product_category" :
entitys.add(new ExcelExportEntity("商品分类" ,"product_category"));
break;
case "short_name" :
entitys.add(new ExcelExportEntity("商品简称" ,"short_name"));
break;
case "brand" :
entitys.add(new ExcelExportEntity("品牌" ,"brand"));
break;
case "product_model" :
entitys.add(new ExcelExportEntity("规格型号" ,"product_model"));
break;
case "color" :
entitys.add(new ExcelExportEntity("颜色" ,"color"));
break;
case "product_size" :
entitys.add(new ExcelExportEntity("尺寸/规格" ,"product_size"));
break;
case "weight" :
entitys.add(new ExcelExportEntity("重量" ,"weight"));
break;
case "min_order_quantity" :
entitys.add(new ExcelExportEntity("最小起订量" ,"min_order_quantity"));
break;
case "standard_sales_price" :
entitys.add(new ExcelExportEntity("标准销售单价" ,"standard_sales_price"));
break;
case "gross_weight" :
entitys.add(new ExcelExportEntity("毛重" ,"gross_weight"));
break;
case "net_weight" :
entitys.add(new ExcelExportEntity("净重" ,"net_weight"));
break;
case "unit_name" :
entitys.add(new ExcelExportEntity("单位名称" ,"unit_name"));
break;
case "packagesize" :
entitys.add(new ExcelExportEntity("包装尺寸" ,"packagesize"));
break;
case "cost_price" :
entitys.add(new ExcelExportEntity("成本价" ,"cost_price"));
break;
case "warranty_period" :
entitys.add(new ExcelExportEntity("保修期" ,"warranty_period"));
break;
case "tax_rate" :
entitys.add(new ExcelExportEntity("税率" ,"tax_rate"));
break;
case "tax_code" :
entitys.add(new ExcelExportEntity("税收分类" ,"tax_code"));
break;
case "warranty_terms" :
entitys.add(new ExcelExportEntity("保修条款" ,"warranty_terms"));
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(ProductsConstant.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(ProductsConstant.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("商品名称(product_name)" ,"product_name"));
selectKeys.add("product_name");
entitys.add(new ExcelExportEntity("商品类型(product_type)" ,"product_type"));
selectKeys.add("product_type");
entitys.add(new ExcelExportEntity("商品分类(product_category)" ,"product_category"));
selectKeys.add("product_category");
entitys.add(new ExcelExportEntity("商品简称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("品牌(brand)" ,"brand"));
selectKeys.add("brand");
entitys.add(new ExcelExportEntity("规格型号(product_model)" ,"product_model"));
selectKeys.add("product_model");
entitys.add(new ExcelExportEntity("颜色(color)" ,"color"));
selectKeys.add("color");
entitys.add(new ExcelExportEntity("尺寸/规格(product_size)" ,"product_size"));
selectKeys.add("product_size");
entitys.add(new ExcelExportEntity("重量(weight)" ,"weight"));
selectKeys.add("weight");
entitys.add(new ExcelExportEntity("最小起订量(min_order_quantity)" ,"min_order_quantity"));
selectKeys.add("min_order_quantity");
entitys.add(new ExcelExportEntity("标准销售单价(standard_sales_price)" ,"standard_sales_price"));
selectKeys.add("standard_sales_price");
entitys.add(new ExcelExportEntity("毛重(gross_weight)" ,"gross_weight"));
selectKeys.add("gross_weight");
entitys.add(new ExcelExportEntity("净重(net_weight)" ,"net_weight"));
selectKeys.add("net_weight");
entitys.add(new ExcelExportEntity("单位名称(unit_name)" ,"unit_name"));
selectKeys.add("unit_name");
entitys.add(new ExcelExportEntity("包装尺寸(packagesize)" ,"packagesize"));
selectKeys.add("packagesize");
entitys.add(new ExcelExportEntity("成本价(cost_price)" ,"cost_price"));
selectKeys.add("cost_price");
entitys.add(new ExcelExportEntity("保修期(warranty_period)" ,"warranty_period"));
selectKeys.add("warranty_period");
entitys.add(new ExcelExportEntity("税率(tax_rate)" ,"tax_rate"));
selectKeys.add("tax_rate");
entitys.add(new ExcelExportEntity("税收分类(tax_code)" ,"tax_code"));
selectKeys.add("tax_code");
entitys.add(new ExcelExportEntity("保修条款(warranty_terms)" ,"warranty_terms"));
selectKeys.add("warranty_terms");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(ProductsConstant.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(ProductsConstant.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(ProductsConstant.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("product_name","商品名称","input"));
columns.add(new ExcelImFieldModel("product_type","商品类型","select"));
columns.add(new ExcelImFieldModel("product_category","商品分类","cascader"));
columns.add(new ExcelImFieldModel("short_name","商品简称","input"));
columns.add(new ExcelImFieldModel("brand","品牌","input"));
columns.add(new ExcelImFieldModel("product_model","规格型号","input"));
columns.add(new ExcelImFieldModel("color","颜色","input"));
columns.add(new ExcelImFieldModel("product_size","尺寸/规格","input"));
columns.add(new ExcelImFieldModel("weight","重量","input"));
columns.add(new ExcelImFieldModel("min_order_quantity","最小起订量","inputNumber"));
columns.add(new ExcelImFieldModel("standard_sales_price","标准销售单价","inputNumber"));
columns.add(new ExcelImFieldModel("gross_weight","毛重","inputNumber"));
columns.add(new ExcelImFieldModel("net_weight","净重","inputNumber"));
columns.add(new ExcelImFieldModel("unit_name","单位名称","input"));
columns.add(new ExcelImFieldModel("packagesize","包装尺寸","input"));
columns.add(new ExcelImFieldModel("cost_price","成本价","inputNumber"));
columns.add(new ExcelImFieldModel("warranty_period","保修期","inputNumber"));
columns.add(new ExcelImFieldModel("tax_rate","税率","select"));
columns.add(new ExcelImFieldModel("tax_code","税收分类","cascader"));
columns.add(new ExcelImFieldModel("warranty_terms","保修条款","textarea"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
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(ProductsConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:ProductsConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,ProductsConstant.TABLERENAMES.get(ProductsConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(ProductsConstant.getFormData(),listData,uniqueModel, tablefieldkey,ProductsConstant.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,ProductForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,ProductForm.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("商品名称(product_name)" ,"product_name"));
selectKeys.add("product_name");
entitys.add(new ExcelExportEntity("商品类型(product_type)" ,"product_type"));
selectKeys.add("product_type");
entitys.add(new ExcelExportEntity("商品分类(product_category)" ,"product_category"));
selectKeys.add("product_category");
entitys.add(new ExcelExportEntity("商品简称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("品牌(brand)" ,"brand"));
selectKeys.add("brand");
entitys.add(new ExcelExportEntity("规格型号(product_model)" ,"product_model"));
selectKeys.add("product_model");
entitys.add(new ExcelExportEntity("颜色(color)" ,"color"));
selectKeys.add("color");
entitys.add(new ExcelExportEntity("尺寸/规格(product_size)" ,"product_size"));
selectKeys.add("product_size");
entitys.add(new ExcelExportEntity("重量(weight)" ,"weight"));
selectKeys.add("weight");
entitys.add(new ExcelExportEntity("最小起订量(min_order_quantity)" ,"min_order_quantity"));
selectKeys.add("min_order_quantity");
entitys.add(new ExcelExportEntity("标准销售单价(standard_sales_price)" ,"standard_sales_price"));
selectKeys.add("standard_sales_price");
entitys.add(new ExcelExportEntity("毛重(gross_weight)" ,"gross_weight"));
selectKeys.add("gross_weight");
entitys.add(new ExcelExportEntity("净重(net_weight)" ,"net_weight"));
selectKeys.add("net_weight");
entitys.add(new ExcelExportEntity("单位名称(unit_name)" ,"unit_name"));
selectKeys.add("unit_name");
entitys.add(new ExcelExportEntity("包装尺寸(packagesize)" ,"packagesize"));
selectKeys.add("packagesize");
entitys.add(new ExcelExportEntity("成本价(cost_price)" ,"cost_price"));
selectKeys.add("cost_price");
entitys.add(new ExcelExportEntity("保修期(warranty_period)" ,"warranty_period"));
selectKeys.add("warranty_period");
entitys.add(new ExcelExportEntity("税率(tax_rate)" ,"tax_rate"));
selectKeys.add("tax_rate");
entitys.add(new ExcelExportEntity("税收分类(tax_code)" ,"tax_code"));
selectKeys.add("tax_code");
entitys.add(new ExcelExportEntity("保修条款(warranty_terms)" ,"warranty_terms"));
selectKeys.add("warranty_terms");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
ExcelModel excelModel = generaterSwapUtil.getExcelParams(ProductsConstant.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(ProductsConstant.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{
ProductEntity entity= productsService.getInfo(id);
if(entity!=null){
//假删除
entity.setDeleteMark(1);
entity.setDeleteUserId(userProvider.get().getUserId());
entity.setDeleteTime(new Date());
productsService.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 productForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid ProductForm productForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
ProductEntity entity= productsService.getInfo(id);
if(entity!=null){
productForm.setProductId(String.valueOf(entity.getProductId()));
if (!isImport) {
String b = productsService.checkForm(productForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
productsService.saveOrUpdate(productForm,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){
ProductEntity entity= productsService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> productMap=JsonUtil.entityToMap(entity);
productMap.put("id", productMap.get("product_id"));
//副表数据
//子表数据
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
productMap = generaterSwapUtil.swapDataDetail(productMap,ProductsConstant.getFormData(),"817386322065883909",isPc?false:false);
//子表数据
return ActionResult.success(productMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
ProductEntity entity= productsService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> productMap=JsonUtil.entityToMap(entity);
productMap.put("id", productMap.get("product_id"));
//副表数据
//子表数据
productMap = generaterSwapUtil.swapDataForm(productMap,ProductsConstant.getFormData(),ProductsConstant.TABLEFIELDKEY,ProductsConstant.TABLERENAMES);
return ActionResult.success(productMap);
}
}

View File

@@ -0,0 +1,992 @@
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.suppinfo.*;
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;
/**
* 供应商信息
* @版本: V5.2.7
* @版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
* @作者: 深圳市乐程软件有限公司
* @日期: 2026-04-24
*/
@Slf4j
@RestController
@Tag(name = "供应商信息" , description = "bcm")
@RequestMapping("/api/bcm/Suppinfo")
public class SuppinfoController {
@Autowired
private GeneraterSwapUtil generaterSwapUtil;
@Autowired
private UserProvider userProvider;
@Autowired
private SuppinfoService companyService;
@Autowired
private PanyInvoiceService panyInvoiceService;
@Autowired
private CompanyBankService companyBankService;
@Autowired
private SupplierService supplierService;
@Autowired
private ConfigValueUtil configValueUtil;
/**
* 列表
*
* @param companyPagination
* @return
*/
@Operation(summary = "获取列表")
@PostMapping("/getList")
public ActionResult list(@RequestBody SuppinfoPagination companyPagination)throws Exception{
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
SupplierEntity supplierEntity = entity.getSupplier();
if(ObjectUtil.isNotEmpty(supplierEntity)){
Map<String, Object> supplierMap=JsonUtil.entityToMap(supplierEntity);
for(String key:supplierMap.keySet()){
companyMap.put("yunzhupaas_mdm_supplier_yunzhupaas_"+key,supplierMap.get(key));
}
}
//子表数据
List<PanyInvoiceEntity> panyInvoiceList = entity.getPanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
companyMap.put("panyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
realList = generaterSwapUtil.swapDataList(realList, SuppinfoConstant.getFormData(), SuppinfoConstant.getColumnData(), companyPagination.getModuleId(),isPc?false:false);
//返回对象
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(companyPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
/**
* 创建
*
* @param companyForm
* @return
*/
@PostMapping()
@Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid SuppinfoForm companyForm) throws Exception {
String b = companyService.checkForm(companyForm,0);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
// try{
companyService.saveOrUpdate(companyForm, null ,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 SuppinfoPagination companyPagination) throws IOException {
if (StringUtil.isEmpty(companyPagination.getSelectKey())){
return ActionResult.fail(MsgCode.IMP011.get());
}
List<CompanyEntity> list= companyService.getList(companyPagination);
List<Map<String, Object>> realList=new ArrayList<>();
for (CompanyEntity entity : list) {
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
SupplierEntity supplierEntity = entity.getSupplier();
if(ObjectUtil.isNotEmpty(supplierEntity)){
Map<String, Object> supplierMap=JsonUtil.entityToMap(supplierEntity);
for(String key:supplierMap.keySet()){
companyMap.put("yunzhupaas_mdm_supplier_yunzhupaas_"+key,supplierMap.get(key));
}
}
//子表数据
List<PanyInvoiceEntity> panyInvoiceList = entity.getPanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
companyMap.put("panyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
realList.add(companyMap);
}
//数据转换
realList = generaterSwapUtil.swapDataList(realList, SuppinfoConstant.getFormData(), SuppinfoConstant.getColumnData(), companyPagination.getModuleId(),false);
String[]keys=!StringUtil.isEmpty(companyPagination.getSelectKey())?companyPagination.getSelectKey():new String[0];
UserInfo userInfo=userProvider.get();
String menuFullName = generaterSwapUtil.getMenuName(companyPagination.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){
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53List = new ArrayList<>();
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92List = new ArrayList<>();
for(String key:keys){
switch(key){
case "company_code" :
entitys.add(new ExcelExportEntity("企业编码" ,"company_code"));
break;
case "company_name" :
entitys.add(new ExcelExportEntity("企业名称" ,"company_name"));
break;
case "short_name" :
entitys.add(new ExcelExportEntity("简称/昵称" ,"short_name"));
break;
case "entity_type" :
entitys.add(new ExcelExportEntity("类型" ,"entity_type"));
break;
case "credit_code" :
entitys.add(new ExcelExportEntity("社会信用代码" ,"credit_code"));
break;
case "org_id" :
entitys.add(new ExcelExportEntity("归属组织" ,"org_id"));
break;
case "province_id" :
entitys.add(new ExcelExportEntity("所属地区" ,"province_id"));
break;
case "tax_type" :
entitys.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "enterprise_scale" :
entitys.add(new ExcelExportEntity("企业规模" ,"enterprise_scale"));
break;
case "enterprise_nature" :
entitys.add(new ExcelExportEntity("企业类型" ,"enterprise_nature"));
break;
case "industry_code" :
entitys.add(new ExcelExportEntity("行业代码" ,"industry_code"));
break;
case "registration_date" :
entitys.add(new ExcelExportEntity("成立日期" ,"registration_date"));
break;
case "registered_capital" :
entitys.add(new ExcelExportEntity("注册资本" ,"registered_capital"));
break;
case "legal_representative" :
entitys.add(new ExcelExportEntity("法定代表人" ,"legal_representative"));
break;
case "phone" :
entitys.add(new ExcelExportEntity("联系电话" ,"phone"));
break;
case "email" :
entitys.add(new ExcelExportEntity("邮箱" ,"email"));
break;
case "website" :
entitys.add(new ExcelExportEntity("网站" ,"website"));
break;
case "address" :
entitys.add(new ExcelExportEntity("地址" ,"address"));
break;
case "business_scope" :
entitys.add(new ExcelExportEntity("经营范围" ,"business_scope"));
break;
case "remark" :
entitys.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_major_person_id" :
entitys.add(new ExcelExportEntity("责任人" ,"yunzhupaas_mdm_supplier_yunzhupaas_major_person_id"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_supplier_level" :
entitys.add(new ExcelExportEntity("供应商级别" ,"yunzhupaas_mdm_supplier_yunzhupaas_supplier_level"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_supplier_type" :
entitys.add(new ExcelExportEntity("供应商类型" ,"yunzhupaas_mdm_supplier_yunzhupaas_supplier_type"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_supplier_category" :
entitys.add(new ExcelExportEntity("供应商分类" ,"yunzhupaas_mdm_supplier_yunzhupaas_supplier_category"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_honor" :
entitys.add(new ExcelExportEntity("荣誉、资质" ,"yunzhupaas_mdm_supplier_yunzhupaas_honor"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_achievement" :
entitys.add(new ExcelExportEntity("供应商业绩" ,"yunzhupaas_mdm_supplier_yunzhupaas_achievement"));
break;
case "yunzhupaas_mdm_supplier_yunzhupaas_finish_project" :
entitys.add(new ExcelExportEntity("完工项目" ,"yunzhupaas_mdm_supplier_yunzhupaas_finish_project"));
break;
case "tableField46dc53-title_code":
tableField46dc53List.add(new ExcelExportEntity("发票抬头编码" ,"title_code"));
break;
case "tableField46dc53-title_name":
tableField46dc53List.add(new ExcelExportEntity("发票抬头名称" ,"title_name"));
break;
case "tableField46dc53-credit_code":
tableField46dc53List.add(new ExcelExportEntity("纳税人识别号" ,"credit_code"));
break;
case "tableField46dc53-tax_type":
tableField46dc53List.add(new ExcelExportEntity("纳税人类别" ,"tax_type"));
break;
case "tableField46dc53-address":
tableField46dc53List.add(new ExcelExportEntity("地址" ,"address"));
break;
case "tableField46dc53-phone":
tableField46dc53List.add(new ExcelExportEntity("电话" ,"phone"));
break;
case "tableField46dc53-bank_name":
tableField46dc53List.add(new ExcelExportEntity("开户银行" ,"bank_name"));
break;
case "tableField46dc53-bank_account":
tableField46dc53List.add(new ExcelExportEntity("银行账户" ,"bank_account"));
break;
case "tableField46dc53-is_defalut":
tableField46dc53List.add(new ExcelExportEntity("是否默认" ,"is_defalut"));
break;
case "tableField46dc53-is_valid":
tableField46dc53List.add(new ExcelExportEntity("是否有效" ,"is_valid"));
break;
case "tableField46dc53-remark":
tableField46dc53List.add(new ExcelExportEntity("备注" ,"remark"));
break;
case "tableFieldad9d92-bank_name":
tableFieldad9d92List.add(new ExcelExportEntity("开户行" ,"bank_name"));
break;
case "tableFieldad9d92-bank_account_name":
tableFieldad9d92List.add(new ExcelExportEntity("账户名" ,"bank_account_name"));
break;
case "tableFieldad9d92-bank_account_number":
tableFieldad9d92List.add(new ExcelExportEntity("银行账号" ,"bank_account_number"));
break;
case "tableFieldad9d92-bank_province":
tableFieldad9d92List.add(new ExcelExportEntity("开户行城市" ,"bank_province"));
break;
case "tableFieldad9d92-remark":
tableFieldad9d92List.add(new ExcelExportEntity("备注" ,"remark"));
break;
default:
break;
}
}
if(tableField46dc53List.size() > 0){
tableField46dc53ExcelEntity.setList(tableField46dc53List);
entitys.add(tableField46dc53ExcelEntity);
}
if(tableFieldad9d92List.size() > 0){
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92List);
entitys.add(tableFieldad9d92ExcelEntity);
}
}
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(SuppinfoConstant.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(SuppinfoConstant.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("企业编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
entitys.add(new ExcelExportEntity("责任人(yunzhupaas_mdm_supplier_yunzhupaas_major_person_id)" ,"yunzhupaas_mdm_supplier_yunzhupaas_major_person_id"));
selectKeys.add("yunzhupaas_mdm_supplier_yunzhupaas_major_person_id");
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
if(tableField46dc53ExcelEntityList.size() > 0){
entitys.add(tableField46dc53ExcelEntity);
}
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
if(tableFieldad9d92ExcelEntityList.size() > 0){
entitys.add(tableFieldad9d92ExcelEntity);
}
ExcelModel excelModel = generaterSwapUtil.getExcelParams(SuppinfoConstant.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(SuppinfoConstant.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 = 2;
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(SuppinfoConstant.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("company_name","企业名称","input"));
columns.add(new ExcelImFieldModel("credit_code","社会信用代码","input"));
columns.add(new ExcelImFieldModel("org_id","归属组织","organizeSelect"));
columns.add(new ExcelImFieldModel("company_code","企业编码","billRule"));
columns.add(new ExcelImFieldModel("short_name","简称/昵称","input"));
columns.add(new ExcelImFieldModel("entity_type","类型","radio"));
columns.add(new ExcelImFieldModel("tax_type","纳税人类别","select"));
columns.add(new ExcelImFieldModel("enterprise_scale","企业规模","select"));
columns.add(new ExcelImFieldModel("enterprise_nature","企业类型","select"));
columns.add(new ExcelImFieldModel("industry_code","行业代码","select"));
columns.add(new ExcelImFieldModel("registration_date","成立日期","datePicker"));
columns.add(new ExcelImFieldModel("registered_capital","注册资本","inputNumber"));
columns.add(new ExcelImFieldModel("legal_representative","法定代表人","input"));
columns.add(new ExcelImFieldModel("phone","联系电话","input"));
columns.add(new ExcelImFieldModel("email","邮箱","input"));
columns.add(new ExcelImFieldModel("website","网站","input"));
columns.add(new ExcelImFieldModel("address","地址","input"));
columns.add(new ExcelImFieldModel("province_id","所属地区","areaSelect"));
columns.add(new ExcelImFieldModel("business_scope","经营范围","textarea"));
columns.add(new ExcelImFieldModel("remark","备注","textarea"));
columns.add(new ExcelImFieldModel("yunzhupaas_mdm_supplier_yunzhupaas_major_person_id","责任人","userSelect"));
//tableField46dc53子表对象
List<ExcelImFieldModel> tableField46dc53columns = new ArrayList<>();
tableField46dc53columns.add(new ExcelImFieldModel("title_name" ,"发票抬头名称"));
tableField46dc53columns.add(new ExcelImFieldModel("credit_code" ,"纳税人识别号"));
tableField46dc53columns.add(new ExcelImFieldModel("tax_type" ,"纳税人类别"));
tableField46dc53columns.add(new ExcelImFieldModel("address" ,"地址"));
tableField46dc53columns.add(new ExcelImFieldModel("phone" ,"电话"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_name" ,"开户银行"));
tableField46dc53columns.add(new ExcelImFieldModel("bank_account" ,"银行账户"));
tableField46dc53columns.add(new ExcelImFieldModel("is_defalut" ,"是否默认"));
tableField46dc53columns.add(new ExcelImFieldModel("is_valid" ,"是否有效"));
tableField46dc53columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableField46dc53","设计子表","table",tableField46dc53columns));
//tableFieldad9d92子表对象
List<ExcelImFieldModel> tableFieldad9d92columns = new ArrayList<>();
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_name" ,"开户行"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_name" ,"账户名"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_account_number" ,"银行账号"));
tableFieldad9d92columns.add(new ExcelImFieldModel("bank_province" ,"开户行城市"));
tableFieldad9d92columns.add(new ExcelImFieldModel("remark" ,"备注"));
columns.add(new ExcelImFieldModel("tableFieldad9d92","设计子表","table",tableFieldad9d92columns));
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(SuppinfoConstant.DBLINKID);
uniqueModel.setUpdate(Objects.equals("2", "2"));
Map<String,String> tablefieldkey = new HashMap<>();
for(String key:SuppinfoConstant.TABLEFIELDKEY.keySet()){
tablefieldkey.put(key,SuppinfoConstant.TABLERENAMES.get(SuppinfoConstant.TABLEFIELDKEY.get(key)));
}
ExcelImportModel excelImportModel = generaterSwapUtil.importData(SuppinfoConstant.getFormData(),listData,uniqueModel, tablefieldkey,SuppinfoConstant.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,SuppinfoForm.class), true);
}else {
create( JsonUtil.getJsonToBean(result,SuppinfoForm.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("企业名称(company_name)" ,"company_name"));
selectKeys.add("company_name");
entitys.add(new ExcelExportEntity("社会信用代码(credit_code)" ,"credit_code"));
selectKeys.add("credit_code");
entitys.add(new ExcelExportEntity("归属组织(org_id)" ,"org_id"));
selectKeys.add("org_id");
entitys.add(new ExcelExportEntity("企业编码(company_code)" ,"company_code"));
selectKeys.add("company_code");
entitys.add(new ExcelExportEntity("简称/昵称(short_name)" ,"short_name"));
selectKeys.add("short_name");
entitys.add(new ExcelExportEntity("类型(entity_type)" ,"entity_type"));
selectKeys.add("entity_type");
entitys.add(new ExcelExportEntity("纳税人类别(tax_type)" ,"tax_type"));
selectKeys.add("tax_type");
entitys.add(new ExcelExportEntity("企业规模(enterprise_scale)" ,"enterprise_scale"));
selectKeys.add("enterprise_scale");
entitys.add(new ExcelExportEntity("企业类型(enterprise_nature)" ,"enterprise_nature"));
selectKeys.add("enterprise_nature");
entitys.add(new ExcelExportEntity("行业代码(industry_code)" ,"industry_code"));
selectKeys.add("industry_code");
entitys.add(new ExcelExportEntity("成立日期(registration_date)" ,"registration_date"));
selectKeys.add("registration_date");
entitys.add(new ExcelExportEntity("注册资本(registered_capital)" ,"registered_capital"));
selectKeys.add("registered_capital");
entitys.add(new ExcelExportEntity("法定代表人(legal_representative)" ,"legal_representative"));
selectKeys.add("legal_representative");
entitys.add(new ExcelExportEntity("联系电话(phone)" ,"phone"));
selectKeys.add("phone");
entitys.add(new ExcelExportEntity("邮箱(email)" ,"email"));
selectKeys.add("email");
entitys.add(new ExcelExportEntity("网站(website)" ,"website"));
selectKeys.add("website");
entitys.add(new ExcelExportEntity("地址(address)" ,"address"));
selectKeys.add("address");
entitys.add(new ExcelExportEntity("所属地区(province_id)" ,"province_id"));
selectKeys.add("province_id");
entitys.add(new ExcelExportEntity("经营范围(business_scope)" ,"business_scope"));
selectKeys.add("business_scope");
entitys.add(new ExcelExportEntity("备注(remark)" ,"remark"));
selectKeys.add("remark");
entitys.add(new ExcelExportEntity("责任人(yunzhupaas_mdm_supplier_yunzhupaas_major_person_id)" ,"yunzhupaas_mdm_supplier_yunzhupaas_major_person_id"));
selectKeys.add("yunzhupaas_mdm_supplier_yunzhupaas_major_person_id");
//tableField46dc53子表对象
ExcelExportEntity tableField46dc53ExcelEntity = new ExcelExportEntity("设计子表(tableField46dc53)","tableField46dc53");
List<ExcelExportEntity> tableField46dc53ExcelEntityList = new ArrayList<>();
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("发票抬头名称(tableField46dc53-title_name)" ,"title_name"));
selectKeys.add("tableField46dc53-title_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人识别号(tableField46dc53-credit_code)" ,"credit_code"));
selectKeys.add("tableField46dc53-credit_code");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("纳税人类别(tableField46dc53-tax_type)" ,"tax_type"));
selectKeys.add("tableField46dc53-tax_type");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("地址(tableField46dc53-address)" ,"address"));
selectKeys.add("tableField46dc53-address");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("电话(tableField46dc53-phone)" ,"phone"));
selectKeys.add("tableField46dc53-phone");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("开户银行(tableField46dc53-bank_name)" ,"bank_name"));
selectKeys.add("tableField46dc53-bank_name");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("银行账户(tableField46dc53-bank_account)" ,"bank_account"));
selectKeys.add("tableField46dc53-bank_account");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否默认(tableField46dc53-is_defalut)" ,"is_defalut"));
selectKeys.add("tableField46dc53-is_defalut");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("是否有效(tableField46dc53-is_valid)" ,"is_valid"));
selectKeys.add("tableField46dc53-is_valid");
tableField46dc53ExcelEntityList.add(new ExcelExportEntity("备注(tableField46dc53-remark)" ,"remark"));
selectKeys.add("tableField46dc53-remark");
tableField46dc53ExcelEntity.setList(tableField46dc53ExcelEntityList);
entitys.add(tableField46dc53ExcelEntity);
//tableFieldad9d92子表对象
ExcelExportEntity tableFieldad9d92ExcelEntity = new ExcelExportEntity("设计子表(tableFieldad9d92)","tableFieldad9d92");
List<ExcelExportEntity> tableFieldad9d92ExcelEntityList = new ArrayList<>();
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行(tableFieldad9d92-bank_name)" ,"bank_name"));
selectKeys.add("tableFieldad9d92-bank_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("账户名(tableFieldad9d92-bank_account_name)" ,"bank_account_name"));
selectKeys.add("tableFieldad9d92-bank_account_name");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("银行账号(tableFieldad9d92-bank_account_number)" ,"bank_account_number"));
selectKeys.add("tableFieldad9d92-bank_account_number");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("开户行城市(tableFieldad9d92-bank_province)" ,"bank_province"));
selectKeys.add("tableFieldad9d92-bank_province");
tableFieldad9d92ExcelEntityList.add(new ExcelExportEntity("备注(tableFieldad9d92-remark)" ,"remark"));
selectKeys.add("tableFieldad9d92-remark");
tableFieldad9d92ExcelEntity.setList(tableFieldad9d92ExcelEntityList);
entitys.add(tableFieldad9d92ExcelEntity);
ExcelModel excelModel = generaterSwapUtil.getExcelParams(SuppinfoConstant.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(SuppinfoConstant.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{
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
//主表数据删除
companyService.delete(entity);
QueryWrapper<SupplierEntity> queryWrapperSupplier=new QueryWrapper<>();
queryWrapperSupplier.lambda().eq(SupplierEntity::getCompanyId,entity.getCompanyId());
//副表数据删除
supplierService.remove(queryWrapperSupplier);
QueryWrapper<PanyInvoiceEntity> queryWrapperPanyInvoice=new QueryWrapper<>();
queryWrapperPanyInvoice.lambda().eq(PanyInvoiceEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
panyInvoiceService.remove(queryWrapperPanyInvoice);
QueryWrapper<CompanyBankEntity> queryWrapperCompanyBank=new QueryWrapper<>();
queryWrapperCompanyBank.lambda().eq(CompanyBankEntity::getCompanyId,entity.getCompanyId());
//子表数据删除
companyBankService.remove(queryWrapperCompanyBank);
}
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 companyForm
* @return
*/
@PutMapping("/{id}")
@Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid SuppinfoForm companyForm,
@RequestParam(value = "isImport", required = false) boolean isImport){
CompanyEntity entity= companyService.getInfo(id);
if(entity!=null){
companyForm.setCompanyId(String.valueOf(entity.getCompanyId()));
if (!isImport) {
String b = companyService.checkForm(companyForm,1);
if (StringUtil.isNotEmpty(b)){
return ActionResult.fail(b );
}
}
try{
companyService.saveOrUpdate(companyForm,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){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
SupplierEntity supplierEntity = entity.getSupplier();
if(ObjectUtil.isNotEmpty(supplierEntity)){
Map<String, Object> supplierMap=JsonUtil.entityToMap(supplierEntity);
for(String key:supplierMap.keySet()){
companyMap.put("yunzhupaas_mdm_supplier_yunzhupaas_"+key,supplierMap.get(key));
}
}
//子表数据
List<PanyInvoiceEntity> panyInvoiceList = entity.getPanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
companyMap.put("panyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
boolean isPc = "pc".equals(ServletUtil.getHeader("yunzhupaas-origin" ));
companyMap = generaterSwapUtil.swapDataDetail(companyMap,SuppinfoConstant.getFormData(),"817082533433836293",isPc?false:false);
//子表数据
companyMap.put("panyInvoiceList",companyMap.get("tableField46dc53"));
companyMap.put("companyBankList",companyMap.get("tableFieldad9d92"));
return ActionResult.success(companyMap);
}
/**
* 获取详情(编辑页)
* 编辑页面使用-不转换数据
* @param id
* @return
*/
@Operation(summary = "信息")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){
CompanyEntity entity= companyService.getInfo(id);
if(entity==null){
return ActionResult.fail(MsgCode.FA001.get());
}
Map<String, Object> companyMap=JsonUtil.entityToMap(entity);
companyMap.put("id", companyMap.get("company_id"));
//副表数据
SupplierEntity supplierEntity = entity.getSupplier();
if(ObjectUtil.isNotEmpty(supplierEntity)){
Map<String, Object> supplierMap=JsonUtil.entityToMap(supplierEntity);
for(String key:supplierMap.keySet()){
companyMap.put("yunzhupaas_mdm_supplier_yunzhupaas_"+key,supplierMap.get(key));
}
}
//子表数据
List<PanyInvoiceEntity> panyInvoiceList = entity.getPanyInvoice();
companyMap.put("tableField46dc53",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
companyMap.put("panyInvoiceList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(panyInvoiceList)));
List<CompanyBankEntity> companyBankList = entity.getCompanyBank();
companyMap.put("tableFieldad9d92",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap.put("companyBankList",JsonUtil.getJsonToList(JsonUtil.getListToJsonArray(companyBankList)));
companyMap = generaterSwapUtil.swapDataForm(companyMap,SuppinfoConstant.getFormData(),SuppinfoConstant.TABLEFIELDKEY,SuppinfoConstant.TABLERENAMES);
return ActionResult.success(companyMap);
}
}