diff --git a/src/main/java/com/steadon/saber/biz/IFeishuRobotBiz.java b/src/main/java/com/steadon/saber/biz/IFeishuRobotBiz.java index 577b0d4b81bd217595cf8704da7d9c1c54d42643..3cc9c1fa8bc28fb381a7c6210c4bcde76dd8539d 100644 --- a/src/main/java/com/steadon/saber/biz/IFeishuRobotBiz.java +++ b/src/main/java/com/steadon/saber/biz/IFeishuRobotBiz.java @@ -2,8 +2,16 @@ package com.steadon.saber.biz; import com.steadon.saber.pojo.SaberResponse; import com.steadon.saber.pojo.domain.FeishuRobot; +import com.steadon.saber.pojo.model.FeishuRobotRequest; +import com.steadon.saber.pojo.model.FeishuRobotSearchRequest; import com.steadon.saber.pojo.model.pageData.PageData; public interface IFeishuRobotBiz { SaberResponse<PageData<FeishuRobot>> getFeishuRobotBatch(Integer pageNo, Integer pageSize); + + SaberResponse<PageData<FeishuRobot>> searchFeishuRobotBatch(FeishuRobotSearchRequest request, Integer pageNo, Integer pageSize); + + SaberResponse<String> deleteRobotById(Integer rid); + + SaberResponse<String> updateFeishuRobot(Integer rid, FeishuRobotRequest request); } diff --git a/src/main/java/com/steadon/saber/biz/impl/FeishuRobotBiz.java b/src/main/java/com/steadon/saber/biz/impl/FeishuRobotBiz.java index d38f754f3e6b70de24d3cde022ec0522e19544cb..ce0f9d3eed054c8d93cb44ce622b3f528e0041a6 100644 --- a/src/main/java/com/steadon/saber/biz/impl/FeishuRobotBiz.java +++ b/src/main/java/com/steadon/saber/biz/impl/FeishuRobotBiz.java @@ -3,13 +3,46 @@ package com.steadon.saber.biz.impl; import com.steadon.saber.biz.IFeishuRobotBiz; import com.steadon.saber.pojo.SaberResponse; import com.steadon.saber.pojo.domain.FeishuRobot; +import com.steadon.saber.pojo.model.FeishuRobotRequest; +import com.steadon.saber.pojo.model.FeishuRobotSearchRequest; import com.steadon.saber.pojo.model.pageData.PageData; +import com.steadon.saber.service.FeishuRobotService; import org.springframework.stereotype.Service; @Service public class FeishuRobotBiz implements IFeishuRobotBiz { + + FeishuRobotService feishuRobotService; + @Override public SaberResponse<PageData<FeishuRobot>> getFeishuRobotBatch(Integer pageNo, Integer pageSize) { - return null; + PageData<FeishuRobot> feishuRobotPageData = feishuRobotService.getFeishuRobotBatch(pageNo, pageSize); + return SaberResponse.success(feishuRobotPageData); + } + + @Override + public SaberResponse<PageData<FeishuRobot>> searchFeishuRobotBatch(FeishuRobotSearchRequest request, Integer pageNo, Integer pageSize) { + PageData<FeishuRobot> feishuRobotPageData = feishuRobotService.searchFeishuRobotBatch(request.getKeyword(), pageNo, pageSize); + return SaberResponse.success(feishuRobotPageData); + } + + @Override + public SaberResponse<String> deleteRobotById(Integer rid) { + FeishuRobot feishuRobot = new FeishuRobot(); + feishuRobot.updateStatus(); + + feishuRobotService.deleteFeishuRobotById(feishuRobot); + return SaberResponse.success(); + } + + @Override + public SaberResponse<String> updateFeishuRobot(Integer rid, FeishuRobotRequest request) { + FeishuRobot feishuRobot = new FeishuRobot(); + feishuRobot.setId(rid); + feishuRobot.loadDataFromReq(request); + feishuRobot.updateStatus(); + + feishuRobotService.updateFeishuRobotById(feishuRobot); + return SaberResponse.success(); } } diff --git a/src/main/java/com/steadon/saber/controller/FeishuRobotController.java b/src/main/java/com/steadon/saber/controller/FeishuRobotController.java new file mode 100644 index 0000000000000000000000000000000000000000..2174747b312bb5a3ac7ef338d99204a769768f64 --- /dev/null +++ b/src/main/java/com/steadon/saber/controller/FeishuRobotController.java @@ -0,0 +1,43 @@ +package com.steadon.saber.controller; + +import com.steadon.saber.biz.IFeishuRobotBiz; +import com.steadon.saber.pojo.SaberResponse; +import com.steadon.saber.pojo.domain.FeishuRobot; +import com.steadon.saber.pojo.model.FeishuRobotRequest; +import com.steadon.saber.pojo.model.FeishuRobotSearchRequest; +import com.steadon.saber.pojo.model.pageData.PageData; +import lombok.AllArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +@RestController +@AllArgsConstructor +@RequestMapping("/saber") +public class FeishuRobotController { + + private IFeishuRobotBiz iFeishuRobotBiz; + + @GetMapping("/robot/list") + public SaberResponse<PageData<FeishuRobot>> showRobot(@RequestParam(value = "page_no", required = false, defaultValue = "1") Integer pageNo, + @RequestParam(value = "page_size", required = false, defaultValue = "10") Integer pageSize){ + return iFeishuRobotBiz.getFeishuRobotBatch(pageNo, pageSize); + } + + @PostMapping("/robot/search") + public SaberResponse<PageData<FeishuRobot>> searchRobot(@Validated @RequestBody FeishuRobotSearchRequest request, + @RequestParam(value = "page_no", required = false, defaultValue = "1") Integer pageNo, + @RequestParam(value = "page_size", required = false, defaultValue = "10") Integer pageSize){ + return iFeishuRobotBiz.searchFeishuRobotBatch(request, pageNo, pageSize); + } + + @DeleteMapping("/robot/delete") + public SaberResponse<String> deleteRobot(@RequestParam(value = "rid") Integer rid){ + return iFeishuRobotBiz.deleteRobotById(rid); + } + + @PostMapping("/robot/update") + public SaberResponse<String> updateRobot(@RequestParam(value = "rid") Integer rid, + @Validated @RequestBody FeishuRobotRequest request){ + return iFeishuRobotBiz.updateFeishuRobot(rid, request); + } +} \ No newline at end of file diff --git a/src/main/java/com/steadon/saber/pojo/domain/FeishuRobot.java b/src/main/java/com/steadon/saber/pojo/domain/FeishuRobot.java index ea3030fd50e5b4e32ef2b12a0de44b7503a5a290..e1dacff8bbd9c9a0164590d08cc43915c866fa30 100644 --- a/src/main/java/com/steadon/saber/pojo/domain/FeishuRobot.java +++ b/src/main/java/com/steadon/saber/pojo/domain/FeishuRobot.java @@ -2,6 +2,7 @@ package com.steadon.saber.pojo.domain; import com.baomidou.mybatisplus.annotation.*; import com.steadon.saber.handler.token.TokenHandler; +import com.steadon.saber.pojo.model.FeishuRobotRequest; import lombok.Data; import java.io.Serial; @@ -67,4 +68,9 @@ public class FeishuRobot implements Serializable { this.updateBy = TokenHandler.getUsername(); this.updateTime = LocalDateTime.now(); } + + public void loadDataFromReq(FeishuRobotRequest request) { + this.name = request.getName(); + this.description = request.getDescription(); + } } diff --git a/src/main/java/com/steadon/saber/pojo/model/FeishuRobotRequest.java b/src/main/java/com/steadon/saber/pojo/model/FeishuRobotRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..b3603b81a7c4fa77d96fa25fc133ea5f2ba4dada --- /dev/null +++ b/src/main/java/com/steadon/saber/pojo/model/FeishuRobotRequest.java @@ -0,0 +1,9 @@ +package com.steadon.saber.pojo.model; + +import lombok.Data; + +@Data +public class FeishuRobotRequest { + private String name; + private String description; +} \ No newline at end of file diff --git a/src/main/java/com/steadon/saber/pojo/model/FeishuRobotSearchRequest.java b/src/main/java/com/steadon/saber/pojo/model/FeishuRobotSearchRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..30ee4ae11a01b2cc1519e055f0507661a1b8c5a0 --- /dev/null +++ b/src/main/java/com/steadon/saber/pojo/model/FeishuRobotSearchRequest.java @@ -0,0 +1,8 @@ +package com.steadon.saber.pojo.model; + +import lombok.Data; + +@Data +public class FeishuRobotSearchRequest { + private String keyword; +} diff --git a/src/main/java/com/steadon/saber/service/FeishuRobotService.java b/src/main/java/com/steadon/saber/service/FeishuRobotService.java index a57e5c3ed71e04c84e04612d9fef3f66fa1470b4..941a8c568494db38409957525d864ba28b93d383 100644 --- a/src/main/java/com/steadon/saber/service/FeishuRobotService.java +++ b/src/main/java/com/steadon/saber/service/FeishuRobotService.java @@ -1,6 +1,8 @@ package com.steadon.saber.service; import com.steadon.saber.pojo.domain.BusinessRobotMerge; +import com.steadon.saber.pojo.domain.FeishuRobot; +import com.steadon.saber.pojo.model.pageData.PageData; import java.util.List; @@ -8,4 +10,12 @@ public interface FeishuRobotService { String getSecretById(String feishuAppId); List<BusinessRobotMerge> getRobotMergeListByAppCode(String appCode); + + PageData<FeishuRobot> getFeishuRobotBatch(Integer pageNo, Integer pageSize); + + PageData<FeishuRobot> searchFeishuRobotBatch(String keyword, Integer pageNo, Integer pageSize); + + void deleteFeishuRobotById(FeishuRobot feishuRobot); + + void updateFeishuRobotById(FeishuRobot feishuRobot); } diff --git a/src/main/java/com/steadon/saber/service/impl/FeishuRobotServiceImpl.java b/src/main/java/com/steadon/saber/service/impl/FeishuRobotServiceImpl.java index 771e9aff721c27f3a291b80bdb21eae23f0f0f12..64402ba2e3be3df076370896effc9359ad5e6cdd 100644 --- a/src/main/java/com/steadon/saber/service/impl/FeishuRobotServiceImpl.java +++ b/src/main/java/com/steadon/saber/service/impl/FeishuRobotServiceImpl.java @@ -1,13 +1,18 @@ package com.steadon.saber.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.steadon.saber.mapper.BusinessRobotMergeMapper; import com.steadon.saber.mapper.FeishuRobotMapper; import com.steadon.saber.pojo.domain.BusinessRobotMerge; import com.steadon.saber.pojo.domain.FeishuRobot; +import com.steadon.saber.pojo.model.pageData.PageData; import com.steadon.saber.service.FeishuRobotService; import lombok.AllArgsConstructor; +import org.springframework.dao.OptimisticLockingFailureException; +import org.springframework.retry.annotation.Retryable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -31,4 +36,48 @@ public class FeishuRobotServiceImpl implements FeishuRobotService { QueryWrapper<BusinessRobotMerge> businessWrapper = new QueryWrapper<BusinessRobotMerge>().eq("app_code", appCode); return businessRobotMergeMapper.selectList(businessWrapper); } + + @Override + public PageData<FeishuRobot> getFeishuRobotBatch(Integer pageNo, Integer pageSize) { + Page<FeishuRobot> page = new Page<>(pageNo, pageSize); + Page<FeishuRobot> feishuRobotPage = feishuRobotMapper.selectPage(page, null); + + PageData<FeishuRobot> feishuRobotPageData = new PageData<>(); + feishuRobotPageData.praiseIPage(feishuRobotPage); + return feishuRobotPageData; + } + + @Override + public PageData<FeishuRobot> searchFeishuRobotBatch(String keyword, Integer pageNo, Integer pageSize) { + QueryWrapper<FeishuRobot> wrapper = new QueryWrapper<FeishuRobot>().like("feishu_app_id", keyword) + .or().like("name", keyword) + .or().like("description", keyword); + + Page<FeishuRobot> page = new Page<>(pageNo, pageSize); + Page<FeishuRobot> feishuRobotPage = feishuRobotMapper.selectPage(page, wrapper); + + PageData<FeishuRobot> feishuRobotPageData = new PageData<>(); + feishuRobotPageData.praiseIPage(feishuRobotPage); + return feishuRobotPageData; + } + + @Override + @Retryable(retryFor = OptimisticLockingFailureException.class) + @Transactional(noRollbackFor = OptimisticLockingFailureException.class) + public void deleteFeishuRobotById(FeishuRobot feishuRobot) { + if (feishuRobotMapper.updateById(feishuRobot) == 0){ + throw new OptimisticLockingFailureException("Optimistic locking failed"); + } + if (feishuRobotMapper.deleteById(feishuRobot) == 0){ + throw new OptimisticLockingFailureException("Optimistic locking failed"); + } + } + + @Override + @Retryable(retryFor = OptimisticLockingFailureException.class) + public void updateFeishuRobotById(FeishuRobot feishuRobot) { + if (feishuRobotMapper.updateById(feishuRobot) == 0) { + throw new OptimisticLockingFailureException("Optimistic locking failed"); + } + } } \ No newline at end of file