feat(sys):费用科目增加复制、导出功能
1、新增 POST /expenseAccountApi/copy 复制接口(回显式,清空主键及科目编码) 2、新增 GET/POST /expenseAccountApi/export 导出接口(按列表查询条件+数据权限全量导出) 3、新增 ExpenseAccountExportVO 导出对象(27列业务字段)
This commit is contained in:
+51
@@ -13,6 +13,7 @@ import com.mhd.basic.application.service.contractManage.ContractManageApplicatio
|
||||
import com.mhd.basic.domain.expenseAccount.service.ExpenseAccountDomainService;
|
||||
import com.mhd.basic.infrastructure.feign.vo.SysDictDataVo;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.ExpenseAccountDTO;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.ExpenseAccountExportVO;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.SearchExpenseAccountDTO;
|
||||
import com.mhd.common.core.enums.DictCode;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
@@ -27,6 +28,7 @@ import com.mhd.system.api.SystemServiceFeign;
|
||||
import com.mhd.system.api.model.LoginUser;
|
||||
import com.mhd.common.core.domain.po.UserPo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -378,6 +380,55 @@ public class ExpenseAccountApplicationService {
|
||||
return expenseAccountDomainService.getInfo(expenseAccountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制费用科目-获取原科目数据供前端回显
|
||||
* <p>前端拿到数据后回显到新增弹窗,用户填写新科目编码后通过 /edit 接口(id 为空走新增)提交保存。
|
||||
* 清空科目编码是为了避免直接复制出重复编码(费用科目编码无唯一性校验)。</p>
|
||||
*/
|
||||
public ExpenseAccountPO copy(ExpenseAccountDTO expenseAccountDTO) {
|
||||
if (expenseAccountDTO == null || expenseAccountDTO.getExpenseAccountId() == null) {
|
||||
throw new ServiceException("原费用科目id不能为空");
|
||||
}
|
||||
// 获取原费用科目信息
|
||||
ExpenseAccountPO original = expenseAccountDomainService.getInfo(expenseAccountDTO.getExpenseAccountId());
|
||||
if (null == original) {
|
||||
throw new ServiceException("原费用科目信息未找到");
|
||||
}
|
||||
// 清空主键,前端提交时走新增
|
||||
original.setExpenseAccountId(null);
|
||||
// 清空科目编码,强制用户输入新编码,避免编码重复
|
||||
original.setSubjectCode(null);
|
||||
// 清空审计字段,新增时由 ExpenseAccountAssembler 重新生成
|
||||
original.setCreateBy(null);
|
||||
original.setCreateByName(null);
|
||||
original.setCreateTime(null);
|
||||
original.setUpdateBy(null);
|
||||
original.setUpdateByName(null);
|
||||
original.setUpdateTime(null);
|
||||
original.setDelFlag(null);
|
||||
// 清空非表字段
|
||||
original.setUnit(null);
|
||||
original.setExpenseAccountPOList(null);
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建费用科目导出数据(不分页全量,按列表页查询条件 + 数据权限过滤)
|
||||
*/
|
||||
public List<ExpenseAccountExportVO> buildExportList(ExpenseAccountDO expenseAccountDO) {
|
||||
List<ExpenseAccountExportVO> exportList = new ArrayList<>();
|
||||
List<ExpenseAccountPO> list = this.queryList(expenseAccountDO);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return exportList;
|
||||
}
|
||||
for (ExpenseAccountPO po : list) {
|
||||
ExpenseAccountExportVO vo = new ExpenseAccountExportVO();
|
||||
BeanUtils.copyProperties(po, vo);
|
||||
exportList.add(vo);
|
||||
}
|
||||
return exportList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param expenseAccountDTO
|
||||
|
||||
+45
@@ -1,5 +1,7 @@
|
||||
package com.mhd.basic.interfaces.facade.expenseAccount;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,9 +15,11 @@ import com.mhd.basic.domain.expenseAccount.repository.todo.SearchExpenseAccountD
|
||||
import com.mhd.basic.domain.sysMultistageDict.repository.po.SysMultistageDictPo;
|
||||
import com.mhd.basic.interfaces.assember.expenseAccount.ExpenseAccountAssembler;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.ExpenseAccountDTO;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.ExpenseAccountExportVO;
|
||||
import com.mhd.basic.interfaces.dto.expenseAccount.SearchExpenseAccountDTO;
|
||||
import com.mhd.common.core.constant.HttpStatus;
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.utils.poi.ExcelUtil;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -26,6 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.mhd.common.core.web.controller.BaseController;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.core.web.page.TableDataInfo;
|
||||
@@ -336,5 +341,45 @@ public class ExpenseAccountApi extends BaseController{
|
||||
return AjaxResult.success(expenseAccountPO.getUnit());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制费用科目
|
||||
* 返回原科目数据(已清空主键、科目编码等字段)供前端回显到新增弹窗,用户填写新科目编码后通过 /edit 接口提交新增
|
||||
*/
|
||||
@ApiOperation("复制费用科目-获取原科目数据用于回显")
|
||||
@PostMapping("/copy")
|
||||
public AjaxResult copy(@RequestBody ExpenseAccountDTO expenseAccountDTO)
|
||||
{
|
||||
try {
|
||||
ExpenseAccountPO expenseAccountPO = expenseAccountApplicationService.copy(expenseAccountDTO);
|
||||
return AjaxResult.success(expenseAccountPO);
|
||||
}catch (Exception e){
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出费用科目
|
||||
* 按列表页当前查询条件 + 数据权限过滤,不分页全量导出
|
||||
*/
|
||||
@ApiOperation("导出费用科目")
|
||||
@RequestMapping(value = "/export", method = {RequestMethod.GET, RequestMethod.POST},
|
||||
produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
public void export(ExpenseAccountDTO expenseAccountDTO, HttpServletResponse response) throws IOException
|
||||
{
|
||||
//转换实体(不用Assembler,避免其自动填充createByName/updateByName干扰查询条件,与/list一致)
|
||||
ExpenseAccountDO expenseAccountDO = new ExpenseAccountDO();
|
||||
BeanUtils.copyProperties(expenseAccountDTO, expenseAccountDO);
|
||||
//查询全量(不分页),并转换为导出对象
|
||||
List<ExpenseAccountExportVO> list = expenseAccountApplicationService.buildExportList(expenseAccountDO);
|
||||
|
||||
//设置下载头,防止浏览器乱码
|
||||
String fileName = URLEncoder.encode("费用科目导出", "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
|
||||
ExcelUtil<ExpenseAccountExportVO> util = new ExcelUtil<>(ExpenseAccountExportVO.class);
|
||||
util.exportExcel(response, list, "费用科目");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user