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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.sinata.shop.modular.system.controller;
 
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.base.tips.ErrorTip;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import com.sinata.core.util.ExcelImportUtil;
import com.sinata.core.util.ToolUtil;
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.modular.system.model.AaaTest;
import com.sinata.shop.modular.system.service.IAaaTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
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("/aaaTest")
public class AaaTestController extends BaseController {
 
    private String PREFIX = "/system/aaaTest/";
 
    @Autowired
    private IAaaTestService aaaTestService;
 
    /**
     * 跳转到示例功能首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "aaaTest.html";
    }
 
    /**
     * 跳转到添加示例功能
     */
    @RequestMapping("/aaaTest_add")
    public String aaaTestAdd() {
        return PREFIX + "aaaTest_add.html";
    }
 
    /**
     * 跳转到修改示例功能
     */
    @RequestMapping("/aaaTest_update/{aaaTestId}")
    public String aaaTestUpdate(@PathVariable Integer aaaTestId, Model model) {
        AaaTest aaaTest = aaaTestService.selectById(aaaTestId);
        model.addAttribute("item",aaaTest);
        LogObjectHolder.me().set(aaaTest);
        return PREFIX + "aaaTest_edit.html";
    }
 
    /**
     * 获取示例功能列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String phone, Integer isLock, String beginTime, String endTime) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
        Wrapper wrapper = new EntityWrapper<AaaTest>().orderBy("id", false);
 
        // 搜索条件
        if (ToolUtil.isNotEmpty(phone)) {
            wrapper.like("phone", phone);
        }
        if (ToolUtil.isNotEmpty(isLock) && isLock != -1) {
            wrapper.and().eq("isLock", isLock);
        }
        // 创建时间
        if (ToolUtil.isNotEmpty(beginTime)) {
            wrapper.ge("create_time", beginTime + " 00:00:00");
        }
        if (ToolUtil.isNotEmpty(endTime)) {
            wrapper.le("create_time", endTime + " 23:59:59");
        }
 
        // 查询数据列表
        List<Map<String, Object>> list = aaaTestService.selectMapsPage(page, wrapper).getRecords();
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    /**
     * 新增示例功能
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "新增示例功能")
    @RequestMapping(value = "/add")
    public Object add(AaaTest aaaTest) {
        aaaTestService.insert(aaaTest);
        return SUCCESS_TIP;
    }
    /**
     * 删除/批量删除
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "删除/批量删除示例功能")
    @RequestMapping(value = "/delete")
    public Object delete(@RequestParam String ids) {
        // 逻辑删除
        aaaTestService.updateForSet("isDelete = 1", new EntityWrapper<AaaTest>().in("id", ids.split(",")));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改示例功能
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "修改示例功能")
    @RequestMapping(value = "/update")
    public Object update(AaaTest aaaTest) {
        System.out.println(aaaTest);
        aaaTestService.updateById(aaaTest);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改示例功能状态
     */
    //@Permission
    @ResponseBody
    @BussinessLog(value = "修改示例功能状态")
    @RequestMapping(value = "/updateState")
    public Object updateState(Integer aaaTestId, Integer state) {
        aaaTestService.updateForSet("isLock = " + state, new EntityWrapper<AaaTest>().eq("id", aaaTestId));
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转示例功能详情
     */
    @RequestMapping(value = "/detail/{aaaTestId}")
    public Object detail(@PathVariable("aaaTestId") Integer aaaTestId, Model model) {
        AaaTest aaaTest = aaaTestService.selectById(aaaTestId);
        model.addAttribute("item",aaaTest);
        return PREFIX + "aaaTest_detail.html";
    }
 
    /**
     * 导出用户信息列表
     */
    @RequestMapping(value = "/export")
    @ResponseBody
    public void export(String phone, HttpServletResponse response) {
        Wrapper wrapper = new EntityWrapper<AaaTest>();
        if (ToolUtil.isNotEmpty(phone)) {
            wrapper.eq("phone", phone);
        }
        List<Map<String, Object>> list = aaaTestService.selectMaps(wrapper);
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("手机号");
        shellList.add("说明");
        shellList.add("注册时间");
        dataList.add(shellList);
 
        // 详细数据列【封装】
        for (Map<String, Object> map : list) {
            shellList = new ArrayList<>();
            shellList.add(map.get("phone"));
            shellList.add(map.get("textMark"));
            shellList.add(map.get("createTime"));
            dataList.add(shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("导出数据"+ DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 跳转到导入页面
     */
    @RequestMapping("/import")
    public String toImport() {
        return PREFIX + "import.html";
    }
 
    /**
     * 上传导入数据
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, path = "/importData")
    public Object importData(@RequestPart("file") MultipartFile file) {
        try {
            String[] titles = new String[]{"phone", "textMark", "createTime"};
            // 读取表格中信息
            List<Map<String, String>> list = ExcelImportUtil.getMapList(file, titles);
            for (Map<String, String> map : list) {
                AaaTest o = new AaaTest();
                o.setPhone(map.get("phone"));
                o.setTextMark(map.get("textMark"));
                o.setCreateTime(new Date());
                aaaTestService.insert(o);
            }
        } catch (IOException e) {
            e.printStackTrace();
            // 操作失败
            return new ErrorTip(500, "数据导入失败!");
        }
        // 操作成功,但有错误数据的提示
        return new ErrorTip(200, "导入成功!");
    }
}