|  |  | 
 |  |  | package com.zy.asrs.wms.system.controller; | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.common.R; | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog; | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam; | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo; | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam; | 
 |  |  | import com.zy.asrs.wms.system.entity.UserLogin; | 
 |  |  | import com.zy.asrs.wms.system.service.UserLoginService; | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletResponse; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Arrays; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  | @RestController | 
 |  |  | @RequestMapping("/api") | 
 |  |  | public class UserLoginController extends BaseController { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private UserLoginService userLoginService; | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')") | 
 |  |  |     @PostMapping("/userLogin/page") | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) { | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<UserLogin, BaseParam> pageParam = new PageParam<>(baseParam, UserLogin.class); | 
 |  |  |         return R.ok().add(userLoginService.page(pageParam, pageParam.buildWrapper(true))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')") | 
 |  |  |     @PostMapping("/userLogin/list") | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) { | 
 |  |  |         return R.ok().add(userLoginService.list()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')") | 
 |  |  |     @GetMapping("/userLogin/{id}") | 
 |  |  |     public R get(@PathVariable("id") Long id) { | 
 |  |  |         return R.ok().add(userLoginService.getById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:save')") | 
 |  |  |     @OperationLog("添加登录日志") | 
 |  |  |     @PostMapping("/userLogin/save") | 
 |  |  |     public R save(@RequestBody UserLogin userLogin) { | 
 |  |  |         if (!userLoginService.save(userLogin)) { | 
 |  |  |             return R.error("添加失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("添加成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:update')") | 
 |  |  |     @OperationLog("修改登录日志") | 
 |  |  |     @PostMapping("/userLogin/update") | 
 |  |  |     public R update(@RequestBody UserLogin userLogin) { | 
 |  |  |         if (!userLoginService.updateById(userLogin)) { | 
 |  |  |             return R.error("修改失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("修改成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:remove')") | 
 |  |  |     @OperationLog("删除登录日志") | 
 |  |  |     @PostMapping("/userLogin/remove/{ids}") | 
 |  |  |     public R remove(@PathVariable Long[] ids) { | 
 |  |  |         if (!userLoginService.removeByIds(Arrays.asList(ids))) { | 
 |  |  |             return R.error("删除失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("删除成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')") | 
 |  |  |     @PostMapping("/userLogin/query") | 
 |  |  |     public R query(@RequestParam(required = false) String condition) { | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>(); | 
 |  |  |         LambdaQueryWrapper<UserLogin> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(UserLogin::getToken, condition); | 
 |  |  |         } | 
 |  |  |         userLoginService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getToken())) | 
 |  |  |         ); | 
 |  |  |         return R.ok().add(vos); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')") | 
 |  |  |     @PostMapping("/userLogin/export") | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(userLoginService.list(), UserLogin.class), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  | package com.zy.asrs.wms.system.controller;
 | 
 |  |  | 
 | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
 |  |  | import com.zy.asrs.framework.common.Cools;
 | 
 |  |  | import com.zy.asrs.framework.common.R;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.CacheData;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam;
 | 
 |  |  | import com.zy.asrs.wms.system.entity.UserLogin;
 | 
 |  |  | import com.zy.asrs.wms.system.service.UserLoginService;
 | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil;
 | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize;
 | 
 |  |  | import org.springframework.web.bind.annotation.*;
 | 
 |  |  | 
 | 
 |  |  | import javax.servlet.http.HttpServletResponse;
 | 
 |  |  | import java.util.ArrayList;
 | 
 |  |  | import java.util.Arrays;
 | 
 |  |  | import java.util.List;
 | 
 |  |  | import java.util.Map;
 | 
 |  |  | 
 | 
 |  |  | @RestController
 | 
 |  |  | @RequestMapping("/api")
 | 
 |  |  | public class UserLoginController extends BaseController {
 | 
 |  |  | 
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private UserLoginService userLoginService;
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')")
 | 
 |  |  |     @PostMapping("/userLogin/page")
 | 
 |  |  |     @CacheData(tableName = {"sys_user_login"})
 | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<UserLogin, BaseParam> pageParam = new PageParam<>(baseParam, UserLogin.class);
 | 
 |  |  |         return R.ok().add(userLoginService.page(pageParam, pageParam.buildWrapper(true)));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')")
 | 
 |  |  |     @PostMapping("/userLogin/list")
 | 
 |  |  |     @CacheData(tableName = {"sys_user_login"})
 | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         return R.ok().add(userLoginService.list());
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')")
 | 
 |  |  |     @GetMapping("/userLogin/{id}")
 | 
 |  |  |     @CacheData(tableName = {"sys_user_login"})
 | 
 |  |  |     public R get(@PathVariable("id") Long id) {
 | 
 |  |  |         return R.ok().add(userLoginService.getById(id));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:save')")
 | 
 |  |  |     @OperationLog("添加登录日志")
 | 
 |  |  |     @PostMapping("/userLogin/save")
 | 
 |  |  |     public R save(@RequestBody UserLogin userLogin) {
 | 
 |  |  |         if (!userLoginService.save(userLogin)) {
 | 
 |  |  |             return R.error("添加失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("添加成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:update')")
 | 
 |  |  |     @OperationLog("修改登录日志")
 | 
 |  |  |     @PostMapping("/userLogin/update")
 | 
 |  |  |     public R update(@RequestBody UserLogin userLogin) {
 | 
 |  |  |         if (!userLoginService.updateById(userLogin)) {
 | 
 |  |  |             return R.error("修改失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("修改成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:remove')")
 | 
 |  |  |     @OperationLog("删除登录日志")
 | 
 |  |  |     @PostMapping("/userLogin/remove/{ids}")
 | 
 |  |  |     public R remove(@PathVariable Long[] ids) {
 | 
 |  |  |         if (!userLoginService.removeByIds(Arrays.asList(ids))) {
 | 
 |  |  |             return R.error("删除失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("删除成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')")
 | 
 |  |  |     @PostMapping("/userLogin/query")
 | 
 |  |  |     public R query(@RequestParam(required = false) String condition) {
 | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>();
 | 
 |  |  |         LambdaQueryWrapper<UserLogin> wrapper = new LambdaQueryWrapper<>();
 | 
 |  |  |         if (!Cools.isEmpty(condition)) {
 | 
 |  |  |             wrapper.like(UserLogin::getToken, condition);
 | 
 |  |  |         }
 | 
 |  |  |         userLoginService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
 | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getToken()))
 | 
 |  |  |         );
 | 
 |  |  |         return R.ok().add(vos);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:userLogin:list')")
 | 
 |  |  |     @PostMapping("/userLogin/export")
 | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<UserLogin, BaseParam> pageParam = new PageParam<>(baseParam, UserLogin.class);
 | 
 |  |  |         List<UserLogin> data = userLoginService.list(pageParam.buildWrapper(true));
 | 
 |  |  | 
 | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(data, UserLogin.class), response);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | }
 |