package com.izouma.nineth.service.netease; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.izouma.nineth.domain.netease.Team; import com.izouma.nineth.dto.PageQuery; import com.izouma.nineth.exception.BusinessException; import com.izouma.nineth.repo.Netease.TeamRepo; import com.izouma.nineth.service.netease.NeteaseUserService; import com.izouma.nineth.utils.JpaUtils; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.Map; @Service @AllArgsConstructor public class TeamService { private TeamRepo teamRepo; private NeteaseUserService neteaseUserService; public Page all(PageQuery pageQuery) { return teamRepo.findAll(JpaUtils.toSpecification(pageQuery, Team.class), JpaUtils.toPageRequest(pageQuery)); } public Team create(Team team) { Map params = new HashMap<>(); params.put("tname", team.getName()); params.put("owner", team.getOwnerid()); params.put("members", JSONObject.toJSONString(team.getMembers())); params.put("joinmode", "0"); params.put("custom", team.getCustom().toString()); params.put("msg", "欢迎加入大厅测试群~~"); String result = neteaseUserService .httpPost("team/create.action", "application/x-www-form-urlencoded;charset=utf-8", params); JSONObject jsonObject = JSON.parseObject(result); Integer code = jsonObject.getInteger("code"); if (code != 200) { throw new BusinessException("注册出错,请核查后重新注册"); } Long id = jsonObject.getLong("tid"); team.setTid(id); return teamRepo.save(team); } }