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, "导入成功!");
|
}
|
}
|