Commit 510b6667 authored by zhangqingle's avatar zhangqingle

增加报名课程培训增加积分,学习报名课程培训扣除积分

parent faa6b78e
......@@ -68,7 +68,7 @@ public class BDiscussController extends PaginationController<BDiscuss> {
@ApiOperation(value="逻辑删除", notes="逻辑删除")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "id", required = false, dataType = "varchar")})
@DeleteMapping("/delete/{id:\\w+}")
@PostMapping("/delete/{id:\\w+}")
public Result delete(@PathVariable String id) {
BDiscuss bDiscuss = new BDiscuss();
bDiscuss.setBusinessId(id);
......
......@@ -353,7 +353,7 @@ public class BLessonController extends PaginationController<BLesson> {
@ApiImplicitParam(name = "businessId", value = "businessId", required = true, dataType = "varchar")
@PostMapping(value = "/release")
public Result release(CurUser curUser, String businessId, BindingResult bindingResult) {
PersistModel data = bLessonService.releaseBLesson(businessId);
PersistModel data = bLessonService.releaseBLesson(businessId, curUser);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
......
......@@ -43,8 +43,21 @@ public class AddLessonDTO {
@ApiModelProperty(value = "课程类型(0:课程 1:培训)",required = true)
private String lessonType;
@ApiModelProperty(value = "积分")
private String value;
@ApiModelProperty(value = "消耗积分")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private Integer valueConsume;
@ApiModelProperty(value = "获得积分")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private Integer valueGain;
@ApiModelProperty(value = "更新积分日期")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private Date valueUpdateDate;
// @ApiModelProperty(value = "积分")
// private String value;
@ApiModelProperty(value = "标签集合,使用','分隔")
private String labels;
......
......@@ -110,9 +110,21 @@ public class BLesson extends IdEntity<BLesson> {
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String hotNumber;
@ApiModelProperty(value = "积分")
@ApiModelProperty(value = "消耗积分")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String value;
private Integer valueConsume;
@ApiModelProperty(value = "获得积分")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private Integer valueGain;
@ApiModelProperty(value = "更新积分日期")
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private Date valueUpdateDate;
// @ApiModelProperty(value = "积分")
// @Length(min = 1,max = 64,message = "长度最小为1,最大为50")
// private String value;
//---------------培训------------------
@DateTimeFormat(pattern="yyyy/MM/dd HH:mm:ss")
......
......@@ -125,7 +125,7 @@ public interface BLessonService{
* @param id
* @return
*/
PersistModel releaseBLesson(String id);
PersistModel releaseBLesson(String id, CurUser curUser);
/**
* 推荐课程
......
......@@ -11,6 +11,9 @@ import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.blesson.dao.BLessonPersonRepository;
import org.rcisoft.business.blesson.entity.BLessonPerson;
import org.rcisoft.business.blesson.service.BLessonPersonService;
import org.rcisoft.business.blesson.service.BLessonService;
import org.rcisoft.business.bpersonvalue.dao.BPersonValueRepository;
import org.rcisoft.business.bpersonvalue.entity.BPersonValue;
import org.rcisoft.common.util.feignDto.*;
import org.rcisoft.common.util.outClient.MTCotactApiRequestClient;
import org.rcisoft.core.aop.PageUtil;
......@@ -22,6 +25,8 @@ import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.IdGen;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.sys.user.bean.CurUser;
import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.dto.MyInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......@@ -53,6 +58,15 @@ public class BLessonPersonServiceImpl implements BLessonPersonService {
@Autowired
MTCotactApiRequestClient mtCotactApiRequestClient;
@Autowired
SysUserMapper sysUserMapper;
@Autowired
BPersonValueRepository bPersonValueRepository;
@Autowired
BLessonServiceImpl bLessonServiceImpl;
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
@Override
......@@ -231,8 +245,14 @@ public class BLessonPersonServiceImpl implements BLessonPersonService {
return new PersistModel(line);
}
if (bLessonPersons == null || bLessonPersons.size() < 1){ //未指派
//TODO 判断用户是否有足够积分
//判断用户是否有足够积分
MyInfoDTO userInfo = sysUserMapper.getNameById(curUser.getUserId());
if (userInfo == null){
throw new ServiceException(ResultServiceEnums.COMPANY_NOT_EXISTS);
}
if (Long.valueOf(userInfo.getValue()) < Long.valueOf(bLesson.getValueConsume())){
throw new ServiceException(ResultServiceEnums.VALUE_NOT_ENOUGH);
}
//查询是否已有已删除
List<BLessonPerson> bLessonPersonReals = bLessonPersonRepository.selectRealByPersonAndLesson(addMyLearnLessonDTO);
if (bLessonPersonReals != null && bLessonPersonReals.size()>0){
......@@ -244,6 +264,12 @@ public class BLessonPersonServiceImpl implements BLessonPersonService {
UserUtil.setCurrentMergeOperation(bLessonPersonReal);
line = bLessonPersonRepository.updateByPrimaryKeySelective(bLessonPersonReal);
//扣除对应积分 添加用户积分详情 更新用户积分
//增加用户积分详情
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0){
BPersonValue bPersonValue = new BPersonValue(curUser.getUserId(),"学习课程",bLesson.getValueConsume(),"1");
bLessonServiceImpl.addValueEvent(curUser,bPersonValue,bLesson);
}
return new PersistModel(line);
}
bLessonPerson = new BLessonPerson();
......@@ -254,9 +280,13 @@ public class BLessonPersonServiceImpl implements BLessonPersonService {
bLessonPerson.setLessonId(addMyLearnLessonDTO.getLessonId());
bLessonPerson.setPersonId(addMyLearnLessonDTO.getUserId());
line = bLessonPersonRepository.insertBLessonPerson(bLessonPerson);
//TODO 扣除对应积分 添加用户积分详情 更新用户积分
//扣除对应积分 添加用户积分详情 更新用户积分
//增加用户积分详情
//积分变化后 s_user表中value字段重新统计
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0){
BPersonValue bPersonValue = new BPersonValue(curUser.getUserId(),"学习课程",bLesson.getValueConsume(),"1");
bLessonServiceImpl.addValueEvent(curUser,bPersonValue,bLesson);
}
//重新统计在学人数
bLessonRepository.personNumberReCount(addMyLearnLessonDTO.getLessonId(),"0");
return new PersistModel(line);
......
......@@ -18,6 +18,10 @@ import org.rcisoft.business.blesson.util.Recursion;
import org.rcisoft.business.blesson.dao.BViewrangeRepository;
import org.rcisoft.business.bmaterial.dao.BMaterialRepository;
import org.rcisoft.business.bmaterial.entity.BMaterial;
import org.rcisoft.business.bpersonvalue.dao.BPersonValueRepository;
import org.rcisoft.business.bpersonvalue.entity.BPersonValue;
import org.rcisoft.business.breleasevalue.dao.BReleaseValueRepository;
import org.rcisoft.business.breleasevalue.entity.BReleaseValue;
import org.rcisoft.common.util.feignDto.*;
import org.rcisoft.common.util.outClient.MTCotactApiRequestClient;
import org.rcisoft.core.aop.PageUtil;
......@@ -29,6 +33,7 @@ import org.rcisoft.core.util.IdGen;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.sys.user.bean.CurUser;
import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.dto.MyInfoDTO;
import org.rcisoft.sys.user.entity.SysUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -90,6 +95,12 @@ public class BLessonServiceImpl implements BLessonService {
@Autowired
MTCotactApiRequestClient cotactApiRequestClient;
@Autowired
BReleaseValueRepository bReleaseValueRepository;
@Autowired
BPersonValueRepository bPersonValueRepository;
@Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public BLesson selectOne(CurUser curUser,String lessonId) {
......@@ -503,18 +514,19 @@ public class BLessonServiceImpl implements BLessonService {
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public PersistModel releaseBLesson(String id) {
public PersistModel releaseBLesson(String id, CurUser curUser) {
BLesson bLesson = new BLesson();
bLesson.setBusinessId(id);
bLesson = bLessonRepository.selectByPrimaryKey(bLesson);
if("0".equals(bLesson.getLessonType()) && bChapterRepository.getlessonHours(id) == 0){
throw new ServiceException(ResultServiceEnums.LESSON_NO_CHAPTER);
}
if (bLesson == null){
throw new ServiceException(ResultServiceEnums.NOT_LESSON_ERROR);
}
if("0".equals(bLesson.getLessonType()) && bChapterRepository.getlessonHours(id) == 0){
throw new ServiceException(ResultServiceEnums.LESSON_NO_CHAPTER);
}
if (!"0".equals(bLesson.getReleaseState())) {
throw new ServiceException(ResultServiceEnums.STATE_NOT_RELEASE);
}
......@@ -526,8 +538,26 @@ public class BLessonServiceImpl implements BLessonService {
bLesson.setReleaseDate(new Date());
UserUtil.setCurrentMergeOperation(bLesson);
int line = bLessonRepository.releaseLesson(bLesson);
//TODO:查询该讲师发布课程获得积分数并
//TODO:增加用户积分详情,更新用户积分表,重新统计用户积分
//查询该讲师发布课程获得积分数
List<BReleaseValue> bReleaseValueList = bReleaseValueRepository.selectReleaseValueByPersonId(curUser);
if(bReleaseValueList != null && bReleaseValueList.size() > 0 && bReleaseValueList.get(0) != null){
//增加用户积分详情
BPersonValue bPersonValue = new BPersonValue();
UserUtil.setCurrentPersistOperation(bPersonValue);
bPersonValue.setPersonId(bLesson.getLecturerId());
bPersonValue.setType("0");
if ("0".equals(bLesson.getLessonType())) {
bPersonValue.setEvent("发布课程");
bPersonValue.setValue(bReleaseValueList.get(0).getLessonValue());
}
if ("1".equals(bLesson.getLessonType())){
bPersonValue.setEvent("发布培训");
bPersonValue.setValue(bReleaseValueList.get(0).getTrainValue());
}
bPersonValueRepository.add(bPersonValue);
//积分变化后 s_user表中value字段重新统计
bPersonValueRepository.updateUserValue(bLesson.getLecturerId(),curUser.getCorpId());
}
//int line = bLessonRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
}
......@@ -1074,9 +1104,7 @@ public class BLessonServiceImpl implements BLessonService {
person.setTrainIsSign("0");
person.setApplyDate(new Date());
person.setIsApply("1");
//TODO 判断积分是否够用
int line = bLessonPersonRepository.updateLessonPersonByUserId(person);
//TODO 更新用户积分明细表 重进计算积分
bLessonRepository.personNumberReCount(lessonId,"1");
return line;
}
......@@ -1086,9 +1114,21 @@ public class BLessonServiceImpl implements BLessonService {
person.setIsApply("1");
person.setApplyDate(new Date());
//TODO 判断积分是否够用
MyInfoDTO userInfo = sysUserMapper.getNameById(curUser.getUserId());
if (userInfo == null){
throw new ServiceException(ResultServiceEnums.COMPANY_NOT_EXISTS);
}
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0 && Integer.parseInt(userInfo.getValue()) < bLesson.getValueConsume()){
throw new ServiceException(ResultServiceEnums.VALUE_NOT_ENOUGH);
}
int line = bLessonPersonRepository.updateByPrimaryKeySelective(person);
//TODO 更新用户积分明细表 重进计算积分
bLessonRepository.personNumberReCount(lessonId,"1");
//扣除对应积分 添加用户积分详情 更新用户积分
//增加用户积分详情
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0){
BPersonValue bPersonValue = new BPersonValue(curUser.getUserId(),"报名培训",bLesson.getValueConsume(),"1");
addValueEvent(curUser,bPersonValue,bLesson);
}
return line;
}
List<BLessonPerson> bLessonPersons = new ArrayList<>();
......@@ -1104,9 +1144,21 @@ public class BLessonServiceImpl implements BLessonService {
//插入 用户id 、培训id、指派状态、报名状态、培训状态、报名时间 、通用字段
// int line = bLessonPersonRepository.insert(bLessonPerson);
//TODO 判断积分是否够用
MyInfoDTO userInfo = sysUserMapper.getNameById(curUser.getUserId());
if (userInfo == null){
throw new ServiceException(ResultServiceEnums.COMPANY_NOT_EXISTS);
}
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0 && Integer.parseInt(userInfo.getValue()) < bLesson.getValueConsume()){
throw new ServiceException(ResultServiceEnums.VALUE_NOT_ENOUGH);
}
int line = this.trainInsert("0",bLesson,bLessonPersons);
//TODO 更新用户积分明细表 重进计算积分
bLessonRepository.personNumberReCount(lessonId,"1");
//扣除对应积分 添加用户积分详情 更新用户积分
//增加用户积分详情
if (bLesson.getValueConsume() != null && bLesson.getValueConsume() != 0){
BPersonValue bPersonValue = new BPersonValue(curUser.getUserId(),"报名培训",bLesson.getValueConsume(),"1");
addValueEvent(curUser,bPersonValue,bLesson);
}
return line;
}
......@@ -1407,7 +1459,7 @@ public class BLessonServiceImpl implements BLessonService {
}
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
@Transactional(propagation = Propagation.REQUIRED, readOnly = false,rollbackFor= Exception.class)
//type: 0报名 1指派
synchronized int trainInsert(String type, BLesson bLesson, List<BLessonPerson> bLessonPersons){
int line = 0;
......@@ -1439,4 +1491,15 @@ public class BLessonServiceImpl implements BLessonService {
return line;
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false,rollbackFor= Exception.class)
public void addValueEvent(CurUser curUser, BPersonValue bPersonValue, BLesson bLesson){
if (curUser != null && bPersonValue != null && bLesson != null){
UserUtil.setCurrentPersistOperation(bPersonValue);
bPersonValueRepository.add(bPersonValue);
//积分变化后 s_user表中value字段重新统计
bPersonValueRepository.updateUserValue(curUser.getUserId(),curUser.getCorpId());
bLessonRepository.personNumberReCount(bLesson.getBusinessId(),"1");
}
}
}
......@@ -25,12 +25,12 @@ public interface BPersonValueRepository extends BaseMapper<BPersonValue> {
"and person_id = #{businessId} " +
"<if test=\"startTime !=null and startTime != '' \"> and create_date &lt;= #{startTime} </if> "+
"<if test=\"endTime !=null and endTime != '' \"> and create_date &gt;= #{endTime} </if> "+
"<if test=\"event !=null and event != '' \"> and event like concat('%',#{event},'%') </if> "+
"<if test=\"event !=null and event != '' \"> and `event` like concat('%',#{event},'%') </if> "+
// "<if test=\"type !=null and type != '' \"> and event like concat('%',#{event},'%') </if> "+
" ORDER BY person_id " +
"<if test=\" valueSort !=null and valueSort != '' and valueSort == '0'.toString() \"> ,type asc,value desc </if> "+
"<if test=\" valueSort !=null and valueSort != '' and valueSort == '1'.toString() \"> ,type desc,value asc </if> "+
"<if test=\" valueSort !=null and valueSort != '' and valueSort == '0'.toString() \"> ,type asc,`value` desc </if> "+
"<if test=\" valueSort !=null and valueSort != '' and valueSort == '1'.toString() \"> ,type desc,`value` asc </if> "+
"<if test=\" dateSort !=null and dateSort != '' and dateSort == '0'.toString() \"> ,create_date asc</if> "+
"<if test=\" dateSort !=null and dateSort != '' and dateSort == '1'.toString() \"> ,create_date desc</if> "+
"</script>")
......@@ -68,7 +68,7 @@ public interface BPersonValueRepository extends BaseMapper<BPersonValue> {
* @return
*/
@Insert("INSERT INTO b_person_value " +
"( remarks,create_by,create_date,update_by,update_date,del_flag,flag,business_id,person_id,event,value,type )" +
"( remarks,create_by,create_date,update_by,update_date,del_flag,flag,business_id,person_id,`event`,`value`,type )" +
" VALUES( #{remarks},#{createBy},#{createDate},#{updateBy},#{updateDate},#{delFlag},#{flag},#{businessId},#{personId},#{event},#{value},#{type} )")
int add(BPersonValue bPersonValue);
}
......
......@@ -29,5 +29,12 @@ public class BPersonValue extends IdEntity<BPersonValue> {
private String type;
// public BPersonValue(String personId, String event, Integer value, String type) {
// this.personId = personId;
// this.event = event;
// this.value = value;
// this.type = type;
// }
}
......@@ -125,7 +125,7 @@ public interface BReleaseValueRepository extends BaseMapper<BReleaseValue> {
* @return
*/
@Select("<script>select business_id, name , `value` ," +
"(select sum(value) from b_person_value where person_id = s_user.business_id and type = 0) valueGain " +
"(select sum(`value`) from b_person_value where person_id = s_user.business_id and type = 0) valueGain " +
" from s_user " +
" where 1=1 and del_flag !=1 and flag = 1 " +
" and corp_id = #{dto.corpId} " +
......@@ -140,8 +140,8 @@ public interface BReleaseValueRepository extends BaseMapper<BReleaseValue> {
"<if test=\"dto.gainValueEnd!=null and dto.gainValueEnd != ''\"> " +
" and (select sum(value) from b_person_value where person_id = s_user.business_id and type = 0) &lt;= #{dto.gainValueEnd} </if> " +
"ORDER BY corp_id " +
"<if test=\"dto.nowValueSort!=null and dto.nowValueSort != '' and dto.nowValueSort == '0'.toString()\"> ,value asc </if> " +
"<if test=\"dto.nowValueSort!=null and dto.nowValueSort != '' and dto.nowValueSort == '1'.toString()\"> ,value desc </if> " +
"<if test=\"dto.nowValueSort!=null and dto.nowValueSort != '' and dto.nowValueSort == '0'.toString()\"> ,`value` asc </if> " +
"<if test=\"dto.nowValueSort!=null and dto.nowValueSort != '' and dto.nowValueSort == '1'.toString()\"> ,`value` desc </if> " +
"<if test=\"dto.gainValueSort!=null and dto.gainValueSort != '' and dto.gainValueSort == '0'.toString()\"> ,valueGain asc </if> " +
"<if test=\"dto.gainValueSort!=null and dto.gainValueSort != '' and dto.gainValueSort == '1'.toString()\"> ,valueGain desc </if> " +
" </script>")
......@@ -165,5 +165,16 @@ public interface BReleaseValueRepository extends BaseMapper<BReleaseValue> {
"and rv.corp_id = #{corpId}" +
"</script>")
String getReleaseId (@Param("name") String name,@Param("corpId")String corpId);
@Select("<script>" +
"select rv.lesson_value lessonValue, rv.train_value trainValue " +
"from b_release_value rv " +
"left join b_release_value_son rvs on rv.business_id = rvs.release_id " +
// "left join s_user su on su.business_id = rvs.user_id " +
"where rv.del_flag != 1 and rv.flag = 1 " +
"and rvs.user_id = #{curUser.userId} " +
"and rv.corp_id = #{curUser.corpId} " +
"</script>")
List<BReleaseValue> selectReleaseValueByPersonId(@Param("curUser")CurUser curUser);
}
......@@ -241,6 +241,7 @@ public enum ResultServiceEnums {
VALUE_IS_ERROR(141,"扣除积分大于当前积分"),
USER_IS_NULL(142,"请选择用户"),
NUM_IS_ERROR(143,"积分输入格式错误"),
VALUE_NOT_ENOUGH(144,"积分输入格式错误"),
;
private Integer code;
......
......@@ -273,7 +273,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @return
*/
@Insert("<script> INSERT INTO b_dictionary " +
"(BUSINESS_ID,PID,TYPE,NAME,VALUE,CREATE_BY,CREATE_DATE,UPDATE_BY,UPDATE_DATE,DEL_FLAG,FLAG,REMARKS,corp_id,sort) VALUES" +
"(BUSINESS_ID,PID,TYPE,NAME,`VALUE`,CREATE_BY,CREATE_DATE,UPDATE_BY,UPDATE_DATE,DEL_FLAG,FLAG,REMARKS,corp_id,sort) VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"(#{item.businessId},#{item.pid},#{item.type},#{item.name},#{item.value},#{item.createBy},#{item.createDate},#{item.updateBy},#{item.updateDate},#{item.delFlag},#{item.flag},#{item.remarks},#{item.corpId},#{item.sort})"+
"</foreach> </script>")
......
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