|
@@ -1,36 +1,20 @@
|
|
package com.platform.controller;
|
|
package com.platform.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.platform.annotation.CanUserUpdateRecord;
|
|
|
|
import com.platform.entity.BrandEntity;
|
|
import com.platform.entity.BrandEntity;
|
|
import com.platform.entity.Result;
|
|
import com.platform.entity.Result;
|
|
import com.platform.entity.SceneEntity;
|
|
import com.platform.entity.SceneEntity;
|
|
-import com.platform.entity.SysUserEntity;
|
|
|
|
-import com.platform.exception.CommonBaseException;
|
|
|
|
import com.platform.service.BrandService;
|
|
import com.platform.service.BrandService;
|
|
-import com.platform.service.SceneService;
|
|
|
|
-import com.platform.service.SysDeptService;
|
|
|
|
-import com.platform.service.SysUserService;
|
|
|
|
import com.platform.service.impl.ZhiHouseService;
|
|
import com.platform.service.impl.ZhiHouseService;
|
|
-import com.platform.utils.Constant;
|
|
|
|
-import com.platform.utils.DepartmentUtils;
|
|
|
|
-import com.platform.vos.CurrentUserLoginVo;
|
|
|
|
import com.platform.vos.RequestScene;
|
|
import com.platform.vos.RequestScene;
|
|
-import io.swagger.annotations.*;
|
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
-
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Controller
|
|
* Controller
|
|
@@ -44,220 +28,13 @@ import java.util.stream.Collectors;
|
|
@RequestMapping("scene")
|
|
@RequestMapping("scene")
|
|
@Slf4j
|
|
@Slf4j
|
|
public class SceneController extends AbstractController{
|
|
public class SceneController extends AbstractController{
|
|
- @Autowired
|
|
|
|
- private SceneService sceneService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private BrandService brandService;
|
|
private BrandService brandService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private SysUserService sysUserService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private SysDeptService sysDeptService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private DepartmentUtils departmentUtils;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
private ZhiHouseService zhiHouseService;
|
|
private ZhiHouseService zhiHouseService;
|
|
|
|
|
|
- public List<Long> getAllSubDeptIds(Long deptId) {
|
|
|
|
- if (null == deptId) {
|
|
|
|
- log.info("部门ID为空");
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- List<Long> allDeptIdList = new ArrayList<>();
|
|
|
|
- int leve = 0;
|
|
|
|
- leve = findDeptIdByParent(deptId, 0, allDeptIdList);
|
|
|
|
- log.info("获取到当前部门以及所有子部门(10层嵌套以内)的id为:{},部门层级为:{}",
|
|
|
|
- JSON.toJSONString(allDeptIdList) , leve);
|
|
|
|
- return allDeptIdList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private int findDeptIdByParent(long deptId, int level, List<Long> deptIdList) {
|
|
|
|
-
|
|
|
|
- if (level > 10) {
|
|
|
|
- log.info("嵌套层数超过了10层");
|
|
|
|
- return level;
|
|
|
|
- }
|
|
|
|
- deptIdList.add(deptId);
|
|
|
|
- //获取所有子部门的id
|
|
|
|
- List<Long> subDeptIdList = sysDeptService.queryDetpIdList(deptId);
|
|
|
|
- if (CollectionUtils.isEmpty(subDeptIdList)) {
|
|
|
|
- //自己算一层,没有子部门,要先加上自己这一层
|
|
|
|
- return level + 1;
|
|
|
|
- }
|
|
|
|
- int maxLevel = 0;
|
|
|
|
- for(Long id : subDeptIdList){
|
|
|
|
- //遍历所有子部门的子部门,并记下子部门中嵌套最深的层数
|
|
|
|
- int tmpLevel = findDeptIdByParent(id, level, deptIdList);
|
|
|
|
- if(tmpLevel > maxLevel){
|
|
|
|
- maxLevel = tmpLevel;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //添加子部门的id
|
|
|
|
- deptIdList.addAll(subDeptIdList);
|
|
|
|
- //叠加子部门的最大层级
|
|
|
|
- level += maxLevel;
|
|
|
|
- //加上自己这一层
|
|
|
|
- level += 1;
|
|
|
|
- return level;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查看列表
|
|
|
|
- */
|
|
|
|
- @PostMapping("/list")
|
|
|
|
- @RequiresPermissions("brand:list")
|
|
|
|
- public Result list(@RequestBody RequestScene requestScene) {
|
|
|
|
- //查询列表数据
|
|
|
|
- if (null == requestScene || org.apache.commons.lang3.StringUtils.isBlank(requestScene.getToken())) {
|
|
|
|
- return Result.failure("缺少必要参数");
|
|
|
|
- }
|
|
|
|
- if(!ObjectUtils.isEmpty(requestScene.getPage())){
|
|
|
|
- requestScene.setPageNum(requestScene.getPage());
|
|
|
|
- }
|
|
|
|
- //看看的页码从1开始算起
|
|
|
|
- if(requestScene.getPageNum()==0){
|
|
|
|
- requestScene.setPageNum(1L);
|
|
|
|
- }
|
|
|
|
- if (!ObjectUtils.isEmpty(requestScene.getLimit())) {
|
|
|
|
- requestScene.setPageSize(requestScene.getLimit());
|
|
|
|
- }
|
|
|
|
- if(!ObjectUtils.isEmpty(requestScene.getName())){
|
|
|
|
- requestScene.setSceneName(requestScene.getName());
|
|
|
|
- }
|
|
|
|
- Long userId = getUserId();
|
|
|
|
- boolean geratedable = false;
|
|
|
|
- if(Constant.SUPER_ADMIN == userId){
|
|
|
|
- requestScene.setUserId(-1L);
|
|
|
|
- } else {
|
|
|
|
- CurrentUserLoginVo user = getUser();
|
|
|
|
- if (user.getRoleId() == 6) {
|
|
|
|
- geratedable = true;
|
|
|
|
- // 获取该公司下所有员工手机号
|
|
|
|
- List<Long> subDeptIds = getAllSubDeptIds(getDeptId());
|
|
|
|
- List<SysUserEntity> users = sysUserService.getSysUserListByDeptIds(subDeptIds);
|
|
|
|
- requestScene.setPhone(users.stream().map(SysUserEntity::getMobile).collect(Collectors.joining(";")));
|
|
|
|
- } else if (user.getRoleId() == 8) {
|
|
|
|
- if ((ObjectUtils.isEmpty(user.getIsPlatformStreamer()) || !user.getIsPlatformStreamer())) {
|
|
|
|
- requestScene.setPhone(user.getMobile());
|
|
|
|
- } else {
|
|
|
|
- requestScene.setUserId(-1L);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- JSONObject mySceneJsonData = zhiHouseService.getSceneFromZhiHouse(requestScene);
|
|
|
|
- if(ObjectUtils.isEmpty(mySceneJsonData) || !mySceneJsonData.containsKey("list")){
|
|
|
|
- return Result.success(null);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<Object> mySceneList = mySceneJsonData.getJSONArray("list");
|
|
|
|
- if (ObjectUtils.isEmpty(mySceneList)) {
|
|
|
|
- return Result.success(mySceneJsonData);
|
|
|
|
- }
|
|
|
|
- boolean finalGeratedable = geratedable;
|
|
|
|
- mySceneList = mySceneList.parallelStream().map(Object -> JSONObject.parseObject(JSONObject.toJSONString(Object)))
|
|
|
|
- .peek(object -> {
|
|
|
|
- object.put("sceneUrl", object.getString("webSite"));
|
|
|
|
- object.put("name",object.getString("sceneName"));
|
|
|
|
- // 查找本地记录
|
|
|
|
- String sceneNum = object.getString("num");
|
|
|
|
- SceneEntity sceneEntity = sceneService.queryByScene(sceneNum);
|
|
|
|
- object.put("id",null);
|
|
|
|
- if(!ObjectUtils.isEmpty(sceneEntity)){
|
|
|
|
- object.put("id",sceneEntity.getId());
|
|
|
|
- object.put("appListPicUrl",sceneEntity.getAppListPicUrl());
|
|
|
|
- object.put("isShow",sceneEntity.getIsShow());
|
|
|
|
- object.put("sceneUrl",sceneEntity.getSceneUrl());
|
|
|
|
- object.put("name",sceneEntity.getName());
|
|
|
|
- // 判断名称是否修改,如果修改,则同步到本地
|
|
|
|
- if (!object.get("sceneName").toString().equals(sceneEntity.getName())) {
|
|
|
|
- sceneEntity.setName(object.get("sceneName").toString());
|
|
|
|
- sceneService.update(sceneEntity,true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- object.put("lived", true);
|
|
|
|
- if(finalGeratedable){
|
|
|
|
- // 查找是否生成直播间记录
|
|
|
|
- BrandEntity brandEntity = brandService.queryByScene(sceneNum);
|
|
|
|
- if (ObjectUtils.isEmpty(brandEntity)) {
|
|
|
|
- object.put("lived", false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
- mySceneJsonData.put("list", mySceneList);
|
|
|
|
- return Result.success(mySceneJsonData);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查看信息
|
|
|
|
- */
|
|
|
|
- @PostMapping("/info")
|
|
|
|
- @RequiresPermissions("brand:info")
|
|
|
|
- public Result info(@RequestBody SceneEntity SceneEntity) {
|
|
|
|
- if(!ObjectUtils.isEmpty(SceneEntity.getId())){
|
|
|
|
- SceneEntity scene = sceneService.queryObject(SceneEntity.getId().intValue());
|
|
|
|
- return Result.success( scene);
|
|
|
|
- }
|
|
|
|
- String token = SceneEntity.getToken();
|
|
|
|
- if(ObjectUtils.isEmpty(token)){
|
|
|
|
- return Result.failure("请传递token信息");
|
|
|
|
- }
|
|
|
|
- // 获取情景信息
|
|
|
|
- RequestScene requestScene = new RequestScene();
|
|
|
|
- requestScene.setToken(token);
|
|
|
|
- requestScene.setNums("'"+SceneEntity.getSceneNum()+"'");
|
|
|
|
- requestScene.setUserId(-1L);
|
|
|
|
- JSONObject mySceneJsonData = zhiHouseService.getSceneFromZhiHouse(requestScene);
|
|
|
|
- if(ObjectUtils.isEmpty(mySceneJsonData) || !mySceneJsonData.containsKey("list")){
|
|
|
|
- return Result.failure("场景码错误!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<Object> mySceneList = mySceneJsonData.getJSONArray("list");
|
|
|
|
- if (ObjectUtils.isEmpty(mySceneList)) {
|
|
|
|
- return Result.failure("场景码错误!");
|
|
|
|
- }
|
|
|
|
- JSONObject scene = JSONObject.parseObject(JSONObject.toJSONString(mySceneList.get(0)));
|
|
|
|
- SceneEntity.setSceneUrl(scene.getString("webSite"));
|
|
|
|
- SceneEntity.setName(scene.getString("sceneName"));
|
|
|
|
- return Result.success(SceneEntity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 删除
|
|
|
|
- */
|
|
|
|
- @CanUserUpdateRecord
|
|
|
|
- @RequestMapping("/delete")
|
|
|
|
- @RequiresPermissions("brand:delete")
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public Result delete(@RequestBody Integer[] ids) {
|
|
|
|
- List<SceneEntity> brandEntityList = new ArrayList<>();
|
|
|
|
- if(ObjectUtils.isEmpty(ids)){
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
- sceneService.deleteBatch(ids);
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 同步四维看看数据
|
|
|
|
- */
|
|
|
|
- @GetMapping("/sync4dkkSceneData")
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public Result sync4dkkSceneData() {
|
|
|
|
- CurrentUserLoginVo user = getUser();
|
|
|
|
- String mobile = user.getMobile();
|
|
|
|
- SysUserEntity userEntity = sysUserService.queryByUserMobile(mobile);
|
|
|
|
- if(ObjectUtils.isEmpty(userEntity.getFdkkUser())){
|
|
|
|
- throw new CommonBaseException(500, "请绑定四维看看账号!");
|
|
|
|
- }
|
|
|
|
- sceneService.sync4dkkSceneData(mobile,user.getUserId());
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 删除
|
|
* 删除
|
|
*/
|
|
*/
|
|
@@ -288,32 +65,4 @@ public class SceneController extends AbstractController{
|
|
}
|
|
}
|
|
return Result.success("生成直播间功能,请前往直播间查看。");
|
|
return Result.success("生成直播间功能,请前往直播间查看。");
|
|
}
|
|
}
|
|
-
|
|
|
|
- @ApiOperation(value = "获取客户所有的非直播间场景数据")
|
|
|
|
- @ApiImplicitParams({
|
|
|
|
- @ApiImplicitParam(name = "token", value = "用户登录的token", paramType = "body", required = true, dataType = "String"),
|
|
|
|
- @ApiImplicitParam(name = "pageNum", value = "当前页码", paramType = "body", required = true, dataType = "Long"),
|
|
|
|
- @ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataType = "Long")}
|
|
|
|
- )
|
|
|
|
- @PostMapping("/getAllScene")
|
|
|
|
- @ResponseBody
|
|
|
|
- public Result getAllScene(@RequestBody @ApiParam(name = "四维看看场景请求体", value = "传入json格式", required = true) RequestScene requestScene) {
|
|
|
|
-
|
|
|
|
- // 排除已绑定直播间的数据
|
|
|
|
- List<String> sceneNums = brandService.queryAllLiveSceneNum();
|
|
|
|
- List<Long> deptIds = null;
|
|
|
|
-
|
|
|
|
- Long userId = getUserId();
|
|
|
|
- if(Constant.SUPER_ADMIN != userId){
|
|
|
|
- //通过部门ID过滤数据
|
|
|
|
- if(null == getDeptId()){
|
|
|
|
- return Result.success( new ArrayList<>());
|
|
|
|
- }
|
|
|
|
- deptIds = departmentUtils.getAllSubDeptIds(getDeptId());
|
|
|
|
- }
|
|
|
|
- List<SceneEntity> brandList = sceneService.selectByDeptIdsAndExceptSceneNums(deptIds,sceneNums);
|
|
|
|
- Map<String ,Object> result = new HashMap<>();
|
|
|
|
- result.put("myScene" , brandList);
|
|
|
|
- return Result.success( result);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|