|
@@ -1,13 +1,111 @@
|
|
|
package boot.modules.calendar.controller;
|
|
|
|
|
|
+import boot.common.respond.ApiCode;
|
|
|
+import boot.common.respond.ApiResult;
|
|
|
+import boot.modules.calendar.param.CalendarParam;
|
|
|
+import boot.modules.calendar.pojo.Calendar;
|
|
|
+import boot.modules.calendar.respond.CalendarDTO;
|
|
|
+import boot.modules.calendar.service.CalendarService;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
@Api(value = "日历模块", tags = "日历")
|
|
|
+@RequestMapping("/calendar")
|
|
|
public class CalendarController {
|
|
|
|
|
|
+ private final CalendarService calendarService;
|
|
|
+
|
|
|
+ @GetMapping("/getCalendars")
|
|
|
+ @ApiOperation(value = "获取所有日历事件",notes = "查询")
|
|
|
+ public ApiResult<List<CalendarDTO>> getAllCalendars() {
|
|
|
+ //查询所有事件
|
|
|
+ List<Calendar> list = calendarService.list();
|
|
|
+
|
|
|
+ List<CalendarDTO> calendars = new ArrayList<>();
|
|
|
+ //转换类型
|
|
|
+ List<Calendar> collect = list.stream()
|
|
|
+ .peek((item) -> {
|
|
|
+ CalendarDTO calendarDTO = BeanUtil.copyProperties(item, CalendarDTO.class);
|
|
|
+ calendars.add(calendarDTO);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return ApiResult.ok(calendars);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/addCalendar")
|
|
|
+ @ApiOperation(value = "添加单个日历事件",notes = "添加")
|
|
|
+ public ApiResult<Object> addCalendar(@RequestBody CalendarParam param){
|
|
|
+
|
|
|
+ if (ObjUtil.isEmpty(param)){
|
|
|
+ //请求是否为空
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //构造SQL条件
|
|
|
+ LambdaQueryWrapper<Calendar> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Calendar::getTitle,param.getTitle());
|
|
|
+
|
|
|
+ Calendar one = calendarService.getOne(wrapper);
|
|
|
+
|
|
|
+ if (ObjUtil.isNotEmpty(one)){
|
|
|
+ //没查到数据 = 这个事件不存在可以添加
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"该事件已存在!请勿重新添加!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加事件
|
|
|
+ boolean save = calendarService.save(BeanUtil.copyProperties(param, Calendar.class));
|
|
|
+
|
|
|
+ return ApiResult.ok(save);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/delById/{id}")
|
|
|
+ @ApiOperation(value = "根据id删除事件",notes = "删除")
|
|
|
+ public ApiResult<Object> delById(@PathVariable Long id){
|
|
|
+
|
|
|
+ if (ObjUtil.isEmpty(id)){
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"id不能为空!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //逻辑删除
|
|
|
+ boolean b = calendarService.removeById(id);
|
|
|
+
|
|
|
+ return ApiResult.ok(b);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/editCalendar")
|
|
|
+ @ApiOperation(value = "根据id修改校历事件",notes = "修改")
|
|
|
+ public ApiResult<Object> editById(@RequestBody CalendarParam param){
|
|
|
+
|
|
|
+ if (ObjUtil.isEmpty(param.getId())){
|
|
|
+ //判断id是否为空
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"id不能为空!!");
|
|
|
+ }
|
|
|
+ //构建SQL条件
|
|
|
+ LambdaQueryWrapper<Calendar> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Calendar::getId,param.getId());
|
|
|
+
|
|
|
+ Calendar calendar = BeanUtil.copyProperties(param, Calendar.class);
|
|
|
+ boolean update = calendarService.update(calendar, wrapper);
|
|
|
+
|
|
|
+ if (update){
|
|
|
+ return ApiResult.ok(update);
|
|
|
+ }else {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"修改出错了啦!请联系管理员!");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|