|
@@ -0,0 +1,80 @@
|
|
|
|
+package com.hssx.ysofficial.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.ysofficial.entity.VipProducts;
|
|
|
|
+import com.hssx.ysofficial.mapper.VipProductsMapper;
|
|
|
|
+import com.hssx.ysofficial.service.VipProductsService;
|
|
|
|
+import com.hssx.ysofficial.utility.HttpRespMsg;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 第一个数据是公司优势 其他是案例 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Reiskuchen
|
|
|
|
+ * @since 2020-02-05
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class VipProductsServiceImpl extends ServiceImpl<VipProductsMapper, VipProducts> implements VipProductsService {
|
|
|
|
+
|
|
|
|
+ @Value("${upload.path}")
|
|
|
|
+ private String uploadPath;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private VipProductsMapper vipProductsMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getVipProductList(Integer pageIndex, Integer pageSize) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ httpRespMsg.data = vipProductsMapper.selectPage(new Page<VipProducts>(pageIndex, pageSize), new QueryWrapper<>());
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg insertOrUpdateVipProduct(VipProducts vipProducts, MultipartFile multipartFile) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ if (multipartFile != null) {
|
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
|
+ File direction = new File(uploadPath);
|
|
|
|
+ String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ String storedFileName = rand + suffix;
|
|
|
|
+ try {
|
|
|
|
+ File savedFile = new File(direction, storedFileName);
|
|
|
|
+ savedFile.createNewFile();
|
|
|
|
+ multipartFile.transferTo(savedFile);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ vipProducts.setImageUrl("/upload/" + storedFileName);
|
|
|
|
+ }
|
|
|
|
+ if (vipProducts.getId() == null) {
|
|
|
|
+ if (vipProductsMapper.insert(vipProducts) == 0) {
|
|
|
|
+ httpRespMsg.setError("新增失败");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (vipProductsMapper.updateById(vipProducts) == 0) {
|
|
|
|
+ httpRespMsg.setError("修改失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg deleteVipProduct(Integer id) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ if (vipProductsMapper.deleteById(id) == 0) {
|
|
|
|
+ httpRespMsg.setError("删除失败");
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+}
|