xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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();
        }
    }
}