| | |
| | | package com.linghu.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.entity.Sectionalization; |
| | | import com.linghu.model.entity.Type; |
| | | import com.linghu.model.entity.User; |
| | | import com.linghu.model.excel.KeywordExcel; |
| | | import com.linghu.model.excel.UserExcel; |
| | | import com.linghu.model.vo.UserPageVO; |
| | | import com.linghu.service.UserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @RequestMapping("/user") |
| | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | /* |
| | | @PostMapping |
| | | @ApiOperation(value = "添加类型") |
| | | public ResponseResult<User> add(@RequestBody User user) { |
| | | boolean success = typeService.save(type); |
| | | if (success) { |
| | | return ResponseResult.success(type); |
| | | } |
| | | return ResponseResult.error("添加类型失败"); |
| | | } |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加") |
| | | public ResponseResult add(@RequestBody User user) { |
| | | List<User> list = userService.list(new LambdaQueryWrapper<User>().eq(User::getUser_email, user.getUser_email())); |
| | | if (list != null && list.size() > 0) { |
| | | return ResponseResult.error("该邮箱已存在"); |
| | | } |
| | | userService.save(user); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @PutMapping |
| | | @ApiOperation(value = "添加") |
| | | public ResponseResult edit(@RequestBody User user) { |
| | | List<User> list = userService.list(new LambdaQueryWrapper<User>() |
| | | .ne(User::getUser_id, user.getUser_id()) |
| | | .eq(User::getUser_email, user.getUser_email())); |
| | | if (list != null && list.size() > 0) { |
| | | return ResponseResult.error("该邮箱已存在"); |
| | | } |
| | | userService.updateById(user); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除用户 |
| | | */ |
| | | |
| | | @DeleteMapping("/{user_id}") |
| | | @ApiOperation(value = "删除") |
| | | public ResponseResult delete(@PathVariable("user_id") Integer user_id) { |
| | | userService.removeById(user_id); |
| | | return ResponseResult.success(); |
| | | |
| | | } |
| | | /** |
| | | * 分页查询 |
| | | */ |
| | | @GetMapping |
| | | @ApiOperation(value = "删除") |
| | | public ResponseResult<Page<UserPageVO>> page(@RequestParam(value = "pageSize", required = false, defaultValue = "10")Integer pageSize, |
| | | @RequestParam(value = "pageNum", required = false,defaultValue = "1")Integer pageNum, |
| | | @RequestParam(value = "sectionalization_id",required = false)Integer sectionalization_id, |
| | | @RequestParam(value = "status" ,required = false)String status) { |
| | | Page<UserPageVO> page = new Page<>(pageNum, pageSize); |
| | | return ResponseResult.success( userService.getPage(page,sectionalization_id,status)); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 下载模板 |
| | | */ |
| | | |
| | | @PostMapping("/downloadTemplate") |
| | | @ApiOperation("下载模板") |
| | | public ResponseEntity<byte[]> downloadTemplate() throws IOException { |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, UserExcel.class).sheet("账号模板").doWrite(new ArrayList<>()); |
| | | |
| | | return ResponseEntity.ok() |
| | | .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=keyword_template.xlsx") |
| | | .contentType(MediaType.APPLICATION_OCTET_STREAM) |
| | | .body(out.toByteArray()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入文件 |
| | | */ |
| | | |
| | | |
| | | |
| | | |
| | | } |