Quellcode durchsuchen

官网后台VIP产品2

Reiskuchen vor 5 Jahren
Ursprung
Commit
2ac124d65c

+ 59 - 0
official_backend/src/main/java/com/hssx/ysofficial/controller/VipProductsController.java

@@ -0,0 +1,59 @@
+package com.hssx.ysofficial.controller;
+
+
+import com.hssx.ysofficial.entity.VipProducts;
+import com.hssx.ysofficial.service.VipProductsService;
+import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * <p>
+ * 第一个数据是公司优势 其他是案例 前端控制器
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-05
+ */
+@RestController
+@RequestMapping("/vip-products")
+public class VipProductsController {
+    @Autowired
+    private VipProductsService vipProductsService;
+
+    /**
+     * 分页获取VIP产品
+     * pageIndex 页面索引
+     * pageSize 页面大小
+     */
+    @RequestMapping("/list")
+    public HttpRespMsg getVipProductList(@RequestParam Integer pageIndex, @RequestParam Integer pageSize) {
+        return vipProductsService.getVipProductList(pageIndex, pageSize);
+    }
+
+    /**
+     * 插入或更新VIP产品
+     * id 要修改的产品id(仅修改时)
+     * title 产品标题
+     * introduction 产品介绍
+     * address 地址
+     * file 照片
+     */
+    @RequestMapping("/insertOrUpdate")
+    public HttpRespMsg insertOrUpdateVipProduct(VipProducts vipProducts, MultipartFile file) {
+        return vipProductsService.insertOrUpdateVipProduct(vipProducts, file);
+    }
+
+    /**
+     * 删除VIP产品
+     * id 要删除的产品id
+     */
+    @RequestMapping("/delete")
+    public HttpRespMsg deleteVipProduct(@RequestParam Integer id) {
+        return vipProductsService.deleteVipProduct(id);
+    }
+}
+

+ 71 - 0
official_backend/src/main/java/com/hssx/ysofficial/entity/VipProducts.java

@@ -0,0 +1,71 @@
+package com.hssx.ysofficial.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 第一个数据是公司优势 其他是案例
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-05
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("vip_products")
+public class VipProducts extends Model<VipProducts> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 产品名称
+     */
+    @TableField("title")
+    private String title;
+
+    /**
+     * 产品图片地址
+     */
+    @TableField("image_url")
+    private String imageUrl;
+
+    /**
+     * 简介
+     */
+    @TableField("introduction")
+    private String introduction;
+
+    /**
+     * 地址
+     */
+    @TableField("address")
+    private String address;
+
+    /**
+     * 置顶 0-否 1-是
+     */
+    @TableField("sticky")
+    private Integer sticky;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 16 - 0
official_backend/src/main/java/com/hssx/ysofficial/mapper/VipProductsMapper.java

@@ -0,0 +1,16 @@
+package com.hssx.ysofficial.mapper;
+
+import com.hssx.ysofficial.entity.VipProducts;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 第一个数据是公司优势 其他是案例 Mapper 接口
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-05
+ */
+public interface VipProductsMapper extends BaseMapper<VipProducts> {
+
+}

+ 22 - 0
official_backend/src/main/java/com/hssx/ysofficial/service/VipProductsService.java

@@ -0,0 +1,22 @@
+package com.hssx.ysofficial.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.ysofficial.entity.VipProducts;
+import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * <p>
+ * 第一个数据是公司优势 其他是案例 服务类
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-05
+ */
+public interface VipProductsService extends IService<VipProducts> {
+    HttpRespMsg getVipProductList(Integer pageIndex, Integer pageSize);
+
+    HttpRespMsg insertOrUpdateVipProduct(VipProducts vipProducts, MultipartFile file);
+
+    HttpRespMsg deleteVipProduct(Integer id);
+}

+ 80 - 0
official_backend/src/main/java/com/hssx/ysofficial/service/impl/VipProductsServiceImpl.java

@@ -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;
+    }
+}

+ 20 - 0
official_backend/src/main/resources/mapper/VipProductsMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.hssx.ysofficial.mapper.VipProductsMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.hssx.ysofficial.entity.VipProducts">
+        <id column="id" property="id" />
+        <result column="title" property="title" />
+        <result column="image_url" property="imageUrl" />
+        <result column="introduction" property="introduction" />
+        <result column="address" property="address" />
+        <result column="sticky" property="sticky" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, title, image_url, introduction, address, sticky
+    </sql>
+
+</mapper>