luofl
2025-03-17 261f390eaa70cbb103b85e872e463c65d16cdeb1
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/SystemUserController.java
@@ -1,5 +1,6 @@
package com.panzhihua.sangeshenbian.api;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.panzhihua.common.controller.BaseController;
@@ -8,9 +9,12 @@
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
import com.panzhihua.common.service.auth.TokenService;
import com.panzhihua.common.utlis.HttpClientUtil;
import com.panzhihua.common.utlis.ServletUtils;
import com.panzhihua.sangeshenbian.model.entity.SystemMenu;
import com.panzhihua.sangeshenbian.model.entity.SystemRoleMenu;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.model.vo.RegionVO;
import com.panzhihua.sangeshenbian.service.ISystemMenuService;
import com.panzhihua.sangeshenbian.service.ISystemRoleMenuService;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
@@ -19,17 +23,23 @@
import com.panzhihua.sangeshenbian.warpper.SystemUserListVo;
import com.panzhihua.sangeshenbian.warpper.TokenVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -38,6 +48,7 @@
 * @Date 2025/2/18 22:30
 */
@Api
@Slf4j
@RestController
@RequestMapping("/systemUser")
public class SystemUserController extends BaseController {
@@ -96,15 +107,75 @@
      LoginReturnVO loginReturnVO = reult.getData();
      TokenVo tokenVo = new TokenVo();
      BeanUtils.copyProperties(loginReturnVO, tokenVo);
      List<SystemRoleMenu> list = systemRoleMenuService.list(new LambdaQueryWrapper<SystemRoleMenu>().eq(SystemRoleMenu::getSystemRoleId, systemUser.getSystemRoleId()));
      List<Integer> collect = list.stream().map(SystemRoleMenu::getSystemMenuId).collect(Collectors.toList());
      Set<String> collect1 = new HashSet<>();
      if(collect.size() > 0){
         List<SystemMenu> systemMenus = systemMenuService.listByIds(collect);
         LambdaQueryWrapper<SystemMenu> queryWrapper = new LambdaQueryWrapper<SystemMenu>().in(SystemMenu::getId, collect);
         switch (systemUser.getAccountLevel()){
            case 2:
               queryWrapper.notIn(SystemMenu::getUrl, Arrays.asList("/system_setting/position_management", "/system_setting/position_management/add", "/system_setting/position_management/del",
                     "/system_setting/role_management", "/system_setting/role_management/add", "/system_setting/role_management/edit", "/system_setting/role_management/del",
                     "/work_order_transaction_management/work_order_item_configuration", "/work_order_transaction_management/work_order_item_configuration/save",
                     "/work_order_transaction_management/problem_type_management", "/work_order_transaction_management/problem_type_management/add",
                     "/work_order_transaction_management/problem_type_management/edit", "/work_order_transaction_management/problem_type_management/del", "/work_order_transaction_management/banner_management",
                     "/work_order_transaction_management/banner_management/add", "/work_order_transaction_management/banner_management/edit", "/work_order_transaction_management/banner_management/del"));
               break;
            case 3:
               queryWrapper.notIn(SystemMenu::getUrl, Arrays.asList("/system_setting/position_management", "/system_setting/position_management/add", "/system_setting/position_management/del",
                     "/system_setting/role_management", "/system_setting/role_management/add", "/system_setting/role_management/edit", "/system_setting/role_management/del",
                     "/work_order_transaction_management/work_order_item_configuration", "/work_order_transaction_management/work_order_item_configuration/save",
                     "/work_order_transaction_management/problem_type_management", "/work_order_transaction_management/problem_type_management/add",
                     "/work_order_transaction_management/problem_type_management/edit", "/work_order_transaction_management/problem_type_management/del", "/work_order_transaction_management/banner_management",
                     "/work_order_transaction_management/banner_management/add", "/work_order_transaction_management/banner_management/edit", "/work_order_transaction_management/banner_management/del"));
               break;
            case 4:
               queryWrapper.notIn(SystemMenu::getUrl, Arrays.asList("/system_setting/position_management", "/system_setting/position_management/add", "/system_setting/position_management/del",
                     "/system_setting/role_management", "/system_setting/role_management/add", "/system_setting/role_management/edit", "/system_setting/role_management/del",
                     "/work_order_transaction_management/work_order_item_configuration", "/work_order_transaction_management/work_order_item_configuration/save",
                     "/work_order_transaction_management/problem_type_management", "/work_order_transaction_management/problem_type_management/add",
                     "/work_order_transaction_management/problem_type_management/edit", "/work_order_transaction_management/problem_type_management/del", "/work_order_transaction_management/banner_management",
                     "/work_order_transaction_management/banner_management/add", "/work_order_transaction_management/banner_management/edit", "/work_order_transaction_management/banner_management/del"));
               break;
            case 5:
               queryWrapper.notIn(SystemMenu::getUrl, Arrays.asList("/system_setting/position_management", "/system_setting/position_management/add", "/system_setting/position_management/del",
                     "/system_setting/role_management", "/system_setting/role_management/add", "/system_setting/role_management/edit", "/system_setting/role_management/del",
                     "/system_setting/people_management", "/system_setting/people_management/add", "/system_setting/people_management/edit", "/system_setting/people_management/del",
                     "/system_setting/people_management/freeze", "/system_setting/unit_management", "/system_setting/people_management/detail", "/system_setting/unit_management/add",
                     "/system_setting/unit_management/edit", "/system_setting/unit_management/del", "/work_order_transaction_management/work_order_item_configuration",
                     "/work_order_transaction_management/work_order_item_configuration/save", "/work_order_transaction_management/problem_type_management",
                     "/work_order_transaction_management/problem_type_management/add", "/work_order_transaction_management/problem_type_management/edit",
                     "/work_order_transaction_management/problem_type_management/del", "/work_order_transaction_management/banner_management",
                     "/work_order_transaction_management/banner_management/add", "/work_order_transaction_management/banner_management/edit", "/work_order_transaction_management/banner_management/del"));
               break;
         }
         List<SystemMenu> systemMenus = systemMenuService.list(queryWrapper);
         collect1 = systemMenus.stream().map(SystemMenu::getUrl).collect(Collectors.toSet());
      }
      tokenVo.setMenu(collect1);
      tokenVo.setName(systemUser.getName());
      tokenVo.setAccountLevel(systemUser.getAccountLevel());
      switch (systemUser.getAccountLevel()){
         case 1:
            tokenVo.setCityCode("510400");
            break;
         case 2:
            tokenVo.setCityCode("510400");
            tokenVo.setDistrictsCode(systemUser.getDistrictsCode());
            break;
         case 3:
            tokenVo.setCityCode("510400");
            tokenVo.setDistrictsCode(systemUser.getDistrictsCode());
            tokenVo.setStreetId(systemUser.getStreetId());
            break;
         case 4:
            tokenVo.setCityCode("510400");
            tokenVo.setDistrictsCode(systemUser.getDistrictsCode());
            tokenVo.setStreetId(systemUser.getStreetId());
            tokenVo.setCommunityId(systemUser.getCommunityId().toString());
            break;
      }
      return R.ok(tokenVo);
   }
   
@@ -127,7 +198,7 @@
   public R<IPage<SystemUserListVo>> list(SystemUserList query){
      Integer id = this.getLoginUserInfoSanGeShenBian().getId();
      SystemUser user = systemUserService.getById(id);
      IPage<SystemUserListVo> list = systemUserService.list(user.getAccountLevel(), query);
      IPage<SystemUserListVo> list = systemUserService.list(user, query);
      return R.ok(list);
   }
   
@@ -197,7 +268,7 @@
   
   @PutMapping("/freeze/{id}")
   @ApiOperation(value = "冻结账号", tags = {"三个身边后台-人员管理"})
   @OperLog(operModul = "三个身边后台",operType = 0,businessType = "冻结账号")
   @OperLog(operModul = "三个身边后台",operType = 2,businessType = "冻结账号")
   public R freeze(@PathVariable("id") Integer id){
      SystemUser systemUser = systemUserService.getById(id);
      if(2 == systemUser.getStatus()){
@@ -211,7 +282,7 @@
   
   @PutMapping("/unfreeze/{id}")
   @ApiOperation(value = "解冻账号", tags = {"三个身边后台-人员管理"})
   @OperLog(operModul = "三个身边后台",operType = 0,businessType = "解冻账号")
   @OperLog(operModul = "三个身边后台",operType = 2,businessType = "解冻账号")
   public R unfreeze(@PathVariable("id") Integer id){
      SystemUser systemUser = systemUserService.getById(id);
      if(1 == systemUser.getStatus()){
@@ -243,4 +314,73 @@
      BeanUtils.copyProperties(systemUser, systemUserVo);
      return R.ok(systemUserVo);
   }
   @GetMapping("/getAdministrativeDivision/{id}/{tier}")
   @ApiOperation(value = "获取行政区划层级联动数据", tags = {"三个身边后台-人员管理"})
   @ApiImplicitParams({
         @ApiImplicitParam(name = "id", value = "上级id", required = false, dataType = "string"),
         @ApiImplicitParam(name = "tier", value = "数据层级(2=区县,3=街道,4=社区)", required = true, dataType = "int"),
   })
   @OperLog(operModul = "三个身边后台",operType = 0,businessType = "获取行政区划层级联动数据")
   public R<List<RegionVO>> getAdministrativeDivision(@PathVariable("id") String id, @PathVariable("tier") Integer tier){
      List<RegionVO> list = new ArrayList<>();
      //区县
      if(2 == tier){
         list = systemUserService.getRegion("510400");
      }
      //街道
      if(3 == tier){
         list = systemUserService.getStreet(id);
      }
      //社区
      if(4 == tier){
         list = systemUserService.getCommunity(id);
      }
      log.info("获取行政区划层级联动数据:{}", list);
      return R.ok(list);
   }
   @GetMapping("/regionTree")
   @ApiOperation(value = "获取区县-街道-社区树",tags = {"三个身边后台-人员管理"})
   public R<List<RegionVO>> regionTree(){
      SystemUserVo loginUserInfo = getLoginUserInfoSanGeShenBian();
      List<RegionVO> list = systemUserService.getRegionTree(loginUserInfo);
      return R.ok(list);
   }
   public static void main(String[] args) {
   }
//   private String ACCESS_TOKEN_URL = "GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
//
//   public String getAppAccessToken(String appId, String appSecret) throws Exception {
//      String accessToken = "0";
//      try {
//         log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret);
//         String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret;
//         String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
//         Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
//         StringRedisTemplate redisTemplate = wxXCXTempSend.stringRedisTemplate;
//         if (resultMap.containsKey("access_token")) {
//            accessToken = resultMap.get("access_token").toString();
//            redisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken);
//         }
//         HttpServletRequest request = ServletUtils.getRequest();
//         String requestURI = request.getRequestURI();
//         //加上时间戳
//         String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//         //这里是 Redis key的前缀,如: sys:tabieId:表名  如果不需要去掉表名也可以
//         String key = MessageFormat.format("{0}:{1}:{2}",  "access_token_request_incr",datetime,requestURI);
//         //查询 key 是否存在, 不存在返回 1 ,存在的话则自增加1
//         redisTemplate.opsForValue().increment(key, 1);
//
//      } catch (IOException ioe) {
//         log.error("小程序http请求异常");
//         ioe.printStackTrace();
//      }
//      return accessToken;
//   }
}