|
@@ -0,0 +1,95 @@
|
|
|
+package com.fjhx.xmhjc.service.product.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
+import com.fjhx.xmhjc.entity.product.po.ProductInfo;
|
|
|
+import com.fjhx.xmhjc.mapper.product.ProductInfoMapper;
|
|
|
+import com.fjhx.xmhjc.service.product.ProductInfoService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.xmhjc.entity.product.vo.ProductInfoVo;
|
|
|
+import com.fjhx.xmhjc.entity.product.dto.ProductInfoSelectDto;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.fjhx.xmhjc.entity.product.dto.ProductInfoDto;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 产品信息表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author hj
|
|
|
+ * @since 2023-11-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, ProductInfo> implements ProductInfoService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductInfoVo> getList(ProductInfoSelectDto dto) {
|
|
|
+ IWrapper<ProductInfo> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("pi", ProductInfo::getId);
|
|
|
+ List<ProductInfoVo> list = this.baseMapper.getList(wrapper);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ProductInfoVo> getPage(ProductInfoSelectDto dto) {
|
|
|
+ IWrapper<ProductInfo> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("pi", ProductInfo::getId);
|
|
|
+ Page<ProductInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductInfoVo detail(Long id) {
|
|
|
+ ProductInfo productInfo = this.getById(id);
|
|
|
+ ProductInfoVo result = BeanUtil.toBean(productInfo, ProductInfoVo.class);
|
|
|
+ List<String> specList = new ArrayList<>();
|
|
|
+ if(StringUtils.isNotBlank(productInfo.getSpec())){
|
|
|
+ specList = Arrays.asList(productInfo.getSpec().split(","));
|
|
|
+ }
|
|
|
+ result.setSpecList(specList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(ProductInfoDto productInfoDto) {
|
|
|
+ if(!CollectionUtils.isEmpty(productInfoDto.getSpecList())){
|
|
|
+ productInfoDto.setSpec(productInfoDto.getSpecList().stream().collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ this.save(productInfoDto);
|
|
|
+ // 保存图片
|
|
|
+ ObsFileUtil.saveFile(productInfoDto.getCoverUrlList(), productInfoDto.getId(), 1);
|
|
|
+
|
|
|
+
|
|
|
+ ObsFileUtil.saveFile(productInfoDto.getContentImgList(), productInfoDto.getId(), 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(ProductInfoDto productInfoDto) {
|
|
|
+ if(!CollectionUtils.isEmpty(productInfoDto.getSpecList())){
|
|
|
+ productInfoDto.setSpec(productInfoDto.getSpecList().stream().collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ this.updateById(productInfoDto);
|
|
|
+ // 保存图片
|
|
|
+ ObsFileUtil.editFile(productInfoDto.getCoverUrlList(), productInfoDto.getId(), 1);
|
|
|
+
|
|
|
+
|
|
|
+ ObsFileUtil.editFile(productInfoDto.getContentImgList(), productInfoDto.getId(), 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|