|
@@ -1,23 +1,99 @@
|
|
|
package edu.travel.commodity.web;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import edu.travel.adapter.service.tenant.SysUserRoleAdapter;
|
|
|
+import edu.travel.adapter.service.tenant.TenantAdapter;
|
|
|
import edu.travel.commodity.entity.ShopUserSession;
|
|
|
-import edu.travel.commodity.service.impl.ShopUserSessionServiceImpl;
|
|
|
+import edu.travel.commodity.service.ShopUserSessionService;
|
|
|
+import edu.travel.commodity.utils.TokenData;
|
|
|
+import edu.travel.exception.BaseException;
|
|
|
+import edu.travel.remote.commodity.ShopUserSessionRemoteController;
|
|
|
+import edu.travel.remote.feign.mode.vo.tenant.SysRoleVo;
|
|
|
+import edu.travel.remote.vo.ShopUserSessionVo;
|
|
|
+import edu.travel.resp.BaseResponse;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 用户客服关联(shop_user_session)表控制层
|
|
|
*
|
|
|
* @author xxxxx
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/shop_user_session")
|
|
|
-public class ShopUserSessionController {
|
|
|
+@RequestMapping("/shopUserSession")
|
|
|
+public class ShopUserSessionController implements ShopUserSessionRemoteController {
|
|
|
/**
|
|
|
* 服务对象
|
|
|
*/
|
|
|
@Autowired
|
|
|
- private ShopUserSessionServiceImpl shopUserSessionServiceImpl;
|
|
|
+ private ShopUserSessionService shopUserSessionService;
|
|
|
+ @Autowired
|
|
|
+ private TenantAdapter tenantAdapter;
|
|
|
+ @Autowired
|
|
|
+ private SysUserRoleAdapter sysUserRoleAdapter;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户客服关联
|
|
|
+ * @param
|
|
|
+ * @return {@link RPCBaseResponse }<{@link String }>
|
|
|
+ */
|
|
|
+
|
|
|
+ @GetMapping("/getUserSession")
|
|
|
+ public RPCBaseResponse<ShopUserSessionVo> getUserSession()
|
|
|
+ {
|
|
|
+ String userId = TokenData.getUserId();
|
|
|
+ LambdaQueryWrapper<ShopUserSession> query = Wrappers.<ShopUserSession>lambdaQuery().eq(ShopUserSession::getUserId, userId)
|
|
|
+ .or()
|
|
|
+ .eq(ShopUserSession::getCustomerId, userId);
|
|
|
+ ShopUserSession one = shopUserSessionService.getOne(query);
|
|
|
+ if(one==null){
|
|
|
+ return getSessionInfo("");
|
|
|
+ }else {
|
|
|
+ return getSessionInfo(one.getId().toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getSessionInfo")
|
|
|
+ public RPCBaseResponse<ShopUserSessionVo> getSessionInfo(@RequestParam("sessionId") String sessionId){
|
|
|
+ String userId = TokenData.getUserId();
|
|
|
+ ShopUserSession one = shopUserSessionService.getById(sessionId);
|
|
|
+ if(one!=null){
|
|
|
+ Long customerId = one.getCustomerId();
|
|
|
+ BaseResponse<List<SysRoleVo>> result = tenantAdapter.getRoleListByUserId(customerId.toString());
|
|
|
+ if(result.getCode()!=200){
|
|
|
+ throw new BaseException(result.getCode(),result.getMsg());
|
|
|
+ }
|
|
|
+ List<SysRoleVo> data = result.getData();
|
|
|
+ List<String> collect = data.stream().map(SysRoleVo::getName).collect(Collectors.toList());
|
|
|
+ if(collect.contains("超级管理员")){
|
|
|
+ //创建会话
|
|
|
+ return RPCBaseResponse.success("success",BeanUtil.toBean(one, ShopUserSessionVo.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取全部管理员
|
|
|
+ RPCBaseResponse<List<String>> admins = sysUserRoleAdapter.getAdmins();
|
|
|
+ if(admins.getCode()!=200){
|
|
|
+ throw new BaseException(admins.getCode(),admins.getMsg());
|
|
|
+ }
|
|
|
+ List<String> data = admins.getData();
|
|
|
+ int randomIndex = ThreadLocalRandom.current().nextInt(data.size());
|
|
|
+ String s = data.get(randomIndex);
|
|
|
+ //新增会话
|
|
|
+ ShopUserSession shopUserSession = new ShopUserSession();
|
|
|
+ shopUserSession.setCustomerId(Long.valueOf(s));
|
|
|
+ shopUserSession.setUserId(Long.valueOf(userId));
|
|
|
+ shopUserSessionService.save(shopUserSession);
|
|
|
+ ShopUserSessionVo bean = BeanUtil.toBean(shopUserSession, ShopUserSessionVo.class);
|
|
|
+ return RPCBaseResponse.success("success",bean);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|