jiangping
2023-08-25 6baf2c39511f7364bb7c7f8071228317aab21203
server/src/main/java/doumeemes/service/system/impl/WxLoginServiceImpl.java
@@ -19,6 +19,7 @@
import doumeemes.dao.ext.DepartmentExtMapper;
import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO;
import doumeemes.dao.ext.dto.WxLoginDTO;
import doumeemes.dao.ext.dto.WxLoginOutDTO;
import doumeemes.dao.ext.vo.CompanyUserExtListVO;
import doumeemes.dao.ext.vo.WxLoginVO;
import doumeemes.dao.system.SystemUserMapper;
@@ -87,7 +88,7 @@
    @Override
    public WxLoginVO wxLogin(String code, HttpServletRequest request) {
        WxLoginVO wxLoginVO = new WxLoginVO();
        String appId = systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.APPID).getCode();
        String appSecret = systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.APPSECRET).getCode();
        String getTokenUrl = GET_ACCESS_TOKEN_URL.replace("CODE", code).replace("APPID", appId).replace("SECRET", appSecret);
@@ -99,9 +100,19 @@
        String openId = tokenJson.getString("openid");
        String getUserInfoUrl = GET_USER_INFO_URL.replace("ACCESS_TOKEN", accessToken).replace("OPENID", openId);
        JSONObject userInfoJson = JSONObject.parseObject(HttpsUtil.get(getUserInfoUrl,true));
        return  loginByUnionIdAndReturn(userInfoJson.getString("unionid"),openId,request);
    }
    private WxLoginVO loginByUnionIdAndReturn(String unionid,String openId,HttpServletRequest request) {
        WxLoginVO wxLoginVO = new WxLoginVO();
        wxLoginVO.setOpenid(openId);
        wxLoginVO.setUnionid(userInfoJson.getString("unionid"));
        CompanyUser companyUser = companyUserExtMapper.selectOne(new QueryWrapper<CompanyUser>().eq("openid",openId).last(" limit 1 "));
        wxLoginVO.setUnionid(unionid);
        CompanyUser companyUser = companyUserExtMapper.selectOne(new QueryWrapper<CompanyUser>().lambda()
                .eq(CompanyUser::getUnionid,wxLoginVO.getUnionid())
                .eq(CompanyUser::getDeleted,Constants.ZERO)
                .last(" limit 1 "));
//        CompanyUser companyUser = companyUserExtMapper.selectOne(new QueryWrapper<CompanyUser>().eq("openid",openId).last(" limit 1 "));
        if(Objects.isNull(companyUser)){
            wxLoginVO.setLoginStatus(Constants.ONE);
            return wxLoginVO;
@@ -111,7 +122,7 @@
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到绑定部门信息");
        }
        Company company = companyExtMapper.selectById(department.getCompanyId());
        if(Objects.isNull(company)||company.getStatus().equals(Constants.ONE)){
        if(Objects.isNull(company)||company.getStatus().equals(Constants.ZERO)){
            wxLoginVO.setLoginStatus(Constants.ONE);
            return wxLoginVO;
        }
@@ -163,6 +174,13 @@
            systemLoginLogService.create(loginLog);
            throw  ee;
        }
        return  wxLoginVO;
    }
    @Override
    public WxLoginVO wxProgramLogin(String unionId,String openId, HttpServletRequest request) {
        return  loginByUnionIdAndReturn(unionId,openId,request);
    }
@@ -223,4 +241,14 @@
        }
    }
    @Override
    public void wxLoginOut(WxLoginOutDTO wxLoginOutDTO) {
        if(!Objects.isNull(wxLoginOutDTO)&&!Objects.isNull(wxLoginOutDTO.getCompanyUserId())){
            companyUserExtMapper.update(null,new UpdateWrapper<CompanyUser>()
                    .set("UNIONID","").set("OPENID","")
                    .eq("id",wxLoginOutDTO.getCompanyUserId())
            );
        }
    }
}