|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
import com.ibeetl.jlw.dao.TeacherOpenCourseScheduleSessionSnapDao;
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseScheduleSession;
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseScheduleSessionSnap;
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseScheduleSessionSnapQuery;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
/**
|
|
|
* 课表快照 Service
|
|
|
* 当分布式ID开启后请勿使用insert(*,true)
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
@Slf4j
|
|
|
public class TeacherOpenCourseScheduleSessionSnapService extends CoreBaseService<TeacherOpenCourseScheduleSessionSnap> implements DeleteResourcesBy{
|
|
|
|
|
|
@Autowired private TeacherOpenCourseScheduleSessionSnapDao teacherOpenCourseScheduleSessionSnapDao;
|
|
|
|
|
|
public PageQuery<TeacherOpenCourseScheduleSessionSnap>queryByCondition(PageQuery query){
|
|
|
PageQuery ret = teacherOpenCourseScheduleSessionSnapDao.queryByCondition(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public PageQuery<TeacherOpenCourseScheduleSessionSnap>queryByConditionQuery(PageQuery query){
|
|
|
PageQuery ret = teacherOpenCourseScheduleSessionSnapDao.queryByConditionQuery(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
public void deleteByList(List list){
|
|
|
String ids = "";
|
|
|
ToolUtils.deleteNullList(list);
|
|
|
for(int i=0;null != list && i<list.size();i++){
|
|
|
ids += list.get(i).toString()+(i==list.size()-1?"":",");
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(ids)){
|
|
|
teacherOpenCourseScheduleSessionSnapDao.deleteByIds(ids);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void deleteTeacherOpenCourseScheduleSessionSnap(String ids){
|
|
|
try {
|
|
|
teacherOpenCourseScheduleSessionSnapDao.deleteTeacherOpenCourseScheduleSessionSnapByIds(ids);
|
|
|
} catch (Exception e) {
|
|
|
throw new PlatformException("批量删除课表快照失败", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String addAll(TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
String msg = "";
|
|
|
List<TeacherOpenCourseScheduleSessionSnap> teacherOpenCourseScheduleSessionSnapList = new ArrayList<>();
|
|
|
try {
|
|
|
teacherOpenCourseScheduleSessionSnapList = JSON.parseArray(teacherOpenCourseScheduleSessionSnapQuery.getTeacherOpenCourseScheduleSessionSnapJsonStr(), TeacherOpenCourseScheduleSessionSnap.class);
|
|
|
} catch (Exception e) {
|
|
|
try {
|
|
|
teacherOpenCourseScheduleSessionSnapList.add(JSONObject.parseObject(teacherOpenCourseScheduleSessionSnapQuery.getTeacherOpenCourseScheduleSessionSnapJsonStr(), TeacherOpenCourseScheduleSessionSnap.class));
|
|
|
} catch (Exception e1) {}
|
|
|
}
|
|
|
ToolUtils.deleteNullList(teacherOpenCourseScheduleSessionSnapList);
|
|
|
if(null != teacherOpenCourseScheduleSessionSnapList && teacherOpenCourseScheduleSessionSnapList.size()>0){
|
|
|
for(int i=0;i<teacherOpenCourseScheduleSessionSnapList.size();i++){
|
|
|
TeacherOpenCourseScheduleSessionSnap teacherOpenCourseScheduleSessionSnap = teacherOpenCourseScheduleSessionSnapList.get(i);
|
|
|
teacherOpenCourseScheduleSessionSnap.setUserId(teacherOpenCourseScheduleSessionSnapQuery.getUserId());
|
|
|
teacherOpenCourseScheduleSessionSnap.setOrgId(teacherOpenCourseScheduleSessionSnapQuery.getOrgId());
|
|
|
}
|
|
|
insertBatch(teacherOpenCourseScheduleSessionSnapList);
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public JsonResult add(TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
String msg = "";
|
|
|
TeacherOpenCourseScheduleSessionSnap teacherOpenCourseScheduleSessionSnap = teacherOpenCourseScheduleSessionSnapQuery.pojo();
|
|
|
teacherOpenCourseScheduleSessionSnapDao.insert(teacherOpenCourseScheduleSessionSnap);
|
|
|
teacherOpenCourseScheduleSessionSnapQuery.setTeacherOpenCourseScheduleSessionSnapId(teacherOpenCourseScheduleSessionSnap.getTeacherOpenCourseScheduleSessionSnapId());
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
jsonResult.setData(teacherOpenCourseScheduleSessionSnap.getTeacherOpenCourseScheduleSessionSnapId());//自增的ID丢进去
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
jsonResult.setMsg(msg);
|
|
|
return jsonResult;
|
|
|
}
|
|
|
|
|
|
public String edit(TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
String msg = "";
|
|
|
TeacherOpenCourseScheduleSessionSnap teacherOpenCourseScheduleSessionSnap = teacherOpenCourseScheduleSessionSnapQuery.pojo();
|
|
|
teacherOpenCourseScheduleSessionSnapDao.updateTemplateById(teacherOpenCourseScheduleSessionSnap);
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public String updateGivenByIds(TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
String msg = "";
|
|
|
if(StringUtils.isNotBlank(teacherOpenCourseScheduleSessionSnapQuery.get_given())){
|
|
|
boolean flag = teacherOpenCourseScheduleSessionSnapDao.updateGivenByIds(teacherOpenCourseScheduleSessionSnapQuery) > 0;
|
|
|
if(!flag){
|
|
|
msg = "更新指定参数失败";
|
|
|
}
|
|
|
}else{
|
|
|
msg = "指定参数为空";
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public List<TeacherOpenCourseScheduleSessionSnap> getValues (Object paras){
|
|
|
return sqlManager.select(SqlId.of("jlw.teacherOpenCourseScheduleSessionSnap.getTeacherOpenCourseScheduleSessionSnapValues"), TeacherOpenCourseScheduleSessionSnap.class, paras);
|
|
|
}
|
|
|
|
|
|
public List<String> getSessionClassNameListBySessionIds (String ids){
|
|
|
return teacherOpenCourseScheduleSessionSnapDao.getSessionClassNameListBySessionIds(ids);
|
|
|
}
|
|
|
|
|
|
public List<TeacherOpenCourseScheduleSessionSnap> getValuesByQuery (TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
return teacherOpenCourseScheduleSessionSnapDao.getValuesByQuery(teacherOpenCourseScheduleSessionSnapQuery);
|
|
|
}
|
|
|
|
|
|
public TeacherOpenCourseScheduleSessionSnap getInfo (Long teacherOpenCourseScheduleSessionSnapId){
|
|
|
TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery = new TeacherOpenCourseScheduleSessionSnapQuery();
|
|
|
teacherOpenCourseScheduleSessionSnapQuery.setTeacherOpenCourseScheduleSessionSnapId(teacherOpenCourseScheduleSessionSnapId);
|
|
|
teacherOpenCourseScheduleSessionSnapQuery.setTeacherOpenCourseScheduleSessionSnapStatusPlural("1,2");//需要根据实际情况来
|
|
|
List<TeacherOpenCourseScheduleSessionSnap> list = teacherOpenCourseScheduleSessionSnapDao.getValuesByQuery(teacherOpenCourseScheduleSessionSnapQuery);
|
|
|
if(null != list && list.size()>0){
|
|
|
return list.get(0);
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public TeacherOpenCourseScheduleSessionSnap getInfo (TeacherOpenCourseScheduleSessionSnapQuery teacherOpenCourseScheduleSessionSnapQuery){
|
|
|
List<TeacherOpenCourseScheduleSessionSnap> list = teacherOpenCourseScheduleSessionSnapDao.getValuesByQuery(teacherOpenCourseScheduleSessionSnapQuery);
|
|
|
if(null != list && list.size()>0){
|
|
|
return list.get(0);
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void resetOperationByTeacherOpenCourseId(Long teacherOpenCourseId) {
|
|
|
log.info("可能需要实现重置操作!");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deleteTeacherOpenCourseAllRelatedByTeacherOpenCourseId(@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId) {
|
|
|
log.info("需要实现删除操作!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 一次性填充,某个集合字段
|
|
|
* 这里填充,{@link TeacherOpenCourseScheduleSession#setSessionTagList}
|
|
|
* @param list
|
|
|
*/
|
|
|
public void fullSessionTagList(List<TeacherOpenCourseScheduleSession> list) {
|
|
|
String scheduleSessionIds = listJoin(list, TeacherOpenCourseScheduleSession::getTeacherOpenCourseScheduleSessionId);
|
|
|
|
|
|
if (StrUtil.isNotBlank(scheduleSessionIds)) {
|
|
|
TeacherOpenCourseScheduleSessionSnapQuery query = new TeacherOpenCourseScheduleSessionSnapQuery();
|
|
|
query.setTeacherOpenCourseScheduleSessionSnapStatus(1);
|
|
|
query.setTeacherOpenCourseScheduleSessionIdPlural(scheduleSessionIds);
|
|
|
List<TeacherOpenCourseScheduleSessionSnap> snapList = getValuesByQuery(query);
|
|
|
|
|
|
// 根据排课ID分组
|
|
|
Map<Long, List<TeacherOpenCourseScheduleSessionSnap>> groupSortedMap = snapList.stream()
|
|
|
.sorted(Comparator.comparing(TeacherOpenCourseScheduleSessionSnap::getTeacherOpenCourseScheduleSessionDayTime))
|
|
|
.collect(groupingBy(TeacherOpenCourseScheduleSessionSnap::getTeacherOpenCourseScheduleSessionId));
|
|
|
|
|
|
list.forEach(item -> {
|
|
|
final Long scheduleSessionId = item.getTeacherOpenCourseScheduleSessionId();
|
|
|
List<TeacherOpenCourseScheduleSessionSnap> listOrDefault = groupSortedMap.getOrDefault(scheduleSessionId, Collections.emptyList());
|
|
|
item.setSessionTagList(listOrDefault);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|