165 lines
5.6 KiB
Java
165 lines
5.6 KiB
Java
package com.ibeetl.jlw.service;
|
|
|
|
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.HandsOnDao;
|
|
import com.ibeetl.jlw.entity.HandsOn;
|
|
import com.ibeetl.jlw.entity.HandsOnSimulationTasks;
|
|
import com.ibeetl.jlw.web.query.HandsOnQuery;
|
|
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 java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* HandsOn Service
|
|
* 当分布式ID开启后请勿使用insert(*,true)
|
|
*/
|
|
|
|
@Service
|
|
@Transactional
|
|
public class HandsOnService extends CoreBaseService<HandsOn>{
|
|
|
|
@Autowired private HandsOnDao handsOnDao;
|
|
@Autowired private HandsOnSimulationTasksService handsOnSimulationTasksService;
|
|
|
|
public PageQuery<HandsOn>queryByCondition(PageQuery query){
|
|
PageQuery ret = handsOnDao.queryByCondition(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public PageQuery<HandsOn>queryByConditionQuery(PageQuery query){
|
|
PageQuery ret = handsOnDao.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)){
|
|
handsOnDao.deleteHandsOnByIds(ids);
|
|
}
|
|
}
|
|
|
|
public void deleteHandsOn(String ids){
|
|
try {
|
|
handsOnDao.deleteHandsOnByIds(ids);
|
|
} catch (Exception e) {
|
|
throw new PlatformException("批量删除HandsOn失败", e);
|
|
}
|
|
}
|
|
|
|
public String addAll(HandsOnQuery handsOnQuery){
|
|
String msg = "";
|
|
List<HandsOn> handsOnList = new ArrayList<>();
|
|
try {
|
|
handsOnList = JSON.parseArray(handsOnQuery.getHandsOnJsonStr(), HandsOn.class);
|
|
} catch (Exception e) {
|
|
try {
|
|
handsOnList.add(JSONObject.parseObject(handsOnQuery.getHandsOnJsonStr(), HandsOn.class));
|
|
} catch (Exception e1) {}
|
|
}
|
|
ToolUtils.deleteNullList(handsOnList);
|
|
if(null != handsOnList && handsOnList.size()>0){
|
|
for(int i=0;i<handsOnList.size();i++){
|
|
HandsOn handsOn = handsOnList.get(i);
|
|
}
|
|
insertBatch(handsOnList);
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public JsonResult add(HandsOn handsOn){
|
|
String msg = "";
|
|
handsOnDao.insert(handsOn);
|
|
JsonResult jsonResult = new JsonResult();
|
|
jsonResult.setData(handsOn.getHandsOnId());//自增的ID丢进去
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
jsonResult.setMsg(msg);
|
|
return jsonResult;
|
|
}
|
|
|
|
public String edit(HandsOnQuery handsOnQuery){
|
|
String msg = "";
|
|
HandsOn handsOn = handsOnQuery.pojo();
|
|
handsOnDao.updateTemplateById(handsOn);
|
|
return msg;
|
|
}
|
|
|
|
public String updateGivenByIds(HandsOnQuery handsOnQuery){
|
|
String msg = "";
|
|
if(StringUtils.isNotBlank(handsOnQuery.get_given())){
|
|
boolean flag = handsOnDao.updateGivenByIds(handsOnQuery) > 0;
|
|
if(!flag){
|
|
msg = "更新指定参数失败";
|
|
}
|
|
}else{
|
|
msg = "指定参数为空";
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public List<HandsOn> getValues (Object paras){
|
|
return sqlManager.select(SqlId.of("jlw.handsOn.getHandsOnValues"), HandsOn.class, paras);
|
|
}
|
|
|
|
public List<HandsOn> getValuesByQuery (HandsOnQuery handsOnQuery){
|
|
return handsOnDao.getValuesByQuery(handsOnQuery);
|
|
}
|
|
|
|
public HandsOn getInfo (Long handsOnId){
|
|
HandsOnQuery handsOnQuery = new HandsOnQuery();
|
|
handsOnQuery.setHandsOnId(handsOnId);
|
|
List<HandsOn> list = handsOnDao.getValuesByQuery(handsOnQuery);
|
|
if(null != list && list.size()>0){
|
|
return list.get(0);
|
|
}else{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public HandsOn getInfo (HandsOnQuery handsOnQuery){
|
|
List<HandsOn> list = handsOnDao.getValuesByQuery(handsOnQuery);
|
|
if(null != list && list.size()>0){
|
|
return list.get(0);
|
|
}else{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 学生端-查询课程实操首页
|
|
* @param teacherOpenCourseId
|
|
*/
|
|
public void getHandonListByTeacherOpenCourseId(Long teacherOpenCourseId) {
|
|
|
|
HandsOnQuery handsOnQuery = new HandsOnQuery();
|
|
handsOnQuery.setTeacherOpenCourseId(teacherOpenCourseId);
|
|
List<HandsOn> handsOnList = handsOnDao.getValuesByQuery(handsOnQuery);
|
|
List<Long> handsOnIds = handsOnList.stream().map(HandsOn::getHandsOnId).distinct().collect(Collectors.toList());
|
|
List<HandsOnSimulationTasks> handsOnSimulationTasks = handsOnSimulationTasksService.queryObjectByHandsOnIds(handsOnIds);
|
|
for (HandsOn handsOn : handsOnList) {
|
|
List<HandsOnSimulationTasks> collect = handsOnSimulationTasks.stream().filter(v -> v.getHandsOnId().equals(handsOn.getHandsOnId())).collect(Collectors.toList());
|
|
handsOn.set("handsOnSimulationTasks", collect);
|
|
}
|
|
|
|
|
|
}
|
|
}
|