فهرست منبع

首页特色图标的修改

Reiskuchen 5 سال پیش
والد
کامیت
2636fa6088

+ 56 - 0
official_backend/src/main/java/com/hssx/ysofficial/controller/CharacteristicController.java

@@ -0,0 +1,56 @@
+package com.hssx.ysofficial.controller;
+
+
+import com.hssx.ysofficial.entity.Characteristic;
+import com.hssx.ysofficial.service.CharacteristicService;
+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-06
+ */
+@RestController
+@RequestMapping("/characteristic")
+public class CharacteristicController {
+    @Autowired
+    private CharacteristicService characteristicService;
+
+    /**
+     * 获取特色的列表
+     */
+    @RequestMapping("/list")
+    public HttpRespMsg getCharacteristicList() {
+        return characteristicService.getCharacteristicList();
+    }
+
+    /**
+     * 新增或更新特色
+     * id 更新时需要的id
+     * name 特色的名字
+     * description 特色的描述
+     * file 特色的图片
+     */
+    @RequestMapping("/insertOrUpdate")
+    public HttpRespMsg insertOrUpdateCharacteristic(Characteristic characteristic, MultipartFile file) {
+        return characteristicService.insertOrUpdateCharacteristic(characteristic, file);
+    }
+
+    /**
+     * 删除特色
+     * id 要删除的特色的id
+     */
+    @RequestMapping("/delete")
+    public HttpRespMsg deleteCharacteristicList(@RequestParam Integer id) {
+        return characteristicService.deleteCharacteristic(id);
+    }
+}
+

+ 59 - 0
official_backend/src/main/java/com/hssx/ysofficial/entity/Characteristic.java

@@ -0,0 +1,59 @@
+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-06
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("characteristic")
+public class Characteristic extends Model<Characteristic> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 特色表主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 特色名字
+     */
+    @TableField("name")
+    private String name;
+
+    /**
+     * 特色描述
+     */
+    @TableField("description")
+    private String description;
+
+    /**
+     * 特色图标
+     */
+    @TableField("image_url")
+    private String imageUrl;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

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

@@ -0,0 +1,16 @@
+package com.hssx.ysofficial.mapper;
+
+import com.hssx.ysofficial.entity.Characteristic;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 显示在首页的特点 Mapper 接口
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-06
+ */
+public interface CharacteristicMapper extends BaseMapper<Characteristic> {
+
+}

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

@@ -0,0 +1,22 @@
+package com.hssx.ysofficial.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.ysofficial.entity.Characteristic;
+import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * <p>
+ * 显示在首页的特点 服务类
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-06
+ */
+public interface CharacteristicService extends IService<Characteristic> {
+    HttpRespMsg getCharacteristicList();
+
+    HttpRespMsg insertOrUpdateCharacteristic(Characteristic characteristic, MultipartFile multipartFile);
+
+    HttpRespMsg deleteCharacteristic(Integer id);
+}

+ 79 - 0
official_backend/src/main/java/com/hssx/ysofficial/service/impl/CharacteristicServiceImpl.java

@@ -0,0 +1,79 @@
+package com.hssx.ysofficial.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hssx.ysofficial.entity.Characteristic;
+import com.hssx.ysofficial.mapper.CharacteristicMapper;
+import com.hssx.ysofficial.service.CharacteristicService;
+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-06
+ */
+@Service
+public class CharacteristicServiceImpl extends ServiceImpl<CharacteristicMapper, Characteristic> implements CharacteristicService {
+
+    @Value("${upload.path}")
+    private String uploadPath;
+
+    @Resource
+    private CharacteristicMapper characteristicMapper;
+
+    @Override
+    public HttpRespMsg getCharacteristicList() {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data = characteristicMapper.selectList(new QueryWrapper<Characteristic>().orderByAsc("id"));
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg insertOrUpdateCharacteristic(Characteristic characteristic, 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();
+            }
+            characteristic.setImageUrl("/upload/" + storedFileName);
+        }
+        if (characteristic.getId() == null) {
+            if (characteristicMapper.insert(characteristic) == 0) {
+                httpRespMsg.setError("新增失败");
+            }
+        } else {
+            if (characteristicMapper.updateById(characteristic) == 0) {
+                httpRespMsg.setError("修改失败");
+            }
+        }
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg deleteCharacteristic(Integer id) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        if (characteristicMapper.deleteById(id) == 0) {
+            httpRespMsg.setError("删除失败");
+        }
+        return httpRespMsg;
+    }
+}

+ 1 - 1
official_backend/src/main/java/com/hssx/ysofficial/utility/CodeGenerator.java

@@ -188,7 +188,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //单独生成逗号隔开
-//        strategy.setInclude("");
+        strategy.setInclude("characteristic");
         //全生成
 //        strategy.setInclude();//表名,多个英文逗号分割
         //多个英文逗号隔开

+ 18 - 0
official_backend/src/main/resources/mapper/CharacteristicMapper.xml

@@ -0,0 +1,18 @@
+<?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.CharacteristicMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.hssx.ysofficial.entity.Characteristic">
+        <id column="id" property="id" />
+        <result column="name" property="name" />
+        <result column="description" property="description" />
+        <result column="image_url" property="imageUrl" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, name, description, image_url
+    </sql>
+
+</mapper>