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")
private String fileType;
@ApiModelProperty(value = "fileUrlAi")
private String fileUrlAi;
@ApiModelProperty(value = "fileWpsId")
private String fileWpsId;
private Long createdBy;
private Long updatedBy;
@ -61,4 +55,4 @@ public class FormPrintConfigVO implements Serializable {
private String ext;
}
}

View File

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

View File

@ -3,7 +3,6 @@ package com.pcloud.booksflow.form.mybatis.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pcloud.booksflow.form.api.dto.DictCodesDTO;
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.Param;

View File

@ -22,8 +22,6 @@
<result column="file_size" jdbcType="INTEGER" property="fileSize" />
<result column="file_name" jdbcType="VARCHAR" property="fileName" />
<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="mode" jdbcType="INTEGER" property="mode" />
<result column="created_by" jdbcType="BIGINT" property="createdBy" />

View File

@ -39,6 +39,10 @@
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-json</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-oss</artifactId>
</dependency>
</dependencies>
</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.FormPrintDTO;
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.common.dto.ResponseDto;
import com.pcloud.common.entity.UploadResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dromara.common.oss.entity.UploadResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -39,8 +38,8 @@ public class FormPrintConfigController {
*/
@ApiOperation("创建或更新表单打印配置")
@PostMapping("/createOrUpdate")
public ResponseDto<FormPrintConfigTpl> createOrUpdate(@Validated @RequestBody FormPrintConfigDTO dto) {
return new ResponseDto<>(formPrintConfigService.createOrUpdate(dto));
public FormPrintConfig createOrUpdate(@Validated @RequestBody FormPrintConfigDTO dto) {
return formPrintConfigService.createOrUpdate(dto);
}
@ -52,8 +51,8 @@ public class FormPrintConfigController {
*/
@ApiOperation("更新模式")
@PostMapping("updateMode")
public ResponseDto<Integer> updateMode(@Validated @RequestBody FormPrintConfigModeDTO dto) {
return new ResponseDto<>(formPrintConfigService.updateMode(dto));
public Integer updateMode(@Validated @RequestBody FormPrintConfigModeDTO dto) {
return formPrintConfigService.updateMode(dto);
}
/**
@ -64,28 +63,21 @@ public class FormPrintConfigController {
*/
@ApiOperation("根据表单ID获取表单打印配置")
@GetMapping("/get")
public ResponseDto<FormPrintConfigVO> getByFormId(@RequestParam Long formId) {
return new ResponseDto<>(formPrintConfigService.getByFormId(formId));
public FormPrintConfigVO getByFormId(@RequestParam Long 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模板")
@PostMapping("uploadFile")
public ResponseDto<?> updateFile(@Validated @RequestBody FormPrintConfigUploadDTO dto) {
formPrintConfigService.createOrUpdate(dto);
return new ResponseDto<>();
public Long updateFile(@Validated @RequestBody FormPrintConfigUploadDTO dto) {
return formPrintConfigService.createOrUpdate(dto);
}
@ApiOperation("获取打印url")
@PostMapping("print")
public ResponseDto<UploadResultInfo> print(@Validated @RequestBody FormPrintDTO dto) throws IOException {
return new ResponseDto<>(formPrintConfigService.print(dto));
public UploadResult print(@Validated @RequestBody FormPrintDTO dto) throws IOException {
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.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.pcloud.booksflow.form.api.dto.FormDictDTO;
import com.pcloud.booksflow.form.mybatis.entity.FormDict;
import com.pcloud.booksflow.form.mybatis.entity.FormDictExample;
import com.pcloud.booksflow.form.mybatis.entity.FormFieldDict;
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.utils.UserUtils;
import com.pcloud.common.exceptions.BizException;
@ -74,7 +75,7 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典对象
*/
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.setUpdatedBy(UserUtils.getUserId());
entity.setUpdateTime(new Date());
return baseMapper.updateByPrimaryKeySelective(entity);
return baseMapper.updateById(entity);
}
/**
@ -108,12 +109,12 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典列表
*/
public List<FormDict> listByName(String name) {
FormDictExample example = new FormDictExample();
FormDictExample.Criteria criteria = example.createCriteria().andDeletedEqualTo(0);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.eq(FormDict::getDeleted, 0);
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 分页结果
*/
public PageBeanNew<FormDict> listByNameAndCode(String name, String code, Integer currentPage, Integer numPerPage) {
FormDictExample example = new FormDictExample();
FormDictExample.Criteria criteria = example.createCriteria().andDeletedEqualTo(0);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.eq(FormDict::getDeleted, 0)
.orderByDesc(FormDict::getId);
if (StrUtil.isNotBlank(name)) {
criteria.andNameLike("%" + name + "%");
queryWrapper.like(FormDict::getName, name);
}
if (StrUtil.isNotBlank(code)) {
criteria.andCodeLike("%" + code + "%");
queryWrapper.like(FormDict::getCode, code);
}
example.setOrderByClause("id desc");
int count = (int) baseMapper.countByExample(example);
List<FormDict> records = baseMapper.selectByExampleWithPaging(example, currentPage * numPerPage, numPerPage);
return new PageBeanNew<>(currentPage, numPerPage, count, records);
Page<FormDict> page = new Page<>(currentPage, numPerPage);
Page<FormDict> result = baseMapper.selectPage(page, queryWrapper);
return new PageBeanNew<>(currentPage, numPerPage, (int) result.getTotal(), result.getRecords());
}
/**
@ -151,33 +152,30 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
* @return 表单字典对象
*/
private long countByCode(String code, Long notId) {
FormDictExample example = new FormDictExample();
FormDictExample.Criteria criteria = example.createCriteria()
.andCodeEqualTo(code)
.andDeletedEqualTo(0);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.eq(FormDict::getCode, code)
.eq(FormDict::getDeleted, 0);
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) {
FormDictExample example = new FormDictExample();
FormDictExample.Criteria criteria = example.createCriteria()
.andNameEqualTo(name)
.andDeletedEqualTo(0);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.eq(FormDict::getName, name)
.eq(FormDict::getDeleted, 0);
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) {
FormDictExample example = new FormDictExample();
example.createCriteria()
.andCodeIn(configTypes)
.andDeletedEqualTo(0);
return baseMapper.selectByExample(example);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.in(FormDict::getCode, configTypes)
.eq(FormDict::getDeleted, 0);
return baseMapper.selectList(queryWrapper);
}
@Transactional
@ -185,7 +183,7 @@ public class FormDictService extends ServiceImpl<FormDictMapper, FormDict> {
for (FormDict dict : dicts) {
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()){
return new HashSet<>();
}
FormDictExample example = new FormDictExample();
example.createCriteria()
.andCodeIn(new ArrayList<>(codes))
.andDeletedEqualTo(0);
List<FormDict> list = baseMapper.selectByExample(example);
LambdaQueryWrapper<FormDict> queryWrapper = new LambdaQueryWrapper<FormDict>()
.in(FormDict::getCode, new ArrayList<>(codes))
.eq(FormDict::getDeleted, 0);
List<FormDict> list = baseMapper.selectList(queryWrapper);
if (list.isEmpty()) {
return codes;
}

View File

@ -95,7 +95,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
criteria.andStatusEqualTo(status);
}
example.setOrderByClause("sort_order asc,name asc");
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example);
List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
//level参数过滤
if (level != null) {
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) {
//查询 顶级节点
FormFieldDictExample example = getTopExample(configType, status);
int count = (int) formFieldDictMapperExt.countByExampleExt(example, queryStr);
int count = (int) baseMapper.countByExampleExt(example, queryStr);
if (count == 0) {
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)) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
}
@ -147,7 +147,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
return 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()) {
allChildren.addAll(directChildren);
@ -205,7 +205,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setDeleted(1);
entity.setUpdateTime(new Date());
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());
FormFieldDictExample example = new FormFieldDictExample();
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.setUpdateTime(new Date());
entity.setUpdatedBy(UserUtils.getUserId());
return formFieldDictMapperExt.updateByPrimaryKeySelective(entity);
return baseMapper.updateByPrimaryKeySelective(entity);
}
@Transactional
public Integer updateStatus(Long id, Integer status) {
Long userId = UserUtils.getUserId();
FormFieldDict item = formFieldDictMapperExt.selectByPrimaryKey(id);
FormFieldDict item = baseMapper.selectByPrimaryKey(id);
if (item == null) {
return 0;
}
@ -260,7 +260,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
entity.setStatus(status);
entity.setUpdateTime(new Date());
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) {
@ -276,7 +276,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
.andParentIdIn(pids)
.andStatusEqualTo(status == 0 ? 1 : 0)
.andDeletedEqualTo(0);
List<FormFieldDict> children = formFieldDictMapperExt.selectByExample(example);
List<FormFieldDict> children = baseMapper.selectByExample(example);
if (children.isEmpty()) {
log.debug("没有找到子节点,结束递归");
return;
@ -292,7 +292,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
_example.createCriteria()
.andConfigTypeEqualTo(configType)
.andIdIn(_ids);
int i = formFieldDictMapperExt.updateByExampleSelective(updateEntity, _example);
int i = baseMapper.updateByExampleSelective(updateEntity, _example);
log.debug("更新表单字段配置【{}】结果:{}", _ids, i);
updateStatusChildren(configType, _ids, status, depth + 1, userId);
}
@ -305,7 +305,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
private void checkDependent(Long id) {
FormFieldDictExample example = new FormFieldDictExample();
example.createCriteria().andParentIdEqualTo(id).andDeletedEqualTo(0);
List<FormFieldDict> dependentDicts = formFieldDictMapperExt.selectByExample(example);
List<FormFieldDict> dependentDicts = baseMapper.selectByExample(example);
if (!dependentDicts.isEmpty()) {
String sss = "";
for (FormFieldDict item : dependentDicts) {
@ -341,7 +341,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
example.setOrderByClause("sort_order asc,name asc");
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example);
List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
if (dicts == null) {
return new ArrayList<>();
@ -367,7 +367,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
.andConfigTypeIn(new ArrayList<>(configTypes))
.andDeletedEqualTo(0);
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()
.collect(
@ -536,7 +536,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (deleted != null) {
criteria.andDeletedEqualTo(deleted);
}
List<FormFieldDict> dicts = formFieldDictMapperExt.selectByExampleWithBLOBs(example);
List<FormFieldDict> dicts = baseMapper.selectByExampleWithBLOBs(example);
return BeanUtil.copyToList(dicts, FormFieldDictVO.class);
}
@ -555,7 +555,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
}
list.add(new DictCodesDTO(configType, itemCodes));
});
List<FormFieldDict> data = formFieldDictMapperExt.getByCodes(list);
List<FormFieldDict> data = baseMapper.getByCodes(list);
if (CollUtil.isEmpty(data)) {
return new HashMap<>();
}
@ -590,7 +590,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (notId != null) {
ca.andIdNotEqualTo(notId);
}
return formFieldDictMapperExt.countByExample(example);
return baseMapper.countByExample(example);
}
private long countByName(String configType, String name, Long notId) {
@ -602,7 +602,7 @@ public class FormFieldDictService extends ServiceImpl<FormFieldDictMapper, FormF
if (notId != null) {
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.convert.Convert;
import com.commons.weboffice.api.model.wps.CreateFileRequest;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigDTO;
import com.pcloud.booksflow.form.api.dto.FormPrintConfigModeDTO;
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.mybatis.entity.Form;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfig;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfigExample;
import com.pcloud.booksflow.form.mybatis.entity.FormPrintConfigTpl;
import com.pcloud.booksflow.form.mybatis.mapper.FormPrintConfigMapperExt;
import com.pcloud.booksflow.form.mybatis.mapper.FormPrintConfigMapper;
import com.pcloud.booksflow.form.utils.UserUtils;
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 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.stereotype.Service;
@ -45,7 +36,7 @@ import java.util.Map;
*/
@Slf4j
@Service
public class FormPrintConfigService {
public class FormPrintConfigService extends ServiceImpl<FormPrintConfigMapper, FormPrintConfig> {
@Autowired
private FormService formService;
@ -56,31 +47,22 @@ public class FormPrintConfigService {
* @param dto 表单打印配置对象
* @return 创建或更新后的表单打印配置对象
*/
public FormPrintConfigTpl createOrUpdate(FormPrintConfigDTO dto) {
public FormPrintConfig createOrUpdate(FormPrintConfigDTO dto) {
// 创建操作
FormPrintConfig config = getEntityByFormId(dto.getFormId());
FormPrintConfigTpl entity = new FormPrintConfigTpl();
if (config != null) {
FormPrintConfig entity = getEntityByFormId(dto.getFormId());
if (entity != null) {
// 更新操作
BeanUtil.copyProperties(dto, entity, "printFields");
if (dto.getPrintFields() != null) {
entity.setPrintFields(JsonUtils.serialize(dto.getPrintFields()));
} else {
entity.setPrintFields("[]");
}
entity.setUpdatedBy(UserUtils.getUserId());
entity.setUpdateTime(new Date());
formPrintConfigMapperExt.updateByPrimaryKeySelective(entity);
entity.setId(entity.getId());
baseMapper.updateById(entity);
} else {
entity = new FormPrintConfig();
BeanUtil.copyProperties(dto, entity, "printFields");
if (dto.getPrintFields() != null) {
entity.setPrintFields(JsonUtils.serialize(dto.getPrintFields()));
} else {
entity.setPrintFields("[]");
}
entity.setCreatedBy(UserUtils.getUserId());
entity.setCreateTime(new Date());
formPrintConfigMapperExt.insertSelective(entity);
baseMapper.insert(entity);
}
return entity;
}
@ -96,7 +78,7 @@ public class FormPrintConfigService {
example.createCriteria()
.andFormIdEqualTo(formId);
example.setOrderByClause("id desc");
List<FormPrintConfigTpl> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
List<FormPrintConfig> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
if (!formPrintConfigs.isEmpty()) {
return BeanUtil.copyProperties(formPrintConfigs.get(0), FormPrintConfigVO.class);
} else {
@ -104,12 +86,12 @@ public class FormPrintConfigService {
}
}
public FormPrintConfigTpl getEntityByFormId(Long formId) {
public FormPrintConfig getEntityByFormId(Long formId) {
FormPrintConfigExample example = new FormPrintConfigExample();
example.createCriteria()
.andFormIdEqualTo(formId);
example.setOrderByClause("id desc");
List<FormPrintConfigTpl> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
List<FormPrintConfig> formPrintConfigs = formPrintConfigMapperExt.selectByExampleWithBLOBs(example);
if (!formPrintConfigs.isEmpty()) {
return formPrintConfigs.get(0);
} else {
@ -131,7 +113,7 @@ public class FormPrintConfigService {
return getByFormId(form.getId());
}
public FormPrintConfigTpl getEntityByFormCode(String formCode) {
public FormPrintConfig getEntityByFormCode(String formCode) {
Form form = formService.getByCode(formCode);
if (form == null) {
return null;
@ -140,12 +122,12 @@ public class FormPrintConfigService {
}
public int updateMode(FormPrintConfigModeDTO dto) {
FormPrintConfigTpl entity = new FormPrintConfigTpl();
FormPrintConfigTpl config = getEntityByFormId(dto.getFormId());
FormPrintConfig entity = new FormPrintConfig();
FormPrintConfig config = getEntityByFormId(dto.getFormId());
if (config != null) {
entity.setId(config.getId());
entity.setMode(dto.getMode());
return formPrintConfigMapperExt.updateByPrimaryKeySelective(entity);
return baseMapper.updateByPrimaryKeySelective(entity);
} else {
entity.setMode(dto.getMode());
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();
FormPrintConfigTpl upEntity = new FormPrintConfigTpl();
FormPrintConfigTpl _config = getEntityByFormId(dto.getFormId());
FormPrintConfig upEntity = new FormPrintConfig();
FormPrintConfig _config = getEntityByFormId(dto.getFormId());
if (_config != null) {
// 更新操作
BeanUtil.copyProperties(dto, upEntity);
upEntity.setId(_config.getId());
upEntity.setUpdatedBy(userId);
upEntity.setUpdateTime(new Date());
formPrintConfigMapperExt.updateByPrimaryKeySelective(upEntity);
baseMapper.updateById(upEntity);
} else {
BeanUtil.copyProperties(dto, upEntity);
upEntity.setCreatedBy(userId);
upEntity.setCreateTime(new Date());
formPrintConfigMapperExt.insertSelective(upEntity);
}
//更新fileWpsId
FormPrintConfig newConfig = getEntityByFormId(dto.getFormId());
if (StringUtil.isNotBlank(newConfig.getFileUrl())) {
updateFileWpsId(userId, newConfig);
baseMapper.insert(upEntity);
}
return upEntity.getId();
}
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 {
public UploadResult print(FormPrintDTO dto) throws IOException {
FormPrintConfig config = null;
if (StringUtil.isNotBlank(dto.getFormCode())) {
if (StringUtils.isNotBlank(dto.getFormCode())) {
config = getEntityByFormCode(dto.getFormCode());
} else if (dto.getFormId() != null) {
config = getEntityByFormId(dto.getFormId());
@ -253,30 +167,28 @@ public class FormPrintConfigService {
if (config == null) {
throw new ServiceException("未找到打印配置");
}
if (StringUtil.isBlank(config.getFileWpsId())) {
throw new ServiceException("未找到wpsId打印文件");
}
String fileName = config.getFileName();
String fileType = config.getFileType();
if (StringUtil.isBlank(fileName)) {
if (StringUtils.isBlank(fileName)) {
throw new ServiceException("未找到文件名");
}
if (StringUtil.isBlank(fileType)) {
if (StringUtils.isBlank(fileType)) {
throw new ServiceException("未找到文件类型");
}
if (!fileType.trim().equalsIgnoreCase("docx")) {
throw new ServiceException("只支持docx文件");
}
String exportUrl = wpsWebOfficeService.getExportUrl(config.getFileWpsId());
byte[] bytes = FileUtils.downloadByteFromUrl(exportUrl);
try (WordTemplateProcessor processor = new WordTemplateProcessor(new ByteArrayInputStream(bytes))) {
processor.push(dto.getData());
XWPFDocument docx = processor.getDocx();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
docx.write(baos);
return OssUtils.uploadFileByte(baos.toByteArray(), fileName, fileType);
}
}
OssClient storage = OssFactory.instance();
// storage.download(config.getFileUrl())
//
// try (WordTemplateProcessor processor = new WordTemplateProcessor(new ByteArrayInputStream(bytes))) {
// processor.push(dto.getData());
// XWPFDocument docx = processor.getDocx();
// try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
// docx.write(baos);
// 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.mapper.FormMapperExt;
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.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -37,7 +37,7 @@ public class FormService {
throw new ServiceException("名称已存在: " + form.getName());
}
form.setId(null);
formMapperExt.insertSelective(form);
formMapper.insert(form);
return form;
}

View File

@ -38,10 +38,6 @@ GET {{baseUrl}}/form-print-config/get?formId=1
Token: {{token}}
### updateTplFileWpsId
GET {{baseUrl}}form-print-config/updateTplFileWpsId?formPrintConfigTplId=1
Token: {{token}}
### form-print-config/print
POST {{baseUrl}}form-print-config/print
@ -62,4 +58,4 @@ Token: {{token}}
{ "ys":"4","ks": "开数4"}
]
}
}
}