package com.qianwen.smartman.modules.notify.controller;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.validation.Valid;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
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.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.qianwen.core.boot.ctrl.BladeController;
|
import com.qianwen.core.mp.support.Condition;
|
import com.qianwen.core.mp.support.Query;
|
import com.qianwen.core.scanner.modular.annotation.PostResource;
|
import com.qianwen.core.secure.BladeUser;
|
import com.qianwen.core.secure.utils.AuthUtil;
|
import com.qianwen.core.tool.api.R;
|
import com.qianwen.core.websocket.distribute.MessageDO;
|
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
|
import com.qianwen.smartman.modules.notify.convert.NotifySystemConvert;
|
import com.qianwen.smartman.modules.notify.entity.NotifySystem;
|
import com.qianwen.smartman.modules.notify.service.INotifySystemService;
|
import com.qianwen.smartman.modules.notify.vo.NotifySystemSelectVO;
|
import com.qianwen.smartman.modules.notify.vo.NotifySystemUnreadVO;
|
import com.qianwen.smartman.modules.notify.vo.NotifySystemVO;
|
import com.qianwen.smartman.modules.notify.websocket.InternalMessageResponseJsonWebSocketMessage;
|
|
import cn.hutool.json.JSONUtil;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
@Api(value = "通知公告表管理", tags = {"通知公告表管理"})
|
@RequestMapping({"blade-notify/notify-system"})
|
@RestController
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/controller/NotifySystemController.class */
|
public class NotifySystemController extends BladeController {
|
private INotifySystemService notifySystemService;
|
private RedisMessageDistributor messageDistributor;
|
|
|
public NotifySystemController(final INotifySystemService notifySystemService, final RedisMessageDistributor messageDistributor) {
|
this.notifySystemService = notifySystemService;
|
this.messageDistributor = messageDistributor;
|
}
|
|
@ApiOperationSupport(order = 1)
|
@GetMapping({"/get/{id}"})
|
@ApiOperation(value = "通知公告表详情", notes = "传入notifySystem")
|
public R<NotifySystemVO> detail(@PathVariable String id) {
|
return R.data(this.notifySystemService.detail(id));
|
}
|
|
@ApiOperationSupport(order = 2)
|
@GetMapping({"/list"})
|
@ApiOperation(value = "通知公告表列表", notes = "传入map")
|
public R<List<NotifySystemVO>> list(@RequestParam @ApiIgnore Map<String, Object> params) {
|
List<NotifySystem> list = this.notifySystemService.list(Condition.getQueryWrapper(params, NotifySystem.class));
|
return R.data(NotifySystemConvert.INSTANCE.convert(list));
|
}
|
|
@ApiOperationSupport(order = 2)
|
@GetMapping({"/count"})
|
@ApiOperation(value = "通知公告表统计值", notes = "传入map")
|
public R<Long> count(@RequestParam @ApiIgnore Map<String, Object> params) {
|
long count = this.notifySystemService.count(Condition.getQueryWrapper(params, NotifySystem.class));
|
return R.data(Long.valueOf(count));
|
}
|
|
@ApiOperationSupport(order = 3)
|
@GetMapping({"/page"})
|
@ApiOperation(value = "通知公告表分页", notes = "传入map")
|
public R<IPage<NotifySystemVO>> page(NotifySystemSelectVO notifySystemSelectVO, Query query) {
|
return R.data(this.notifySystemService.pageNotifySystem(notifySystemSelectVO, Condition.getPage(query)));
|
}
|
|
@PostMapping({"/insert"})
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "通知公告表新增", notes = "传入notifySystemVO")
|
public R<NotifySystemVO> insert(@Valid @RequestBody NotifySystemVO notifySystemVO) {
|
NotifySystem notifySystem = NotifySystemConvert.INSTANCE.convert(notifySystemVO);
|
this.notifySystemService.save(notifySystem);
|
return R.data(NotifySystemConvert.INSTANCE.convert(notifySystem));
|
}
|
|
@DeleteMapping({"/remove"})
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "通知公告表删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键", required = true) @RequestBody List<Long> ids) {
|
if (ids.isEmpty()) {
|
return R.status(false);
|
}
|
return R.status(this.notifySystemService.removeByIds(ids));
|
}
|
|
@ApiOperationSupport(order = 7)
|
@PostResource({"/{state}"})
|
@ApiOperation("修改通知状态")
|
public R<String> changeState(@RequestBody List<String> idList, @PathVariable("state") Integer state, BladeUser bladeUser) {
|
LambdaUpdateWrapper<NotifySystem> updateWrapper = Wrappers.<NotifySystem>update().lambda()
|
.set(NotifySystem::getStatus, state)
|
.eq(NotifySystem::getNotifyUser, bladeUser.getUserId()).in(NotifySystem::getId, idList);
|
boolean flag = this.notifySystemService.update(updateWrapper);
|
/*
|
boolean flag = this.notifySystemService.update((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
|
return v0.getStatus();
|
}, state)).eq((v0) -> {
|
return v0.getNotifyUser();
|
}, bladeUser.getUserId())).in((v0) -> {
|
return v0.getId();
|
}, idList));*/
|
InternalMessageResponseJsonWebSocketMessage internalMessageResponseJsonWebSocketMessage = new InternalMessageResponseJsonWebSocketMessage();
|
long unNotificationCount = this.notifySystemService.count(Wrappers.<NotifySystem>lambdaQuery()
|
.ne(NotifySystem::getStatus, 1)
|
.eq(NotifySystem::getNotifyUser, AuthUtil.getUserId()));
|
/*
|
long unNotificationCount = this.notifySystemService.count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().ne((v0) -> {
|
return v0.getStatus();
|
}, 1)).eq((v0) -> {
|
return v0.getNotifyUser();
|
}, AuthUtil.getUserId()));*/
|
internalMessageResponseJsonWebSocketMessage.setHaveUnread(unNotificationCount > 0);
|
MessageDO messageDO = new MessageDO();
|
messageDO.setNeedBroadcast(Boolean.FALSE);
|
messageDO.setMessageText(JSONUtil.toJsonStr(internalMessageResponseJsonWebSocketMessage));
|
messageDO.setSessionKeys(Arrays.asList(AuthUtil.getUserId()));
|
this.messageDistributor.distribute(messageDO);
|
return R.status(flag);
|
}
|
|
@ApiOperationSupport(order = 3)
|
@GetMapping({"/getUnreadList"})
|
@ApiOperation(value = "获取未读通知-铃铛", notes = "传入map")
|
public R<NotifySystemUnreadVO> getUnreadList() {
|
NotifySystemUnreadVO result = this.notifySystemService.getUnreadList();
|
return R.data(result);
|
}
|
}
|