瀏覽代碼

招聘信息后台增删改查

Reiskuchen 5 年之前
父節點
當前提交
ccb7a8a9b0

+ 57 - 0
official_backend/src/main/java/com/hssx/ysofficial/controller/RecruitmentController.java

@@ -0,0 +1,57 @@
+package com.hssx.ysofficial.controller;
+
+
+import com.hssx.ysofficial.service.RecruitmentService;
+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-14
+ */
+@RestController
+@RequestMapping("/recruitment")
+public class RecruitmentController {
+    @Autowired
+    private RecruitmentService recruitmentService;
+
+    /**
+     * 获取招聘信息列表
+     */
+    @RequestMapping("/list")
+    public HttpRespMsg getRecruitmentList() {
+        return recruitmentService.getRecruitmentList();
+    }
+
+    /**
+     * 删除招聘信息
+     * id 要删除的招聘信息id
+     */
+    @RequestMapping("/delete")
+    public HttpRespMsg deleteRecruitmentList(@RequestParam Integer id) {
+        return recruitmentService.deleteRecruitmentList(id);
+    }
+
+    /**
+     * 新增或修改招聘信息
+     * id 修改时需要的id
+     * title 标题
+     * content 内容
+     * date 日期字符串 格式yyyy-MM-dd
+     * file 图片
+     */
+    @RequestMapping("/insertOrUpdate")
+    public HttpRespMsg editRecruitmentList(Integer id, @RequestParam String title, @RequestParam String content,
+                                           @RequestParam String date, MultipartFile file) {
+        return recruitmentService.editRecruitmentList(id, title, content, date, file);
+    }
+}
+

+ 66 - 0
official_backend/src/main/java/com/hssx/ysofficial/entity/Recruitment.java

@@ -0,0 +1,66 @@
+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 java.time.LocalDate;
+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-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("recruitment")
+public class Recruitment extends Model<Recruitment> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 职位名称
+     */
+    @TableField("title")
+    private String title;
+
+    /**
+     * 内容
+     */
+    @TableField("content")
+    private String content;
+
+    /**
+     * 图片
+     */
+    @TableField("pic_url")
+    private String picUrl;
+
+    /**
+     * 发布日期
+     */
+    @TableField("publish_time")
+    private LocalDate publishTime;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

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

@@ -0,0 +1,16 @@
+package com.hssx.ysofficial.mapper;
+
+import com.hssx.ysofficial.entity.Recruitment;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-14
+ */
+public interface RecruitmentMapper extends BaseMapper<Recruitment> {
+
+}

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

@@ -0,0 +1,22 @@
+package com.hssx.ysofficial.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.ysofficial.entity.Recruitment;
+import com.hssx.ysofficial.utility.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-14
+ */
+public interface RecruitmentService extends IService<Recruitment> {
+    HttpRespMsg getRecruitmentList();
+
+    HttpRespMsg deleteRecruitmentList(Integer id);
+
+    HttpRespMsg editRecruitmentList(Integer id, String title, String content, String date, MultipartFile file);
+}

+ 79 - 0
official_backend/src/main/java/com/hssx/ysofficial/service/impl/RecruitmentServiceImpl.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.Recruitment;
+import com.hssx.ysofficial.mapper.RecruitmentMapper;
+import com.hssx.ysofficial.service.RecruitmentService;
+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.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.UUID;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author Reiskuchen
+ * @since 2020-02-14
+ */
+@Service
+public class RecruitmentServiceImpl extends ServiceImpl<RecruitmentMapper, Recruitment> implements RecruitmentService {
+
+    @Resource
+    private RecruitmentMapper recruitmentMapper;
+
+    @Value("${upload.path}")
+    private String uploadPath;
+
+    @Override
+    public HttpRespMsg getRecruitmentList() {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data = recruitmentMapper.selectList(new QueryWrapper<>());
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg deleteRecruitmentList(Integer id) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data = recruitmentMapper.deleteById(id);
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg editRecruitmentList(Integer id, String title, String content, String date, MultipartFile multipartFile) {
+        Recruitment recruitment = new Recruitment()
+                .setId(id)
+                .setTitle(title)
+                .setContent(content)
+                .setPublishTime(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+        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();
+            }
+            recruitment.setPicUrl("/upload/" + storedFileName);
+        }
+        if (id != null) {
+            recruitmentMapper.updateById(recruitment);
+        } else {
+            recruitmentMapper.insert(recruitment);
+        }
+        return new 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("feedback");
+        strategy.setInclude("recruitment");
         //全生成
 //        strategy.setInclude();//表名,多个英文逗号分割
         //多个英文逗号隔开

+ 19 - 0
official_backend/src/main/resources/mapper/RecruitmentMapper.xml

@@ -0,0 +1,19 @@
+<?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.RecruitmentMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.hssx.ysofficial.entity.Recruitment">
+        <id column="id" property="id" />
+        <result column="title" property="title" />
+        <result column="content" property="content" />
+        <result column="pic_url" property="picUrl" />
+        <result column="publish_time" property="publishTime" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, title, content, pic_url, publish_time
+    </sql>
+
+</mapper>