feat:新增打印模板相关接口
parent
4b08408511
commit
8fcf74187b
@ -0,0 +1,96 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.printtemplate;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.printtemplate.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.printtemplate.PrintTemplateDO;
|
||||||
|
import cn.iocoder.yudao.module.mes.service.printtemplate.PrintTemplateService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 打印模板")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mes/print-template")
|
||||||
|
@Validated
|
||||||
|
public class PrintTemplateController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PrintTemplateService printTemplateService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建打印模板")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:create')")
|
||||||
|
public CommonResult<Long> createPrintTemplate(@Valid @RequestBody PrintTemplateSaveReqVO createReqVO) {
|
||||||
|
return success(printTemplateService.createPrintTemplate(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新打印模板")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:update')")
|
||||||
|
public CommonResult<Boolean> updatePrintTemplate(@Valid @RequestBody PrintTemplateSaveReqVO updateReqVO) {
|
||||||
|
printTemplateService.updatePrintTemplate(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除打印模板")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:delete')")
|
||||||
|
public CommonResult<Boolean> deletePrintTemplate(@RequestParam("id") Long id) {
|
||||||
|
printTemplateService.deletePrintTemplate(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得打印模板")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:query')")
|
||||||
|
public CommonResult<PrintTemplateRespVO> getPrintTemplate(@RequestParam("id") Long id) {
|
||||||
|
PrintTemplateDO printTemplate = printTemplateService.getPrintTemplate(id);
|
||||||
|
return success(BeanUtils.toBean(printTemplate, PrintTemplateRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得打印模板分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:query')")
|
||||||
|
public CommonResult<PageResult<PrintTemplateRespVO>> getPrintTemplatePage(@Valid PrintTemplatePageReqVO pageReqVO) {
|
||||||
|
PageResult<PrintTemplateDO> pageResult = printTemplateService.getPrintTemplatePage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, PrintTemplateRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出打印模板 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:print-template:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportPrintTemplateExcel(@Valid PrintTemplatePageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<PrintTemplateDO> list = printTemplateService.getPrintTemplatePage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "打印模板.xls", "数据", PrintTemplateRespVO.class,
|
||||||
|
BeanUtils.toBean(list, PrintTemplateRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.printtemplate.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum PrintTemplateTypeEnum {
|
||||||
|
|
||||||
|
MATERIAL_PRODUCT(1),
|
||||||
|
EQUIPMENT_LEDGER(2),
|
||||||
|
KEY_COMPONENT(3),
|
||||||
|
MOLD(4),
|
||||||
|
SPARE_PARTS(5);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
public static PrintTemplateTypeEnum fromValue(int value) {
|
||||||
|
for (PrintTemplateTypeEnum type : PrintTemplateTypeEnum.values()) {
|
||||||
|
if (type.getValue() == value) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown value: " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.dal.mysql.printtemplate;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.printtemplate.PrintTemplateDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.printtemplate.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印模板 Mapper
|
||||||
|
*
|
||||||
|
* @author 必硕智能
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface PrintTemplateMapper extends BaseMapperX<PrintTemplateDO> {
|
||||||
|
|
||||||
|
default PrintTemplateDO selectByNo(String no) {
|
||||||
|
return selectOne(PrintTemplateDO::getTemplateCode, no);
|
||||||
|
}
|
||||||
|
|
||||||
|
default PrintTemplateDO selectByTemplateType(Integer templateType) {
|
||||||
|
return selectOne(PrintTemplateDO::getTemplateType, templateType);
|
||||||
|
}
|
||||||
|
|
||||||
|
default PageResult<PrintTemplateDO> selectPage(PrintTemplatePageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<PrintTemplateDO>()
|
||||||
|
.eqIfPresent(PrintTemplateDO::getTemplateCode, reqVO.getTemplateCode())
|
||||||
|
.likeIfPresent(PrintTemplateDO::getTemplateName, reqVO.getTemplateName())
|
||||||
|
.eqIfPresent(PrintTemplateDO::getTemplateType, reqVO.getTemplateType())
|
||||||
|
.eqIfPresent(PrintTemplateDO::getTemplateJson, reqVO.getTemplateJson())
|
||||||
|
.eqIfPresent(PrintTemplateDO::getRemark, reqVO.getRemark())
|
||||||
|
.eqIfPresent(PrintTemplateDO::getIsEnable, reqVO.getIsEnable())
|
||||||
|
.betweenIfPresent(PrintTemplateDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(PrintTemplateDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.service.printtemplate;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.printtemplate.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.printtemplate.PrintTemplateDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印模板 Service 接口
|
||||||
|
*
|
||||||
|
* @author 必硕智能
|
||||||
|
*/
|
||||||
|
public interface PrintTemplateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建打印模板
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createPrintTemplate(@Valid PrintTemplateSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新打印模板
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updatePrintTemplate(@Valid PrintTemplateSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除打印模板
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deletePrintTemplate(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得打印模板
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 打印模板
|
||||||
|
*/
|
||||||
|
PrintTemplateDO getPrintTemplate(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得打印模板分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 打印模板分页
|
||||||
|
*/
|
||||||
|
PageResult<PrintTemplateDO> getPrintTemplatePage(PrintTemplatePageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.service.printtemplate;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.printtemplate.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.printtemplate.PrintTemplateDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.mysql.printtemplate.PrintTemplateMapper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印模板 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 必硕智能
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class PrintTemplateServiceImpl implements PrintTemplateService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PrintTemplateMapper printTemplateMapper;
|
||||||
|
@Resource
|
||||||
|
private AutoCodeUtil autoCodeUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createPrintTemplate(PrintTemplateSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
PrintTemplateDO printTemplate = BeanUtils.toBean(createReqVO, PrintTemplateDO.class);
|
||||||
|
if (printTemplateMapper.selectByTemplateType(printTemplate.getTemplateType()) != null) {
|
||||||
|
throw exception(PRINT_TEMPLATE_TYPE_EXISTS);
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(printTemplate.getTemplateCode())) {
|
||||||
|
printTemplate.setTemplateCode(autoCodeUtil.genSerialCode("PRINT_TEMPLATE_CODE", null));
|
||||||
|
} else {
|
||||||
|
if (printTemplateMapper.selectByNo(printTemplate.getTemplateCode()) != null) {
|
||||||
|
throw exception(PRINT_TEMPLATE_CODE_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printTemplateMapper.insert(printTemplate);
|
||||||
|
// 返回
|
||||||
|
return printTemplate.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePrintTemplate(PrintTemplateSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validatePrintTemplateExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
PrintTemplateDO updateObj = BeanUtils.toBean(updateReqVO, PrintTemplateDO.class);
|
||||||
|
PrintTemplateDO typeExists = printTemplateMapper.selectByTemplateType(updateObj.getTemplateType());
|
||||||
|
if (typeExists != null && !typeExists.getId().equals(updateObj.getId())) {
|
||||||
|
throw exception(PRINT_TEMPLATE_TYPE_EXISTS);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(updateObj.getTemplateCode())) {
|
||||||
|
PrintTemplateDO codeExists = printTemplateMapper.selectByNo(updateObj.getTemplateCode());
|
||||||
|
if (codeExists != null && !codeExists.getId().equals(updateObj.getId())) {
|
||||||
|
throw exception(PRINT_TEMPLATE_CODE_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printTemplateMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deletePrintTemplate(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validatePrintTemplateExists(id);
|
||||||
|
// 删除
|
||||||
|
printTemplateMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validatePrintTemplateExists(Long id) {
|
||||||
|
if (printTemplateMapper.selectById(id) == null) {
|
||||||
|
throw exception(PRINT_TEMPLATE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PrintTemplateDO getPrintTemplate(Long id) {
|
||||||
|
return printTemplateMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<PrintTemplateDO> getPrintTemplatePage(PrintTemplatePageReqVO pageReqVO) {
|
||||||
|
return printTemplateMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue