Commit bf60ebce authored by root's avatar root

course label

parent 9762209c
......@@ -20,7 +20,7 @@ import org.rcisoft.core.result.Result;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ZhangQingle
* @author
* @date 2019/9/11
*/
......
......@@ -11,7 +11,7 @@ import java.util.List;
import java.util.Map;
/**
* @author ZhangQingle
* @author
* @date 2019/9/10
*/
@Repository
......
......@@ -13,7 +13,7 @@ import javax.persistence.Table;
/**
* @author ZhangQingle
* @author
* @date 2019/9/10
*/
@Entity
......
......@@ -18,7 +18,7 @@ import java.util.List;
/**
* @author ZhangQingle
* @author
* @date 2019/9/10
*/
@Service
......
package org.rcisoft.business.bcourse.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.bcourse.entity.BCourse;
import org.rcisoft.business.bcourse.service.BCourseService;
import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/BCourse")
public class BCourseController extends PaginationController<BCourse> {
@Autowired
private BCourseService bCourseServiceImpl;
@ApiOperation(value="查询课程分类", notes="查询课程分类生成json数组")
@PostMapping(value = "/selectCourse")
public String queryCourse(BCourse bCourse){
return bCourseServiceImpl.getCourse(bCourse);
}
@ApiOperation(value="查询课程分类", notes="查询课程分类")
@PostMapping(value = "/queryCourse")
public Result queryBCourse(BCourse bCourse){
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCourseServiceImpl.queryBCourse(bCourse));
}
@ApiOperation(value="根据条件分页查询", notes="根据条件分页查询标签")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "condition", value = "模糊查询条件", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "cName", value = "课程名", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBCourseByPagination")
public GridModel queryBCourseByPagination(BCourse bCourse){
bCourse.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
bCourseServiceImpl.queryBCourseByPagination(getPaginationUtility(), bCourse);
GridModel gridModel = getGridModelResponse();
return gridModel;
}
@ApiOperation(value="物理删除", notes="根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "varchar")
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/remove")
public Result remove(HttpServletRequest request) {
String id = request.getParameter("ID");
PersistModel data = bCourseServiceImpl.removeCourse(id);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
@ApiOperation(value="更新课程名", notes="根据ID更新课程名")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "name", value = "cName", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/update")
public Result update(BCourse bCourse){
PersistModel data = bCourseServiceImpl.updateCourse(bCourse,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCourse.getBusinessId());
}
@ApiOperation(value="插入课程分类", notes="插入课程分类")
@ApiImplicitParams({@ApiImplicitParam(name = "pid", value = "parentId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "name", value = "cName", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/insert")
public Result insert(BCourse bCourse){
PersistModel data = bCourseServiceImpl.insertCourse(bCourse,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCourse.getParentId());
}
@ApiOperation(value="插入课程分类", notes="插入一级课程分类")
@ApiImplicitParams({@ApiImplicitParam(name = "order_by", value = "orderBy", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "name", value = "cName", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/insertTop")
public Result insertTop(BCourse bCourse){
PersistModel data = bCourseServiceImpl.insertTopCourse(bCourse,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bCourse.getParentId());
}
}
package org.rcisoft.business.bcourse.dao;
import org.apache.ibatis.annotations.*;
import org.rcisoft.business.bcourse.entity.BCourse;
import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BCourseRepository extends BaseMapper<BCourse> {
// @Select("SELECT * from t_course WHERE del_flag='0' AND flag='1'")
// @ResultMap(value = "BaseResultMap")
// List<TCourse> selectCourse();
@Select("<script>SELECT * FROM b_course where del_flag != 1 and flag = 1 " +
"<if test=\"condition!=null and condition != ''\"> and c_name like CONCAT('%',#{condition},'%') </if>" +
"ORDER BY order_by</script>")
@ResultMap(value = "BaseResultMap")
List<BCourse> selectCourses(BCourse bCourse);
@Select("SELECT * from b_course WHERE del_flag='0' AND flag='1'AND c_name=#{cName}")
List<BCourse> selectOneByName(@Param("cName") String id);
@Update("UPDATE b_course SET del_flag='1' WHERE business_id = #{businessId}")
int removeCourse(@Param("businessId") String id);
// 编辑只改名字不该父节点
@Update("UPDATE b_course SET c_name = #{cName} WHERE business_id = #{businessId}")
int updateCourse(BCourse bCourse);
}
package org.rcisoft.business.bcourse.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.rcisoft.core.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "b_course")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BCourse extends IdEntity<BCourse> {
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String cName;
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String parentId;
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String orderBy;
@Transient
private String condition;//模糊查询条件
}
package org.rcisoft.business.bcourse.service;
import org.rcisoft.business.bcourse.entity.BCourse;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import java.util.List;
public interface BCourseService {
String getCourse(BCourse bCourse);
List<BCourse> queryBCourse(BCourse bCourse);
List<BCourse> queryBCourseByPagination(PageUtil pageUtil, BCourse bCourse);
PersistModel insertCourse(BCourse bCourse, String token);
PersistModel insertTopCourse(BCourse bCourse, String token);
PersistModel removeCourse(String id);
PersistModel updateCourse(BCourse bCourse, String token);
}
package org.rcisoft.business.bcourse.service.impl;
import org.rcisoft.business.bcourse.dao.BCourseRepository;
import org.rcisoft.business.bcourse.entity.BCourse;
import org.rcisoft.business.bcourse.service.BCourseService;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BCourseServiceImpl implements BCourseService {
@Autowired
private BCourseRepository bCourseRepository;
@Override
public String getCourse(BCourse bCourse) {
List<BCourse> list = bCourseRepository.selectCourses(bCourse);
String json = "[" + getCourseJson("00000000", list) + "]";
return json;
}
@Override
public List<BCourse> queryBCourse(BCourse bCourse) {
List<BCourse> list = bCourseRepository.selectCourses(bCourse);
return list;
}
@Override
public List<BCourse> queryBCourseByPagination(PageUtil pageUtil, BCourse bCourse) {
return bCourseRepository.selectCourses(bCourse);
}
@Override
public PersistModel insertCourse(BCourse bCourse, String token) {
List<BCourse> list = bCourseRepository.selectOneByName(bCourse.getCName());
if(list.size()>0){
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
}
UserUtil.setCurrentPersistOperation(bCourse);
return new PersistModel(bCourseRepository.insert(bCourse), MessageConstant.MESSAGE_ALERT_SUCCESS) ;
}
@Override
public PersistModel insertTopCourse(BCourse bCourse, String token) {
bCourse.setParentId("00000000");
List<BCourse> list = bCourseRepository.selectOneByName(bCourse.getCName());
if(list.size()>0){
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
}
UserUtil.setCurrentPersistOperation(bCourse);
return new PersistModel(bCourseRepository.insert(bCourse), MessageConstant.MESSAGE_ALERT_SUCCESS);
}
@Override
public PersistModel removeCourse(String id) {
return new PersistModel(
bCourseRepository.removeCourse(id), MessageConstant.MESSAGE_ALERT_SUCCESS);
}
@Override
public PersistModel updateCourse(BCourse bCourse, String token) {
List<BCourse> list = bCourseRepository.selectOneByName(bCourse.getCName());
if(list.size()>0){
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
}
UserUtil.setCurrentMergeOperation(bCourse);
return new PersistModel(bCourseRepository.updateByPrimaryKeySelective(bCourse), MessageConstant.MESSAGE_ALERT_SUCCESS);
}
private String getCourseJson(String treeid, List<BCourse> list) {
String str = "";
try {
StringBuffer sb = new StringBuffer();
for (BCourse t : list) {
if (t.getParentId().equals(treeid)) {
sb.append("{\"business_id\":" + t.getBusinessId() + ",\"c_name:\"" +
t.getCName() + ",\"nodes\":[" + getCourseJson(t.getBusinessId(), list) + "]},");
}
}
str = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
if (str.endsWith(",")) {
str = str.substring(0, str.length() - 1);
}
return str;
}
}
package org.rcisoft.business.blabel.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.blabel.entity.BLabel;
import org.rcisoft.business.blabel.service.BLabelService;
import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/BLabel")
public class BLabelController extends PaginationController<BLabel> {
@Autowired
private BLabelService bLabelService;
@ApiOperation(value="根据条件分页查询", notes="根据条件分页查询标签")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "condition", value = "模糊查询条件", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "lName", value = "标签名", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBlabelsByPagination")
public GridModel queryBlabelsByPagination(BLabel param){
param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
bLabelService.queryBlabelsByPagination(getPaginationUtility(),param);
GridModel gridModel = getGridModelResponse();
return gridModel;
}
@ApiOperation(value="物理删除", notes="根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "varchar")
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/remove")
public Result remove(HttpServletRequest request) {
String id =request.getParameter("ID");
PersistModel data = bLabelService.removeLabel(id);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
@ApiOperation(value="更新标签名", notes="根据ID更新标签名")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "name", value = "lName", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/update")
public Result update(BLabel bLabel){
PersistModel data = bLabelService.updateLabel(bLabel,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bLabel.getBusinessId());
}
@ApiOperation(value="插入新标签", notes="插入新标签")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "name", value = "lName", required = true, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/insert")
public Result insert(BLabel bLabel){
PersistModel data = bLabelService.insertLabel(bLabel,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
null);
}
}
package org.rcisoft.business.blabel.dao;
import org.apache.ibatis.annotations.*;
import org.rcisoft.business.blabel.entity.BLabel;
import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BLabelRepository extends BaseMapper<BLabel> {
// 查询所有数据
// @Select("SELECT * from t_label where del_flag='0' and flag='1'")
@Select("<script>SELECT * FROM b_label where del_flag != 1 and flag = 1 " +
"<if test=\"condition!=null and condition != ''\"> and l_name like CONCAT('%',#{condition},'%') </if>" +
"</script>")
@ResultMap(value = "BaseResultMap")
List<BLabel> queryBlabels(BLabel bLabel);
// 增加标签是检查标签名重复
@Select("SELECT * from b_label where l_name=#{lName} AND del_flag='0' and flag='1'")
List<BLabel> checknameByName(BLabel bLabel);
// 新增标签
@Insert("INSERT INTO b_label VALUES(UUID(),'',NOW(),'',NOW(),'0','1',#{lName})")
//@Insert("<script>INSERT INTO b_label" +
// "(create_date,update_date,create_by,update_by,remarks,del_flag,flag,business_id,l_name)VALUES" +
// "<foreach collection=\"list\" item=\"item\" separator=\",\">" +
// "( #{item.createDate},#{item.updateDate},#{item.createBy},#{item.updateBy},#{item.remarks},#{item.delFlag},#{item.flag},#{item.businessId},#{item.l_name})" +
// "</foreach></script>")
int insertLabel(BLabel bLabel);
// 修改标签
@Update("UPDATE b_label SET l_name=#{lName} where business_id = #{businessId}")
int updateLabel(BLabel bLabel);
// 逻辑删除标签
@Update("UPDATE b_label SET del_flag='1' where business_id = #{businessId}")
int removeLabel(@Param("businessId") String id);
}
package org.rcisoft.business.blabel.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.rcisoft.core.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "b_label")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BLabel extends IdEntity<BLabel> {
// private static final long serialVersionUID = 4660799781307219222L;//
// /*标签id*/
// @Length(min = 1,max = 64,message = "长度最小为1,最大为50")
// private String businessId;
/*标签名称*/
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
private String lName;
@Transient
private String condition;//模糊查询条件
}
package org.rcisoft.business.blabel.service;
import org.rcisoft.business.blabel.entity.BLabel;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import java.util.List;
public interface BLabelService {
List<BLabel> queryBlabelsByPagination(PageUtil pageUtil, BLabel model);
PersistModel insertLabel(BLabel bLabel, String token);
PersistModel updateLabel(BLabel bLabel, String token);
PersistModel removeLabel(String id);
}
package org.rcisoft.business.blabel.service.impl;
import org.rcisoft.business.blabel.dao.BLabelRepository;
import org.rcisoft.business.blabel.entity.BLabel;
import org.rcisoft.business.blabel.service.BLabelService;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class BLabelServiceImpl implements BLabelService {
@Autowired
private BLabelRepository bLabelRepository;
@Override
public List<BLabel> queryBlabelsByPagination(PageUtil pageUtil, BLabel bLabel) {
return bLabelRepository.queryBlabels(bLabel);
}
@Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel insertLabel(BLabel bLabel, String token) {
List<BLabel> line = bLabelRepository.checknameByName(bLabel);
if(line.size()>0){
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
}
UserUtil.setCurrentPersistOperation(bLabel);
return new PersistModel(bLabelRepository.insert(bLabel),MessageConstant.MESSAGE_ALERT_SUCCESS) ;
}
@Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel updateLabel(BLabel bLabel, String token) {
List<BLabel> line = bLabelRepository.checknameByName(bLabel);
if(line.size()>0){
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
}
UserUtil.setCurrentMergeOperation(bLabel);
return new PersistModel(bLabelRepository.updateByPrimaryKeySelective(bLabel), MessageConstant.MESSAGE_ALERT_SUCCESS);
}
@Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeLabel(String id) {
int line = bLabelRepository.removeLabel(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.bcourse.dao.BCourseRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.bcourse.entity.BCourse">
<id column="business_id" jdbcType="VARCHAR" property="businessId"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="del_flag" jdbcType="VARCHAR" property="delFlag"/>
<result column="flag" jdbcType="VARCHAR" property="flag"/>
<result column="remarks" jdbcType="VARCHAR" property="remarks"/>
<result column="c_name" jdbcType="VARCHAR" property="cName"/>
<result column="parent_id" jdbcType="VARCHAR" property="parentId"/>
<result column="order_by" jdbcType="VARCHAR" property="orderBy"/>
</resultMap>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.blabel.dao.BLabelRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.blabel.entity.BLabel">
<id column="business_id" jdbcType="VARCHAR" property="businessId"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="del_flag" jdbcType="VARCHAR" property="delFlag"/>
<result column="flag" jdbcType="VARCHAR" property="flag"/>
<result column="remarks" jdbcType="VARCHAR" property="remarks"/>
<result column="l_name" jdbcType="VARCHAR" property="lName"/>
</resultMap>
</mapper>
\ No newline at end of file
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