puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.sinata.shop.modular.mall.controller;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import com.sinata.shop.core.common.annotion.BussinessLog;
import com.sinata.shop.core.common.annotion.Permission;
import com.sinata.shop.core.common.constant.factory.PageFactory;
import com.sinata.shop.core.log.LogObjectHolder;
import com.sinata.shop.core.shiro.ShiroKit;
import com.sinata.shop.modular.mall.model.TNotice;
import com.sinata.shop.modular.mall.service.ITNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 公告信息控制器
 *
 * @author goku
 */
@Controller
@RequestMapping("/tNotice")
public class TNoticeController extends BaseController {
 
    private String PREFIX = "/mall/tNotice/";
 
    @Autowired
    private ITNoticeService tNoticeService;
 
    /**
     * 跳转到公告信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tNotice.html";
    }
 
    /**
     * 跳转到添加公告信息
     */
    @RequestMapping("/tNotice_add")
    public String tNoticeAdd() {
        return PREFIX + "tNotice_add.html";
    }
 
    /**
     * 跳转到修改公告信息
     */
    @RequestMapping("/tNotice_update/{tNoticeId}")
    public String tNoticeUpdate(@PathVariable Integer tNoticeId, Model model) {
        TNotice tNotice = tNoticeService.selectById(tNoticeId);
        model.addAttribute("item", tNotice);
        LogObjectHolder.me().set(tNotice);
        return PREFIX + "tNotice_edit.html";
    }
 
    /**
     * 获取公告信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String title) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
        Integer merchantId = ShiroKit.getUserId();
        Wrapper<TNotice> wrapper = new EntityWrapper<TNotice>()
                .setSqlSelect("id", "title", "cover_plan", "content", "create_time")
                .orderBy("id", false)
                .addFilter("id in (SELECT other_id from t_notice_message WHERE user_type=2 and type =2 and user_id = {0})", merchantId)
                .like(StrUtil.isNotBlank(title), "title", title)
                .ge(StrUtil.isNotBlank(beginTime), "create_time", beginTime + " 00:00:00")
                .le(StrUtil.isNotBlank(endTime), "create_time", endTime + " 23:59:59");
 
        // 查询数据列表
        List<Map<String, Object>> list = tNoticeService.selectMapsPage(page, wrapper).getRecords();
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
 
    /**
     * 获取公告信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/export")
    public void list(String beginTime, String endTime, String title, HttpServletResponse response) throws IOException {
        Integer merchantId = ShiroKit.getUserId();
        Wrapper<TNotice> wrapper = new EntityWrapper<TNotice>()
                .orderBy("id", false)
                .addFilter("id in (SELECT other_id from t_notice_message WHERE user_type=2 and type =2 and user_id = {0})", merchantId)
                .like(StrUtil.isNotBlank(title), "title", title)
                .ge(StrUtil.isNotBlank(beginTime), "create_time", beginTime + " 00:00:00")
                .le(StrUtil.isNotBlank(endTime), "create_time", endTime + " 23:59:59");
        List<TNotice> notices = this.tNoticeService.selectList(wrapper);
 
        List<List<Object>> dataList = new ArrayList<>();
        List<Object> titles = CollUtil.newArrayList("发布时间", "公告标题", "公告详情");
        dataList.add(titles);
 
        for (TNotice notice : notices) {
            dataList.add(CollUtil.newArrayList(DateUtil.format(notice.getCreateTime(), "YYYY-MM-dd HH:mm"),
                    notice.getTitle(),
                    notice.getContent()));
        }
        ExcelExportUtil.easySheet("导出数据" + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
    }
 
    /**
     * 新增公告信息
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "新增公告信息")
    @RequestMapping(value = "/add")
    public Object add(TNotice tNotice) {
        tNoticeService.insert(tNotice);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除/批量删除
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "删除/批量删除公告信息")
    @RequestMapping(value = "/delete")
    public Object delete(@RequestParam String ids) {
        // 逻辑删除
        tNoticeService.updateForSet("is_delete = 1", new EntityWrapper<TNotice>().in("id", ids.split(",")));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改公告信息
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "修改公告信息")
    @RequestMapping(value = "/update")
    public Object update(TNotice tNotice) {
        tNoticeService.updateById(tNotice);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改公告信息状态
     */
    @ResponseBody
    @BussinessLog(value = "修改公告信息状态")
    @RequestMapping(value = "/updateState")
    public Object updateState(Integer tNoticeId, Integer state) {
        tNoticeService.updateForSet("state = " + state, new EntityWrapper<TNotice>().eq("id", tNoticeId));
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转公告信息详情
     */
    @RequestMapping(value = "/detail/{tNoticeId}")
    public Object detail(@PathVariable("tNoticeId") Integer tNoticeId, Model model) {
        TNotice tNotice = tNoticeService.selectById(tNoticeId);
        model.addAttribute("item", tNotice);
        return PREFIX + "tNotice_detail.html";
    }
}