| | |
| | | package com.linghu.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.handler.SheetWriteHandler; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
| | | import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.linghu.listener.PlatformExcelListener; |
| | | import com.linghu.listener.UserExcelListener; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.entity.Platform; |
| | | 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.ExcelDataWithRow; |
| | | import com.linghu.model.excel.PlatformExcel; |
| | | import com.linghu.model.excel.UserExcel; |
| | | import com.linghu.model.vo.UserPageVO; |
| | | import com.linghu.service.SectionalizationService; |
| | | import com.linghu.service.UserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DataValidationHelper; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/user") |
| | |
| | | |
| | | @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(); |
| | | public ResponseResult add(@Valid @RequestBody User user) { |
| | | return userService.addUser(user); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @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(); |
| | | @ApiOperation(value = "修改") |
| | | public ResponseResult edit(@Valid @RequestBody User user) { |
| | | return userService.editUser(user); |
| | | |
| | | } |
| | | |
| | |
| | | * 分页查询 |
| | | */ |
| | | @GetMapping |
| | | @ApiOperation(value = "删除") |
| | | @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") |
| | | @GetMapping("/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()); |
| | | return userService.downloadUser(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入文件 |
| | | */ |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/importUserExcel") |
| | | @ApiOperation("导入用户数据") |
| | | public ResponseResult importUserExcel(@RequestParam("file") MultipartFile file) { |
| | | return userService.importUser(file); |
| | | } |
| | | } |