| | |
| | | package org.springblade.modules.system.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.PropertyNamingStrategy; |
| | | import com.alibaba.fastjson.serializer.SerializeConfig; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import io.swagger.annotations.*; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.cache.CacheNames; |
| | | import org.springblade.common.param.ToObject; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.launch.constant.AppConstant; |
| | | import org.springblade.core.log.annotation.ApiLog; |
| | | import org.springblade.core.log.logger.BladeLogger; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.constant.RoleConstant; |
| | | import org.springblade.core.tool.jackson.JsonUtil; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.excel.PoliceUserExcel; |
| | | import org.springblade.modules.system.excel.PoliceUserImporter; |
| | | import org.springblade.modules.system.excel.UserExcel; |
| | | import org.springblade.modules.system.excel.UserImporter; |
| | | import org.springblade.modules.system.service.IUserService; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; |
| | | import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE; |
| | | |
| | | /** |
| | |
| | | * @author Chill |
| | | */ |
| | | @NonDS |
| | | @ApiIgnore |
| | | //@ApiIgnore |
| | | @RestController |
| | | @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME+"/user") |
| | | @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/user") |
| | | @AllArgsConstructor |
| | | @Api(value = "用户管理", tags = "用户管理") |
| | | public class UserController { |
| | | |
| | | private final IUserService userService; |
| | | private final BladeRedis bladeRedis; |
| | | private final BladeLogger bladeLogger; |
| | | |
| | | /** |
| | | * 查询单条 |
| | |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "查看详情", notes = "传入id") |
| | | @GetMapping("/detail") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | // @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<UserVO> detail(User user) { |
| | | User detail = userService.getOne(Condition.getQueryWrapper(user)); |
| | | return R.data(UserWrapper.build().entityVO(detail)); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "查看详情返回String", notes = "传入id") |
| | | @GetMapping("/details") |
| | | // @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<String> details(User user) { |
| | | UserVO detail = userService.getuserById(user.getId()); |
| | | SerializeConfig config = new SerializeConfig(); |
| | | config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase; |
| | | String json1 = JSON.toJSONString(detail, config); |
| | | return R.data(json1); |
| | | } |
| | | |
| | | /** |
| | |
| | | return R.data(UserWrapper.build().pageVO(pages)); |
| | | } |
| | | |
| | | @GetMapping("/searchUser") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "搜索用户", notes = "传入name") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<List<UserVO>> searchUser(@ApiIgnore User user, Query query, String deptId, BladeUser bladeUser) { |
| | | IPage<User> pages = userService.selectUserPage(Condition.getPage(query), user, deptId, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId())); |
| | | return R.data(UserWrapper.build().listVO(pages.getRecords())); |
| | | } |
| | | |
| | | @GetMapping("/searchUserByDistrictId") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "通过小区Id搜索用户", notes = "传入districtId") |
| | | // @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<List<UserVO>> searchUserByDistrictId(String districtId) { |
| | | List<User> resutl = userService.searchUserByDistrictId(districtId); |
| | | return R.data(UserWrapper.build().listVO(resutl)); |
| | | } |
| | | |
| | | /** |
| | | * 自定义用户列表 |
| | | */ |
| | |
| | | }) |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "列表", notes = "传入account和realName") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R<IPage<UserVO>> page(@ApiIgnore User user, Query query, Long deptId, BladeUser bladeUser) { |
| | | // @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | @ApiLog("自定义用户列表") |
| | | public R<IPage<UserVO>> page(@ApiIgnore User user, Query query, String deptId, BladeUser bladeUser) { |
| | | bladeLogger.info("自定义用户列表", JsonUtil.toJson(user)); |
| | | IPage<User> pages = userService.selectUserPage(Condition.getPage(query), user, deptId, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId())); |
| | | return R.data(UserWrapper.build().pageVO(pages)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 按条件查询用户信息 |
| | | * |
| | | * @param user |
| | | * @return |
| | | */ |
| | | @GetMapping("/getUserListByParam") |
| | | public R getUserListByParam(UserVO user) { |
| | | return R.data(userService.getUserListByParam(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/submit") |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiLog("新增或修改") |
| | | @ApiOperation(value = "新增或修改", notes = "传入User") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | @PreAuth("hasAnyRole('administrator', 'admin','wygly')") |
| | | public R submit(@Valid @RequestBody User user) { |
| | | bladeLogger.info("新增或修改", JsonUtil.toJson(user)); |
| | | CacheUtil.clear(USER_CACHE); |
| | | return R.status(userService.submit(user)); |
| | | } |
| | |
| | | */ |
| | | @PostMapping("/update") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiLog("修改") |
| | | @ApiOperation(value = "修改", notes = "传入User") |
| | | public R update(@Valid @RequestBody User user) { |
| | | bladeLogger.info("修改", JsonUtil.toJson(user)); |
| | | CacheUtil.clear(USER_CACHE); |
| | | CacheUtil.clear(SYS_CACHE); |
| | | return R.status(userService.updateUser(user)); |
| | | } |
| | | |
| | |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "删除", notes = "传入id集合") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | @ApiLog("删除") |
| | | public R remove(@RequestParam String ids) { |
| | | bladeLogger.info("删除", JsonUtil.toJson(ids)); |
| | | CacheUtil.clear(USER_CACHE); |
| | | return R.status(userService.removeUser(ids)); |
| | | } |
| | |
| | | */ |
| | | @PostMapping("/grant") |
| | | @ApiOperationSupport(order = 7) |
| | | @ApiLog("设置菜单权限") |
| | | @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R grant(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds, |
| | | @ApiParam(value = "roleId集合", required = true) @RequestParam String roleIds) { |
| | | bladeLogger.info("设置菜单权限", JsonUtil.toJson(userIds)); |
| | | boolean temp = userService.grant(userIds, roleIds); |
| | | return R.status(temp); |
| | | } |
| | |
| | | @PostMapping("/reset-password") |
| | | @ApiOperationSupport(order = 8) |
| | | @ApiOperation(value = "初始化密码", notes = "传入userId集合") |
| | | @ApiLog("重置密码") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMIN) |
| | | public R resetPassword(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds) { |
| | | bladeLogger.info("重置密码", JsonUtil.toJson(userIds)); |
| | | boolean temp = userService.resetPassword(userIds); |
| | | return R.status(temp); |
| | | } |
| | |
| | | */ |
| | | @PostMapping("/update-password") |
| | | @ApiOperationSupport(order = 9) |
| | | @ApiLog("修改密码") |
| | | @ApiOperation(value = "修改密码", notes = "传入密码") |
| | | public R updatePassword(BladeUser user, @ApiParam(value = "旧密码", required = true) @RequestParam String oldPassword, |
| | | @ApiParam(value = "新密码", required = true) @RequestParam String newPassword, |
| | | @ApiParam(value = "新密码", required = true) @RequestParam String newPassword1) { |
| | | bladeLogger.info("修改密码", JsonUtil.toJson(ToObject.toMap("oldPassword:" + oldPassword, "newPassword:" + newPassword, "newPassword1:" + newPassword1))); |
| | | boolean temp = userService.updatePassword(user.getUserId(), oldPassword, newPassword, newPassword1); |
| | | return R.status(temp); |
| | | } |
| | |
| | | * 修改基本信息 |
| | | */ |
| | | @PostMapping("/update-info") |
| | | @ApiLog("自定义用户列表") |
| | | @ApiOperationSupport(order = 10) |
| | | @ApiOperation(value = "修改基本信息", notes = "传入User") |
| | | public R updateInfo(@Valid @RequestBody User user) { |
| | | bladeLogger.info("修改基本信息", JsonUtil.toJson(user)); |
| | | CacheUtil.clear(USER_CACHE); |
| | | return R.status(userService.updateUserInfo(user)); |
| | | } |
| | |
| | | */ |
| | | @PostMapping("import-user") |
| | | @ApiOperationSupport(order = 12) |
| | | @ApiLog("导入用户") |
| | | @ApiOperation(value = "导入用户", notes = "传入excel") |
| | | public R importUser(MultipartFile file, Integer isCovered) { |
| | | UserImporter userImporter = new UserImporter(userService, isCovered == 1); |
| | |
| | | * 导出用户 |
| | | */ |
| | | @GetMapping("export-user") |
| | | @ApiLog("导出用户") |
| | | @ApiOperationSupport(order = 13) |
| | | @ApiOperation(value = "导出用户", notes = "传入user") |
| | | public void exportUser(@ApiIgnore @RequestParam Map<String, Object> user, BladeUser bladeUser, HttpServletResponse response) { |
| | | bladeLogger.info("导出用户", JsonUtil.toJson(bladeUser)); |
| | | String deptId = (String) user.get("deptId"); |
| | | // 置空 |
| | | user.put("deptId", ""); |
| | | QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class); |
| | | if (!AuthUtil.isAdministrator()) { |
| | | queryWrapper.lambda().eq(User::getTenantId, bladeUser.getTenantId()); |
| | | } |
| | | queryWrapper.lambda().eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED); |
| | | List<UserExcel> list = userService.exportUser(queryWrapper); |
| | | List<UserExcel> list = userService.exportUser(queryWrapper, deptId); |
| | | ExcelUtil.export(response, "用户数据" + DateUtil.time(), "用户数据表", list, UserExcel.class); |
| | | } |
| | | |
| | |
| | | */ |
| | | @PostMapping("/unlock") |
| | | @ApiOperationSupport(order = 19) |
| | | @ApiLog("用户解锁") |
| | | @ApiOperation(value = "账号解锁", notes = "传入id") |
| | | public R unlock(String userIds) { |
| | | bladeLogger.info("用户解锁", JsonUtil.toJson(userIds)); |
| | | if (StringUtil.isBlank(userIds)) { |
| | | return R.fail("请至少选择一个用户"); |
| | | } |
| | |
| | | return R.success("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/getUserInfo") |
| | | public R getUserInfo() { |
| | | //根据保安员编码查询保安员信息 |
| | | return R.data(userService.getUserInfo(AuthUtil.getUserId())); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | */ |
| | | @GetMapping("/getUserInfoByCode") |
| | | @ApiOperation(value = "查询物业人员/网格人员", notes = "houseCode") |
| | | public R getUserInfoByCode(@RequestParam("houseCode") String houseCode, @RequestParam(value = "type", defaultValue = "2") String type) { |
| | | return R.data(userService.getUserInfoByCode(houseCode, type)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过小区id查询物业人员/网格人员 |
| | | */ |
| | | @GetMapping("/getUserInfoByDistrictId") |
| | | @ApiOperation(value = "查询物业人员/网格人员", notes = "houseCode") |
| | | public R getUserInfoByDistrictId(@RequestParam("districtId") String districtId, @RequestParam(value = "building", required = false) String building) { |
| | | return R.data(userService.getUserInfoByDistrictId(districtId, building)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过机构查询物业公司人员 |
| | | */ |
| | | @GetMapping("/getUserInfoByPropertyCompanyId") |
| | | @ApiOperation(value = "通过机构查询物业公司人员", notes = "propertyCompanyId") |
| | | public R getUserInfoByPropertyId(@RequestParam("propertyCompanyId") String propertyCompanyId, @RequestParam("roleId") String roleId) { |
| | | return R.data(userService.getUserInfoByPropertyId(propertyCompanyId, roleId)); |
| | | } |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | | @GetMapping("/handleUserDept") |
| | | public R handleUserDept() { |
| | | return R.data(userService.handleUserDept()); |
| | | } |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | | @GetMapping("/handleUser") |
| | | public R handleUser() { |
| | | return R.data(userService.handleUser()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 民警数据导入 |
| | | */ |
| | | @PostMapping("/policemanDataHandle") |
| | | public R policemanDataHandle(MultipartFile file) { |
| | | PoliceUserImporter policeUserImporter = new PoliceUserImporter(userService); |
| | | ExcelUtil.save(file, policeUserImporter, PoliceUserExcel.class); |
| | | return R.success("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 通过经纬度查询最近的民警人员 |
| | | * longitude |
| | | * latitude |
| | | */ |
| | | @GetMapping("/getPoliceUser") |
| | | @ApiLog("通过经纬度查询最近的民警人员") |
| | | @ApiOperation(value = "通过经纬度查询最近的民警人员") |
| | | public R getPoliceUser(@RequestParam("longitude") String longitude, @RequestParam(value = "latitude") String latitude, @RequestParam(value = "houseCode", required = false) String houseCode) { |
| | | bladeLogger.info("通过经纬度查询最近的民警人员", JsonUtil.toJson(ToObject.toMap("longitude:" + longitude, "latitude:" + latitude, "houseCode:" + houseCode))); |
| | | return R.data(userService.getPoliceUser(longitude, latitude, houseCode)); |
| | | } |
| | | |
| | | } |