diff --git a/src/main/java/com/glxp/udi/admin/controller/param/SystemPDFTemplateController.java b/src/main/java/com/glxp/udi/admin/controller/param/SystemPDFTemplateController.java index d6cf20d..ce77f6d 100644 --- a/src/main/java/com/glxp/udi/admin/controller/param/SystemPDFTemplateController.java +++ b/src/main/java/com/glxp/udi/admin/controller/param/SystemPDFTemplateController.java @@ -1,5 +1,7 @@ package com.glxp.udi.admin.controller.param; +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.glxp.udi.admin.annotation.AuthRuleAnnotation; import com.glxp.udi.admin.common.res.BaseResponse; @@ -8,9 +10,9 @@ import com.glxp.udi.admin.req.param.SystemPDFTemplateRequest; import com.glxp.udi.admin.req.param.SystemPDFTemplateSaveRequest; import com.glxp.udi.admin.res.PageSimpleResponse; import com.glxp.udi.admin.res.param.SystemPDFTemplateResponse; -import com.glxp.udi.admin.res.param.SystemPDFTemplateSelectResponse; import com.glxp.udi.admin.service.param.SystemPDFTemplateService; import com.glxp.udi.admin.util.JasperUtils; +import com.glxp.udi.admin.util.PageUtil; import com.glxp.udi.common.enums.ResultEnum; import com.glxp.udi.common.util.ResultVOUtils; import org.apache.commons.lang3.StringUtils; @@ -24,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.File; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -55,24 +58,27 @@ public class SystemPDFTemplateController { return ResultVOUtils.success(pageSimpleResponse); } - @AuthRuleAnnotation("system/pdf/template/list") - @GetMapping("/system/pdf/template/pdfTemplates") - public BaseResponse pdfTemplates(@RequestParam(value = "page", defaultValue = "1") Integer page, - @RequestParam(value = "limit", defaultValue = "100") Integer limit) { - - Page pageResult = systemPDFTemplateService.listPDFTemplates(page, limit); - PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); - pageSimpleResponse.setTotal(pageResult.getTotal()); - List systemPDFTemplateSelectResponses = pageResult.getRecords().stream().map(e -> { - SystemPDFTemplateSelectResponse systemPDFTemplateSelectResponse = new SystemPDFTemplateSelectResponse(); - BeanUtils.copyProperties(e, systemPDFTemplateSelectResponse); - systemPDFTemplateSelectResponse.setIdStr(String.valueOf(e.getId())); - return systemPDFTemplateSelectResponse; - }).collect(Collectors.toList()); - pageSimpleResponse.setList(systemPDFTemplateSelectResponses); - return ResultVOUtils.success(pageSimpleResponse); + /** + * 查询客户专属和公共的打印模板 + * + * @param systemPDFTemplateRequest + * @return + */ + @PostMapping("/system/pdf/template/customerTemplates") + public BaseResponse customerTemplates(@RequestBody SystemPDFTemplateRequest systemPDFTemplateRequest) { + IPage page = systemPDFTemplateService.findCustomerTemplates(systemPDFTemplateRequest); + List systemPDFTemplateResponses =new ArrayList<>(page.getRecords().size()); + if (page.getTotal() > 0) { + page.getRecords().forEach(systemPDFTemplateEntity -> { + SystemPDFTemplateResponse systemPDFTemplateResponse = new SystemPDFTemplateResponse(); + BeanUtil.copyProperties(systemPDFTemplateEntity, systemPDFTemplateResponse); + systemPDFTemplateResponses.add(systemPDFTemplateResponse); + }); + } + return ResultVOUtils.success(PageUtil.page(page, systemPDFTemplateResponses)); } + @AuthRuleAnnotation("system/pdf/template/save") @PostMapping("/system/pdf/template/save") public BaseResponse save(@RequestBody @Valid SystemPDFTemplateSaveRequest systemPDFTemplateSaveRequest, BindingResult bindingResult) { @@ -95,7 +101,6 @@ public class SystemPDFTemplateController { if (!b) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } - return ResultVOUtils.success(); } diff --git a/src/main/java/com/glxp/udi/admin/dao/param/SystemPDFTemplateDao.java b/src/main/java/com/glxp/udi/admin/dao/param/SystemPDFTemplateDao.java index ce38ccd..d91c966 100644 --- a/src/main/java/com/glxp/udi/admin/dao/param/SystemPDFTemplateDao.java +++ b/src/main/java/com/glxp/udi/admin/dao/param/SystemPDFTemplateDao.java @@ -27,4 +27,5 @@ public interface SystemPDFTemplateDao extends BaseMapper findCustomerTemplates(SystemPDFTemplateRequest systemPDFTemplateRequest) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StrUtil.isNotBlank(systemPDFTemplateRequest.getCustomerId()), "customerId", systemPDFTemplateRequest.getCustomerId()) + .or() + .isNull("customerId"); + + IPage page = new Page<>(systemPDFTemplateRequest.getPage(), systemPDFTemplateRequest.getLimit()); + return systemPDFTemplateDao.selectPage(page, wrapper); + } + } diff --git a/src/main/java/com/glxp/udi/admin/util/PageUtil.java b/src/main/java/com/glxp/udi/admin/util/PageUtil.java new file mode 100644 index 0000000..fdc4cf5 --- /dev/null +++ b/src/main/java/com/glxp/udi/admin/util/PageUtil.java @@ -0,0 +1,43 @@ +package com.glxp.udi.admin.util; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.glxp.udi.admin.res.PageSimpleResponse; + +import java.util.List; + +/** + * 分页工具 + */ +public class PageUtil { + + /** + * 根据mybatis-plus的分页对象封装分页参数对象 + * + * @param page mybatis-plus分页对象 + * @param 查询数据实体类 + * @return + */ + public static PageSimpleResponse page(IPage page) { + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setTotal(page.getTotal()); + pageSimpleResponse.setList(page.getRecords()); + return pageSimpleResponse; + } + + /** + * 根据mybatis-plus的分页对象和自定义结果集封装分页返回对象 + * + * @param page mybatis-plus分页对象 + * @param list 自定义结果集 + * @param 查询数据实体类 + * @param 接口响应实体类 + * @return + */ + public static PageSimpleResponse page(IPage page, List list) { + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setTotal(page.getTotal()); + pageSimpleResponse.setList(list); + return pageSimpleResponse; + } + +}