ZpglController.java 18.8 KB
Newer Older
1 2
package cn.timer.api.controller.zpgl;

3 4 5 6 7
import cn.hutool.core.util.StrUtil;
import cn.timer.api.bean.kqgl.UserEquiRelation;
import cn.timer.api.bean.kqmk.*;
import cn.timer.api.bean.qyzx.QyzxEmpEntAsso;
import cn.timer.api.bean.qyzx.QyzxEmpLogin;
8 9 10 11 12 13
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.bean.zpgl.ZpglRcxx;
import cn.timer.api.bean.zpgl.ZpglZwxx;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.enuminterface.JxglEnumInterface;
14 15
import cn.timer.api.config.enums.CommonEnum;
import cn.timer.api.config.enums.SysRoleType;
16
import cn.timer.api.config.exception.CustomException;
17 18 19 20 21 22 23
import cn.timer.api.controller.kqgl.ClockInTool;
import cn.timer.api.controller.kqgl.atttimer.RealTimeUpdate;
import cn.timer.api.controller.zpgl.sevice.ZpglService;
import cn.timer.api.dao.kqgl.UserEquiRelationMapper;
import cn.timer.api.dao.kqmk.KqglAssoKqzdkfsMapper;
import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
24
import cn.timer.api.dao.zpgl.ZpglRcxxMapper;
25
import cn.timer.api.dto.zpgl.ZpglRcxxDto;
26
import cn.timer.api.dto.zpgl.ZpglRcxxEntryDto;
27
import cn.timer.api.utils.Md5;
28 29
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
30
import cn.timer.api.utils.query.BaseQuery;
31
import cn.timer.api.config.enuminterface.YgEnumInterface.jobStatus;
32 33
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
34
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
35 36
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
37
import com.github.yulichang.query.MPJQueryWrapper;
38 39
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
40
import io.swagger.annotations.ApiParam;
41
import lombok.extern.slf4j.Slf4j;
42
import org.springframework.beans.factory.annotation.Autowired;
43 44 45 46 47 48 49
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
50
import org.springframework.util.StringUtils;
51
import org.springframework.validation.annotation.Validated;
52
import org.springframework.web.bind.annotation.*;
53
import org.springframework.web.client.RestTemplate;
54 55

import javax.transaction.Transactional;
56
import java.text.ParseException;
57
import java.text.SimpleDateFormat;
58
import java.util.Date;
59 60 61
import java.util.HashMap;
import java.util.List;
import java.util.Map;
62

63 64 65 66 67 68 69
/**
 * 招聘管理
 *
 * @author wuqingjun
 * @email 284718418@qq.com
 * @date 2022-03-08 15:14:40
 */
70 71 72
@Api(tags = "招聘管理")
@Transactional(rollbackOn = Exception.class)
@RestController
73
@RequestMapping(value = "/zpgl", produces = {"application/json"})
74
@Slf4j
75 76
public class ZpglController {

77 78 79 80 81
    @Value(value = "${config-8timer.init-password}")
    private String pwd;
    // 回调地址
    @Value("${config-8timer.machine8timerUrl}")
    public String mac_command;
82
    @Autowired
83
    private KqglAssoKqzdkfsMapper kqglassokqzdkfsmapper;
84
    @Autowired
85 86 87 88 89 90 91 92 93
    private QyzxEmpLoginMapper qyzxEmpLoginMapper;
    @Autowired
    private RealTimeUpdate realtimeupdate;
    @Autowired
    private UserEquiRelationMapper userequirelationmapper;
    @Autowired
    private YgglMainEmpMapper ygglMainEmpMapper;
    @Autowired
    private ZpglService zpglService;
94 95
    @Autowired
    private ZpglRcxxMapper zpglRcxxMapper;
96

97 98 99 100 101 102 103 104 105
    /**
     * 招聘-招聘中
     *
     * @param
     * @return
     */
    @GetMapping(value = "/recruit")
    @ApiOperation(value = "1.招聘列表", httpMethod = "GET", notes = "招聘列表")
    @ApiOperationSupport(order = 1)
106
    public Result<Object> recruit(@CurrentUser UserBean userBean, BaseQuery baseQuery,
107 108 109
                                  @ApiParam("搜索关键字") @RequestParam(required = false) String query,
                                  @ApiParam("职位ID") @RequestParam(required = false) Integer zpglZwxxId,
                                  @ApiParam("状态") @RequestParam(required = false) Integer status) {
110 111 112
        try {
            Page<ZpglRcxx> page = new Page<ZpglRcxx>(baseQuery.getPageNum(), baseQuery.getPageSize());
            QueryWrapper<ZpglRcxx> queryWrapper = new QueryWrapper<>();
113
            queryWrapper.lambda().eq(ZpglRcxx::getOrgCode, userBean.getOrgCode()).eq(ZpglRcxx::getDeleteFlag,0);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
            if (!StringUtils.isEmpty(zpglZwxxId) && zpglZwxxId > 0) {
                queryWrapper.lambda().eq(ZpglRcxx::getZpglZwxxId, zpglZwxxId);
            }
            if (!StringUtils.isEmpty(query)) {
                queryWrapper.lambda().and(qw -> qw.like(ZpglRcxx::getName, query).or().eq(ZpglRcxx::getMobile, query).or().eq(ZpglRcxx::getMail, query));
            }
            queryWrapper.lambda().eq(ZpglRcxx::getStatus, status);
            IPage<ZpglRcxx> ygglMainEmpPage = ZpglRcxx.builder().build().selectPage(page, queryWrapper);
            List<ZpglRcxx> zpglRcxxs = page.getRecords();
            ygglMainEmpPage.getCurrent();
            ygglMainEmpPage.getPages();
            ygglMainEmpPage.getTotal();
            ygglMainEmpPage.getSize();
            Map<String, Object> map = new HashMap<>(2);
            map.put("zpglRcxxs", zpglRcxxs);
129 130 131 132 133 134 135 136
            map.put("FILTERING", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.FILTERING.getType())));
            map.put("FILTER_PASS", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.FILTER_PASS.getType())));
            map.put("INTERVIEW", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.INTERVIEW.getType())));
            map.put("INTERVIEWED", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.INTERVIEWED.getType())));
            map.put("INTERVIEW_PASS", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.INTERVIEW_PASS.getType())));
            map.put("EMPLOY", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.EMPLOY.getType())));
            map.put("OFFER", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.OFFER.getType())));
            map.put("ENTRYING", ZpglRcxx.builder().build().selectCount(new QueryWrapper<ZpglRcxx>().lambda().eq(ZpglRcxx::getDeleteFlag,0).eq(ZpglRcxx::getStatus, JxglEnumInterface.ResumeStatus.ENTRYING.getType())));
137 138 139 140 141
            return ResultUtil.data(ygglMainEmpPage, map, "搜索成功");

        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-招聘列表失败");
142
        }
143

144
    }
145

146 147 148 149 150 151 152 153 154 155
    /**
     * 招聘-招聘中
     *
     * @param
     * @return
     */
    @GetMapping(value = "/zwxx")
    @ApiOperation(value = "2.职位信息", httpMethod = "GET", notes = "职位信息")
    @ApiOperationSupport(order = 2)
    public Result<Object> zwxx(@CurrentUser UserBean userBean) {
156 157
        try {
            QueryWrapper<ZpglZwxx> queryWrapper = new QueryWrapper<>();
158
            queryWrapper.lambda().eq(ZpglZwxx::getOrgCode, userBean.getOrgCode()).eq(ZpglZwxx::getDeleteFlag,0);
159 160 161 162 163 164
            List<ZpglZwxx> zpglZwxxs = ZpglZwxx.builder().build().selectList(queryWrapper);
            return ResultUtil.data(zpglZwxxs, "查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-职位信息失败");
        }
165
    }
166

167
    /**
168
     * 招聘-变更人才信息状态
169 170 171 172 173
     *
     * @param
     * @return
     */
    @PostMapping(value = "/operation")
174
    @ApiOperation(value = "3.招聘-变更人才信息状态", httpMethod = "POST", notes = "招聘-变更人才信息状态")
175
    @ApiOperationSupport(order = 3)
176
    public Result<Object> operation(@CurrentUser UserBean userBean, @RequestBody ZpglRcxxDto zpglRcxxDto) {
177
        try {
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            return zpglService.updateZpglRcxx(userBean,zpglRcxxDto)?ResultUtil.success():ResultUtil.error();
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-变更状态失败");
        }
    }

    /**
     * 添加员工档案
     *
     * @param userBean
     * @param addygdaDto
     * @return
     */
    @PostMapping(value = "/addygda")
    @ApiOperation(value = "4.招聘-确认入职添加员工档案", httpMethod = "POST", notes = "接口发布说明")
    @ApiOperationSupport(order = 4)
195
    public Result<Object> addygda(@CurrentUser UserBean userBean, @Validated @RequestBody ZpglRcxxEntryDto addygdaDto) {
196
        try {
197 198 199 200 201
            ZpglRcxx zpglRcxx = ZpglRcxx.builder().id(addygdaDto.getId()).build().selectById();
            if(StringUtils.isEmpty(zpglRcxx)){
                return ResultUtil.error("确认入职添加员工档案失败");
            }

202
            Integer orgCode = userBean.getOrgCode();
203 204
            //自定义工号
            String customNum = addygdaDto.getCustomNum();
205
            String name = addygdaDto.getName();
206 207 208 209
            String phone = zpglRcxx.getMobile();
            String zjNum = zpglRcxx.getIdCard();
            //考勤组id
            Integer attgroupid = addygdaDto.getAttgroupid();
210 211 212 213 214 215

            Integer jobType = addygdaDto.getJobType();
            Date rzTime = addygdaDto.getRzTime() == null ? new Date() : addygdaDto.getRzTime();
            Integer syq = addygdaDto.getSyq();
            Integer sex = addygdaDto.getSex();
            Integer bmgwId = addygdaDto.getBmgwId();
216 217 218
            ZpglRcxxDto zpglRcxxDto = new ZpglRcxxDto();
            zpglRcxxDto.setId(zpglRcxx.getId());
            zpglRcxxDto.setStatus(addygdaDto.getStatus());
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

            QyzxEmpLogin login = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
                    .eq(!StrUtil.hasBlank(phone), QyzxEmpLogin::getPhone, phone).one();
            if (login == null) {
                // 初始化密码 pwd
                login = QyzxEmpLogin.builder().phone(phone).pw(Md5.md5(pwd))
                        .sts(CommonEnum.U_STS_ON.getType()).orgId(userBean.getOrgCode()).username(name).build();
                if (!login.insert()) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return ResultUtil.error("添加员工登录表失败,请检查输入信息");
                }
            }

            YgglMainEmp ygglMainEmp = ygglMainEmpMapper.selectOne(new QueryWrapper<YgglMainEmp>().lambda()
                    .eq(YgglMainEmp::getPhone, phone).eq(YgglMainEmp::getOrgCode, orgCode));
            if(!StringUtils.isEmpty(ygglMainEmp)){
                return ResultUtil.error("该手机号已被使用,请输入正确手机号");
            }
            QyzxEmpEntAsso.builder().empNum(login.getId()).orgCode(orgCode).userType(SysRoleType.U_TYPE_EMP.getType())
                    .status(CommonEnum.U_STS_ON.getType()).build().insert();
239
            ygglMainEmp = YgglMainEmp.builder().name(name).phone(phone).zjType(addygdaDto.getZjType()).zjNum(zjNum).jobType(jobType)
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
                    .jobStatus(jobStatus.SHIYONG.getType()).rzTime(rzTime).syq(syq).sex(sex)
                    .empNum(login.getId()).orgCode(orgCode).bmgwId(bmgwId).customNum(customNum).build();

            if (addygdaDto.getAttgroupid() != null) {
                KqglAssoYhkqz.builder().kqzid(attgroupid).userid(login.getId()).qyid(userBean.getOrgCode()).build().insert();

                List<KqglAssoKqzdkfs> kqjs = kqglassokqzdkfsmapper.selectList(new QueryWrapper<KqglAssoKqzdkfs>().lambda().eq(KqglAssoKqzdkfs::getKqzId, addygdaDto.getAttgroupid()).eq(KqglAssoKqzdkfs::getType, 1));

                for (KqglAssoKqzdkfs abp : kqjs) {
                    KqglAssoKqj kqj = KqglAssoKqj.builder().id(abp.getDkfsid()).build().selectById();
                    KqglAssoYhsb kqjry = KqglAssoYhsb.builder().build().selectOne(new QueryWrapper<KqglAssoYhsb>().lambda().eq(KqglAssoYhsb::getUserId, login.getId()).eq(KqglAssoYhsb::getKqjid, kqj.getId()));
                    if (kqjry == null) {
                        String url = mac_command + "/addUserName";
                        HttpHeaders headers = new HttpHeaders();
                        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
                        params.add("devId", kqj.getCode());
                        params.add("userId", login.getId());
                        params.add("userName", ygglMainEmp.getName());
                        RestTemplate restTemplate = new RestTemplate();
                        HttpEntity httpEntity = new HttpEntity(params, headers);
                        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity, String.class);

                        KqglAssoYhsb.builder().build().delete(new QueryWrapper<KqglAssoYhsb>().lambda().eq(KqglAssoYhsb::getUserId, login.getId()).eq(KqglAssoYhsb::getKqjid, kqj.getId()));

                        KqglAssoYhsb uskqj = KqglAssoYhsb.builder().userId(login.getId()).kqjid(kqj.getId()).type(1).build();

                        UserEquiRelation isgly = userequirelationmapper.selectByuserId(login.getId());
                        if (isgly != null) {
                            uskqj.setIsGly(isgly.getIsGly());
                        } else {
                            uskqj.setIsGly(0);
271
                        }
272 273
                        if (!uskqj.insert()){
                            return ResultUtil.error("操作失败--新增用户与设备关系");
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
                }

            }

            if (syq == 0) {
                ygglMainEmp.setZzTime(rzTime);
            } else {

                String sdf = new SimpleDateFormat("yyyy-MM-dd").format(rzTime);

                String zztime = ClockInTool.requires_extra_times(sdf, syq, 4, 1);

                ygglMainEmp.setZzTime(ClockInTool.strToDateLong(zztime));
            }

            ygglMainEmp.insert();

            //假期规则初始化
            String current_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            List<KqglAssoLeaveRules> rul = KqglAssoLeaveRules.builder().build().selectList(new QueryWrapper<KqglAssoLeaveRules>().lambda().eq(KqglAssoLeaveRules::getOrgCode, orgCode));
            for (KqglAssoLeaveRules r : rul) {
                if (r.getLeaveBalance() == 0) {
                    KqglAssoLeaveEmployeeBalance.builder().leaveRulesId(r.getId()).userid(ygglMainEmp.getEmpNum()).balanceDays(-1).modifyUserid(userBean.getEmpNum()).modifyTimer(current_time).orgCode(userBean.getOrgCode()).build().insert();
                } else {
                    KqglAssoLeaveEmployeeBalance.builder().leaveRulesId(r.getId()).userid(ygglMainEmp.getEmpNum()).balanceDays(0.0).modifyUserid(userBean.getEmpNum()).modifyTimer(current_time).orgCode(userBean.getOrgCode()).build().insert();
                }
302
            }
303 304 305 306
            // 招聘-变更人才信息状态
            // 添加面试流程记录
            zpglService.updateZpglRcxx(userBean,zpglRcxxDto);
            // 维护微信公众平台表++++++++++++++++++++++++++++++++++++++++++++
307 308 309 310 311 312
            try {
                realtimeupdate.AttendanceTask(userBean.getOrgCode(), ygglMainEmp.getEmpNum(), 2, null);
            } catch (ParseException e) {
                e.printStackTrace();
            }

313
            return ResultUtil.success("确认入职成功!");
314

315 316
        } catch (Exception e) {
            e.printStackTrace();
317
            throw new CustomException("招聘-确认入职失败");
318
        }
319

320
    }
321

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    /**
     * 招聘-已淘汰
     *
     * @param
     * @return
     */
    @GetMapping(value = "/recruit/fail")
    @ApiOperation(value = "5.招聘-已淘汰列表", httpMethod = "GET", notes = "招聘-已淘汰列表")
    @ApiOperationSupport(order = 5)
    public Result<Object> recruitFail(@CurrentUser UserBean userBean, BaseQuery baseQuery,
                                  @ApiParam("搜索关键字") @RequestParam(required = false) String query,
                                  @ApiParam("职位ID") @RequestParam(required = false) Integer zpglZwxxId,
                                  @ApiParam("状态") @RequestParam(required = false) Integer status) {
        try {
            Page<ZpglRcxx> page = new Page<ZpglRcxx>(baseQuery.getPageNum(), baseQuery.getPageSize());
            MPJQueryWrapper<ZpglRcxx> queryWrapper = new MPJQueryWrapper<>();
            queryWrapper.selectAll(ZpglRcxx.class).select("zf.fail_cause")
            .leftJoin("zpgl_fail zf on t.zpgl_fail_id = zf.id");
            queryWrapper.eq("t.org_code", userBean.getOrgCode()).eq("t.delete_flag",0).eq("zf.org_code", userBean.getOrgCode());
            if (!StringUtils.isEmpty(zpglZwxxId) && zpglZwxxId > 0) {
                queryWrapper.eq("t.zpgl_zwxx_id", zpglZwxxId);
            }
            if (!StringUtils.isEmpty(query)) {
                queryWrapper.and(qw -> qw.like("t.name", query).or().eq("t.mobile", query).or().eq("t.mail", query));
            }
            queryWrapper.eq("t.status", 9);
            queryWrapper.eq("zf.zpgl_rcxx_status", status);

            IPage<ZpglRcxx> zpglRcxxPage = zpglRcxxMapper.selectJoinPage(page,ZpglRcxx.class,queryWrapper);
            List<ZpglRcxx> zpglRcxxs = page.getRecords();
            zpglRcxxPage.getCurrent();
            zpglRcxxPage.getPages();
            zpglRcxxPage.getTotal();
            zpglRcxxPage.getSize();
            return ResultUtil.data(zpglRcxxPage, zpglRcxxs, "搜索成功");

        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-已淘汰列表失败");
        }

    }
    /**
     * 招聘-逻辑删除人才信息
     *
     * @param
     * @return
     */
    @PostMapping(value = "/edit/{id}")
    @ApiOperation(value = "5.招聘-删除人才信息", httpMethod = "GET", notes = "删除人才信息")
    @ApiOperationSupport(order = 5)
    public Result<Object> edit(@CurrentUser UserBean userBean, @PathVariable Integer id) {
        try {
            return ZpglRcxx.builder().id(id).deleteFlag(1).userId(userBean.getEmpNum()).build().updateById()?ResultUtil.success("操作成功"):ResultUtil.error("操作失败");
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-删除人才信息失败");
        }

    }

383
}