Browse Source

完善职位发布逻辑

王育民 5 years ago
parent
commit
8920e29413

+ 2 - 0
src/main/java/cn/minbb/job/controller/rest/CompanyController.java

@@ -75,6 +75,7 @@ public class CompanyController {
             return ResponseResult.<JobVo>ok(false).code(Const.ReturnCode.FAILED).message("未能获取用户信息").build();
         }
         Company company = companyService.findOneById(user.getCompany().getId());
+        String type = params.get("type");
         String name = params.get("name");
         String salary = params.get("salary");
         String place = params.get("place");
@@ -87,6 +88,7 @@ public class CompanyController {
         }
         List<JobTag> jobTagList = jobTagService.findAllByIdIn(jobTagIdList);
         Job job = new Job();
+        job.setType(type);
         job.setName(name);
         job.setSalary(salary);
         job.setPlace(place);

+ 41 - 0
src/main/java/cn/minbb/job/controller/rest/JobController.java

@@ -0,0 +1,41 @@
+package cn.minbb.job.controller.rest;
+
+import cn.minbb.job.data.Const;
+import cn.minbb.job.data.ResponseResult;
+import cn.minbb.job.model.Job;
+import cn.minbb.job.model.User;
+import cn.minbb.job.model.vo.JobVo;
+import cn.minbb.job.service.JobService;
+import cn.minbb.job.system.UserSession;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RequestMapping("/job")
+@RestController
+public class JobController {
+
+    private final JobService jobService;
+
+    public JobController(JobService jobService) {
+        this.jobService = jobService;
+    }
+
+    @DeleteMapping("")
+    public ResponseResult<JobVo> jobDeletePage(@RequestParam Integer id) {
+        User user = UserSession.getUserAuthentication();
+        if (null == user) {
+            return ResponseResult.<JobVo>ok(false).code(Const.ReturnCode.FAILED).message("未能获取用户信息").build();
+        } else {
+            Job job = jobService.findOneById(id);
+            if (null != job) {
+                job.setIsEnabled(Boolean.FALSE);
+                jobService.saveOne(job);
+            }
+            return ResponseResult.<JobVo>ok(true).code(Const.ReturnCode.SUCCESS).message("删除成功").build();
+        }
+    }
+}

+ 24 - 11
src/main/java/cn/minbb/job/controller/web/CompanyController.java

@@ -1,12 +1,10 @@
 package cn.minbb.job.controller.web;
 
 import cn.minbb.job.data.Const;
-import cn.minbb.job.model.Company;
-import cn.minbb.job.model.Industry;
-import cn.minbb.job.model.JobTag;
-import cn.minbb.job.model.User;
+import cn.minbb.job.model.*;
 import cn.minbb.job.service.CompanyService;
 import cn.minbb.job.service.IndustryService;
+import cn.minbb.job.service.JobService;
 import cn.minbb.job.service.JobTagService;
 import cn.minbb.job.system.UserSession;
 import lombok.extern.log4j.Log4j2;
@@ -25,11 +23,13 @@ public class CompanyController {
 
     private final CompanyService companyService;
     private final IndustryService industryService;
+    private final JobService jobService;
     private final JobTagService jobTagService;
 
-    public CompanyController(CompanyService companyService, IndustryService industryService, JobTagService jobTagService) {
+    public CompanyController(CompanyService companyService, IndustryService industryService, JobService jobService, JobTagService jobTagService) {
         this.companyService = companyService;
         this.industryService = industryService;
+        this.jobService = jobService;
         this.jobTagService = jobTagService;
     }
 
@@ -37,8 +37,12 @@ public class CompanyController {
     public ModelAndView companyPage(@RequestParam(name = "id", required = false) Integer id, ModelAndView modelAndView) {
         Company company = companyService.findOneById(id);
         if (null != company) {
+            List<Job> jobList1 = jobService.findAllByCompanyAndType(company, "全职");
+            List<Job> jobList2 = jobService.findAllByCompanyAndType(company, "实习");
             company.setPriority(company.getPriority() + 1);
             companyService.saveOne(company);
+            modelAndView.addObject("jobList1", jobList1);
+            modelAndView.addObject("jobList2", jobList2);
             modelAndView.addObject("company", company);
             modelAndView.setViewName(Const.ViewName.VIEW_COMPANY);
         } else {
@@ -50,12 +54,21 @@ public class CompanyController {
     @GetMapping("/info")
     public ModelAndView companyInfo(ModelAndView modelAndView) {
         User user = UserSession.getUserAuthentication();
-        List<Industry> industryList = industryService.findAll();
-        List<JobTag> jobTagList = jobTagService.findAll();
-        modelAndView.addObject("jobTagList", jobTagList);
-        modelAndView.addObject("industryList", industryList);
-        if (null != user) modelAndView.addObject("company", user.getCompany());
-        modelAndView.setViewName(Const.ViewName.VIEW_COMPANY_INFO);
+        if (null == user) {
+            modelAndView.setViewName(Const.ViewName.VIEW_REDIRECT);
+        } else {
+            Company company = companyService.findOneById(user.getCompany().getId());
+            List<Job> jobList1 = jobService.findAllByCompanyAndType(company, "全职");
+            List<Job> jobList2 = jobService.findAllByCompanyAndType(company, "实习");
+            List<Industry> industryList = industryService.findAll();
+            List<JobTag> jobTagList = jobTagService.findAll();
+            modelAndView.addObject("jobList1", jobList1);
+            modelAndView.addObject("jobList2", jobList2);
+            modelAndView.addObject("jobTagList", jobTagList);
+            modelAndView.addObject("industryList", industryList);
+            modelAndView.addObject("company", user.getCompany());
+            modelAndView.setViewName(Const.ViewName.VIEW_COMPANY_INFO);
+        }
         return modelAndView;
     }
 }

+ 26 - 1
src/main/java/cn/minbb/job/controller/web/JobController.java

@@ -1,10 +1,13 @@
 package cn.minbb.job.controller.web;
 
 import cn.minbb.job.data.Const;
+import cn.minbb.job.model.Job;
+import cn.minbb.job.service.JobService;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 
 @Controller
@@ -12,7 +15,29 @@ import org.springframework.web.servlet.ModelAndView;
 @RequestMapping("/job")
 public class JobController {
 
-    public JobController() {
+    private final JobService jobService;
+
+    public JobController(JobService jobService) {
+        this.jobService = jobService;
+    }
+
+    @GetMapping("")
+    public ModelAndView jobPage(@RequestParam Integer id, ModelAndView modelAndView) {
+        Job job = jobService.findOneById(id);
+        if (null == job) {
+            modelAndView.setViewName(Const.ViewName.VIEW_REDIRECT);
+        } else {
+            Integer priority = job.getPriority();
+            if (null == priority) {
+                priority = 1;
+            } else {
+                priority += 1;
+            }
+            job.setPriority(priority);
+            modelAndView.addObject("job", jobService.saveOne(job));
+            modelAndView.setViewName(Const.ViewName.VIEW_JOB);
+        }
+        return modelAndView;
     }
 
     @GetMapping("/full")

+ 1 - 0
src/main/java/cn/minbb/job/data/Const.java

@@ -49,6 +49,7 @@ public class Const {
         String VIEW_SIGN_UP_USER = "sign-up-user";
         String VIEW_SIGN_UP_COMPANY = "sign-up-company";
         String VIEW_ABOUT = "about";
+        String VIEW_JOB = "job";
         String VIEW_JOB_FULL = "job-full";
         String VIEW_JOB_PRACTICE = "job-practice";
         String VIEW_COMPANY = "company";

+ 3 - 0
src/main/java/cn/minbb/job/model/Job.java

@@ -33,6 +33,9 @@ public class Job extends Auditable {
     @Column(name = "education", columnDefinition = "VARCHAR(32) COMMENT '学历'")
     private String education;
 
+    @Column(name = "type", columnDefinition = "VARCHAR(20) COMMENT '类型'")
+    private String type;
+
     @Column(name = "description", columnDefinition = "VARCHAR(1000) COMMENT '描述'")
     private String description;
 

+ 7 - 0
src/main/java/cn/minbb/job/service/JobService.java

@@ -1,7 +1,14 @@
 package cn.minbb.job.service;
 
+import cn.minbb.job.model.Company;
 import cn.minbb.job.model.Job;
 
+import java.util.List;
+
 public interface JobService {
     Job saveOne(Job job);
+
+    Job findOneById(Integer id);
+
+    List<Job> findAllByCompanyAndType(Company company, String type);
 }

+ 19 - 0
src/main/java/cn/minbb/job/service/impl/JobServiceImpl.java

@@ -1,10 +1,15 @@
 package cn.minbb.job.service.impl;
 
+import cn.minbb.job.model.Company;
 import cn.minbb.job.model.Job;
 import cn.minbb.job.model.repository.JobRepository;
 import cn.minbb.job.service.JobService;
+import cn.minbb.job.util.SortTool;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class JobServiceImpl implements JobService {
 
@@ -18,4 +23,18 @@ public class JobServiceImpl implements JobService {
     public Job saveOne(Job job) {
         return jobRepository.save(job);
     }
+
+    @Override
+    public Job findOneById(Integer id) {
+        return jobRepository.findById(id).orElse(null);
+    }
+
+    @Override
+    public List<Job> findAllByCompanyAndType(Company company, String type) {
+        Job job = new Job();
+        job.setCompany(company);
+        job.setType(type);
+        job.setIsEnabled(Boolean.TRUE);
+        return jobRepository.findAll(Example.of(job), SortTool.priorityDown());
+    }
 }

+ 73 - 5
src/main/resources/templates/company-info.html

@@ -31,6 +31,42 @@
     </section>
 
     <div class="container">
+        <div class="row">
+            <div class="col-md-12">
+                <h3 class="pb-3 mb-4 font-italic border-bottom">全部职位</h3>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">全职招聘</h5>
+                    <div th:if="${jobList1.isEmpty()}">还没有发布任何职位哦!快去发布招聘信息吧!</div>
+                    <div class="media text-muted pt-3" th:each="job1 : ${jobList1}">
+                        <img alt="32x32" class="mr-2 rounded" data-holder-rendered="true" style="width: 32px; height: 32px;" th:src="${company.getBrand()}"/>
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <a th:href="${'/job?id=' + job1.getId()}"><strong class="text-gray-dark" th:text="${job1.getName()}"></strong></a>
+                                <a href="#" onclick="deleteJob(this);" th:data-id="${job1.getId()}">删除</a>
+                            </div>
+                            <span class="d-block" th:text="${#strings.abbreviate(job1.getDescription(), 32)}"></span>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">实习招聘</h5>
+                    <div th:if="${jobList2.isEmpty()}">还没有发布任何职位哦!快去发布招聘信息吧!</div>
+                    <div class="media text-muted pt-3" th:each="job2 : ${jobList2}">
+                        <img alt="32x32" class="mr-2 rounded" data-holder-rendered="true" style="width: 32px; height: 32px;" th:src="${company.getBrand()}"/>
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <a th:href="${'/job?id=' + job2.getId()}"><strong class="text-gray-dark" th:text="${job2.getName()}"></strong></a>
+                                <a href="#" onclick="deleteJob(this);" th:data-id="${job2.getId()}">删除</a>
+                            </div>
+                            <span class="d-block" th:text="${#strings.abbreviate(job2.getDescription(), 32)}"></span>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+
         <div class="row" style="margin-top: 24px;"></div>
     </div>
 
@@ -103,13 +139,21 @@
                 </div>
                 <div class="modal-body">
                     <form>
+                        <div class="form-group">
+                            <label for="select-type">职位类型</label>
+                            <select class="form-control" id="select-type">
+                                <option value="">--- 请选择 ---</option>
+                                <option value="全职">全职</option>
+                                <option value="实习">实习</option>
+                            </select>
+                        </div>
                         <div class="form-group">
                             <label for="input-name">岗位名称</label>
                             <input class="form-control" id="input-name" type="text" placeholder="岗位名称" maxlength="32"/>
                         </div>
                         <div class="form-group">
                             <label for="input-salary">薪资待遇</label>
-                            <input class="form-control" id="input-salary" type="text" placeholder="岗位名称" maxlength="32"/>
+                            <input class="form-control" id="input-salary" type="text" placeholder="薪资待遇" maxlength="32"/>
                             <small class="form-text text-muted">?-?K ·?薪</small>
                         </div>
                         <div class="form-group">
@@ -220,9 +264,12 @@
             let tag = $("input:checkbox[name='tag']:checked").map(function (index, elem) {
                 return $(elem).val();
             }).get().join(',');
-            let name = $('#input-name').val(), salary = $('#input-salary').val(), place = $('#input-place').val(), education = $('#select-education').val(),
-                description = $('#textarea-description').val();
-            if (name === "") {
+            let type = $('#select-type').val(), name = $('#input-name').val(), salary = $('#input-salary').val(), place = $('#input-place').val(),
+                education = $('#select-education').val(), description = $('#textarea-description').val();
+            if (type === '') {
+                alert("职位类型不能为空");
+                return;
+            } else if (name === "") {
                 alert("职位名称不能为空");
                 return;
             } else if (salary === "") {
@@ -242,7 +289,7 @@
                 url: '/company/job',
                 type: 'POST',
                 contentType: "application/json; charset=utf-8",
-                data: JSON.stringify({"name": name, "salary": salary, "place": place, "education": education, "description": description, "tag": tag}),
+                data: JSON.stringify({"type": type, "name": name, "salary": salary, "place": place, "education": education, "description": description, "tag": tag}),
                 dataType: "json",
                 success: function (data) {
                     if (data.success) {
@@ -256,6 +303,27 @@
                 }
             });
         }
+
+        function deleteJob(obj) {
+            if (confirm("确定删除该职位吗?")) {
+                $.ajax({
+                    url: '/job?id=' + obj.dataset.id,
+                    type: 'DELETE',
+                    contentType: "application/json; charset=utf-8",
+                    dataType: "json",
+                    success: function (data) {
+                        if (data.success) {
+                            window.location.reload();
+                        } else {
+                            alert("请重试");
+                        }
+                    },
+                    error: function (data) {
+                        console.log(data);
+                    }
+                });
+            }
+        }
     </script>
 </th:block>
 </body>

+ 34 - 2
src/main/resources/templates/company.html

@@ -110,10 +110,42 @@
 
     <div class="container">
         <div class="row">
-            <div class="col">
-                ...
+            <div class="col-md-12">
+                <h3 class="pb-3 mb-4 font-italic border-bottom">全部职位</h3>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">全职招聘</h5>
+                    <div th:if="${jobList1.isEmpty()}">还没有发布任何招聘信息哦!</div>
+                    <div class="media text-muted pt-3" th:each="job1 : ${jobList1}">
+                        <img alt="32x32" class="mr-2 rounded" data-holder-rendered="true" style="width: 32px; height: 32px;" th:src="${company.getBrand()}"/>
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <a th:href="${'/job?id=' + job1.getId()}"><strong class="text-gray-dark" th:text="${job1.getName()}"></strong></a>
+                                <a href="#" onclick="deleteJob(this);" th:data-id="${job1.getId()}">删除</a>
+                            </div>
+                            <span class="d-block" th:text="${#strings.abbreviate(job1.getDescription(), 32)}"></span>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">实习招聘</h5>
+                    <div th:if="${jobList2.isEmpty()}">还没有发布任何招聘信息哦!</div>
+                    <div class="media text-muted pt-3" th:each="job2 : ${jobList2}">
+                        <img alt="32x32" class="mr-2 rounded" data-holder-rendered="true" style="width: 32px; height: 32px;" th:src="${company.getBrand()}"/>
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <a th:href="${'/job?id=' + job2.getId()}"><strong class="text-gray-dark" th:text="${job2.getName()}"></strong></a>
+                                <a href="#" onclick="deleteJob(this);" th:data-id="${job2.getId()}">删除</a>
+                            </div>
+                            <span class="d-block" th:text="${#strings.abbreviate(job2.getDescription(), 32)}"></span>
+                        </div>
+                    </div>
+                </div>
             </div>
         </div>
+
+        <div class="row" style="margin-top: 24px;"></div>
     </div>
 </th:block>
 </body>

+ 1 - 0
src/main/resources/templates/fragments/header.html

@@ -58,6 +58,7 @@
                 <div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav">
                     <a class="dropdown-item" href="/user/info" th:if="${user.hasRole(T(cn.minbb.job.enumerate.Role).USER)}">个人信息</a>
                     <a class="dropdown-item" href="/company/info" th:if="${user.hasRole(T(cn.minbb.job.enumerate.Role).COMPANY)}">企业信息</a>
+                    <a class="dropdown-item" href="/company/resume" th:if="${user.hasRole(T(cn.minbb.job.enumerate.Role).COMPANY)}">收到简历</a>
                     <a class="dropdown-item" href="/school/info" th:if="${user.hasRole(T(cn.minbb.job.enumerate.Role).SCHOOL)}">学校信息</a>
                     <div th:if="${user.hasRole(T(cn.minbb.job.enumerate.Role).ADMIN)}">
                         <div class="dropdown-divider"></div>

+ 135 - 0
src/main/resources/templates/job.html

@@ -0,0 +1,135 @@
+<!DOCTYPE html>
+<html lang="zh-CN" xmlns="http://www.w3.org/1999/html"
+      xmlns:th="http://www.thymeleaf.org"
+      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
+      layout:decorate="~{layouts/layout}">
+<head>
+    <meta charset="UTF-8"/>
+    <title>职位信息 - [[${APP_NAME}]]</title>
+</head>
+<body>
+<th:block layout:fragment="content">
+    <section class="jumbotron text-center">
+        <div class="container">
+            <h1 class="jumbotron-heading" th:text="${job.getName()}"></h1>
+            <p class="lead text-muted" th:text="${job.getSalary() + ' / ' + job.getEducation() + ' / ' + job.getType()}"></p>
+            <p>
+                <a class="btn btn-secondary my-2" th:href="${'/job?id=' + job.getId()}">支持一下</a>
+                <a class="btn btn-primary my-2" href="#modal-job" data-toggle="modal">投递简历</a>
+            </p>
+            <p>
+                当前热度:<span th:text="${job.getPriority()}"></span>
+            </p>
+        </div>
+    </section>
+
+    <div class="container">
+        <div class="row">
+            <div class="col-md-12">
+                <h3 class="pb-3 mb-4 font-italic border-bottom">职位详情</h3>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">职位简介</h5>
+                    <div class="media text-muted pt-3">
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <strong class="text-gray-dark" th:text="${job.getDescription()}"></strong>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="my-3 p-3 bg-white rounded box-shadow">
+                    <h5 class="border-bottom border-gray pb-2 mb-0">工作地点</h5>
+                    <div class="media text-muted pt-3">
+                        <div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
+                            <div class="d-flex justify-content-between align-items-center w-100">
+                                <strong class="text-gray-dark" th:text="${job.getPlace()}"></strong>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+
+        <div class="row" style="margin-top: 24px;"></div>
+    </div>
+
+    <!-- 完善企业信息模态框 -->
+    <div class="modal fade" id="modal-company" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">完善企业信息</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">&times;</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <form>
+                        <div class="form-group">
+                            <label for="input-brand">商标</label>
+                            <input class="form-control-file" id="input-brand" type="file" accept="image/png, image/jpg, image/jpeg"/>
+                        </div>
+                        <div class="form-group">
+                            <label for="select-nature">企业性质</label>
+                            <select class="form-control" id="select-nature">
+                                <option value="">--- 请选择 ---</option>
+                                <option value="国有企业">国有企业</option>
+                                <option value="集体所有制">集体所有制</option>
+                                <option value="私营企业">私营企业</option>
+                                <option value="股份制企业">股份制企业</option>
+                                <option value="有限合伙企业">有限合伙企业</option>
+                                <option value="联营企业">联营企业</option>
+                                <option value="外商投资企业">外商投资企业</option>
+                                <option value="个人独资企业">个人独资企业</option>
+                            </select>
+                        </div>
+                        <div class="form-group">
+                            <label for="input-scale">企业规模</label>
+                            <input class="form-control" id="input-scale" type="text" placeholder="企业规模" maxlength="16"/>
+                            <small class="form-text text-muted">? 人 / ? 千人</small>
+                        </div>
+                        <div class="form-group">
+                            <label for="textarea-introduction">企业简介</label>
+                            <textarea class="form-control" id="textarea-introduction" rows="3" maxlength="500"></textarea>
+                        </div>
+                    </form>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
+                    <button type="button" class="btn btn-primary" onclick="active();">认证并激活</button>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    <script src="https://files.minbb.cn/plugins/jquery/3.4.0/jquery.js"></script>
+    <script>
+        $(document).ready(function () {
+        });
+
+        function deleteJob(obj) {
+            if (confirm("确定投递简历吗?")) {
+                $.ajax({
+                    url: '/job?id=' + obj.dataset.id,
+                    type: 'DELETE',
+                    contentType: "application/json; charset=utf-8",
+                    dataType: "json",
+                    success: function (data) {
+                        if (data.success) {
+                            window.location.reload();
+                        } else {
+                            alert("请重试");
+                        }
+                    },
+                    error: function (data) {
+                        console.log(data);
+                    }
+                });
+            }
+        }
+    </script>
+</th:block>
+</body>
+</html>