| | |
| | | package com.ots.project.demo.controller; |
| | | |
| | | import com.ots.common.exception.BusinessException; |
| | | import com.ots.common.utils.StringUtils; |
| | | import com.ots.common.utils.poi.ExcelUtil; |
| | |
| | | import org.springframework.ui.ModelMap; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 操作控制 |
| | | * |
| | | * @author ots |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/demo/operate") |
| | | public class DemoOperateController extends BaseController { |
| | | private String prefix = "demo/operate"; |
| | | |
| | | private final static Map<Integer, UserOperateModel> users = new LinkedHashMap<Integer, UserOperateModel>(); |
| | | |
| | | { |
| | | users.put(1, new UserOperateModel(1, "1000001", "测试1", "0", "15888888888", "ry@qq.com", 150.0, "0")); |
| | | users.put(2, new UserOperateModel(2, "1000002", "测试2", "1", "15666666666", "ry@qq.com", 180.0, "1")); |
| | |
| | | users.put(26, new UserOperateModel(26, "1000026", "测试26", "1", "15666666666", "ry@qq.com", 250.0, "1")); |
| | | } |
| | | |
| | | /** |
| | | * 表格 |
| | | */ |
| | | @GetMapping("/table") |
| | | public String table() { |
| | | return prefix + "/table"; |
| | | } |
| | | |
| | | /** |
| | | * 其他 |
| | | */ |
| | | @GetMapping("/other") |
| | | public String other() { |
| | | return prefix + "/other"; |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | */ |
| | | @PostMapping("/list") |
| | | @ResponseBody |
| | | public TableDataInfo list(UserOperateModel userModel) { |
| | | TableDataInfo rspData = new TableDataInfo(); |
| | | List<UserOperateModel> userList = new ArrayList<UserOperateModel>(users.values()); |
| | | |
| | | // 查询条件过滤 |
| | | if (StringUtils.isNotEmpty(userModel.getSearchValue())) { |
| | | userList.clear(); |
| | | for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet()) { |
| | |
| | | return rspData; |
| | | } |
| | | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | @GetMapping("/add") |
| | | public String add(ModelMap mmap) { |
| | | return prefix + "/add"; |
| | | } |
| | | |
| | | /** |
| | | * 新增保存用户 |
| | | */ |
| | | @PostMapping("/add") |
| | | @ResponseBody |
| | | public AjaxResult addSave(UserOperateModel user) { |
| | |
| | | return AjaxResult.success(users.put(userId, user)); |
| | | } |
| | | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @GetMapping("/edit/{userId}") |
| | | public String edit(@PathVariable("userId") Integer userId, ModelMap mmap) { |
| | | mmap.put("user", users.get(userId)); |
| | | return prefix + "/edit"; |
| | | } |
| | | |
| | | /** |
| | | * 修改保存用户 |
| | | */ |
| | | @PostMapping("/edit") |
| | | @ResponseBody |
| | | public AjaxResult editSave(UserOperateModel user) { |
| | | return AjaxResult.success(users.put(user.getUserId(), user)); |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | */ |
| | | @PostMapping("/export") |
| | | @ResponseBody |
| | | public AjaxResult export(UserOperateModel user) { |
| | |
| | | return util.exportExcel(list, "用户数据"); |
| | | } |
| | | |
| | | /** |
| | | * 下载模板 |
| | | */ |
| | | @GetMapping("/importTemplate") |
| | | @ResponseBody |
| | | public AjaxResult importTemplate() { |
| | |
| | | return util.importTemplateExcel("用户数据"); |
| | | } |
| | | |
| | | /** |
| | | * 导入数据 |
| | | */ |
| | | @PostMapping("/importData") |
| | | @ResponseBody |
| | | public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { |
| | |
| | | return AjaxResult.success(message); |
| | | } |
| | | |
| | | /** |
| | | * 删除用户 |
| | | */ |
| | | @PostMapping("/remove") |
| | | @ResponseBody |
| | | public AjaxResult remove(String ids) { |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 查看详细 |
| | | */ |
| | | @GetMapping("/detail/{userId}") |
| | | public String detail(@PathVariable("userId") Integer userId, ModelMap mmap) { |
| | | mmap.put("user", users.get(userId)); |
| | | return prefix + "/detail"; |
| | | } |
| | | |
| | | @PostMapping("/clean") |
| | | @ResponseBody |
| | | public AjaxResult clean() { |
| | |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * 导入用户数据 |
| | | * |
| | | * @param userList 用户数据列表 |
| | | * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 |
| | | * @return 结果 |
| | | */ |
| | | public String importUser(List<UserOperateModel> userList, Boolean isUpdateSupport) { |
| | | if (StringUtils.isNull(userList) || userList.size() == 0) { |
| | | throw new BusinessException("Import user data cannot be empty!"); |
| | |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | for (UserOperateModel user : userList) { |
| | | try { |
| | | |
| | | // 验证是否存在这个用户 |
| | | boolean userFlag = false; |
| | | for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet()) { |
| | | if (entry.getValue().getUserName().equals(user.getUserName())) { |