package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.modular.system.model.Recruit;
|
import com.stylefeng.guns.modular.system.model.TRegion;
|
import com.stylefeng.guns.modular.system.service.IRecruitService;
|
import com.stylefeng.guns.modular.system.service.ITRegionService;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.Assert;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.*;
|
|
/**
|
* 招聘
|
* @author pzb
|
* @Date 2022/5/27 16:42
|
*/
|
@Controller
|
@RequestMapping("/recruit")
|
public class RecruitController {
|
|
private String PREFIX = "/system/recruit/";
|
|
@Autowired
|
private ITRegionService regionService;
|
|
@Autowired
|
private IRecruitService recruitService;
|
|
/**
|
* 跳转到列表页
|
* @return
|
*/
|
@GetMapping("/showRecruit")
|
public String showRecruit(){
|
return PREFIX + "recruit.html";
|
}
|
|
|
/**
|
* 跳转到添加页
|
* @return
|
*/
|
@GetMapping("/recruit_add")
|
public String recruit_add(Model model){
|
List<TRegion> regions = regionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("regions", regions);
|
return PREFIX + "recruit_add.html";
|
}
|
|
/**
|
* 跳转到编辑页
|
* @param model
|
* @param id
|
* @return
|
*/
|
@GetMapping("/recruit_update")
|
public String recruit_update(Model model, Integer id){
|
Recruit recruit = recruitService.selectById(id);
|
model.addAttribute("recruit", recruit);
|
String[] split = recruit.getWelfare().split(",");
|
List<String> list = Arrays.asList("年底双薪", "五险一金", "包吃", "包住", "饭补", "周末双休", "交通补助", "加班补助", "话补", "房补");
|
List<Map<String, Object>> list1 = new ArrayList<>();
|
for (String s : list) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("name", s);
|
map.put("checked", false);
|
for (String s1 : split) {
|
if(s.equals(s1)){
|
map.put("checked", true);
|
break;
|
}
|
}
|
list1.add(map);
|
}
|
model.addAttribute("welfare", list1);
|
List<TRegion> regions = regionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("province", regions);
|
|
TRegion region = regionService.selectOne(new EntityWrapper<TRegion>().eq("code", recruit.getProvinceCode()));
|
List<TRegion> regions1 = regionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", region.getId()));
|
model.addAttribute("city", regions1);
|
return PREFIX + "recruit_edit.html";
|
}
|
|
|
/**
|
* 获取行政区域数据
|
* @param code
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getRegion")
|
public ResultUtil getRegion(String code){
|
try {
|
TRegion region = regionService.selectOne(new EntityWrapper<TRegion>().eq("code", code));
|
List<TRegion> regions = regionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", region.getId()));
|
return ResultUtil.success(regions);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 添加招聘
|
* @param recruit
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/addRecruit")
|
public ResultUtil addRecruit(Recruit recruit){
|
try {
|
recruit.setCompanyType(ShiroKit.getUser().getRoleType());
|
recruit.setCompanyId(ShiroKit.getUser().getObjectId());
|
recruit.setProvinceName(regionService.selectOne(new EntityWrapper<TRegion>().eq("code", recruit.getProvinceCode())).getName());
|
recruit.setCityName(regionService.selectOne(new EntityWrapper<TRegion>().eq("code", recruit.getCityCode())).getName());
|
recruit.setFirstPageShow(2);
|
recruit.setCreateTime(new Date());
|
recruit.setInsertUser(ShiroKit.getUser().getId());
|
if(recruit.getInterviewOrNot() == 1){
|
recruit.setStartSalary(0D);
|
recruit.setEndSalary(0D);
|
}
|
recruitService.insert(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.paranErr();
|
}
|
}
|
|
/**
|
* 获取列表数据
|
* @param createTime
|
* @param title
|
* @param experienceRequirements
|
* @param insertUser
|
* @param driverType
|
* @param offset
|
* @param limit
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/list")
|
public Object list(String createTime, String title, String experienceRequirements, String insertUser, String driverType, Integer offset, Integer limit){
|
try {
|
return recruitService.list(createTime, title, experienceRequirements, insertUser, driverType, offset, limit);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 修改数据
|
* @param recruit
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/updateRecruit")
|
public ResultUtil updateRecruit(Recruit recruit){
|
try {
|
recruit.setProvinceName(regionService.selectOne(new EntityWrapper<TRegion>().eq("code", recruit.getProvinceCode())).getName());
|
recruit.setCityName(regionService.selectOne(new EntityWrapper<TRegion>().eq("code", recruit.getCityCode())).getName());
|
if(recruit.getInterviewOrNot() == 1){
|
recruit.setStartSalary(0D);
|
recruit.setEndSalary(0D);
|
}
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 删除数据
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/deleteRecruit")
|
public ResultUtil deleteRecruit(Integer id){
|
try {
|
Recruit recruit = recruitService.selectById(id);
|
recruit.setStatus(6);
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 发布招聘
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/releaseRecruit")
|
public ResultUtil releaseRecruit(Integer id){
|
try {
|
Recruit recruit = recruitService.selectById(id);
|
if(recruit.getStatus() == 2){
|
return ResultUtil.error("不允许重复操作");
|
}
|
if(recruit.getStatus() == 3){
|
return ResultUtil.error("招聘信息已关闭了");
|
}
|
recruit.setStatus(2);
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 关闭
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/closeRecruit")
|
public ResultUtil closeRecruit(Integer id){
|
try {
|
Recruit recruit = recruitService.selectById(id);
|
if(recruit.getStatus() == 3){
|
return ResultUtil.error("不允许重复操作");
|
}
|
recruit.setStatus(3);
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 首页推荐
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/homeRecommend")
|
public ResultUtil homeRecommend(Integer id){
|
|
Integer maxRecommend = 8;
|
|
try {
|
Recruit recruit = recruitService.selectById(id);
|
if(recruit.getFirstPageShow() == 1){
|
return ResultUtil.error("不允许重复操作");
|
}
|
int statusCount = recruitService.selectCount(new EntityWrapper<Recruit>().eq("firstPageShow", 1).eq("status", 2));
|
if(statusCount >= maxRecommend) {
|
return ResultUtil.error("首页推荐最多8个!");
|
}
|
recruit.setFirstPageShow(1);
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 取消首页推荐
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/cancelHomeRecommend")
|
public ResultUtil cancelHomeRecommend(Integer id){
|
try {
|
Recruit recruit = recruitService.selectById(id);
|
if(recruit.getFirstPageShow() == 2){
|
return ResultUtil.error("不允许重复操作");
|
}
|
recruit.setFirstPageShow(2);
|
recruitService.updateById(recruit);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
}
|