h5 动态表单

This commit is contained in:
lizhengwei 2026-02-13 16:40:22 +08:00
parent f8502840ca
commit a2d76a5828
11 changed files with 118 additions and 236 deletions

View File

@ -47,12 +47,6 @@ public class FormPrintConfigVO implements Serializable {
@ApiModelProperty(value = "fileType") @ApiModelProperty(value = "fileType")
private String fileType; private String fileType;
@ApiModelProperty(value = "fileUrlAi")
private String fileUrlAi;
@ApiModelProperty(value = "fileWpsId")
private String fileWpsId;
private Long createdBy; private Long createdBy;
private Long updatedBy; private Long updatedBy;

View File

@ -98,16 +98,6 @@ public class FormPrintConfig implements Serializable {
*/ */
private String fileType; private String fileType;
/**
* file_wps_id
*/
private String fileWpsId;
/**
* AI模板文件url
*/
private String fileUrlAi;
/** /**
* 模板文件url * 模板文件url
*/ */

View File

@ -3,7 +3,6 @@ package com.pcloud.booksflow.form.mybatis.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pcloud.booksflow.form.api.dto.DictCodesDTO; import com.pcloud.booksflow.form.api.dto.DictCodesDTO;
import com.pcloud.booksflow.form.mybatis.entity.FormFieldDict; import com.pcloud.booksflow.form.mybatis.entity.FormFieldDict;
import com.pcloud.booksflow.form.mybatis.entity.FormFieldDictExample;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;

View File

@ -22,8 +22,6 @@
<result column="file_size" jdbcType="INTEGER" property="fileSize" /> <result column="file_size" jdbcType="INTEGER" property="fileSize" />
<result column="file_name" jdbcType="VARCHAR" property="fileName" /> <result column="file_name" jdbcType="VARCHAR" property="fileName" />
<result column="file_type" jdbcType="VARCHAR" property="fileType" /> <result column="file_type" jdbcType="VARCHAR" property="fileType" />
<result column="file_wps_id" jdbcType="VARCHAR" property="fileWpsId" />
<result column="file_url_ai" jdbcType="VARCHAR" property="fileUrlAi" />
<result column="file_url" jdbcType="VARCHAR" property="fileUrl" /> <result column="file_url" jdbcType="VARCHAR" property="fileUrl" />
<result column="mode" jdbcType="INTEGER" property="mode" /> <result column="mode" jdbcType="INTEGER" property="mode" />
<result column="created_by" jdbcType="BIGINT" property="createdBy" /> <result column="created_by" jdbcType="BIGINT" property="createdBy" />

View File

@ -39,6 +39,10 @@
<groupId>org.dromara</groupId> <groupId>org.dromara</groupId>
<artifactId>ruoyi-common-json</artifactId> <artifactId>ruoyi-common-json</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-oss</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -6,12 +6,11 @@ import com.pcloud.booksflow.form.api.dto.FormPrintConfigModeDTO;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigUploadDTO; import com.pcloud.booksflow.form.api.dto.FormPrintConfigUploadDTO;
import com.pcloud.booksflow.form.api.dto.FormPrintDTO; import com.pcloud.booksflow.form.api.dto.FormPrintDTO;
import com.pcloud.booksflow.form.api.vo.FormPrintConfigVO; import com.pcloud.booksflow.form.api.vo.FormPrintConfigVO;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfigTpl; import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfig;
import com.pcloud.booksflow.form.service.FormPrintConfigService; import com.pcloud.booksflow.form.service.FormPrintConfigService;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.entity.UploadResultInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.dromara.common.oss.entity.UploadResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -39,8 +38,8 @@ public class FormPrintConfigController {
*/ */
@ApiOperation("创建或更新表单打印配置") @ApiOperation("创建或更新表单打印配置")
@PostMapping("/createOrUpdate") @PostMapping("/createOrUpdate")
public ResponseDto<FormPrintConfigTpl> createOrUpdate(@Validated @RequestBody FormPrintConfigDTO dto) { public FormPrintConfig createOrUpdate(@Validated @RequestBody FormPrintConfigDTO dto) {
return new ResponseDto<>(formPrintConfigService.createOrUpdate(dto)); return formPrintConfigService.createOrUpdate(dto);
} }
@ -52,8 +51,8 @@ public class FormPrintConfigController {
*/ */
@ApiOperation("更新模式") @ApiOperation("更新模式")
@PostMapping("updateMode") @PostMapping("updateMode")
public ResponseDto<Integer> updateMode(@Validated @RequestBody FormPrintConfigModeDTO dto) { public Integer updateMode(@Validated @RequestBody FormPrintConfigModeDTO dto) {
return new ResponseDto<>(formPrintConfigService.updateMode(dto)); return formPrintConfigService.updateMode(dto);
} }
/** /**
@ -64,28 +63,21 @@ public class FormPrintConfigController {
*/ */
@ApiOperation("根据表单ID获取表单打印配置") @ApiOperation("根据表单ID获取表单打印配置")
@GetMapping("/get") @GetMapping("/get")
public ResponseDto<FormPrintConfigVO> getByFormId(@RequestParam Long formId) { public FormPrintConfigVO getByFormId(@RequestParam Long formId) {
return new ResponseDto<>(formPrintConfigService.getByFormId(formId)); return formPrintConfigService.getByFormId(formId);
} }
@ApiOperation("ai解析word")
@GetMapping("/aiParsesWord")
public ResponseDto<Integer> aiParsesWord(@RequestParam Long formId) {
return new ResponseDto<>(formPrintConfigService.aiParsesWord(formId));
}
@ApiOperation("上传word模板") @ApiOperation("上传word模板")
@PostMapping("uploadFile") @PostMapping("uploadFile")
public ResponseDto<?> updateFile(@Validated @RequestBody FormPrintConfigUploadDTO dto) { public Long updateFile(@Validated @RequestBody FormPrintConfigUploadDTO dto) {
formPrintConfigService.createOrUpdate(dto); return formPrintConfigService.createOrUpdate(dto);
return new ResponseDto<>();
} }
@ApiOperation("获取打印url") @ApiOperation("获取打印url")
@PostMapping("print") @PostMapping("print")
public ResponseDto<UploadResultInfo> print(@Validated @RequestBody FormPrintDTO dto) throws IOException { public UploadResult print(@Validated @RequestBody FormPrintDTO dto) throws IOException {
return new ResponseDto<>(formPrintConfigService.print(dto)); return formPrintConfigService.print(dto);
} }

View File

@ -2,13 +2,14 @@ package com.pcloud.booksflow.form.service;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pcloud.booksflow.form.api.dto.FormDictDTO; import com.pcloud.booksflow.form.api.dto.FormDictDTO;
import com.pcloud.booksflow.form.mybatis.entity.FormDict; import com.pcloud.booksflow.form.mybatis.entity.FormDict;
import com.pcloud.booksflow.form.mybatis.entity.FormDictExample; import com.pcloud.booksflow.form.mybatis.entity.FormDictExample;
import com.pcloud.booksflow.form.mybatis.entity.FormFieldDict; import com.pcloud.booksflow.form.mybatis.entity.FormFieldDict;
import com.pcloud.booksflow.form.mybatis.mapper.FormDictMapper; import com.pcloud.booksflow.form.mybatis.mapper.FormDictMapper;
import com.pcloud.booksflow.form.mybatis.mapper.FormDictMapperExt;
import com.pcloud.booksflow.form.mybatis.mapper.FormFieldDictMapper; import com.pcloud.booksflow.form.mybatis.mapper.FormFieldDictMapper;
import com.pcloud.booksflow.form.utils.UserUtils; import com.pcloud.booksflow.form.utils.UserUtils;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
@ -74,7 +75,7 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典对象 * @return 表单字典对象
*/ */
public FormDict getById(Long id) { public FormDict getById(Long id) {
return baseMapper.selectByPrimaryKey(id); return baseMapper.selectById(id);
} }
/** /**
@ -98,7 +99,7 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
entity.setDeleted(1); entity.setDeleted(1);
entity.setUpdatedBy(UserUtils.getUserId()); entity.setUpdatedBy(UserUtils.getUserId());
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
return baseMapper.updateByPrimaryKeySelective(entity); return baseMapper.updateById(entity);
} }
/** /**
@ -108,12 +109,12 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典列表 * @return 表单字典列表
*/ */
public List<FormDict> listByName(String name) { public List<FormDict> listByName(String name) {
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
FormDictExample.Criteria criteria = example.createCriteria().andDeletedEqualTo(0); .eq(FormDict::getDeleted, 0);
if (name != null && !name.isEmpty()) { if (name != null && !name.isEmpty()) {
criteria.andNameLike(name + "%"); queryWrapper.likeRight(FormDict::getName, name);
} }
return baseMapper.selectByExample(example); return baseMapper.selectList(queryWrapper);
} }
/** /**
@ -126,21 +127,21 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 分页结果 * @return 分页结果
*/ */
public PageBeanNew<FormDict> listByNameAndCode(String name, String code, Integer currentPage, Integer numPerPage) { public PageBeanNew<FormDict> listByNameAndCode(String name, String code, Integer currentPage, Integer numPerPage) {
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
FormDictExample.Criteria criteria = example.createCriteria().andDeletedEqualTo(0); .eq(FormDict::getDeleted, 0)
.orderByDesc(FormDict::getId);
if (StrUtil.isNotBlank(name)) { if (StrUtil.isNotBlank(name)) {
criteria.andNameLike("%" + name + "%"); queryWrapper.like(FormDict::getName, name);
} }
if (StrUtil.isNotBlank(code)) { if (StrUtil.isNotBlank(code)) {
criteria.andCodeLike("%" + code + "%"); queryWrapper.like(FormDict::getCode, code);
} }
example.setOrderByClause("id desc"); Page<FormDict> page = new Page<>(currentPage, numPerPage);
int count = (int) baseMapper.countByExample(example); Page<FormDict> result = baseMapper.selectPage(page, queryWrapper);
List<FormDict> records = baseMapper.selectByExampleWithPaging(example, currentPage * numPerPage, numPerPage); return new PageBeanNew<>(currentPage, numPerPage, (int) result.getTotal(), result.getRecords());
return new PageBeanNew<>(currentPage, numPerPage, count, records);
} }
/** /**
@ -151,33 +152,30 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典对象 * @return 表单字典对象
*/ */
private long countByCode(String code, Long notId) { private long countByCode(String code, Long notId) {
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
FormDictExample.Criteria criteria = example.createCriteria() .eq(FormDict::getCode, code)
.andCodeEqualTo(code) .eq(FormDict::getDeleted, 0);
.andDeletedEqualTo(0);
if (notId != null) { if (notId != null) {
criteria.andIdNotEqualTo(notId); queryWrapper.ne(FormDict::getId, notId);
} }
return baseMapper.countByExample(example); return baseMapper.selectCount(queryWrapper);
} }
private long countByName(String name, Long notId) { private long countByName(String name, Long notId) {
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
FormDictExample.Criteria criteria = example.createCriteria() .eq(FormDict::getName, name)
.andNameEqualTo(name) .eq(FormDict::getDeleted, 0);
.andDeletedEqualTo(0);
if (notId != null) { if (notId != null) {
criteria.andIdNotEqualTo(notId); queryWrapper.ne(FormDict::getId, notId);
} }
return baseMapper.countByExample(example); return baseMapper.selectCount(queryWrapper);
} }
public List<FormDict> list(List<String> configTypes) { public List<FormDict> list(List<String> configTypes) {
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
example.createCriteria() .in(FormDict::getCode, configTypes)
.andCodeIn(configTypes) .eq(FormDict::getDeleted, 0);
.andDeletedEqualTo(0); return baseMapper.selectList(queryWrapper);
return baseMapper.selectByExample(example);
} }
@Transactional @Transactional
@ -185,7 +183,7 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
for (FormDict dict : dicts) { for (FormDict dict : dicts) {
dict.setId(null); dict.setId(null);
} }
return baseMapper.batchInsert(dicts); return baseMapper.insertBatchSomeColumn(dicts);
} }
/** /**
@ -197,11 +195,10 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
if(codes == null || codes.isEmpty()){ if(codes == null || codes.isEmpty()){
return new HashSet<>(); return new HashSet<>();
} }
FormDictExample example = new FormDictExample(); LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
example.createCriteria() .in(FormDict::getCode, new ArrayList<>(codes))
.andCodeIn(new ArrayList<>(codes)) .eq(FormDict::getDeleted, 0);
.andDeletedEqualTo(0); List<FormDict> list = baseMapper.selectList(queryWrapper);
List<FormDict> list = baseMapper.selectByExample(example);
if (list.isEmpty()) { if (list.isEmpty()) {
return codes; return codes;
} }

View File

@ -95,7 +95,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
criteria.andStatusEqualTo(status); criteria.andStatusEqualTo(status);
} }
example.setOrderByClause("sort_order asc,name asc"); example.setOrderByClause("sort_order asc,name asc");
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example); List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
//level参数过滤 //level参数过滤
if (level != null) { if (level != null) {
final int _l; final int _l;
@ -119,11 +119,11 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
public PageBeanNew<FormFieldDictVO> page(String configType, String queryStr, Integer status, Integer currentPage, Integer numPerPage) { public PageBeanNew<FormFieldDictVO> page(String configType, String queryStr, Integer status, Integer currentPage, Integer numPerPage) {
//查询 顶级节点 //查询 顶级节点
FormFieldDictExample example = getTopExample(configType, status); FormFieldDictExample example = getTopExample(configType, status);
int count = (int) formFieldDictMapperExt.countByExampleExt(example, queryStr); int count = (int) baseMapper.countByExampleExt(example, queryStr);
if (count == 0) { if (count == 0) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>()); return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
} }
List<FormFieldDict> records = formFieldDictMapperExt.selectByExampleWithPagingBLOBs(example, currentPage * numPerPage, numPerPage, queryStr); List<FormFieldDict> records = baseMapper.selectByExampleWithPagingBLOBs(example, currentPage * numPerPage, numPerPage, queryStr);
if (CollUtil.isEmpty(records)) { if (CollUtil.isEmpty(records)) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>()); return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
} }
@ -147,7 +147,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
return new ArrayList<>(); return new ArrayList<>();
} }
List<FormFieldDict> allChildren = new ArrayList<>(); List<FormFieldDict> allChildren = new ArrayList<>();
List<FormFieldDict> directChildren = formFieldDictMapperExt.selectByExampleWithBLOBs(getFormFieldDictExample(configType, status, parentIds)); List<FormFieldDict> directChildren = baseMapper.selectByExampleWithBLOBs(getFormFieldDictExample(configType, status, parentIds));
if (!directChildren.isEmpty()) { if (!directChildren.isEmpty()) {
allChildren.addAll(directChildren); allChildren.addAll(directChildren);
@ -205,7 +205,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setDeleted(1); entity.setDeleted(1);
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
entity.setUpdatedBy(UserUtils.getUserId()); entity.setUpdatedBy(UserUtils.getUserId());
return formFieldDictMapperExt.updateByPrimaryKeySelective(entity); return baseMapper.updateByPrimaryKeySelective(entity);
} }
/** /**
@ -222,7 +222,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setUpdatedBy(UserUtils.getUserId()); entity.setUpdatedBy(UserUtils.getUserId());
FormFieldDictExample example = new FormFieldDictExample(); FormFieldDictExample example = new FormFieldDictExample();
example.createCriteria().andConfigTypeEqualTo(configType).andDeletedEqualTo(0); example.createCriteria().andConfigTypeEqualTo(configType).andDeletedEqualTo(0);
return formFieldDictMapperExt.updateByExampleSelective(entity, example); return baseMapper.updateByExampleSelective(entity, example);
} }
/** /**
@ -238,14 +238,14 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setSortOrder(sortOrder); entity.setSortOrder(sortOrder);
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
entity.setUpdatedBy(UserUtils.getUserId()); entity.setUpdatedBy(UserUtils.getUserId());
return formFieldDictMapperExt.updateByPrimaryKeySelective(entity); return baseMapper.updateByPrimaryKeySelective(entity);
} }
@Transactional @Transactional
public Integer updateStatus(Long id, Integer status) { public Integer updateStatus(Long id, Integer status) {
Long userId = UserUtils.getUserId(); Long userId = UserUtils.getUserId();
FormFieldDict item = formFieldDictMapperExt.selectByPrimaryKey(id); FormFieldDict item = baseMapper.selectByPrimaryKey(id);
if (item == null) { if (item == null) {
return 0; return 0;
} }
@ -260,7 +260,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setStatus(status); entity.setStatus(status);
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
entity.setUpdatedBy(userId); entity.setUpdatedBy(userId);
return formFieldDictMapperExt.updateByPrimaryKeySelective(entity); return baseMapper.updateByPrimaryKeySelective(entity);
} }
private void updateStatusChildren(String configType, List<Long> pids, Integer status, int depth, Long userId) { private void updateStatusChildren(String configType, List<Long> pids, Integer status, int depth, Long userId) {
@ -276,7 +276,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
.andParentIdIn(pids) .andParentIdIn(pids)
.andStatusEqualTo(status == 0 ? 1 : 0) .andStatusEqualTo(status == 0 ? 1 : 0)
.andDeletedEqualTo(0); .andDeletedEqualTo(0);
List<FormFieldDict> children = formFieldDictMapperExt.selectByExample(example); List<FormFieldDict> children = baseMapper.selectByExample(example);
if (children.isEmpty()) { if (children.isEmpty()) {
log.debug("没有找到子节点,结束递归"); log.debug("没有找到子节点,结束递归");
return; return;
@ -292,7 +292,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
_example.createCriteria() _example.createCriteria()
.andConfigTypeEqualTo(configType) .andConfigTypeEqualTo(configType)
.andIdIn(_ids); .andIdIn(_ids);
int i = formFieldDictMapperExt.updateByExampleSelective(updateEntity, _example); int i = baseMapper.updateByExampleSelective(updateEntity, _example);
log.debug("更新表单字段配置【{}】结果:{}", _ids, i); log.debug("更新表单字段配置【{}】结果:{}", _ids, i);
updateStatusChildren(configType, _ids, status, depth + 1, userId); updateStatusChildren(configType, _ids, status, depth + 1, userId);
} }
@ -305,7 +305,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
private void checkDependent(Long id) { private void checkDependent(Long id) {
FormFieldDictExample example = new FormFieldDictExample(); FormFieldDictExample example = new FormFieldDictExample();
example.createCriteria().andParentIdEqualTo(id).andDeletedEqualTo(0); example.createCriteria().andParentIdEqualTo(id).andDeletedEqualTo(0);
List<FormFieldDict> dependentDicts = formFieldDictMapperExt.selectByExample(example); List<FormFieldDict> dependentDicts = baseMapper.selectByExample(example);
if (!dependentDicts.isEmpty()) { if (!dependentDicts.isEmpty()) {
String sss = ""; String sss = "";
for (FormFieldDict item : dependentDicts) { for (FormFieldDict item : dependentDicts) {
@ -341,7 +341,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
example.setOrderByClause("sort_order asc,name asc"); example.setOrderByClause("sort_order asc,name asc");
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example); List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
if (dicts == null) { if (dicts == null) {
return new ArrayList<>(); return new ArrayList<>();
@ -367,7 +367,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
.andConfigTypeIn(new ArrayList<>(configTypes)) .andConfigTypeIn(new ArrayList<>(configTypes))
.andDeletedEqualTo(0); .andDeletedEqualTo(0);
example.setOrderByClause("sort_order asc,name asc"); example.setOrderByClause("sort_order asc,name asc");
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example); List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
Map<String, List<FormFieldDict>> result = dicts.stream() Map<String, List<FormFieldDict>> result = dicts.stream()
.collect( .collect(
@ -536,7 +536,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (deleted != null) { if (deleted != null) {
criteria.andDeletedEqualTo(deleted); criteria.andDeletedEqualTo(deleted);
} }
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example); List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
return BeanUtil.copyToList(dicts, FormFieldDictVO.class); return BeanUtil.copyToList(dicts, FormFieldDictVO.class);
} }
@ -555,7 +555,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
} }
list.add(new DictCodesDTO(configType, itemCodes)); list.add(new DictCodesDTO(configType, itemCodes));
}); });
List<FormFieldDict> data = formFieldDictMapperExt.getByCodes(list); List<FormFieldDict> data = baseMapper.getByCodes(list);
if (CollUtil.isEmpty(data)) { if (CollUtil.isEmpty(data)) {
return new HashMap<>(); return new HashMap<>();
} }
@ -590,7 +590,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (notId != null) { if (notId != null) {
ca.andIdNotEqualTo(notId); ca.andIdNotEqualTo(notId);
} }
return formFieldDictMapperExt.countByExample(example); return baseMapper.countByExample(example);
} }
private long countByName(String configType, String name, Long notId) { private long countByName(String configType, String name, Long notId) {
@ -602,7 +602,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (notId != null) { if (notId != null) {
ca.andIdNotEqualTo(notId); ca.andIdNotEqualTo(notId);
} }
return formFieldDictMapperExt.countByExample(example); return baseMapper.countByExample(example);
} }
} }

View File

@ -2,10 +2,7 @@ package com.pcloud.booksflow.form.service;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.commons.weboffice.api.model.wps.CreateFileRequest; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.commons.weboffice.api.model.wps.CreateFileResponse;
import com.commons.weboffice.api.model.wps.UserPermission;
import com.commons.weboffice.api.service.wps.WpsWebOfficeService;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigDTO; import com.pcloud.booksflow.form.api.dto.FormPrintConfigDTO;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigModeDTO; import com.pcloud.booksflow.form.api.dto.FormPrintConfigModeDTO;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigUploadDTO; import com.pcloud.booksflow.form.api.dto.FormPrintConfigUploadDTO;
@ -13,22 +10,16 @@ import com.pcloud.booksflow.form.api.dto.FormPrintDTO;
import com.pcloud.booksflow.form.api.vo.FormPrintConfigVO; import com.pcloud.booksflow.form.api.vo.FormPrintConfigVO;
import com.pcloud.booksflow.form.mybatis.entity.Form; import com.pcloud.booksflow.form.mybatis.entity.Form;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfig; import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfig;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfigExample; import com.pcloud.booksflow.form.mybatis.mapper.FormPrintConfigMapper;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfigTpl;
import com.pcloud.booksflow.form.mybatis.mapper.FormPrintConfigMapperExt;
import com.pcloud.booksflow.form.utils.UserUtils; import com.pcloud.booksflow.form.utils.UserUtils;
import com.pcloud.booksflow.form.utils.poi.WordTemplateProcessor; import com.pcloud.booksflow.form.utils.poi.WordTemplateProcessor;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.FileUtils;
import com.pcloud.common.utils.aliyun.OssUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.llm.cockpit.api.domain.dto.request.WorkflowRequestBody;
import com.pcloud.llm.cockpit.api.domain.dto.response.CompletionResponse;
import com.pcloud.llm.cockpit.client.DifyClient;
import com.pcloud.universe.commons.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.entity.UploadResult;
import org.dromara.common.oss.factory.OssFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -45,7 +36,7 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Service @Service
public class FormPrintConfigService { public class FormPrintConfigService extends ServiceImpl<FormPrintConfigMapper, FormPrintConfig> {
@Autowired @Autowired
private FormService formService; private FormService formService;
@ -56,31 +47,22 @@ public class FormPrintConfigService {
* @param dto 表单打印配置对象 * @param dto 表单打印配置对象
* @return 创建或更新后的表单打印配置对象 * @return 创建或更新后的表单打印配置对象
*/ */
public FormPrintConfigTpl createOrUpdate(FormPrintConfigDTO dto) { public FormPrintConfig createOrUpdate(FormPrintConfigDTO dto) {
// 创建操作 // 创建操作
FormPrintConfig config = getEntityByFormId(dto.getFormId()); FormPrintConfig entity = getEntityByFormId(dto.getFormId());
FormPrintConfigTpl entity = new FormPrintConfigTpl(); if (entity != null) {
if (config != null) {
// 更新操作 // 更新操作
BeanUtil.copyProperties(dto, entity, "printFields"); BeanUtil.copyProperties(dto, entity, "printFields");
if (dto.getPrintFields() != null) {
entity.setPrintFields(JsonUtils.serialize(dto.getPrintFields()));
} else {
entity.setPrintFields("[]");
}
entity.setUpdatedBy(UserUtils.getUserId()); entity.setUpdatedBy(UserUtils.getUserId());
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
formPrintConfigMapperExt.updateByPrimaryKeySelective(entity); entity.setId(entity.getId());
baseMapper.updateById(entity);
} else { } else {
entity = new FormPrintConfig();
BeanUtil.copyProperties(dto, entity, "printFields"); BeanUtil.copyProperties(dto, entity, "printFields");
if (dto.getPrintFields() != null) {
entity.setPrintFields(JsonUtils.serialize(dto.getPrintFields()));
} else {
entity.setPrintFields("[]");
}
entity.setCreatedBy(UserUtils.getUserId()); entity.setCreatedBy(UserUtils.getUserId());
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
formPrintConfigMapperExt.insertSelective(entity); baseMapper.insert(entity);
} }
return entity; return entity;
} }
@ -96,7 +78,7 @@ public class FormPrintConfigService {
example.createCriteria() example.createCriteria()
.andFormIdEqualTo(formId); .andFormIdEqualTo(formId);
example.setOrderByClause("id desc"); example.setOrderByClause("id desc");
List<FormPrintConfigTpl> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example); List<FormPrintConfig> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
if (!formPrintConfigs.isEmpty()) { if (!formPrintConfigs.isEmpty()) {
return BeanUtil.copyProperties(formPrintConfigs.get(0), FormPrintConfigVO.class); return BeanUtil.copyProperties(formPrintConfigs.get(0), FormPrintConfigVO.class);
} else { } else {
@ -104,12 +86,12 @@ public class FormPrintConfigService {
} }
} }
public FormPrintConfigTpl getEntityByFormId(Long formId) { public FormPrintConfig getEntityByFormId(Long formId) {
FormPrintConfigExample example = new FormPrintConfigExample(); FormPrintConfigExample example = new FormPrintConfigExample();
example.createCriteria() example.createCriteria()
.andFormIdEqualTo(formId); .andFormIdEqualTo(formId);
example.setOrderByClause("id desc"); example.setOrderByClause("id desc");
List<FormPrintConfigTpl> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example); List<FormPrintConfig> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
if (!formPrintConfigs.isEmpty()) { if (!formPrintConfigs.isEmpty()) {
return formPrintConfigs.get(0); return formPrintConfigs.get(0);
} else { } else {
@ -131,7 +113,7 @@ public class FormPrintConfigService {
return getByFormId(form.getId()); return getByFormId(form.getId());
} }
public FormPrintConfigTpl getEntityByFormCode(String formCode) { public FormPrintConfig getEntityByFormCode(String formCode) {
Form form = formService.getByCode(formCode); Form form = formService.getByCode(formCode);
if (form == null) { if (form == null) {
return null; return null;
@ -140,12 +122,12 @@ public class FormPrintConfigService {
} }
public int updateMode(FormPrintConfigModeDTO dto) { public int updateMode(FormPrintConfigModeDTO dto) {
FormPrintConfigTpl entity = new FormPrintConfigTpl(); FormPrintConfig entity = new FormPrintConfig();
FormPrintConfigTpl config = getEntityByFormId(dto.getFormId()); FormPrintConfig config = getEntityByFormId(dto.getFormId());
if (config != null) { if (config != null) {
entity.setId(config.getId()); entity.setId(config.getId());
entity.setMode(dto.getMode()); entity.setMode(dto.getMode());
return formPrintConfigMapperExt.updateByPrimaryKeySelective(entity); return baseMapper.updateByPrimaryKeySelective(entity);
} else { } else {
entity.setMode(dto.getMode()); entity.setMode(dto.getMode());
entity.setCreatedBy(UserUtils.getUserId()); entity.setCreatedBy(UserUtils.getUserId());
@ -154,98 +136,30 @@ public class FormPrintConfigService {
} }
} }
public void createOrUpdate(FormPrintConfigUploadDTO dto) { public Long createOrUpdate(FormPrintConfigUploadDTO dto) {
// 创建操作 // 创建操作
Long userId = UserUtils.getUserId(); Long userId = UserUtils.getUserId();
FormPrintConfigTpl upEntity = new FormPrintConfigTpl(); FormPrintConfig upEntity = new FormPrintConfig();
FormPrintConfigTpl _config = getEntityByFormId(dto.getFormId()); FormPrintConfig _config = getEntityByFormId(dto.getFormId());
if (_config != null) { if (_config != null) {
// 更新操作 // 更新操作
BeanUtil.copyProperties(dto, upEntity); BeanUtil.copyProperties(dto, upEntity);
upEntity.setId(_config.getId()); upEntity.setId(_config.getId());
upEntity.setUpdatedBy(userId); upEntity.setUpdatedBy(userId);
upEntity.setUpdateTime(new Date()); upEntity.setUpdateTime(new Date());
formPrintConfigMapperExt.updateByPrimaryKeySelective(upEntity); baseMapper.updateById(upEntity);
} else { } else {
BeanUtil.copyProperties(dto, upEntity); BeanUtil.copyProperties(dto, upEntity);
upEntity.setCreatedBy(userId); upEntity.setCreatedBy(userId);
upEntity.setCreateTime(new Date()); upEntity.setCreateTime(new Date());
formPrintConfigMapperExt.insertSelective(upEntity); baseMapper.insert(upEntity);
}
return upEntity.getId();
} }
//更新fileWpsId public UploadResult print(FormPrintDTO dto) throws IOException {
FormPrintConfig newConfig = getEntityByFormId(dto.getFormId());
if (StringUtil.isNotBlank(newConfig.getFileUrl())) {
updateFileWpsId(userId, newConfig);
}
}
public Integer updateFileWpsId(Long userId, FormPrintConfig entity) {
if (!"docx".equals(entity.getFileType())) {
throw new ServiceException("请上传docx文件");
}
CreateFileRequest rq = new CreateFileRequest();
rq.setFileUrl(entity.getFileUrl());
rq.setFileName(entity.getFileName());
rq.setFileSize(entity.getFileSize());
rq.setFileType(entity.getFileType());
rq.setUserPermission(buildWpsFileUserPermission(userId));
CreateFileResponse fileRecord = wpsWebOfficeService.createFileRecord(userId, rq);
String fileId = fileRecord.getFileId();
Map<String, Object> map = new HashMap<>();
map.put("formFields", null);//TODO 待开发
map.put("fileUrl", entity.getFileUrl());
WorkflowRequestBody requestBody = WorkflowRequestBody.builder()
.user("auto").inputs(map).build();
CompletionResponse response = difyClient.workflowsRunBlocking("*******", requestBody);
log.info("dify response: {}", response);
//更新
FormPrintConfigTpl upEntity = new FormPrintConfigTpl();
upEntity.setId(entity.getId());
upEntity.setFileWpsId(fileId);
return formPrintConfigMapperExt.updateByPrimaryKeySelective(upEntity);
}
public Integer aiParsesWord(Long formId) {
Long userId = UserUtils.getUserId();
FormPrintConfig _entity = getEntityByFormId(formId);
String fileUrl = _entity.getFileUrl();
CreateFileRequest request = new CreateFileRequest();
request.setFileUrl(fileUrl);
request.setFileType(_entity.getFileType());
CreateFileResponse fileRecord = wpsWebOfficeService.createFileRecord(userId, request);
String fileId = fileRecord.getFileId();
//更新
FormPrintConfigTpl upEntity = new FormPrintConfigTpl();
upEntity.setId(_entity.getId());
upEntity.setFileWpsId(fileId);
return formPrintConfigMapperExt.updateByPrimaryKeySelective(upEntity);
}
private UserPermission buildWpsFileUserPermission(Long userId) {
return UserPermission
.builder()
.userId(Convert.toStr(userId))
.read(true)
.update(true)
.download(true)
.rename(false)
.history(false)
.copy(true)
.print(true)
.saveAs(true)
.comment(true)
.build();
}
public UploadResultInfo print(FormPrintDTO dto) throws IOException {
FormPrintConfig config = null; FormPrintConfig config = null;
if (StringUtil.isNotBlank(dto.getFormCode())) { if (StringUtils.isNotBlank(dto.getFormCode())) {
config = getEntityByFormCode(dto.getFormCode()); config = getEntityByFormCode(dto.getFormCode());
} else if (dto.getFormId() != null) { } else if (dto.getFormId() != null) {
config = getEntityByFormId(dto.getFormId()); config = getEntityByFormId(dto.getFormId());
@ -253,30 +167,28 @@ public class FormPrintConfigService {
if (config == null) { if (config == null) {
throw new ServiceException("未找到打印配置"); throw new ServiceException("未找到打印配置");
} }
if (StringUtil.isBlank(config.getFileWpsId())) {
throw new ServiceException("未找到wpsId打印文件");
}
String fileName = config.getFileName(); String fileName = config.getFileName();
String fileType = config.getFileType(); String fileType = config.getFileType();
if (StringUtil.isBlank(fileName)) { if (StringUtils.isBlank(fileName)) {
throw new ServiceException("未找到文件名"); throw new ServiceException("未找到文件名");
} }
if (StringUtil.isBlank(fileType)) { if (StringUtils.isBlank(fileType)) {
throw new ServiceException("未找到文件类型"); throw new ServiceException("未找到文件类型");
} }
if (!fileType.trim().equalsIgnoreCase("docx")) { if (!fileType.trim().equalsIgnoreCase("docx")) {
throw new ServiceException("只支持docx文件"); throw new ServiceException("只支持docx文件");
} }
String exportUrl = wpsWebOfficeService.getExportUrl(config.getFileWpsId()); OssClient storage = OssFactory.instance();
// storage.download(config.getFileUrl())
byte[] bytes = FileUtils.downloadByteFromUrl(exportUrl); //
try (WordTemplateProcessor processor = new WordTemplateProcessor(new ByteArrayInputStream(bytes))) { // try (WordTemplateProcessor processor = new WordTemplateProcessor(new ByteArrayInputStream(bytes))) {
processor.push(dto.getData()); // processor.push(dto.getData());
XWPFDocument docx = processor.getDocx(); // XWPFDocument docx = processor.getDocx();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { // try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
docx.write(baos); // docx.write(baos);
return OssUtils.uploadFileByte(baos.toByteArray(), fileName, fileType); // return storage.upload(file, suffix);
} // }
} // }
return null;
} }
} }

View File

@ -5,7 +5,7 @@ import com.pcloud.booksflow.form.api.constant.BaseConstant;
import com.pcloud.booksflow.form.mybatis.entity.*; import com.pcloud.booksflow.form.mybatis.entity.*;
import com.pcloud.booksflow.form.mybatis.mapper.FormMapperExt; import com.pcloud.booksflow.form.mybatis.mapper.FormMapperExt;
import com.pcloud.booksflow.form.utils.TenantHelper; import com.pcloud.booksflow.form.utils.TenantHelper;
import com.pcloud.common.exceptions.BizException; import org.dromara.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -37,7 +37,7 @@ public class FormService {
throw new ServiceException("名称已存在: " + form.getName()); throw new ServiceException("名称已存在: " + form.getName());
} }
form.setId(null); form.setId(null);
formMapperExt.insertSelective(form); formMapper.insert(form);
return form; return form;
} }

View File

@ -38,10 +38,6 @@ GET {{baseUrl}}/form-print-config/get?formId=1
Token: {{token}} Token: {{token}}
### updateTplFileWpsId
GET {{baseUrl}}form-print-config/updateTplFileWpsId?formPrintConfigTplId=1
Token: {{token}}
### form-print-config/print ### form-print-config/print
POST {{baseUrl}}form-print-config/print POST {{baseUrl}}form-print-config/print