模版新增修改关联的相关实现
This commit is contained in:
@@ -60,18 +60,18 @@ public class TemplateInstanceController extends AbstractFileUploadController {
|
|||||||
@Resource
|
@Resource
|
||||||
private FileApi fileApi;
|
private FileApi fileApi;
|
||||||
|
|
||||||
@PostMapping("/upload-file")
|
// @PostMapping("/upload-file")
|
||||||
@Operation(summary = "上传模板实例文件")
|
// @Operation(summary = "上传模板实例文件")
|
||||||
public CommonResult<Map<String, String> >upload(MultipartFile file) {
|
// public CommonResult<Map<String, String> >upload(MultipartFile file) {
|
||||||
Map<String, String> fileMap = new HashMap<>();
|
// Map<String, String> fileMap = new HashMap<>();
|
||||||
try {
|
// try {
|
||||||
String fileWhitReturn = fileApi.createFile(file.getBytes(), file.getOriginalFilename());
|
// String fileWhitReturn = fileApi.createFile(file.getBytes(), file.getOriginalFilename());
|
||||||
fileMap.put("fileUrl", fileWhitReturn);
|
// fileMap.put("fileUrl", fileWhitReturn);
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
return success(fileMap);
|
// return success(fileMap);
|
||||||
}
|
// }
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建模板实例")
|
@Operation(summary = "创建模板实例")
|
||||||
@PreAuthorize("@ss.hasPermission('bse:template-instance:create')")
|
@PreAuthorize("@ss.hasPermission('bse:template-instance:create')")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.base.controller.admin.templtp;
|
package cn.iocoder.yudao.module.base.controller.admin.templtp;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.business.annotation.FileUploadController;
|
import cn.iocoder.yudao.framework.business.annotation.FileUploadController;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
@@ -11,14 +12,17 @@ import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TmplItmRespVO;
|
|||||||
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TmplItmSaveReqVO;
|
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TmplItmSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.TmplItmDO;
|
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.TmplItmDO;
|
||||||
import cn.iocoder.yudao.module.base.service.tmpltp.TmplItmService;
|
import cn.iocoder.yudao.module.base.service.tmpltp.TmplItmService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 模板条款")
|
@Tag(name = "管理后台 - 模板条款")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -28,32 +32,56 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TmplItmController {
|
public class TmplItmController {
|
||||||
private final TmplItmService tmplItmService;
|
private final TmplItmService tmplItmService;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建模板条款")
|
@Operation(summary = "创建模板条款")
|
||||||
public CommonResult<TmplItmRespVO> createTmplItm(@Valid @RequestBody TmplItmSaveReqVO createReqVO) {
|
public CommonResult<TmplItmRespVO> createTmplItm(@Valid @RequestBody TmplItmSaveReqVO createReqVO) {
|
||||||
TmplItmRespVO tmplItm = tmplItmService.createTmplItm(createReqVO);
|
TmplItmRespVO tmplItm = tmplItmService.createTmplItm(createReqVO);
|
||||||
return success(tmplItm);
|
return success(tmplItm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新模板条款")
|
@Operation(summary = "更新模板条款")
|
||||||
public CommonResult<Boolean> updateTmplItm(@Valid @RequestBody TmplItmSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateTmplItm(@Valid @RequestBody TmplItmSaveReqVO updateReqVO) {
|
||||||
tmplItmService.updateTmplItm(updateReqVO);
|
tmplItmService.updateTmplItm(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "删除模板条款", description = "")
|
@Operation(summary = "删除模板条款", description = "")
|
||||||
public CommonResult<Boolean> deleteTmplItm(@RequestBody BatchDeleteReqVO req) {
|
public CommonResult<Boolean> deleteTmplItm(@RequestBody BatchDeleteReqVO req) {
|
||||||
return success(tmplItmService.deleteTmplItm(req.getIds()));
|
return success(tmplItmService.deleteTmplItm(req.getIds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/id")
|
@GetMapping("/id")
|
||||||
@Operation(summary = "根据id获得模板条款")
|
@Operation(summary = "根据id获得模板条款")
|
||||||
public CommonResult<TmplItmRespVO> getTmplItm(@RequestBody String id) {
|
public CommonResult<TmplItmRespVO> getTmplItm(@RequestBody String id) {
|
||||||
return success(BeanUtils.toBean(tmplItmService.getById(id), TmplItmRespVO.class));
|
return success(BeanUtils.toBean(tmplItmService.getById(id), TmplItmRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public CommonResult<List<TmplItmRespVO>> listTmplItm(){
|
public CommonResult<List<TmplItmRespVO>> listTmplItm(Map<String, Object> params) {
|
||||||
return success(BeanUtils.toBean(tmplItmService.list(), TmplItmRespVO.class));
|
// 创建查询条件构造器
|
||||||
|
QueryWrapper<TmplItmDO> queryWrapper = new QueryWrapper<>();
|
||||||
|
|
||||||
|
// 遍历Map参数,动态添加查询条件
|
||||||
|
if (params != null && !params.isEmpty()) {
|
||||||
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
// 过滤掉空值和空字符串
|
||||||
|
if (value != null &&
|
||||||
|
!(value instanceof String && StringUtils.isBlank((String) value))) {
|
||||||
|
queryWrapper.eq(key, value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 执行带条件的查询
|
||||||
|
List<TmplItmDO> list = tmplItmService.list(queryWrapper);
|
||||||
|
return success(BeanUtils.toBean(list, TmplItmRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "分页获得模板条款")
|
@Operation(summary = "分页获得模板条款")
|
||||||
public CommonResult<PageResult<TmplItmRespVO>> pageTmplItm(@Validated TmpItmPageReqVO pageReqVO) {
|
public CommonResult<PageResult<TmplItmRespVO>> pageTmplItm(@Validated TmpItmPageReqVO pageReqVO) {
|
||||||
|
|||||||
@@ -129,8 +129,14 @@ public class TmplTpController extends AbstractFileUploadController implements Bu
|
|||||||
@PutMapping("/updateStatus")
|
@PutMapping("/updateStatus")
|
||||||
@Operation(summary = "更新模板字段状态")
|
@Operation(summary = "更新模板字段状态")
|
||||||
@PreAuthorize("@ss.hasPermission('bse:tmpl-tp:update')")
|
@PreAuthorize("@ss.hasPermission('bse:tmpl-tp:update')")
|
||||||
public CommonResult<Boolean> updateStatus(@RequestBody TmplTpSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateStatus(@RequestBody Map<String,Object> params) {
|
||||||
tmplTpService.updateStatus(updateReqVO.getId(), updateReqVO.getSts());
|
if (params == null){
|
||||||
|
throw new RuntimeException("参数不能为空");
|
||||||
|
}
|
||||||
|
if (!params.containsKey("id") || !params.containsKey("status")){
|
||||||
|
throw new RuntimeException("参数id或者状态不能为空");
|
||||||
|
}
|
||||||
|
tmplTpService.updateStatus(Long.valueOf(params.get("id").toString()), params.get("status").toString());
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class TemplateInstanceSaveReqVO {
|
|||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
@Schema(description = "原始文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "原始文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotEmpty(message = "原始文件内容不能为空")
|
// @NotEmpty(message = "原始文件内容不能为空")
|
||||||
private String originalContent;
|
private String originalContent;
|
||||||
|
|
||||||
@Schema(description = "文件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "文件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
|||||||
@@ -53,4 +53,7 @@ public interface TmplTpMapper extends BaseMapperX<TmplTpDO> {
|
|||||||
" and bti.deleted = 0\n" +
|
" and bti.deleted = 0\n" +
|
||||||
"and btt.id = #{id}")
|
"and btt.id = #{id}")
|
||||||
List<Map<String, Object>>getClause(@Param("id") Long id);
|
List<Map<String, Object>>getClause(@Param("id") Long id);
|
||||||
|
|
||||||
|
@Select("select * from bse_tmpl_tp where id= #{id}")
|
||||||
|
TmplTpDO getTmplTpById(@Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,12 @@ public class TemplateInstanceServiceImpl implements TemplateInstanceService {
|
|||||||
public void updateTemplateInstance(TemplateInstanceSaveReqVO updateReqVO) {
|
public void updateTemplateInstance(TemplateInstanceSaveReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateTemplateInstanceExists(updateReqVO.getId());
|
validateTemplateInstanceExists(updateReqVO.getId());
|
||||||
|
// TemplateInstanceDO templateInstanceDO = templateInstanceMapper.selectById(updateReqVO.getId());
|
||||||
|
// //获取保存旧文件内容防止被更新
|
||||||
|
// String originalContent = templateInstanceDO.getOriginalContent();
|
||||||
// 更新
|
// 更新
|
||||||
TemplateInstanceDO updateObj = BeanUtils.toBean(updateReqVO, TemplateInstanceDO.class);
|
TemplateInstanceDO updateObj = BeanUtils.toBean(updateReqVO, TemplateInstanceDO.class);
|
||||||
|
updateObj.setOriginalContent(null); //重新赋值,防止原始文件被更改
|
||||||
templateInstanceMapper.updateById(updateObj);
|
templateInstanceMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateStatusUpdate(Long id, String status) {
|
private boolean validateStatusUpdate(Long id, String status) {
|
||||||
TmplTpDO tmplTpDO = this.getById(id);
|
TmplTpDO tmplTpDO = baseMapper.getTmplTpById(id);
|
||||||
String currentSts = tmplTpDO.getSts();
|
String currentSts = tmplTpDO.getSts();
|
||||||
|
|
||||||
// 获取当前状态对应的枚举实例
|
// 获取当前状态对应的枚举实例
|
||||||
|
|||||||
Reference in New Issue
Block a user