提交 83dbe07f authored 作者: liupengfei's avatar liupengfei

--no commit message

上级 81e0ef36
......@@ -15,8 +15,20 @@ import com.zrqx.resource.commons.vo.bg.ResourceRelationVo;
@Mapper
public interface ResourceRelationMapper extends BaseMapper<ResourceRelation> {
String NOT_BLANK = "@com.zrqx.core.util.datatype.StringUtils@isNotBlank";
/**
* 日期查询条件
*/
String DATETIME_QUERY_CONDITIONS =
" <if test = '" + NOT_BLANK + "(beginTime)'> "
+ " and a.uploadTime &gt;= concat(#{beginTime}, ' 00:00:00' ) "
+ " </if> "
+ " <if test = '" + NOT_BLANK + "(endTime)'> "
+ " and a.uploadTime &lt;= concat(#{endTime}, ' 23:59:59') "
+ " </if> ";
@Select("<script>"
+ "select id ,resourceId,resourceType,createTime,sort "
+ "select id ,resourceId,resourceType,createTime,sort,isTop "
+ "from res_resource_relation "
+ "where objectId = #{id} "
+ "<if test='resourceType != null'> "
......@@ -59,4 +71,48 @@ public interface ResourceRelationMapper extends BaseMapper<ResourceRelation> {
*/
@Select("SELECT MAX(sort) FROM res_annex_resource where objectType = #{resourceType}")
Integer getMaxSort(@Param("resourceType")Integer resourceType);
/**
* 查找相关文章
* @param entity
* @return
*/
@Select("<script>"
+ "select b.id ,b.resourceId,b.resourceType,b.sort,b.isTop,"
+ "a.name,a.author,a.keywords,a.uploadTime,a.status "
+ "from res_resource_relation b left join res_article_library a on b.resourceId = a.id "
+ "where b.objectId = #{id} "
+ "<if test='resourceType != null'> "
+ " and b.resourceType = #{resourceType} "
+ "</if>"
+ "<if test='"+ NOTBLANK +"(name)'>"
+ " AND (a.name like concat('%',#{name},'%') OR a.author like concat('%',#{name},'%')) "
+ "</if>"
+ DATETIME_QUERY_CONDITIONS
+ "<if test='status != null'> "
+ " and a.status = #{status} "
+ "</if>"
+" order by b.isTop desc,sort asc "
+ "</script>")
List<ResourceRelationVo> queryArticleByIdAndResourceType(QueryResourceRelationForm entity);
/**
* 查找相关视频
* @param entity
* @return
*/
@Select("<script>"
+ "select b.id ,b.resourceId,b.resourceType,b.sort,b.isTop,"
+ "a.name,a.author,a.uploadTime,a.status "
+ "from res_resource_relation b left join res_video_library a on b.resourceId = a.id "
+ "where b.objectId = #{id} "
+ "<if test='resourceType != null'> "
+ " and b.resourceType = #{resourceType} "
+ "</if>"
+ "<if test='"+ NOTBLANK +"(name)'>"
+ " AND (a.name like concat('%',#{name},'%') OR a.author like concat('%',#{name},'%')) "
+ "</if>"
+" order by b.isTop desc,sort asc "
+ "</script>")
List<ResourceRelationVo> queryVideoByIdAndResourceType(QueryResourceRelationForm entity);
}
package com.zrqx.resource.bg.mapper.articlelibrary;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibraryDiyType;
/**
* 文章库和自定义分类
*/
public interface ArticleLibraryDiyTypeMapper extends BaseMapper<ArticleLibraryDiyType> {
}
package com.zrqx.resource.bg.mapper.articlelibrary;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.resource.bg.mapper.MapperConstants;
import com.zrqx.resource.commons.form.bg.articlelibrary.QueryArticleLibraryForm;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibrary;
import com.zrqx.resource.commons.vo.bg.articlelibrary.ArticleLibraryListVO;
/**
* 文章库
*/
public interface ArticleLibraryMapper extends BaseMapper<ArticleLibrary> {
/**
* 分页查询
* @param form
* @return
*/
@Select("<script>"
+ "select * "
+ "from res_article_Library a left join res_Video_Library_Diy_Type ad "
+ "on a.id = ad.vlid "
+ "where 1=1 "
+ "<if test='"+ NOTBLANK +"(form.name)'>"
+ " AND (a.name like concat('%',#{form.name},'%') OR a.author like concat('%',#{form.name},'%')) "
+ "</if>"
+ MapperConstants.DATETIME_QUERY_CONDITION
+ " order by a.uploadTime desc "
+ "</script>")
List<ArticleLibraryListVO> query(@Param("form")QueryArticleLibraryForm form);
}
package com.zrqx.resource.bg.service.articlelibrary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.resource.bg.mapper.articlelibrary.ArticleLibraryDiyTypeMapper;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibraryDiyType;
/**
* 文章库和自定义分类
*/
@Service
public class ArticleLibraryDiyTypeSerivceImpl extends BaseServiceImpl<ArticleLibraryDiyType,Integer> implements ArticleLibraryDiyTypeService {
@Autowired
private ArticleLibraryDiyTypeMapper mapper;
@Override
public BaseMapper<ArticleLibraryDiyType> getMapper() {
return mapper;
}
}
package com.zrqx.resource.bg.service.articlelibrary;
import com.zrqx.core.service.BaseService;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibraryDiyType;
/**
* 文章库和自定义分类
*/
public interface ArticleLibraryDiyTypeService extends BaseService<ArticleLibraryDiyType,Integer>{
}
package com.zrqx.resource.bg.service.articlelibrary;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zrqx.core.commons.redis.Redis;
import com.zrqx.core.enums.resource.LibraryStatusEnum;
import com.zrqx.core.enums.resource.ResourceTypeEnum;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.bg.mapper.ResourceRelationMapper;
import com.zrqx.resource.bg.mapper.articlelibrary.ArticleLibraryDiyTypeMapper;
import com.zrqx.resource.bg.mapper.articlelibrary.ArticleLibraryMapper;
import com.zrqx.resource.bg.mapper.videolibrary.VideoLibraryMapper;
import com.zrqx.resource.commons.form.bg.articlelibrary.QueryArticleLibraryForm;
import com.zrqx.resource.commons.form.bg.articlelibrary.SaveUpdateArticleLibraryForm;
import com.zrqx.resource.commons.model.acupointlibrary.AcupointLibrary;
import com.zrqx.resource.commons.model.acupointlibrary.AcupointLibraryDiyType;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibrary;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibraryDiyType;
import com.zrqx.resource.commons.model.resourcerelation.ResourceRelation;
import com.zrqx.resource.commons.model.videolibrary.VideoLibrary;
import com.zrqx.resource.commons.vo.bg.articlelibrary.ArticleLibraryListVO;
import tk.mybatis.mapper.entity.Example;
/**
* 文章库
*/
@Service
public class ArticleLibrarySerivceImpl extends BaseServiceImpl<ArticleLibrary,String> implements ArticleLibraryService {
@Autowired
private ArticleLibraryMapper mapper;
@Autowired
private ArticleLibraryDiyTypeMapper diyTypeMapper;
@Autowired
private ResourceRelationMapper resourceRelationMapper;
@Autowired
private VideoLibraryMapper videoLibraryMapper;
@Autowired
private Redis redis;
@Override
public BaseMapper<ArticleLibrary> getMapper() {
return mapper;
}
@Override
public boolean saveOrUpdate(SaveUpdateArticleLibraryForm form) {
ArticleLibrary entity = new ArticleLibrary();
BeanUtils.copyProperties(form, entity);
if(entity.getId() == null) {
//添加
entity.setEditor(redis.getUser().getUserName());
entity.setEditorId(redis.getUser().getUserId());
entity.setUploadTime(new Date());
entity.setResourceType(ResourceTypeEnum.ARTICLE_LIBRARY.getCode());
mapper.insert(entity);
if(StringUtils.isNotBlank(form.getObjectId())) {
ResourceRelation resourceRelation = new ResourceRelation();
resourceRelation.setCreateTime(new Date());
resourceRelation.setObjectId(form.getObjectId());
resourceRelation.setResourceId(entity.getId());
resourceRelation.setResourceType(ResourceTypeEnum.ARTICLE_LIBRARY.getCode());
resourceRelation.setIsTop(form.getIsTop());
resourceRelation.setSort(form.getSort());
resourceRelationMapper.insert(resourceRelation);
}
}else {
//修改
entity.setEditor(redis.getUser().getUserName());
entity.setEditorId(redis.getUser().getUserId());
entity.setUploadTime(new Date());
mapper.updateByPrimaryKeySelective(entity);
ArticleLibraryDiyType diyType = new ArticleLibraryDiyType();
diyType.setArticleId(entity.getId());
diyTypeMapper.delete(diyType);
}
//添加当前对象与自定义关系
if(form.getDiyType() != null && form.getDiyType().size() > 0){
List<ArticleLibraryDiyType> list = form.getDiyType();
list.forEach(li -> li.setArticleId(entity.getId()));
diyTypeMapper.insertList(list);
}
if(form.getVideoType() != null && form.getVideoType() == 1 && StringUtils.isNotBlank(form.getTimeLength())) {
String videoId = saveVideo(form);
ArticleLibrary articleLibrary = new ArticleLibrary();
articleLibrary.setId(entity.getId());
articleLibrary.setVideoId(videoId);
mapper.updateByPrimaryKeySelective(articleLibrary);
}
return true;
}
/**
* 保存视频
* @param form
* @return
* @author yzg
* @date: 2018年11月22日 下午2:38:56
*/
public String saveVideo(SaveUpdateArticleLibraryForm form) {
VideoLibrary entity = new VideoLibrary();
entity.setName(form.getVideoName());
entity.setVideo(form.getVideo());
entity.setSize(form.getSize());
entity.setTimeLength(form.getTimeLength());
entity.setStatus(LibraryStatusEnum.STATUS_1.getCode());
entity.setUploadTime(new Date());
entity.setResourceType(ResourceTypeEnum.VIDEO_LIBRARY.getCode());
entity.setBrowseNum(50);
entity.setReadTextPower(1);
entity.setClickNum(50);
entity.setSalesNum(0);
videoLibraryMapper.insert(entity);
return entity.getId();
}
/**
* 批量删除
*/
@Override
public boolean batchDelete(List<String> ids) {
if (ids.size() == 0) {
throw new BaseException("没有选中任何数据,请重新选择");
}
Example example = new Example(AcupointLibrary.class);
example.createCriteria().andIn("id", ids);
mapper.deleteByExample(example);
//还需删除与自定义分类关系
example = new Example(AcupointLibraryDiyType.class);
example.createCriteria().andIn("articleId", ids);
diyTypeMapper.deleteByExample(example);
//----关联资源
example = new Example(ResourceRelation.class);
example.createCriteria().andIn("objectId", ids).orIn("resourceId", ids);
resourceRelationMapper.deleteByExample(example);
return true;
}
@Override
public PageInfo<ArticleLibraryListVO> page(QueryArticleLibraryForm form, PageParam pageParam) {
startPage(pageParam);
return new PageInfo<ArticleLibraryListVO>(mapper.query(form));
}
}
package com.zrqx.resource.bg.service.articlelibrary;
import java.util.List;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.resource.commons.form.bg.articlelibrary.QueryArticleLibraryForm;
import com.zrqx.resource.commons.form.bg.articlelibrary.SaveUpdateArticleLibraryForm;
import com.zrqx.resource.commons.model.articlelibrary.ArticleLibrary;
import com.zrqx.resource.commons.vo.bg.articlelibrary.ArticleLibraryListVO;
/**
* 文章库
*/
public interface ArticleLibraryService extends BaseService<ArticleLibrary,String>{
/**
* 添加或修改文章
* @param form
* @return
*/
boolean saveOrUpdate(SaveUpdateArticleLibraryForm form);
/**
* 批量删除
* @param ids
* @return
*/
boolean batchDelete(List<String> ids);
/**
* 分页查询
* @param form
* @param pageParam
* @return
*/
PageInfo<ArticleLibraryListVO> page(QueryArticleLibraryForm form, PageParam pageParam);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论