Merge branch 'dev' of http://47.97.8.94:19527/yj/zn-cloud into dev
This commit is contained in:
commit
59d1f12688
@ -31,6 +31,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode OA_SHIFTJOBS_NOT_EXISTS = new ErrorCode(1_009_001_107, "调岗申请不存在");
|
||||
ErrorCode OA_SECOND_NOT_EXISTS = new ErrorCode(1_009_001_108, "借调申请不存在");
|
||||
ErrorCode OA_IMPREST_NOT_EXISTS = new ErrorCode(1_009_001_109, "备用金申请不存在");
|
||||
ErrorCode OA_INCENTIVE_NOT_EXISTS = new ErrorCode(1_009_001_110, "奖惩申请不存在");
|
||||
|
||||
// ========== 流程模型 1-009-002-000 ==========
|
||||
ErrorCode MODEL_KEY_EXISTS = new ErrorCode(1_009_002_000, "已经存在流程标识为【{}】的流程");
|
||||
|
@ -0,0 +1,85 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAIncentiveConvert;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 Controller
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Tag(name = "管理后台 - OA 奖惩申请")
|
||||
@RestController
|
||||
@RequestMapping("/bpm/oa/incentive")
|
||||
@Validated
|
||||
public class BpmOAIncentiveController {
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveService incentiveService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi userApi;
|
||||
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建请求申请")
|
||||
public CommonResult<Long> createIncentive(@Valid @RequestBody BpmOAIncentiveCreateReqVO createReqVO) {
|
||||
|
||||
return success(incentiveService.createIncentive(getLoginUserId(), createReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得奖惩申请")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<BpmOAIncentiveRespVO> getIncentive(@RequestParam("id") Long id) {
|
||||
|
||||
BpmOAIncentiveDO incentive = incentiveService.getIncentive(id);
|
||||
|
||||
//获得 用户信息集合
|
||||
List<AdminUserRespDTO> userRespDTO = userApi.getUserListByDeptIds(incentive.getIncentiveDeptIds()).getCheckedData();
|
||||
|
||||
//获得 部门信息集合
|
||||
Map<Long, DeptRespDTO> deptRespDTOS = deptApi.getDeptMap(incentive.getIncentiveDeptIds());
|
||||
|
||||
Map<String, List<String>> userInfo = new HashMap<>();
|
||||
//遍历 部门map集合
|
||||
deptRespDTOS.forEach((key, value) -> {
|
||||
|
||||
List<String> userName = userRespDTO.stream().filter(user -> user.getDeptId().toString().contains(key.toString())
|
||||
&& incentive.getIncentiveUserIds().contains(user.getId()))
|
||||
.map(AdminUserRespDTO::getNickname).collect(Collectors.toList());
|
||||
|
||||
userInfo.put(value.getName(), userName);
|
||||
});
|
||||
|
||||
BpmOAIncentiveRespVO bpmOAIncentiveRespVO = BpmOAIncentiveConvert.INSTANCE.convert(incentive);
|
||||
bpmOAIncentiveRespVO.setUserInfo(userInfo);
|
||||
return success(bpmOAIncentiveRespVO);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 奖惩申请创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode()
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOAIncentiveCreateReqVO {
|
||||
|
||||
@Schema(description = "奖惩类型 字典值参考 bpm_oa_incentive_type", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "奖惩人编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩人编号不能为空")
|
||||
private Set<Long> incentiveUserIds;
|
||||
|
||||
@Schema(description = "奖惩人部门编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩人部门编号不能为空")
|
||||
private Set<Long> incentiveDeptIds;
|
||||
|
||||
@Schema(description = "奖惩时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime time;
|
||||
|
||||
@Schema(description = "奖惩金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩金额不能为空")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "奖惩事由", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩事由不能为空")
|
||||
private String reason;
|
||||
|
||||
@Schema(description = "上传文件", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.BpmOABaseRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 奖惩申请响应数据 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOAIncentiveRespVO extends BpmOABaseRespVO {
|
||||
|
||||
@Schema(description = "奖惩类型 字典值参考 bpm_oa_incentive_type")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "奖惩人编号")
|
||||
private Set<Long> incentiveUserIds;
|
||||
|
||||
@Schema(description = "奖惩人部门编号")
|
||||
private Set<Long> incentiveDeptIds;
|
||||
|
||||
@Schema(description = "奖惩人信息列表 key:部门名称, value:用户名称集合")
|
||||
private Map<String, List<String>> userInfo;
|
||||
|
||||
@Schema(description = "奖惩时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime time;
|
||||
|
||||
@Schema(description = "奖惩金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "奖惩事由")
|
||||
private String reason;
|
||||
|
||||
@Schema(description = "上传文件")
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.bpm.convert.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Convert
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Mapper
|
||||
public interface BpmOAIncentiveConvert {
|
||||
|
||||
BpmOAIncentiveConvert INSTANCE = Mappers.getMapper(BpmOAIncentiveConvert.class);
|
||||
|
||||
BpmOAIncentiveDO convert(BpmOAIncentiveCreateReqVO bean);
|
||||
|
||||
BpmOAIncentiveRespVO convert(BpmOAIncentiveDO bean);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.dataobject.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 DO
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@TableName(value ="bpm_oa_incentive", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BpmOAIncentiveDO extends BaseDO {
|
||||
|
||||
|
||||
/**
|
||||
* 出差表单主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 申请人的用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 奖惩类型
|
||||
* 1:奖励 2:惩罚
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 奖惩人用户编号
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> incentiveUserIds;
|
||||
|
||||
/**
|
||||
* 奖惩人部门编号
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> incentiveDeptIds;
|
||||
|
||||
/**
|
||||
* 奖惩时间
|
||||
*/
|
||||
private LocalDateTime time;
|
||||
|
||||
/**
|
||||
* 奖惩金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 奖惩事由
|
||||
*/
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 用章的结果
|
||||
*
|
||||
* 枚举 {@link BpmProcessInstanceResultEnum}
|
||||
* 考虑到简单,所以直接复用了 BpmProcessInstanceResultEnum 枚举,也可以自己定义一个枚举哈
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 对应的流程编号
|
||||
*
|
||||
* 关联 ProcessInstance 的 id 属性
|
||||
*/
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 附件基本信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.mysql.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Mapper
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Mapper
|
||||
public interface BpmOAIncentiveMapper extends BaseMapperX<BpmOAIncentiveDO> {
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Service 接口
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
public interface BpmOAIncentiveService {
|
||||
|
||||
/**
|
||||
* 创建奖惩申请
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createIncentive(Long userId, @Valid BpmOAIncentiveCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新奖惩申请的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param result 结果
|
||||
*/
|
||||
void updateIncentiveResult(Long id, Integer result);
|
||||
|
||||
/**
|
||||
* 获得奖惩申请
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 奖惩申请
|
||||
*/
|
||||
BpmOAIncentiveDO getIncentive(Long id);
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
||||
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAIncentiveConvert;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOAIncentiveMapper;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_INCENTIVE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 Service 实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BpmOAIncentiveServiceImpl extends BpmOABaseService implements BpmOAIncentiveService{
|
||||
|
||||
/**
|
||||
* OA 奖惩对应的流程定义 KEY
|
||||
*/
|
||||
public static final String PROCESS_KEY = "oa_incentive";
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveMapper incentiveMapper;
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceApi processInstanceApi;
|
||||
|
||||
@Override
|
||||
public Long createIncentive(Long userId, BpmOAIncentiveCreateReqVO createReqVO) {
|
||||
|
||||
//插入OA 奖惩申请
|
||||
BpmOAIncentiveDO incentive = BpmOAIncentiveConvert.INSTANCE.convert(createReqVO).setUserId(userId)
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
incentiveMapper.insert(incentive) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(incentive.getId()))).getCheckedData();
|
||||
|
||||
// 将工作流的编号,更新到 OA 奖惩单中
|
||||
incentiveMapper.updateById(new BpmOAIncentiveDO().setId(incentive.getId()).setProcessInstanceId(processInstanceId));
|
||||
|
||||
List<UploadUserFile> fileItems = createReqVO.getFileItems() ;
|
||||
//这里的逻辑,如果fileItems不为空,且有数据,那么说明是上传了附件的,则需要更工作流文件表对应的实例Id
|
||||
if (fileItems != null && !fileItems.isEmpty()) {
|
||||
uploadBpmFileProcessInstanceId(processInstanceId,fileItems) ;
|
||||
}
|
||||
return incentive.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIncentiveResult(Long id, Integer result) {
|
||||
|
||||
validateLeaveExists(id);
|
||||
incentiveMapper.updateById(new BpmOAIncentiveDO().setId(id).setResult(result));
|
||||
}
|
||||
|
||||
private void validateLeaveExists(Long id) {
|
||||
if (incentiveMapper.selectById(id) == null) {
|
||||
throw exception(OA_INCENTIVE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BpmOAIncentiveDO getIncentive(Long id) {
|
||||
|
||||
return incentiveMapper.selectById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa.listener;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventListener;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveService;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveServiceImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* OA 奖惩的结果的监听器实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Component
|
||||
public class BpmOAIncentiveResultListener extends BpmProcessInstanceResultEventListener {
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveService incentiveService;
|
||||
|
||||
@Override
|
||||
protected String getProcessDefinitionKey() {
|
||||
return BpmOAIncentiveServiceImpl.PROCESS_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvent(BpmProcessInstanceResultEvent event) {
|
||||
incentiveService.updateIncentiveResult(Long.parseLong(event.getBusinessKey()), event.getResult());
|
||||
}
|
||||
}
|
@ -74,6 +74,9 @@ public interface ErrorCodeConstants {
|
||||
// ========== 通知公告 1-002-008-000 ==========
|
||||
ErrorCode NOTICE_NOT_FOUND = new ErrorCode(1_002_008_001, "当前通知公告不存在");
|
||||
|
||||
ErrorCode USER_GROUP_NOT_EXISTS = new ErrorCode(1_002_008_002, "用户组不存在");
|
||||
ErrorCode USER_GROUP_IS_DISABLE = new ErrorCode(1_002_008_003, "名字为【{}】的用户组已被禁用");
|
||||
|
||||
// ========== 短信渠道 1-002-011-000 ==========
|
||||
ErrorCode SMS_CHANNEL_NOT_EXISTS = new ErrorCode(1_002_011_000, "短信渠道不存在");
|
||||
ErrorCode SMS_CHANNEL_DISABLE = new ErrorCode(1_002_011_001, "短信渠道不处于开启状态,不允许选择");
|
||||
|
@ -1,14 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePushReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import cn.iocoder.yudao.module.system.service.notice.NoticeGroupService;
|
||||
import cn.iocoder.yudao.module.system.service.notice.NoticeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -32,7 +32,7 @@ public class NoticeController {
|
||||
private NoticeService noticeService;
|
||||
|
||||
@Resource
|
||||
private WebSocketSenderApi webSocketSenderApi;
|
||||
private NoticeGroupService groupService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建通知公告")
|
||||
@ -77,18 +77,16 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@PostMapping("/push")
|
||||
@Operation(summary = "推送通知公告", description = "只发送给 websocket 连接在线的用户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@Operation(summary = "推送通知公告")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:update')")
|
||||
public CommonResult<Boolean> push(@RequestParam("id") Long id) {
|
||||
NoticeDO notice = noticeService.getNotice(id);
|
||||
Assert.notNull(notice, "公告不能为空");
|
||||
public CommonResult<Boolean> push(@Valid @RequestBody NoticePushReqVO pushReqVO) {
|
||||
|
||||
// 通过 websocket 推送给在线的用户
|
||||
//webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), "notice-push", notice);
|
||||
|
||||
//小程序发送公告订阅消息
|
||||
//获取改造方式, push 方法传入需要推送的用户ID集合【 将ID集合查询出用户集合, 只获取openId的用户,进行推送 】
|
||||
noticeService.sendNotice(notice);
|
||||
noticeService.sendNotice(pushReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,110 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.notice.NoticeGroupConvert;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.notice.NoticeGroupService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
|
||||
@Tag(name = "管理后台 - 用户组")
|
||||
@RestController
|
||||
@RequestMapping("/system/notice/user-group")
|
||||
@Validated
|
||||
public class NoticeGroupController {
|
||||
|
||||
@Resource
|
||||
private NoticeGroupService userGroupService;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建用户组")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice-gropu:create')")
|
||||
public CommonResult<Long> createUserGroup(@Valid @RequestBody NoticeGroupCreateReqVO createReqVO) {
|
||||
return success(userGroupService.createUserGroup(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新用户组")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice-gropu:update')")
|
||||
public CommonResult<Boolean> updateUserGroup(@Valid @RequestBody NoticeGroupUpdateReqVO updateReqVO) {
|
||||
userGroupService.updateUserGroup(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除用户组")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:notice-gropu:delete')")
|
||||
public CommonResult<Boolean> deleteUserGroup(@RequestParam("id") Long id) {
|
||||
userGroupService.deleteUserGroup(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得用户组")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice-gropu:query')")
|
||||
public CommonResult<NoticeGroupRespVO> getUserGroup(@RequestParam("id") Long id) {
|
||||
|
||||
NoticeGroupDO userGroup = userGroupService.getUserGroup(id);
|
||||
|
||||
//获得用户信息
|
||||
List<AdminUserDO> userDOS = userService.getUserList(userGroup.getMemberUserIds());
|
||||
//获得部门信息 map
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(convertList(userDOS, AdminUserDO::getDeptId));
|
||||
|
||||
List<UserRespVO> userRespVOS = convertList(userDOS, user -> UserConvert.INSTANCE.convert(user, deptMap.get(user.getDeptId())));
|
||||
|
||||
NoticeGroupRespVO noticeGroupRespVO = NoticeGroupConvert.INSTANCE.convert(userGroup);
|
||||
noticeGroupRespVO.setUserInfo(userRespVOS);
|
||||
noticeGroupRespVO.setMemberDeptIds(deptMap.keySet());
|
||||
|
||||
return success(noticeGroupRespVO);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得用户组分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice-gropu:query')")
|
||||
public CommonResult<PageResult<NoticeGroupRespVO>> getUserGroupPage(@Valid NoticeGroupPageReqVO pageVO) {
|
||||
PageResult<NoticeGroupDO> pageResult = userGroupService.getUserGroupPage(pageVO);
|
||||
return success(NoticeGroupConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取用户组精简信息列表", description = "只包含被开启的用户组,主要用于前端的下拉选项")
|
||||
public CommonResult<List<NoticeGroupRespVO>> getSimpleUserGroups() {
|
||||
// 获用户门列表,只要开启状态的
|
||||
List<NoticeGroupDO> list = userGroupService.getUserGroupListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
// 排序后,返回给前端
|
||||
return success(NoticeGroupConvert.INSTANCE.convertList2(list));
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Schema(description = "公告推送信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NoticePushReqVO {
|
||||
|
||||
@Schema(description = "公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "推送类型 | 0:全员 1:部门 2:用户组", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "推送部门编号")
|
||||
private List<Long> deptIds;
|
||||
|
||||
@Schema(description = "推送用户组编号")
|
||||
private Set<Long> groupId;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo.group;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户组 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class NoticeGroupBaseVO {
|
||||
|
||||
@Schema(description = "组名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
||||
@NotNull(message = "组名不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
|
||||
@NotNull(message = "描述不能为空")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "成员编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3")
|
||||
@NotNull(message = "成员编号数组不能为空")
|
||||
private Set<Long> memberUserIds;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo.group;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 用户组创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class NoticeGroupCreateReqVO extends NoticeGroupBaseVO {
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo.group;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 用户组分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class NoticeGroupPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "组名", example = "芋道")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo.group;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Schema(description = "管理后台 - 用户组 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class NoticeGroupRespVO extends NoticeGroupBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "成员部门编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[126][128]")
|
||||
@NotNull(message = "成员部门编号数组不能为空")
|
||||
private Set<Long> memberDeptIds;
|
||||
|
||||
@Schema(description = "成员信息")
|
||||
private List<UserRespVO> userInfo;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notice.vo.group;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 用户组更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class NoticeGroupUpdateReqVO extends NoticeGroupBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@ -12,8 +12,8 @@ import java.util.Date;
|
||||
/**
|
||||
* 功能描述
|
||||
*
|
||||
* @author: yj
|
||||
* @date: 2024年04月07日 19:44
|
||||
* @author yj
|
||||
* date 2024年04月07日 19:44
|
||||
*/
|
||||
@Mapper
|
||||
public interface NoticeConvert {
|
||||
@ -27,14 +27,14 @@ public interface NoticeConvert {
|
||||
* @param miniProgramState 小程序的状态
|
||||
* @return
|
||||
*/
|
||||
default SubscribeMessageReqDTO convertCompanyNotice(String openId, NoticeDO notice, String nickname, String miniProgramState) {
|
||||
default SubscribeMessageReqDTO convertCompanyNotice(String openId, NoticeDO notice, String noticeLabel, String nickname, String miniProgramState) {
|
||||
SubscribeMessageReqDTO message = new SubscribeMessageReqDTO();
|
||||
message.setToUser(openId);
|
||||
message.setTemplateId("OF4-948Vz9rtE_VA55rmDxo4azOwmrjjk33jDpOiPiY");
|
||||
//通知类型
|
||||
MsgData noticeType = new MsgData();
|
||||
noticeType.setName("thing1");
|
||||
noticeType.setValue(notice.getType()+""); //这里根据业务需求填写具体的公告类型 如全员公告, xxx公告
|
||||
noticeType.setValue(noticeLabel); //这里根据业务需求填写具体的公告类型 如全员公告, xxx公告
|
||||
message.addData(noticeType);
|
||||
|
||||
//公告标题
|
||||
@ -67,7 +67,7 @@ public interface NoticeConvert {
|
||||
message.addData(createTime);
|
||||
|
||||
message.setMiniprogramState(miniProgramState);
|
||||
message.setPage("pages/index");
|
||||
message.setPage("/subPages/notice/detail?id=" + notice.getId());
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.system.convert.notice;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户组 Convert
|
||||
*
|
||||
|
||||
*/
|
||||
@Mapper
|
||||
public interface NoticeGroupConvert {
|
||||
|
||||
NoticeGroupConvert INSTANCE = Mappers.getMapper(NoticeGroupConvert.class);
|
||||
|
||||
NoticeGroupDO convert(NoticeGroupCreateReqVO bean);
|
||||
|
||||
NoticeGroupDO convert(NoticeGroupUpdateReqVO bean);
|
||||
|
||||
NoticeGroupRespVO convert(NoticeGroupDO bean);
|
||||
|
||||
List<NoticeGroupRespVO> convertList(List<NoticeGroupDO> list);
|
||||
|
||||
PageResult<NoticeGroupRespVO> convertPage(PageResult<NoticeGroupDO> page);
|
||||
|
||||
@Named("convertList2")
|
||||
List<NoticeGroupRespVO> convertList2(List<NoticeGroupDO> list);
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 公告推送 用户组
|
||||
*/
|
||||
@TableName(value = "system_notice_group", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NoticeGroupDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号,自增
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 组名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 成员用户编号数组
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> memberUserIds;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公告推送用户组 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface NoticeGroupMapper extends BaseMapperX<NoticeGroupDO> {
|
||||
|
||||
default PageResult<NoticeGroupDO> selectPage(NoticeGroupPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<NoticeGroupDO>()
|
||||
.likeIfPresent(NoticeGroupDO::getName, reqVO.getName())
|
||||
.eqIfPresent(NoticeGroupDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(NoticeGroupDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(NoticeGroupDO::getId));
|
||||
}
|
||||
|
||||
default List<NoticeGroupDO> selectListByStatus(Integer status) {
|
||||
return selectList(NoticeGroupDO::getStatus, status);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package cn.iocoder.yudao.module.system.service.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户组 Service 接口
|
||||
*
|
||||
|
||||
*/
|
||||
public interface NoticeGroupService {
|
||||
|
||||
/**
|
||||
* 创建用户组
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createUserGroup(@Valid NoticeGroupCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新用户组
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUserGroup(@Valid NoticeGroupUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除用户组
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUserGroup(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户组
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 用户组
|
||||
*/
|
||||
NoticeGroupDO getUserGroup(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户组列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 用户组列表
|
||||
*/
|
||||
List<NoticeGroupDO> getUserGroupList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定状态的用户组列表
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 用户组列表
|
||||
*/
|
||||
List<NoticeGroupDO> getUserGroupListByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 获得用户组分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 用户组分页
|
||||
*/
|
||||
PageResult<NoticeGroupDO> getUserGroupPage(NoticeGroupPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 校验用户组们是否有效。如下情况,视为无效:
|
||||
* 1. 用户组编号不存在
|
||||
* 2. 用户组被禁用
|
||||
*
|
||||
* @param ids 用户组编号数组
|
||||
*/
|
||||
void validUserGroups(Set<Long> ids);
|
||||
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package cn.iocoder.yudao.module.system.service.notice;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.group.NoticeGroupUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.notice.NoticeGroupConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeGroupMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_GROUP_IS_DISABLE;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_GROUP_NOT_EXISTS;
|
||||
|
||||
|
||||
/**
|
||||
* 用户组 Service 实现类
|
||||
*
|
||||
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class NoticeGroupServiceImpl implements NoticeGroupService {
|
||||
|
||||
@Resource
|
||||
private NoticeGroupMapper userGroupMapper;
|
||||
|
||||
@Override
|
||||
public Long createUserGroup(NoticeGroupCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
NoticeGroupDO userGroup = NoticeGroupConvert.INSTANCE.convert(createReqVO);
|
||||
userGroupMapper.insert(userGroup);
|
||||
// 返回
|
||||
return userGroup.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserGroup(NoticeGroupUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateUserGroupExists(updateReqVO.getId());
|
||||
// 更新
|
||||
NoticeGroupDO updateObj = NoticeGroupConvert.INSTANCE.convert(updateReqVO);
|
||||
userGroupMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long id) {
|
||||
// 校验存在
|
||||
this.validateUserGroupExists(id);
|
||||
// 删除
|
||||
userGroupMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateUserGroupExists(Long id) {
|
||||
if (userGroupMapper.selectById(id) == null) {
|
||||
throw exception(USER_GROUP_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoticeGroupDO getUserGroup(Long id) {
|
||||
return userGroupMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NoticeGroupDO> getUserGroupList(Collection<Long> ids) {
|
||||
return userGroupMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<NoticeGroupDO> getUserGroupListByStatus(Integer status) {
|
||||
return userGroupMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<NoticeGroupDO> getUserGroupPage(NoticeGroupPageReqVO pageReqVO) {
|
||||
return userGroupMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validUserGroups(Set<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得用户组信息
|
||||
List<NoticeGroupDO> userGroups = userGroupMapper.selectBatchIds(ids);
|
||||
Map<Long, NoticeGroupDO> userGroupMap = CollectionUtils.convertMap(userGroups, NoticeGroupDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
NoticeGroupDO userGroup = userGroupMap.get(id);
|
||||
if (userGroup == null) {
|
||||
throw exception(USER_GROUP_NOT_EXISTS);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(userGroup.getStatus())) {
|
||||
throw exception(USER_GROUP_IS_DISABLE, userGroup.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.service.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePushReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
|
||||
@ -50,7 +51,7 @@ public interface NoticeService {
|
||||
|
||||
/**
|
||||
* 小程序发送公告订阅消息
|
||||
* @param notice
|
||||
* @param pushReqVO 推送信息
|
||||
*/
|
||||
void sendNotice(NoticeDO notice) ;
|
||||
void sendNotice(NoticePushReqVO pushReqVO) ;
|
||||
}
|
||||
|
@ -7,18 +7,24 @@ import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePushReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeGroupDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper;
|
||||
import cn.iocoder.yudao.module.system.service.dict.DictDataService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
|
||||
@ -35,9 +41,15 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
@Resource
|
||||
private NoticeMapper noticeMapper;
|
||||
|
||||
@Resource
|
||||
private NoticeGroupService noticeGroupService;
|
||||
|
||||
@Resource(name = NOTIFY_THREAD_POOL_TASK_EXECUTOR)
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public Long createNotice(NoticeSaveReqVO createReqVO) {
|
||||
NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class);
|
||||
@ -90,25 +102,55 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
private SubscribeMessageSendApi subscribeMessageSendApi;
|
||||
|
||||
@Override
|
||||
public void sendNotice(NoticeDO notice) {
|
||||
public void sendNotice(NoticePushReqVO pushReqVO) {
|
||||
|
||||
//获得公告信息
|
||||
NoticeDO notice = getNotice(pushReqVO.getId());
|
||||
if (notice == null) {
|
||||
throw exception(NOTICE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 获得公告类型 字典label
|
||||
DictDataDO dictDataDO = dictDataService.getDictData("system_notice_type", String.valueOf(notice.getType()));
|
||||
|
||||
//获取当前登陆用户的名称
|
||||
LoginUser user = SecurityFrameworkUtils.getLoginUser() ;
|
||||
AdminUserDO currentUser = userService.getUser(user.getId()) ;
|
||||
|
||||
//查询所有状态是开启的用户
|
||||
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
for(AdminUserDO adminUserDO : list) {
|
||||
List<AdminUserDO> userDOs = new ArrayList<>();
|
||||
switch (pushReqVO.getType()) {
|
||||
|
||||
//全员推送
|
||||
case 0:
|
||||
//获得用户信息
|
||||
userDOs = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
break;
|
||||
//部门推送
|
||||
case 1:
|
||||
//获得用户信息
|
||||
userDOs = userService.getUserListByDeptIds(pushReqVO.getDeptIds());
|
||||
break;
|
||||
//用户组推送
|
||||
case 2:
|
||||
//获得用户组信息
|
||||
List<NoticeGroupDO> groupDOs = noticeGroupService.getUserGroupList(pushReqVO.getGroupId());
|
||||
|
||||
//获得用户组中 用户信息
|
||||
userDOs = userService.getUserList(groupDOs.stream().flatMap(group -> group.getMemberUserIds().stream()).collect(Collectors.toSet()));
|
||||
break;
|
||||
}
|
||||
|
||||
for(AdminUserDO adminUserDO : userDOs) {
|
||||
if( adminUserDO.getOpenId() != null && !adminUserDO.getOpenId().isEmpty()) {
|
||||
// System.out.println("====" + adminUserDO.getNickname());
|
||||
|
||||
threadPoolTaskExecutor.execute(() -> {
|
||||
|
||||
//获取openId有值的用户
|
||||
subscribeMessageSendApi.sendCompanyNotice(NoticeConvert.INSTANCE.convertCompanyNotice(
|
||||
adminUserDO.getOpenId(), notice , currentUser.getNickname(),
|
||||
adminUserDO.getOpenId(), notice, dictDataDO.getLabel(), currentUser.getNickname(),
|
||||
"formal"));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user