Commit 5098fe46 authored by luzhuang's avatar luzhuang

更新代码

parent bd0ceaed
package org.rcisoft.business.blesson.dao;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.blesson.dto.AddMyLearnLessonDTO;
......@@ -38,6 +40,24 @@ public interface BCollectRepository extends BaseMapper<BCollect> {
@ResultMap(value = "BaseResultMap")
List<BCollect> selectByPersonAndLesson(AddMyLearnLessonDTO param);
/**
* 查询关系表中是否已存在此关系
* @param personId
* @param lessonId
* @return
*/
@Select("select * from b_collect where person_id =#{personId} and lesson_id =#{lessonId} ")
List<BCollect> selectOneData(@Param("personId") String personId,@Param("lessonId") String lessonId);
/**
* 取消收藏课程或培训
* @param personId
* @param lessonId
* @return
*/
@Delete("delete from b_collect where person_id =#{personId} and lesson_id =#{lessonId} ")
int notColletLesson(@Param("personId") String personId,@Param("lessonId") String lessonId);
}
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Repository
public interface BLessonPersonRepository extends BaseMapper<BLessonPerson> {
......@@ -278,7 +279,10 @@ public interface BLessonPersonRepository extends BaseMapper<BLessonPerson> {
"where lesson_id= #{lessonId} and person_id=#{personId} and del_flag != 1 ")
int updateLessonPersonByUserId(BLessonPerson lessonPerson);
// @Insert("")
// int insertLessonPerson(BLessonPerson lessonPerson);
@Select("select count(0) x ,(select max_apply_person from b_lesson where business_id = #{lessonId} ) y " +
"from b_lesson_person where lesson_id = #{lessonId} ")
Map<String,Object> selecTraningNum(@Param("lessonId") String lessonId);
}
......@@ -18,10 +18,12 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "b_collect")
public class BCollect extends IdEntity<BCollect> {
public class BCollect{
protected String businessId;
private String personId;
private String lessonId;
......
......@@ -235,6 +235,17 @@ public interface BLessonService{
*/
int toTraining(CurUser curUser,String lessonId);
/**
* 收藏课程或课程
* @param curUser
* @param lessonId
* @return
*/
PersistModel colletLesson(CurUser curUser,String lessonId);
PersistModel notColletLesson(CurUser curUser,String lessonId);
/**
* 单一查询我参加培训的信息
......
......@@ -2,9 +2,11 @@ package org.rcisoft.business.blesson.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.rcisoft.business.bcourse.dao.BCourseRepository;
import org.rcisoft.business.bcourse.dto.AllCourseDTO;
import org.rcisoft.business.bfile.dao.BTrainFileRepository;
......@@ -803,7 +805,6 @@ public class BLessonServiceImpl implements BLessonService {
// }
//插入收藏表
BCollect bCollect = new BCollect();
UserUtil.setCurrentPersistOperation(bCollect);
bCollect.setLessonId(lessonId);
bCollect.setPersonId(curUser.getUserId());
int line = bCollectRepository.insertSelective(bCollect);
......@@ -817,7 +818,14 @@ public class BLessonServiceImpl implements BLessonService {
public int toTraining(CurUser curUser, String lessonId) {
BLessonPerson person = new BLessonPerson();
BLessonPerson bLessonPerson = new BLessonPerson();
//tep1 判断该用户是否被指派该培训或已经报名
Map<String,Object> xy = bLessonPersonRepository.selecTraningNum(lessonId);
int x = Integer.parseInt(String.valueOf(xy.get("x")));
int y = Integer.parseInt(String.valueOf(xy.get("y")));
if( x >= y){
throw new ServiceException(ResultServiceEnums.PERSON_MAX);
}
//tep2 判断该用户是否被指派该培训或已经报名
person = bLessonPersonRepository.getAppointInTraining(lessonId, curUser.getUserId());
if (person != null) {
......@@ -844,6 +852,29 @@ public class BLessonServiceImpl implements BLessonService {
}
@Override
public PersistModel colletLesson(CurUser curUser, String lessonId) {
//先判断是否收藏该课程或培训
List<BCollect> one = bCollectRepository.selectOneData(curUser.getUserId(),lessonId);
if(one.size() > 0 ){
return new PersistModel(1);
}
BCollect bCollect = new BCollect();
bCollect.setBusinessId(IdGen.uuid());
bCollect.setLessonId(lessonId);
bCollect.setPersonId(curUser.getUserId());
int line = bCollectRepository.insert(bCollect);
return new PersistModel(line);
}
@Override
public PersistModel notColletLesson(CurUser curUser, String lessonId) {
return new PersistModel(bCollectRepository.notColletLesson(curUser.getUserId(),lessonId));
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public BLesson findOneMyTrain(CurUser curUser, String businessId) {
......
......@@ -222,6 +222,7 @@ public enum ResultServiceEnums {
CHANGE_FILE_ERROR(120,"文件转换失败"),
NOT_LESSON_ERROR(121,"该课程不存在"),
JSON_ERROR(122,"JSON格式不正确"),
PERSON_MAX(123,"报名人数已满"),
;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment