|
|
@@ -0,0 +1,156 @@
|
|
|
+package com.crm.custom.service.impl;
|
|
|
+
|
|
|
+import com.crm.custom.dao.mapper.GoldenGoodsVideoMapper;
|
|
|
+import com.crm.custom.dao.repository.GoldenGoodsRepository;
|
|
|
+import com.crm.custom.dao.repository.GoldenGoodsVideoRepository;
|
|
|
+import com.crm.custom.service.GoldenGoodsVideoService;
|
|
|
+import com.crm.custom.service.impl.base.BaseUploadServiceImpl;
|
|
|
+import com.crm.rely.backend.core.constant.Constants;
|
|
|
+import com.crm.rely.backend.core.dto.base.PageDto;
|
|
|
+import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
|
|
|
+import com.crm.rely.backend.core.entity.base.SingleLongEntity;
|
|
|
+import com.crm.rely.backend.core.exception.ServiceException;
|
|
|
+import com.crm.rely.backend.model.dto.golden.goods.GoldenGoodsVideoListDto;
|
|
|
+import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
|
|
|
+import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoAddEntity;
|
|
|
+import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoDeleteEntitys;
|
|
|
+import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoSearchEntity;
|
|
|
+import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoUpdateEntity;
|
|
|
+import com.crm.rely.backend.model.pojo.table.GoldenGoodsTable;
|
|
|
+import com.crm.rely.backend.model.pojo.table.GoldenGoodsVideoTable;
|
|
|
+import com.crm.rely.backend.model.pojo.view.GoldenGoodsVideoListView;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class GoldenGoodsVideoServiceImpl extends BaseUploadServiceImpl implements GoldenGoodsVideoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoldenGoodsVideoRepository repository;
|
|
|
+ @Autowired
|
|
|
+ private GoldenGoodsVideoMapper mapper;
|
|
|
+ @Autowired
|
|
|
+ private GoldenGoodsRepository goldenGoodsRepository;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultWithPagerDto<GoldenGoodsVideoListDto> customPageList(GoldenGoodsVideoSearchEntity entity, CustomInfoEntity infoEntity) throws ServiceException {
|
|
|
+ if (infoEntity == null || infoEntity.getId() == null) {
|
|
|
+ entity.setCustomId(-1l);
|
|
|
+ }else {
|
|
|
+ entity.setCustomId(infoEntity.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count = mapper.customCountList(entity);
|
|
|
+ PageDto pageDto = PageDto.format(entity, count);
|
|
|
+ if (count == null || count <= 0) {
|
|
|
+ return ResultWithPagerDto.success(pageDto);
|
|
|
+ }
|
|
|
+ List<GoldenGoodsVideoListView> views = mapper.customPageList(entity);
|
|
|
+ if (views == null || views.size() <= 0) {
|
|
|
+ throw new ServiceException(Constants.SYSTEM_ERROR);
|
|
|
+ }
|
|
|
+ List<GoldenGoodsVideoListDto> dtos = new ArrayList<>(views.size());
|
|
|
+
|
|
|
+ for (GoldenGoodsVideoListView view : views) {
|
|
|
+ GoldenGoodsVideoListDto dto = new GoldenGoodsVideoListDto();
|
|
|
+ BeanUtils.copyProperties(view, dto);
|
|
|
+
|
|
|
+ if ((infoEntity != null && infoEntity.getId() != null && view.getCustomId() != null) || view.getPayType() == 0) {
|
|
|
+ dto.setPayType(0);
|
|
|
+ }else{
|
|
|
+ dto.setFileUrl(null);
|
|
|
+ dto.setLinkUrl(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ dtos.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultWithPagerDto.success(pageDto, dtos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void add(GoldenGoodsVideoAddEntity entity) throws ServiceException {
|
|
|
+ GoldenGoodsTable goldenGoodsTable = goldenGoodsRepository.getFirstById(entity.getGoodsId());
|
|
|
+ if (goldenGoodsTable == null) {
|
|
|
+ throw ServiceException.exception(Constants.INFO_NOT_FOUND);
|
|
|
+ }
|
|
|
+ GoldenGoodsVideoTable table = new GoldenGoodsVideoTable();
|
|
|
+ BeanUtils.copyProperties(entity, table);
|
|
|
+ repository.save(table);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delete(GoldenGoodsVideoDeleteEntitys entity) throws ServiceException {
|
|
|
+ List<GoldenGoodsVideoTable> tables = repository.findAllByIdIn(entity.getIds());
|
|
|
+ if (tables == null) {
|
|
|
+ throw ServiceException.exception(Constants.INFO_NOT_FOUND);
|
|
|
+ }
|
|
|
+ repository.delete(tables);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void update(GoldenGoodsVideoUpdateEntity entity) throws ServiceException {
|
|
|
+ GoldenGoodsVideoTable table = repository.findFirstById(entity.getId());
|
|
|
+ if (table == null) {
|
|
|
+ throw ServiceException.exception(Constants.INFO_NOT_FOUND);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(entity, table);
|
|
|
+ repository.save(table);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultWithPagerDto<GoldenGoodsVideoListDto> searchPageList(GoldenGoodsVideoSearchEntity entity) throws ServiceException {
|
|
|
+ Integer count = mapper.countList(entity);
|
|
|
+ PageDto pageDto = PageDto.format(entity, count);
|
|
|
+ if (count == null || count <= 0) {
|
|
|
+ return ResultWithPagerDto.success(pageDto);
|
|
|
+ }
|
|
|
+ List<GoldenGoodsVideoTable> tables = mapper.pageList(entity);
|
|
|
+ if (tables == null || tables.size() <= 0) {
|
|
|
+ throw new ServiceException(Constants.SYSTEM_ERROR);
|
|
|
+ }
|
|
|
+ List<GoldenGoodsVideoListDto> dtos = new ArrayList<>(tables.size());
|
|
|
+
|
|
|
+ for (GoldenGoodsVideoTable table : tables) {
|
|
|
+ GoldenGoodsVideoListDto dto = transformSearchListDto(table);
|
|
|
+ dtos.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultWithPagerDto.success(pageDto, dtos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoldenGoodsVideoListDto searchSingle(SingleLongEntity entity) throws ServiceException {
|
|
|
+ GoldenGoodsVideoTable table = repository.getFirstById(entity.getId());
|
|
|
+ if (table == null) {
|
|
|
+ throw ServiceException.exception(Constants.INFO_NOT_FOUND);
|
|
|
+ }
|
|
|
+
|
|
|
+ return transformSearchListDto(table);
|
|
|
+ }
|
|
|
+
|
|
|
+ private GoldenGoodsVideoListDto transformSearchListDto(GoldenGoodsVideoTable table) {
|
|
|
+ GoldenGoodsVideoListDto dto = new GoldenGoodsVideoListDto();
|
|
|
+ BeanUtils.copyProperties(table, dto);
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String uploadFile(Long goodsId, MultipartFile file) throws Exception {
|
|
|
+
|
|
|
+ String middlePath = "/goods/video/" + goodsId;
|
|
|
+ String path = saveFile(middlePath, file);
|
|
|
+
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|