You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.2 KiB
119 lines
4.2 KiB
package com.hai.service.impl;
|
|
|
|
import com.hai.common.exception.ErrorCode;
|
|
import com.hai.common.exception.ErrorHelp;
|
|
import com.hai.common.exception.SysCode;
|
|
import com.hai.dao.CmsPatchMapper;
|
|
import com.hai.dao.SecDictionaryMapper;
|
|
import com.hai.entity.CmsPatch;
|
|
import com.hai.entity.CmsPatchExample;
|
|
import com.hai.entity.SecDictionary;
|
|
import com.hai.entity.SecDictionaryExample;
|
|
import com.hai.service.CmsPatchService;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Service(value = "cmsPatchService")
|
|
public class CmsPatchServiceImpl implements CmsPatchService {
|
|
|
|
@Resource
|
|
private CmsPatchMapper cmsPatchMapper;
|
|
@Resource
|
|
private SecDictionaryMapper secDictionaryMapper;
|
|
|
|
@Override
|
|
public int addPatch(CmsPatch cmsPatch) throws Exception {
|
|
if (cmsPatch.getPatchType() == 3) {
|
|
// 若视频附件,则patch_path存储封面图,video_path存储真实的路径
|
|
cmsPatch.setVideoPath(cmsPatch.getPatchPath());
|
|
cmsPatch.setPatchPath(getVideoFront());
|
|
}
|
|
|
|
return cmsPatchMapper.insert(cmsPatch);
|
|
}
|
|
|
|
@Override
|
|
public int addListPatch(List<CmsPatch> patchList, Long contentId) throws Exception {
|
|
String videoFront = getVideoFront();
|
|
for(CmsPatch item : patchList) {
|
|
if (item.getPatchType() == 3) {
|
|
// 若视频附件,则patch_path存储封面图,video_path存储真实的路径
|
|
item.setVideoPath(item.getPatchPath());
|
|
item.setPatchPath(videoFront);
|
|
}
|
|
}
|
|
|
|
return cmsPatchMapper.addListPatch(patchList, contentId);
|
|
}
|
|
|
|
@Override
|
|
public int delPatch(Long id) throws Exception {
|
|
CmsPatch patch = cmsPatchMapper.selectByPrimaryKey(id);
|
|
if (patch == null) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_PATCH_NOT_FOUND, "");
|
|
}
|
|
|
|
return cmsPatchMapper.deleteByPrimaryKey(id);
|
|
}
|
|
|
|
@Override
|
|
public List<CmsPatch> getListPatch(Map<String, String> paramsMap) throws Exception {
|
|
CmsPatchExample example = new CmsPatchExample();
|
|
CmsPatchExample.Criteria criteria = example.createCriteria();
|
|
|
|
if (StringUtils.isNotBlank(paramsMap.get("contentId"))) {
|
|
criteria.andContentIdEqualTo(Long.valueOf(paramsMap.get("contentId")));
|
|
}
|
|
if (StringUtils.isNotBlank(paramsMap.get("patchName"))) {
|
|
criteria.andPatchNameLike("%" +paramsMap.get("patchName")+ "%");
|
|
}
|
|
if (StringUtils.isNotBlank(paramsMap.get("patchType"))) {
|
|
criteria.andPatchTypeEqualTo(Integer.valueOf(paramsMap.get("patchType")));
|
|
}
|
|
example.setOrderByClause("sort ASC, add_time DESC");
|
|
|
|
return cmsPatchMapper.selectByExample(example);
|
|
}
|
|
|
|
@Override
|
|
@Transactional
|
|
public int delPatchesByContentId(Map<String, String> paramsMap) throws Exception {
|
|
if (StringUtils.isBlank(paramsMap.get("contentId"))) {
|
|
return 0;
|
|
}
|
|
|
|
CmsPatchExample example = new CmsPatchExample();
|
|
CmsPatchExample.Criteria criteria = example.createCriteria();
|
|
|
|
criteria.andContentIdEqualTo(Long.valueOf(paramsMap.get("contentId")));
|
|
if (StringUtils.isNotBlank(paramsMap.get("patchType"))) {
|
|
criteria.andPatchTypeEqualTo(Integer.valueOf(paramsMap.get("patchType")));
|
|
}
|
|
|
|
return cmsPatchMapper.deleteByExample(example);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @desc 在数据字典中查询 CMS视频附件的封面图
|
|
*/
|
|
private String getVideoFront() throws Exception{
|
|
SecDictionaryExample example = new SecDictionaryExample();
|
|
SecDictionaryExample.Criteria criteria = example.createCriteria();
|
|
|
|
criteria.andCodeTypeEqualTo("CMS_VIDEO_FRONT");
|
|
criteria.andStatusEqualTo(1);
|
|
example.setOrderByClause("sort_id ASC");
|
|
|
|
List<SecDictionary> resultList = secDictionaryMapper.selectByExample(example);
|
|
if (resultList != null && resultList.size() > 0) {
|
|
return resultList.get(0).getCodeValue();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|