xiangpei
2025-06-12 8bfcdc67288b607e333da334ec84abc58ff6dfc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package cn.lili.controller.setting;
 
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.enums.SwitchEnum;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.BeanUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.message.entity.dos.NoticeMessage;
import cn.lili.modules.message.entity.dto.NoticeMessageDetailDTO;
import cn.lili.modules.message.entity.enums.NoticeMessageParameterEnum;
import cn.lili.modules.message.service.NoticeMessageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.elasticsearch.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 管理端,会员站内信管理接口
 *
 * @author Chopper
 * @since 2020/11/17 4:31 下午
 */
@Slf4j
@RestController
@Api(tags = "管理端,会员站内信管理接口")
@RequestMapping("/manager/setting/noticeMessage")
public class NoticeMessageManagerController {
    @Autowired
    private NoticeMessageService noticeMessageService;
 
    @ApiOperation(value = "消息模板分页")
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "消息类型", dataType = "String", paramType = "query",
                    allowableValues = "MEMBER,OTHER,STORE,WECHAT", allowMultiple = true)
    })
    public ResultMessage<IPage<NoticeMessage>> getPage(PageVO pageVO, String type) {
        return ResultUtil.data(noticeMessageService.getMessageTemplate(pageVO, type));
    }
 
 
    @ApiOperation(value = "根据id获取通知详情")
    @ApiImplicitParam(name = "id", value = "模板id", dataType = "String", paramType = "path")
    @GetMapping("/{id}")
    public ResultMessage<NoticeMessageDetailDTO> get(@PathVariable String id) {
        //根据id获取当前消息模板
        NoticeMessage noticeMessage = noticeMessageService.getById(id);
        if (noticeMessage != null) {
            NoticeMessageDetailDTO noticeMessageDetailDTO = new NoticeMessageDetailDTO();
            BeanUtil.copyProperties(noticeMessage, noticeMessageDetailDTO);
            //组织消息变量
            String[] variableNames = noticeMessage.getVariable().split(",");
            //定义返回参数中变量列表
            List<String> variableValues = new ArrayList<>();
            //循环消息变量赋值
            if (variableNames.length > 0) {
                for (String variableName : variableNames) {
                    if (NoticeMessageParameterEnum.getValueByType(variableName) != null) {
                        variableValues.add(NoticeMessageParameterEnum.getValueByType(variableName));
                    }
                }
                noticeMessageDetailDTO.setVariables(variableValues);
            }
 
            return ResultUtil.data(noticeMessageDetailDTO);
        }
        throw new ResourceNotFoundException(ResultCode.NOTICE_NOT_EXIST.message());
    }
 
 
    @ApiOperation(value = "修改站内信模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeContent", value = "站内信内容", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "noticeTitle", value = "站内信模板标题", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "模板id", dataType = "String", paramType = "path")
    })
    @PutMapping("/{id}")
    public ResultMessage<NoticeMessage> updateNoticeTemplate(@RequestParam String noticeContent,
                                                             @RequestParam String noticeTitle,
                                                             @PathVariable String id) {
        //根据id获取当前消息模板
        NoticeMessage noticeMessage = noticeMessageService.getById(id);
        if (noticeMessage != null) {
            noticeMessage.setNoticeContent(noticeContent);
            noticeMessage.setNoticeTitle(noticeTitle);
            noticeMessageService.updateById(noticeMessage);
            return ResultUtil.data(noticeMessage);
        }
        throw new ResourceNotFoundException(ResultCode.NOTICE_NOT_EXIST.message());
    }
 
    @ApiOperation(value = "修改站内信状态")
 
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "站内信状态", dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "站内信状态", dataType = "String", paramType = "path")
    })
    @PutMapping("/{id}/{status}")
    public ResultMessage<NoticeMessage> status(@PathVariable String id, @PathVariable String status) {
        //根据id获取当前消息模板
        NoticeMessage messageTemplate = noticeMessageService.getById(id);
        if (messageTemplate != null) {
            //校验传递站内信是否符合规范
            Boolean b = EnumUtils.isValidEnum(SwitchEnum.class, status);
            if (b) {
                //赋值执行修改操作
                messageTemplate.setNoticeStatus(status);
                noticeMessageService.updateById(messageTemplate);
                return ResultUtil.data(messageTemplate);
            }
            throw new ServiceException(ResultCode.NOTICE_ERROR);
        }
        throw new ResourceNotFoundException(ResultCode.NOTICE_NOT_EXIST.message());
    }
 
}