Commit 9762209c authored by root's avatar root

Banner

parent 549622b6
package org.rcisoft.business.bbanner.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.common.component.Global;
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.business.bbanner.entity.BBanner;
import org.rcisoft.business.bbanner.service.BBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.rcisoft.core.result.Result;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ZhangQingle
* @date 2019/9/11
*/
@RestController
@RequestMapping("/Banner")
@Slf4j
public class BBannerController extends PaginationController<BBanner> {
@Autowired
private BBannerService bBannerService;
@Autowired
private Global global;
@ApiOperation(value="添加/编辑Banner", notes="businessId为空时是添加方法,不为空时是修改方法")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "title", value = "标题", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "imageUrl", value = "图片地址", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "isEexternalLink", value = "是否为外部链接(0:否,1:是)", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "externalUrl", value = "外部URL", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "lineType", value = "类型(0:线下,1:线上)", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "courseId", value = "课程ID", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "sort", value = "排序", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PostMapping(value = "/add")
// @PreAuthorize("hasRole('ROLE_1001')")
public Result add(BBanner BBanner) {
PersistModel data = bBannerService.persist(BBanner);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
BBanner);
}
@ApiOperation(value="删除Banner", notes="根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar")
@PostMapping(value = "/remove")
public Result remove(String businessId) {
PersistModel data = bBannerService.removeBanner(businessId);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
businessId);
}
@ApiOperation(value="唯一查找", notes="根据ID查找一条记录")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar")
@GetMapping(value = "/one")
public Result queryOne(String businessId) {
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bBannerService.selectOne(businessId));
}
@ApiOperation(value="获取banner分页", notes="根据条件分页查询")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "title", value = "标题", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "isExternalLink", value = "是否为外部链接(0:否,1:是)", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "externalUrl", value = "外部URL", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "lineType", value = "类型(0:线下,1:线上)", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBBannerByPagination")
public GridModel queryBBannerByPagination(BBanner param) {
bBannerService.queryBannerByPagination(getPaginationUtility(),param);
GridModel gridModel = getGridModelResponse();
return gridModel;
}
}
package org.rcisoft.business.bbanner.dao;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.bbanner.entity.BBanner;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* @author ZhangQingle
* @date 2019/9/10
*/
@Repository
public interface BBannerRepository extends BaseMapper<BBanner> {
/**
* 根据条件查找
* @param param
* @return
*/
@Select("<script>select * from b_banner where del_flag='0' and flag = '1' " +
" <if test=\"title!=null and title != ''\">and title like CONCAT('%',#{title},'%')</if>" +
" <if test=\"isExternalLink!=null and isExternalLink != ''\">and is_external_link=#{isExternalLink}</if>" +
" <if test=\"lineType!=null and lineType != ''\">and line_type=#{lineType}</if>" +
" <if test=\"remarks!=null and remarks != ''\">and remarks like CONCAT('%',#{remarks},'%')</if>" +
" order by banner_sort asc" +
"</script>")
@ResultMap(value = "BaseResultMap" )
List<BBanner> queryBanners(BBanner param);
/**
* 按id查询个数
* @param id
* @return
*/
@Select("<script>select count(business_id) from b_banner where del_flag='0' and flag = '1' and business_id=#{id} " +
"</script>")
int selectCountById(String id);
/**
* 更新
* @param model
* @return
*/
@Update({"<script>",
"update b_banner",
" <set>",
" <if test='updateBy != null'>update_by=#{updateBy},</if>",
" <if test='updateDate != null'>update_date=#{updateDate},</if>",
" <if test='delFlag != null'>del_flag=#{delFlag},</if>",
" <if test='flag != null'>flag=#{flag},</if>",
" <if test='remarks != null'>remarks=#{remarks},</if>",
" <if test='title != null'>title=#{title},</if>",
" <if test='imageUrl != null'>image_url=#{imageUrl},</if>",
" <if test='isExternalLink != null'>is_external_link=#{isExternalLink},</if>",
" <if test='bannerSort != null'>banner_sort=#{bannerSort},</if>",
" external_url=#{externalUrl},",
" line_type=#{lineType},",
" course_id=#{courseId}",
" </set>",
"where business_id=#{businessId}",
"</script>"})
int updateById(BBanner model);
@Update("update b_banner set del_flag = 1 where business_id = #{id}")
int deleteBanner(String id);
}
package org.rcisoft.business.bbanner.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.rcisoft.core.entity.IdEntity;
import org.rcisoft.sys.dept.entity.SysDept;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author ZhangQingle
* @date 2019/9/10
*/
@Entity
@Table(name = "b_banner")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BBanner extends IdEntity<SysDept> {
private static final long serialVersionUID = 8683139175568024924L;
//标题
@Length(min = 1,max = 64,message = "长度最小为1,最大为64")
@NotBlank
private String title;
//图片地址
@Length(min = 1,max = 128,message = "长度最小为1,最大为256")
@NotBlank
private String imageUrl;
//是否为外部链接(0:否,1:是)
@Length(min = 1,max = 1,message = "长度最小为1,最大为1")
@NotBlank
private String isExternalLink;
//外部URL
private String externalUrl;
//类型(0:线下,1:线上)
private String lineType;
//课程ID
private String courseId;
//排序
private Integer bannerSort;
}
\ No newline at end of file
package org.rcisoft.business.bbanner.service;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.business.bbanner.entity.BBanner;
import java.util.List;
public interface BBannerService {
/**
* 插入/修改
* @param model
* @return
*/
PersistModel persist(BBanner model);
/**
* 逻辑删除
* @param id
* @return
*/
PersistModel removeBanner(String id);
/**
* 唯一查找
* @param businessId
* @return
*/
BBanner selectOne(String businessId);
/**
* 获取图片分页
* @param pageUtil
* @param model
* @return
*/
List<BBanner> queryBannerByPagination(PageUtil pageUtil, BBanner model);
}
package org.rcisoft.business.bbanner.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.DelStatus;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.business.bbanner.dao.BBannerRepository;
import org.rcisoft.business.bbanner.entity.BBanner;
import org.rcisoft.business.bbanner.service.BBannerService;
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;
/**
* @author ZhangQingle
* @date 2019/9/10
*/
@Service
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public class BBannerServiceImpl implements BBannerService {
@Autowired
private BBannerRepository bBannerRepository;
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
@Override
public PersistModel persist(BBanner model) {
int line = 0;
//外部链接但外部URL为空或长度为0 抛异常
if ("1".equals(model.getIsExternalLink()) && StringUtils.isEmpty(model.getExternalUrl()))
// throw new ServiceException(ResultServiceEnums.INSERT_DATA_EXIST);
throw new ServiceException("必填项未填写");
//内部链接但类型或课程ID为空或长度为0 抛异常
if ("0".equals(model.getIsExternalLink()) && (StringUtils.isEmpty(model.getLineType()) || StringUtils.isEmpty(model.getCourseId())))
throw new ServiceException("必填项未填写");
// throw new ServiceException(ResultServiceEnums.INSERT_DATA_EXIST);
if (model.getBusinessId() != null) {
if (bBannerRepository.selectCountById(model.getBusinessId()) == 0){
throw new ServiceException("该数据不存在");
}
UserUtil.setCurrentMergeOperation(model);
line = bBannerRepository.updateById(model);
} else {
UserUtil.setCurrentPersistOperation(model);
line = bBannerRepository.insertSelective(model);
}
return new PersistModel(line);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
@Override
public PersistModel removeBanner(String id) {
if (StringUtils.isEmpty(id)){
throw new ServiceException("请选择");
}
return new PersistModel(1,bBannerRepository.deleteBanner(id));
}
@Override
public BBanner selectOne(String businessId) {
return bBannerRepository.selectByPrimaryKey(businessId);
}
@Override
public List<BBanner> queryBannerByPagination(PageUtil pageUtil, BBanner model) {
return bBannerRepository.queryBanners(model);
}
}
<?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.bbanner.dao.BBannerRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.bbanner.entity.BBanner">
<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="title" jdbcType="VARCHAR" property="title"/>
<result column="image_url" jdbcType="VARCHAR" property="imageUrl"/>
<result column="is_external_link" jdbcType="INTEGER" property="isExternalLink"/>
<result column="external_url" jdbcType="VARCHAR" property="externalUrl"/>
<result column="line_type" jdbcType="VARCHAR" property="lineType"/>
<result column="course_id" jdbcType="VARCHAR" property="courseId"/>
<result column="banner_sort" jdbcType="LONGVARCHAR" property="bannerSort"/>
</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