|  |  | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
 |  |  | import com.dy.pipIrrGlobal.pojoBa.BaUser; | 
 |  |  | import com.dy.pipIrrGlobal.util.DistrictLevel; | 
 |  |  | import com.dy.pipIrrGlobal.util.Org; | 
 |  |  | import com.mysql.cj.util.StringUtils; | 
 |  |  | import io.swagger.v3.oas.annotations.Hidden; | 
 |  |  | 
 |  |  | import jakarta.validation.Valid; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | //import org.springframework.cache.CacheManager; | 
 |  |  | import org.springframework.http.MediaType; | 
 |  |  | import org.springframework.validation.BindingResult; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import java.util.Arrays; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  | import java.util.UUID; | 
 |  |  | 
 |  |  |             ) | 
 |  |  |     }) | 
 |  |  |     @GetMapping(path = "allOrg") | 
 |  |  |     public BaseResponse<List<Org>> allOrg(){ | 
 |  |  |     public BaseResponse<List<Org.OrgVo>> allOrg(){ | 
 |  |  |         //List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ; | 
 |  |  |         return BaseResponseUtils.buildSuccess(Org.ObjMap); | 
 |  |  |         return BaseResponseUtils.buildSuccess(Org.OrgList); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  | 
 |  |  |     @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) { | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         if(!vo.phone.equals("admin")){ | 
 |  |  |             if(vo.phone.length() != 11){ | 
 |  |  |                 return BaseResponseUtils.buildFail("手机号(长度不是11位)不正确"); | 
 |  |  |                 return BaseResponseUtils.buildErrorMsg("手机号(长度不是11位)不正确"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ | 
 |  |  |             return BaseResponseUtils.buildFail("未选择组织单位"); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("未选择组织单位"); | 
 |  |  |         } | 
 |  |  |         //把组织单位标签作为数据源名称 | 
 |  |  |         DataSourceContext.set(vo.orgTag); | 
 |  |  |  | 
 |  |  |         //得到所有用户账号 | 
 |  |  |         List<String> phones = sv.getPhones(); | 
 |  |  |         if(!phones.contains(vo.phone)){ | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("账号不存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         String uuid ; | 
 |  |  |         BaUser userPo ; | 
 |  |  | 
 |  |  |             uVo.token = uuid ; | 
 |  |  |             return BaseResponseUtils.buildSuccess(uVo); | 
 |  |  |         }else{ | 
 |  |  |             return BaseResponseUtils.buildFail("登录失败"); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("密码错误"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
 |  |  |     public BaseResponse<UserVo> loginForm(@Parameter(description = "form表单数据", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult){ | 
 |  |  |         if(bindingResult != null && bindingResult.hasErrors()){ | 
 |  |  |             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
 |  |  |         } | 
 |  |  |         if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ | 
 |  |  |             return BaseResponseUtils.buildFail("未选择组织单位"); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("未选择组织单位"); | 
 |  |  |         } | 
 |  |  |         //把组织单位标签作为数据源名称 | 
 |  |  |         DataSourceContext.set(vo.orgTag); | 
 |  |  | 
 |  |  |             uVo.token = uuid ; | 
 |  |  |             return BaseResponseUtils.buildSuccess(uVo); | 
 |  |  |         }else{ | 
 |  |  |             return BaseResponseUtils.buildFail("登录失败"); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("登录失败"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |             this.sv.logout(token) ; | 
 |  |  |             return BaseResponseUtils.buildSuccess(true); | 
 |  |  |         }else{ | 
 |  |  |             return BaseResponseUtils.buildFail("未从header中得到token"); | 
 |  |  |             return BaseResponseUtils.buildErrorMsg("未从header中得到token"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         BaUser userPo = this.sv.getByUuid(token) ; | 
 |  |  |         return userPo == null ? null : userPo.id ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 此方法供子模块系统调用,所以不公开在API接口中 | 
 |  |  |      * 方法功能:验证是否已经登录 | 
 |  |  |      * @param token 登录用户token | 
 |  |  |      * @return SsoVo | 
 |  |  |      */ | 
 |  |  |     @Hidden | 
 |  |  |     @GetMapping(path = "ssoCheck") | 
 |  |  |     public SsoVo ssoCheck(String token){ | 
 |  |  |         BaUser userPo = this.sv.getByUuid(token) ; | 
 |  |  |         SsoVo vo = new SsoVo(); | 
 |  |  |         if(userPo != null){ | 
 |  |  |             vo.dataSourceName = userPo.orgTag ; | 
 |  |  |             vo.logined = true ; | 
 |  |  |             vo.hasPower = true ;//默认有权限。2023-12-21 经商议,由前端鉴权 | 
 |  |  |         }else{ | 
 |  |  |             vo.logined = false ; | 
 |  |  |             vo.hasPower = true ;//默认有权限。2023-12-21 经商议,由前端鉴权 | 
 |  |  |         } | 
 |  |  |         return vo ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 此方法供子模块系统调用,所以不公开在API接口中 | 
 |  |  |      * 方法功能:验证是否已经登录,如果登录了,再验证权限 | 
 |  |  | 
 |  |  |      * @return SsoVo | 
 |  |  |      */ | 
 |  |  |     @Hidden | 
 |  |  |     @GetMapping(path = "ssoCheck") | 
 |  |  |     public SsoVo ssoCheck(String token, String privilege, String[] allPrivilege, String[] anyPrivilege){ | 
 |  |  |     @GetMapping(path = "ssoPowerCheck") | 
 |  |  |     public SsoVo ssoPowerCheck(String token, String privilege, String[] allPrivilege, String[] anyPrivilege){ | 
 |  |  |         BaUser userPo = this.sv.getByUuid(token) ; | 
 |  |  |         SsoVo vo = new SsoVo(); | 
 |  |  |         if(userPo != null){ | 
 |  |  | 
 |  |  |         CurUserVo vo = new CurUserVo(); | 
 |  |  |         if(userPo != null){ | 
 |  |  |             vo.id = userPo.id ; | 
 |  |  |             vo.name = userPo.name ; | 
 |  |  |             vo.name = userPo.userName; | 
 |  |  |         } | 
 |  |  |         return vo ; | 
 |  |  |     } |