mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
feat: 添加钉钉机器人及模板相关的DTO、实体、服务和控制器
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dingtalkBot.dto.*;
|
||||
import cn.lihongjie.coal.dingtalkBot.service.DingtalkBotService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
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.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dingtalkBot")
|
||||
@SysLog(module = "钉钉机器人")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class DingtalkBotController {
|
||||
@Autowired private DingtalkBotService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public DingtalkBotDto create(@RequestBody CreateDingtalkBotDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public DingtalkBotDto update(@RequestBody UpdateDingtalkBotDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public DingtalkBotDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
public SendMsgResponse send(@RequestBody SendMsgRequest request) {
|
||||
return this.service.send(request);
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<DingtalkBotDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateDingtalkBotDto extends OrgCommonDto {
|
||||
|
||||
|
||||
private String url;
|
||||
|
||||
|
||||
|
||||
@Comment(
|
||||
"机器人分组"
|
||||
)
|
||||
private String botGroup;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class DingtalkBotDto extends OrgCommonDto {
|
||||
|
||||
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment(
|
||||
"机器人分组"
|
||||
)
|
||||
private String botGroup;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class SendMsgRequest {
|
||||
|
||||
private List<String> dingtalkBotIds;
|
||||
|
||||
private String dingtalkBotTemplateId;
|
||||
|
||||
|
||||
private Map<String, Object> params;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data public class SendMsgResponse {
|
||||
|
||||
|
||||
private List<SendMsgResult> results;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data public class SendMsgResult {
|
||||
|
||||
|
||||
private DingtalkBotDto bot;
|
||||
|
||||
private String response;
|
||||
|
||||
|
||||
private String stackTrace;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateDingtalkBotDto extends OrgCommonDto {
|
||||
|
||||
private String url;
|
||||
|
||||
|
||||
|
||||
@Comment(
|
||||
"机器人分组"
|
||||
)
|
||||
private String botGroup;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_dingtalkBot_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class DingtalkBotEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@Comment("机器人地址")
|
||||
private String url;
|
||||
|
||||
|
||||
@Comment(
|
||||
"机器人分组"
|
||||
)
|
||||
private String botGroup;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.dingtalkBot.dto.CreateDingtalkBotDto;
|
||||
import cn.lihongjie.coal.dingtalkBot.dto.DingtalkBotDto;
|
||||
import cn.lihongjie.coal.dingtalkBot.dto.UpdateDingtalkBotDto;
|
||||
import cn.lihongjie.coal.dingtalkBot.entity.DingtalkBotEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface DingtalkBotMapper
|
||||
extends BaseMapper<
|
||||
DingtalkBotEntity, DingtalkBotDto, CreateDingtalkBotDto, UpdateDingtalkBotDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.dingtalkBot.entity.DingtalkBotEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface DingtalkBotRepository extends BaseRepository<DingtalkBotEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package cn.lihongjie.coal.dingtalkBot.service;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.FreeMakerUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.dingtalkBot.dto.*;
|
||||
import cn.lihongjie.coal.dingtalkBot.entity.DingtalkBotEntity;
|
||||
import cn.lihongjie.coal.dingtalkBot.mapper.DingtalkBotMapper;
|
||||
import cn.lihongjie.coal.dingtalkBot.repository.DingtalkBotRepository;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.entity.DingtalkBotTemplateEntity;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.service.DingtalkBotTemplateService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class DingtalkBotService extends BaseService<DingtalkBotEntity, DingtalkBotRepository> {
|
||||
@Autowired DingtalkBotTemplateService dingtalkBotTemplateService;
|
||||
@Autowired ObjectMapper objectMapper;
|
||||
@Autowired private DingtalkBotRepository repository;
|
||||
@Autowired private DingtalkBotMapper mapper;
|
||||
@Autowired private ConversionService conversionService;
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public DingtalkBotDto create(CreateDingtalkBotDto request) {
|
||||
DingtalkBotEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public DingtalkBotDto update(UpdateDingtalkBotDto request) {
|
||||
DingtalkBotEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public DingtalkBotDto getById(String id) {
|
||||
DingtalkBotEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<DingtalkBotDto> list(CommonQuery query) {
|
||||
Page<DingtalkBotEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public SendMsgResponse send(SendMsgRequest request) {
|
||||
|
||||
SendMsgResponse response = new SendMsgResponse();
|
||||
ArrayList<SendMsgResult> results = new ArrayList<>();
|
||||
response.setResults(results);
|
||||
List<DingtalkBotEntity> all = this.repository.findAllById(request.getDingtalkBotIds());
|
||||
|
||||
DingtalkBotTemplateEntity dingtalkBotTemplateEntity =
|
||||
dingtalkBotTemplateService.get(request.getDingtalkBotTemplateId());
|
||||
|
||||
for (DingtalkBotEntity dingtalkBotEntity : all) {
|
||||
|
||||
results.add(doSend(dingtalkBotEntity, dingtalkBotTemplateEntity, request.getParams()));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private SendMsgResult doSend(
|
||||
DingtalkBotEntity dingtalkBotEntity,
|
||||
DingtalkBotTemplateEntity dingtalkBotTemplateEntity,
|
||||
Map<String, Object> params) {
|
||||
|
||||
SendMsgResult sendMsgResult = new SendMsgResult();
|
||||
|
||||
sendMsgResult.setBot(mapper.toDto(dingtalkBotEntity));
|
||||
HashMap<Object, Object> body = new HashMap<>();
|
||||
|
||||
body.put("msgtype", "markdown");
|
||||
body.put(
|
||||
"markdown",
|
||||
new HashMap<String, Object>() {
|
||||
{
|
||||
put(
|
||||
"title",
|
||||
FreeMakerUtils.render(
|
||||
dingtalkBotTemplateEntity.getTitle(), params));
|
||||
put(
|
||||
"text",
|
||||
FreeMakerUtils.render(
|
||||
dingtalkBotTemplateEntity.getTemplate(), params));
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
String post =
|
||||
HttpUtil.post(
|
||||
dingtalkBotEntity.getUrl(), objectMapper.writeValueAsString(body));
|
||||
|
||||
log.info("发送钉钉消息成功, 返回结果: {}", post);
|
||||
|
||||
sendMsgResult.setResponse(post);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("发送钉钉消息失败", e);
|
||||
|
||||
sendMsgResult.setStackTrace(e.getMessage());
|
||||
}
|
||||
return sendMsgResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.CreateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.DingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.UpdateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.service.DingtalkBotTemplateService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
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.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dingtalkBotTemplate")
|
||||
@SysLog(module = "钉钉机器人模板")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class DingtalkBotTemplateController {
|
||||
@Autowired private DingtalkBotTemplateService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public DingtalkBotTemplateDto create(@RequestBody CreateDingtalkBotTemplateDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public DingtalkBotTemplateDto update(@RequestBody UpdateDingtalkBotTemplateDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public DingtalkBotTemplateDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<DingtalkBotTemplateDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateDingtalkBotTemplateDto extends OrgCommonDto {
|
||||
|
||||
@Comment("模板内容")
|
||||
private String template;
|
||||
|
||||
|
||||
@Comment("模板标题")
|
||||
private String title;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class DingtalkBotTemplateDto extends OrgCommonDto {
|
||||
|
||||
@Comment("模板内容")
|
||||
private String template;
|
||||
|
||||
|
||||
@Comment("模板标题")
|
||||
private String title;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateDingtalkBotTemplateDto extends OrgCommonDto {
|
||||
|
||||
@Comment("模板内容")
|
||||
private String template;
|
||||
|
||||
|
||||
@Comment("模板标题")
|
||||
private String title;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_dingtalkBotTemplate_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class DingtalkBotTemplateEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@Comment("模板内容")
|
||||
private String template;
|
||||
|
||||
|
||||
@Comment("模板标题")
|
||||
private String title;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.CreateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.DingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.UpdateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.entity.DingtalkBotTemplateEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface DingtalkBotTemplateMapper
|
||||
extends BaseMapper<
|
||||
DingtalkBotTemplateEntity,
|
||||
DingtalkBotTemplateDto,
|
||||
CreateDingtalkBotTemplateDto,
|
||||
UpdateDingtalkBotTemplateDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.entity.DingtalkBotTemplateEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface DingtalkBotTemplateRepository extends BaseRepository<DingtalkBotTemplateEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.dingtalkBotTemplate.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.CreateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.DingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.dto.UpdateDingtalkBotTemplateDto;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.entity.DingtalkBotTemplateEntity;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.mapper.DingtalkBotTemplateMapper;
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.repository.DingtalkBotTemplateRepository;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class DingtalkBotTemplateService
|
||||
extends BaseService<DingtalkBotTemplateEntity, DingtalkBotTemplateRepository> {
|
||||
@Autowired private DingtalkBotTemplateRepository repository;
|
||||
|
||||
@Autowired private DingtalkBotTemplateMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public DingtalkBotTemplateDto create(CreateDingtalkBotTemplateDto request) {
|
||||
DingtalkBotTemplateEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public DingtalkBotTemplateDto update(UpdateDingtalkBotTemplateDto request) {
|
||||
DingtalkBotTemplateEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public DingtalkBotTemplateDto getById(String id) {
|
||||
DingtalkBotTemplateEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<DingtalkBotTemplateDto> list(CommonQuery query) {
|
||||
Page<DingtalkBotTemplateEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
19
src/main/resources/scripts/dict/enum/dingtalkBotDict.groovy
Normal file
19
src/main/resources/scripts/dict/enum/dingtalkBotDict.groovy
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.dingtalkBot.controller.DingtalkBotController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(DingtalkBotController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.dingtalkBotTemplate.controller.DingtalkBotTemplateController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(DingtalkBotTemplateController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user