|
|
@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.validation.Valid;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/course/playSourceConfig")
|
|
|
@@ -48,6 +49,9 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
List<FsCoursePlaySourceConfigVO> list = fsCoursePlaySourceConfigService.selectCoursePlaySourceConfigVOListByMap(params);
|
|
|
+ for (FsCoursePlaySourceConfigVO item : list) {
|
|
|
+ item.setCompanyIds(parseCompanyIds(item.getCompanyIdsText(), item.getCompanyId()));
|
|
|
+ }
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
@@ -61,6 +65,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
|
|
|
FsCoursePlaySourceConfigVO configVO = new FsCoursePlaySourceConfigVO();
|
|
|
BeanUtils.copyProperties(config, configVO);
|
|
|
+ configVO.setCompanyIds(parseCompanyIds(config.getCompanyIds(), config.getCompanyId()));
|
|
|
return AjaxResult.success(configVO);
|
|
|
}
|
|
|
|
|
|
@@ -90,6 +95,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
config.setCompanyId(loginUser.getCompany().getCompanyId());
|
|
|
+ applyCompanyIds(config.getCompanyId(), param.getCompanyIds(), config);
|
|
|
config.setCompanyUserId(loginUser.getUser().getUserId());
|
|
|
config.setIsDel(0);
|
|
|
config.setCreateTime(LocalDateTime.now());
|
|
|
@@ -117,7 +123,8 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
}
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- if (!loginUser.getCompany().getCompanyId().equals(config.getCompanyId())) {
|
|
|
+ Long currentCompanyId = loginUser.getCompany().getCompanyId();
|
|
|
+ if (!belongsToCompany(config, currentCompanyId)) {
|
|
|
return AjaxResult.error("非法操作");
|
|
|
}
|
|
|
|
|
|
@@ -132,6 +139,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
}
|
|
|
|
|
|
BeanUtils.copyProperties(param, config);
|
|
|
+ applyCompanyIds(config.getCompanyId(), param.getCompanyIds(), config);
|
|
|
fsCoursePlaySourceConfigService.updateById(config);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
@@ -171,4 +179,64 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
}
|
|
|
return R.ok().put("date",start);
|
|
|
}
|
|
|
+
|
|
|
+ private static void applyCompanyIds(Long companyId, List<Long> companyIds, FsCoursePlaySourceConfig config) {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ if (companyIds != null) {
|
|
|
+ for (Long id : companyIds) {
|
|
|
+ if (id != null) {
|
|
|
+ ids.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ids.isEmpty() && companyId != null) {
|
|
|
+ ids.add(companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ List<Long> distinct = ids.stream().distinct().collect(Collectors.toList());
|
|
|
+ config.setCompanyId(config.getCompanyId() != null ? config.getCompanyId() : distinct.get(0));
|
|
|
+ config.setCompanyIds(distinct.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
|
|
+ } else {
|
|
|
+ config.setCompanyIds(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<Long> parseCompanyIds(String companyIds, Long companyId) {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ if (companyIds != null && !companyIds.trim().isEmpty()) {
|
|
|
+ for (String s : companyIds.split(",")) {
|
|
|
+ String v = s == null ? "" : s.trim();
|
|
|
+ if (!v.isEmpty()) {
|
|
|
+ try {
|
|
|
+ ids.add(Long.parseLong(v));
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ids.isEmpty() && companyId != null) {
|
|
|
+ ids.add(companyId);
|
|
|
+ }
|
|
|
+ return ids.stream().distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean belongsToCompany(FsCoursePlaySourceConfig config, Long companyId) {
|
|
|
+ if (companyId == null || config == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (companyId.equals(config.getCompanyId())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String companyIds = config.getCompanyIds();
|
|
|
+ if (companyIds == null || companyIds.trim().isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (String s : companyIds.split(",")) {
|
|
|
+ if (s != null && s.trim().equals(String.valueOf(companyId))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|