|
@@ -0,0 +1,174 @@
|
|
|
+package org.jeecg.modules.system.controller;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.system.entity.CdPrintTemplate;
|
|
|
+import org.jeecg.modules.system.service.ICdPrintTemplateService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+@Api("打印模板接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/system/cdPrintTemplate")
|
|
|
+@Slf4j
|
|
|
+public class CdPrintTemplateController {
|
|
|
+ @Autowired
|
|
|
+ private ICdPrintTemplateService cdPrintTemplateService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="templateName", value="名称",required=true, dataType="String"),
|
|
|
+ @ApiImplicitParam(name="departmentId", value="组织列表id",required=true, dataType="String"),
|
|
|
+ })
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<CdPrintTemplate>> queryPageList(CdPrintTemplate cdPrintTemplate,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ Result<IPage<CdPrintTemplate>> result = new Result<IPage<CdPrintTemplate>>();
|
|
|
+ QueryWrapper<CdPrintTemplate> queryWrapper = QueryGenerator.initQueryWrapper(cdPrintTemplate, req.getParameterMap());
|
|
|
+ Page<CdPrintTemplate> page = new Page<CdPrintTemplate>(pageNo, pageSize);
|
|
|
+ queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0.toString());
|
|
|
+ IPage<CdPrintTemplate> pageList = cdPrintTemplateService.page(page, queryWrapper);
|
|
|
+ result.setSuccess(true);
|
|
|
+ result.setResult(pageList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增和编辑", notes = "新增打印模板和修改打印模板")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="id", value="id",required=true, dataType="String"),
|
|
|
+ @ApiImplicitParam(name="templateName", value="模板名称",required=true, dataType="String"),
|
|
|
+ @ApiImplicitParam(name="templateFile", value="模板文件",required=true, dataType="String"),
|
|
|
+ @ApiImplicitParam(name="departmentId", value="组织列表id",required=true, dataType="String"),
|
|
|
+ })
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<CdPrintTemplate> add(@RequestBody CdPrintTemplate cdPrintTemplate, BindingResult bindingResult) {
|
|
|
+ Result<CdPrintTemplate> result = new Result<CdPrintTemplate>();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (bindingResult.hasErrors()){
|
|
|
+
|
|
|
+ bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
|
|
|
+ result.error500(sb.toString());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String id = cdPrintTemplate.getId();
|
|
|
+ CdPrintTemplate saveYpffscPrintTemplate = null;
|
|
|
+ if(oConvertUtils.isEmpty(id)){
|
|
|
+ cdPrintTemplate.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
|
|
|
+ saveYpffscPrintTemplate = cdPrintTemplateService.add(cdPrintTemplate);
|
|
|
+ result.success("保存成功!");
|
|
|
+ }else{
|
|
|
+ CdPrintTemplate ypffscPrintTemplateEntity = cdPrintTemplateService.getById(cdPrintTemplate.getId());
|
|
|
+ if(ypffscPrintTemplateEntity==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ saveYpffscPrintTemplate = cdPrintTemplateService.edit(cdPrintTemplate);
|
|
|
+ result.success("保存成功!");
|
|
|
+ }
|
|
|
+ result.setResult(saveYpffscPrintTemplate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增和编辑", notes = "新增打印模板和修改打印模板")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="id", value="id",required=true, dataType="String"),
|
|
|
+ })
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<CdPrintTemplate> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ Result<CdPrintTemplate> result = new Result<CdPrintTemplate>();
|
|
|
+ CdPrintTemplate ypffscPrintTemplate = cdPrintTemplateService.getById(id);
|
|
|
+ if(ypffscPrintTemplate==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ ypffscPrintTemplate.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
|
|
|
+ cdPrintTemplateService.edit(ypffscPrintTemplate);
|
|
|
+ result.success("删除成功!");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增和编辑", notes = "新增打印模板和修改打印模板")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="id", value="id",required=true, dataType="String"),
|
|
|
+ })
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<CdPrintTemplate> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ Result<CdPrintTemplate> result = new Result<CdPrintTemplate>();
|
|
|
+ CdPrintTemplate cdPrintTemplate = cdPrintTemplateService.getById(id);
|
|
|
+ if(cdPrintTemplate==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ result.setResult(cdPrintTemplate);
|
|
|
+ result.setSuccess(true);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据模板名称查找模板", notes = "根据组织、语言查找模板")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="templateName", value="名称",required=true, dataType="String"),
|
|
|
+ })
|
|
|
+ @GetMapping(value = "/query")
|
|
|
+
|
|
|
+ public Result<CdPrintTemplate> query(@RequestParam(name="templateName",required=true) String templateName,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ Result<CdPrintTemplate> result = new Result<CdPrintTemplate>();
|
|
|
+ LambdaQueryWrapper<CdPrintTemplate> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CdPrintTemplate::getTemplateName, templateName);
|
|
|
+ List<CdPrintTemplate> printTemplateList = cdPrintTemplateService.list(queryWrapper);
|
|
|
+ if (printTemplateList.size() == 0){
|
|
|
+ result.error500("名称为" + templateName + "的模板未定义");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ printTemplateList = printTemplateList.stream().filter(e -> e.getDepartmentId().equals("")).collect(Collectors.toList());
|
|
|
+ if (printTemplateList.size() == 0){
|
|
|
+ result.error500("组织为当前组织或者为空的模板未定义");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ result.setResult(printTemplateList.get(0));
|
|
|
+ result.success("操作成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|