|
@@ -0,0 +1,156 @@
|
|
|
|
+package com.xjrsoft.module.base.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
|
+import com.xjrsoft.common.page.ConventPage;
|
|
|
|
+import com.xjrsoft.common.page.PageOutput;
|
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
|
+import com.xjrsoft.module.base.dto.AddWhitelistManagementDto;
|
|
|
|
+import com.xjrsoft.module.base.dto.UpdateWhitelistManagementDto;
|
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.xjrsoft.module.base.entity.TreeNode;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+
|
|
|
|
+import com.xjrsoft.module.base.dto.WhitelistManagementPageDto;
|
|
|
|
+import com.xjrsoft.module.base.entity.WhitelistManagement;
|
|
|
|
+import com.xjrsoft.module.base.service.IWhitelistManagementService;
|
|
|
|
+import com.xjrsoft.module.base.vo.WhitelistManagementPageVo;
|
|
|
|
+
|
|
|
|
+import com.xjrsoft.module.base.vo.WhitelistManagementVo;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* @title: 白名单管理
|
|
|
|
+* @Author brealinxx
|
|
|
|
+* @Date: 2024-06-24
|
|
|
|
+* @Version 1.0
|
|
|
|
+*/
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/base" + "/whitelistManagement")
|
|
|
|
+@Api(value = "/base" + "/whitelistManagement",tags = "白名单管理代码")
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+public class WhitelistManagementController {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(WhitelistManagementController.class);
|
|
|
|
+ private final IWhitelistManagementService whitelistManagementService;
|
|
|
|
+
|
|
|
|
+ @GetMapping(value = "/page")
|
|
|
|
+ @ApiOperation(value="白名单管理列表(分页)")
|
|
|
|
+ @SaCheckPermission("whitelistmanagement:detail")
|
|
|
|
+ public RT<PageOutput<WhitelistManagementPageVo>> page(@Valid WhitelistManagementPageDto dto){
|
|
|
|
+ Page<WhitelistManagementPageVo> page = whitelistManagementService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
|
|
|
|
+ PageOutput<WhitelistManagementPageVo> pageOutput = ConventPage.getPageOutput(page, WhitelistManagementPageVo.class);
|
|
|
|
+ return RT.ok(pageOutput);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping(value = "/info")
|
|
|
|
+ @ApiOperation(value="根据id查询白名单管理信息")
|
|
|
|
+ @SaCheckPermission("whitelistmanagement:detail")
|
|
|
|
+ public RT<WhitelistManagementVo> info(@RequestParam Long id){
|
|
|
|
+ WhitelistManagement whitelistManagement = whitelistManagementService.getById(id);
|
|
|
|
+ if (whitelistManagement == null) {
|
|
|
|
+ return RT.error("找不到此数据!");
|
|
|
|
+ }
|
|
|
|
+ return RT.ok(BeanUtil.toBean(whitelistManagement, WhitelistManagementVo.class));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @PostMapping
|
|
|
|
+ @ApiOperation(value = "新增白名单管理")
|
|
|
|
+ @SaCheckPermission("whitelistmanagement:add")
|
|
|
|
+ public RT<Boolean> add(@Valid @RequestBody AddWhitelistManagementDto dto){
|
|
|
|
+ WhitelistManagement whitelistManagement = BeanUtil.toBean(dto, WhitelistManagement.class);
|
|
|
|
+ boolean isSuccess = whitelistManagementService.save(whitelistManagement);
|
|
|
|
+ return RT.ok(isSuccess);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PutMapping
|
|
|
|
+ @ApiOperation(value = "修改白名单管理")
|
|
|
|
+ @SaCheckPermission("whitelistmanagement:edit")
|
|
|
|
+ public RT<Boolean> update(@Valid @RequestBody UpdateWhitelistManagementDto dto){
|
|
|
|
+
|
|
|
|
+ WhitelistManagement whitelistManagement = BeanUtil.toBean(dto, WhitelistManagement.class);
|
|
|
|
+ return RT.ok(whitelistManagementService.updateById(whitelistManagement));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @DeleteMapping
|
|
|
|
+ @ApiOperation(value = "删除白名单管理")
|
|
|
|
+ @SaCheckPermission("whitelistmanagement:delete")
|
|
|
|
+ public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
|
|
|
|
+ return RT.ok(whitelistManagementService.removeBatchByIds(ids));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/structure")
|
|
|
|
+ @ApiOperation(value = "获取年级班级树结构")
|
|
|
|
+ public ResponseEntity<List<TreeNode>> getTreeStructure() {
|
|
|
|
+ List<TreeNode> treeStructure = whitelistManagementService.getTreeStructure();
|
|
|
|
+ return ResponseEntity.ok(treeStructure);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/import")
|
|
|
|
+ @ApiOperation(value = "导入")
|
|
|
|
+ public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
|
|
|
|
+ List<WhitelistManagementPageVo> savedDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(WhitelistManagementPageVo.class).sheet().doReadSync();
|
|
|
|
+ List<WhitelistManagement> whitelistManagements = new ArrayList<>();
|
|
|
|
+ List<String> errorLogs = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (WhitelistManagementPageVo vo : savedDataList) {
|
|
|
|
+ try {
|
|
|
|
+ if (whitelistManagementService.checkExist(vo.getCredentialNumber())) continue;
|
|
|
|
+
|
|
|
|
+ String name = whitelistManagementService.GetName(vo.getName()).toString();
|
|
|
|
+ String credentialNumber = whitelistManagementService.GetCredentialNumber(vo.getCredentialNumber()).toString();
|
|
|
|
+ Long userId = whitelistManagementService.getUserId(credentialNumber);
|
|
|
|
+ Long phone = whitelistManagementService.GetPhone(Long.parseLong(vo.getPhone().toString()));
|
|
|
|
+
|
|
|
|
+ if (!name.isEmpty() && !credentialNumber.isEmpty() && !phone.toString().isEmpty()) {
|
|
|
|
+ WhitelistManagement whitelistManagement = new WhitelistManagement();
|
|
|
|
+ whitelistManagement.setCreateDate(new Date());
|
|
|
|
+ whitelistManagement.setDeleteMark(0);
|
|
|
|
+ whitelistManagement.setEnabledMark(0);
|
|
|
|
+ whitelistManagement.setUserId(userId);
|
|
|
|
+ whitelistManagement.setName(name);
|
|
|
|
+ whitelistManagement.setCredentialNumber(credentialNumber);
|
|
|
|
+ whitelistManagement.setPhone(phone);
|
|
|
|
+ whitelistManagements.add(whitelistManagement);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ errorLogs.add(String.format("[意外错误(检查输入的是否正确且存在,输入错误可能返回 null)] 姓名: %s, 身份证: %s, 手机号: %s - 错误信息:%s", vo.getName(), vo.getCredentialNumber(), vo.getPhone(), e.getMessage()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Boolean result = whitelistManagementService.saveBatch(whitelistManagements);
|
|
|
|
+ if (!errorLogs.isEmpty()) {
|
|
|
|
+ String detailedMessage = String.format("[导入完成但存在问题(检查输入的是否正确且存在,输入错误可能返回 null)] ", String.join("; ", errorLogs));
|
|
|
|
+ return RT.error(400, detailedMessage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return RT.ok(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|