| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.api.ApiController; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.example.jz.modle.R; |
| | | import com.example.jz.modle.dto.ManagerDto; |
| | | import com.example.jz.modle.dto.UserExpDto; |
| | | import com.example.jz.modle.entity.*; |
| | | import com.example.jz.service.*; |
| | | import com.example.jz.utils.EasyExcelUtils; |
| | | import com.example.jz.utils.Md5Utils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 用户表(User)表控制层 |
| | |
| | | } |
| | | |
| | | |
| | | @GetMapping("/status") |
| | | @ApiOperation("禁用/启用用户") |
| | | public R updateStatus(Integer id, Integer status) { |
| | | int newStatus = 0; |
| | | if (status != null) { |
| | | if (status == 1) { |
| | | newStatus = 0; |
| | | } else { |
| | | newStatus = 1; |
| | | } |
| | | } |
| | | userService.update(new UpdateWrapper<User>().set("status", newStatus).eq("id", id)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/manager") |
| | | @ApiOperation("添加管理") |
| | | public R addManager(@RequestBody ManagerDto managerDto) { |
| | |
| | | } |
| | | |
| | | @DeleteMapping("/manager") |
| | | @ApiOperation("删除管理") |
| | | @ApiOperation("删除管理人员") |
| | | public R removeManager(@RequestParam Integer id) { |
| | | causeService.list(new LambdaQueryWrapper<Cause>().eq(Cause::getUserId, id)).forEach(item -> { |
| | | causeService.deleteCause(item.getId()); |
| | | }); |
| | | List<Cause> list = causeService.list(new LambdaQueryWrapper<Cause>().eq(Cause::getUserId, id)); |
| | | if (!Objects.isNull(list) && list.size() != 0){ |
| | | ArrayList<Map> maps = new ArrayList<>(); |
| | | for (Cause cause : list) { |
| | | HashMap<String, String> map = new HashMap<>(); |
| | | map.put("caseName", cause.getName()); |
| | | map.put("caseNumber", cause.getNumber()); |
| | | maps.add(map); |
| | | } |
| | | return R.failed(maps, "该警员还有案件关联,若要删除请先修改对应案件关联的警员"); |
| | | } |
| | | // causeService.list(new LambdaQueryWrapper<Cause>().eq(Cause::getUserId, id)).forEach(item -> { |
| | | // causeService.deleteCause(item.getId()); |
| | | // }); |
| | | // userService.remove(new LambdaQueryWrapper<User>().eq(User::getId, id)); |
| | | messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getCopId, id)); |
| | | return R.ok(userService.removeById(id)); |
| | | } |
| | | |
| | | @DeleteMapping("/crowd") |
| | | @ApiOperation("删除普通用户") |
| | | public R removeCrowd(@RequestParam Integer id){ |
| | | List<Report> list = reportService.list(Wrappers.<Report>lambdaQuery().eq(Report::getUserId, id)); |
| | | for (Report report : list) { |
| | | groupUserService.remove(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getUserId, report.getId())); |
| | | messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getUserId, report.getId())); |
| | | reportService.removeById(report.getId()); |
| | | } |
| | | userService.remove(Wrappers.<User>lambdaQuery().eq(User::getId, id)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @GetMapping("/manager") |
| | | @ApiOperation("分页查询所有数据") |
| | | public R selectManager(Page<User> page, User user) { |
| | | return R.ok(userService.page(page, new QueryWrapper<User>() |
| | | .eq("role", 1) |
| | | .eq("role", 1).ne("id", 1) |
| | | .and(StringUtils.isNotBlank(user.getUserMobile()) && StringUtils.isNotBlank(user.getRealName()), new Consumer<QueryWrapper<User>>() { |
| | | @Override |
| | | public void accept(QueryWrapper<User> userQueryWrapper) { |
| | |
| | | user.setLoginPassword(Md5Utils.md5(user.getUserIdcard().substring(user.getUserIdcard().length() - 6))); |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | /** |
| | | * 转为管理员 |
| | | * |
| | | * @param id 用户id |
| | | * @return |
| | | */ |
| | | @GetMapping("/toManager/{id}") |
| | | @ApiOperation("转为管理员") |
| | | public R toManager(@PathVariable Serializable id) { |
| | | User user = userService.getById(id); |
| | | user.setRole(1); |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("用户信息导出") |
| | | @PostMapping("/exp") |
| | | public void UserExp(HttpServletResponse response){ |
| | | List<User> list = userService.list(Wrappers.<User>lambdaQuery().eq(User::getRole, 0).eq(User::getStatus, 1)); |
| | | List<UserExpDto> userExpDtos = list.stream().map(user -> { |
| | | UserExpDto userExpDto = new UserExpDto(); |
| | | BeanUtils.copyProperties(user, userExpDto); |
| | | return userExpDto; |
| | | }).collect(Collectors.toList()); |
| | | String sheetName = "用户导出"; |
| | | EasyExcelUtils.export1(response, sheetName, UserExpDto.class, userExpDtos, "用户导出"); |
| | | } |
| | | } |