src/main/java/org/springblade/modules/FTP/DataHanlder.java
@@ -5,16 +5,22 @@ import liquibase.pro.packaged.M; import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.api.R; import org.springblade.modules.dispatcher.entity.Dispatcher; import org.springblade.modules.dispatcher.service.IDispatcherService; import org.springblade.modules.experience.entity.Experience; import org.springblade.modules.experience.service.IExperienceService; import org.springblade.modules.securitypaper.entity.SecurityPaper; import org.springblade.modules.securitypaper.service.SecurityPaperService; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IDeptService; import org.springblade.modules.system.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.text.SimpleDateFormat; import java.util.*; @Component public class DataHanlder { @@ -25,6 +31,21 @@ //声明对象 private static DataHanlder hanlder; @Autowired private SecurityPaperService securityPaperService; @Autowired private IExperienceService experienceService; @Autowired private IDispatcherService dispatcherService; @Autowired private MyAsyncService myAsyncService; @Autowired private IDeptService iDeptService; /** * 初始化 */ @@ -32,6 +53,11 @@ public void init(){ hanlder = this; hanlder.userService = this.userService; hanlder.securityPaperService = this.securityPaperService; hanlder.experienceService = this.experienceService; hanlder.myAsyncService = this.myAsyncService; hanlder.dispatcherService = this.dispatcherService; hanlder.iDeptService = this.iDeptService; } @@ -56,22 +82,45 @@ Result result1 = new Result(); if (result.getCode()==200){ user1.setReasonForLeav(""); //校验保安员证编号 Result result2 = hanlder.checkSecurityNumber(user1); //去新增 hanlder.userService.save(user1); //设置返回结果 result1.setCode(200); result1.setUserId(user1.getId()); result1.setMsg("新增成功"); hanlder.userService.save(result2.getUser()); if (result2.getCode()==200){ //设置返回结果 result1.setCode(200); result1.setUserId(user1.getId()); result1.setMsg("新增成功"); }else { //设置返回结果 result1.setCode(203); result1.setUserId(user1.getId()); result1.setMsg(result2.getMsg()); } }else if (result.getCode()==201){ //去修改 user1.setReasonForLeav(""); User data = result.getUser(); user1.setId(data.getId()); hanlder.userService.updateById(user1); //校验保安员证编号 Result result2 = hanlder.checkSecurityNumber(user1); User user2 = result2.getUser(); user2.setId(data.getId()); hanlder.userService.updateById(user2); //设置返回结果 result1.setCode(201); result1.setUserId(user1.getId()); result1.setMsg("修改成功"); if (result2.getCode()==200) { result1.setCode(201); result1.setUserId(user1.getId()); result1.setMsg("修改成功"); }else { //设置返回结果 result1.setCode(204); result1.setUserId(user1.getId()); result1.setMsg(result2.getMsg()); } }else { //不新增,不修改 //设置返回结果 @@ -79,7 +128,6 @@ result1.setUserId(null); result1.setMsg(result.getMsg()); } System.out.println("result1 = " + result1); Map<String, Object> map1 = new HashMap<>(1); map1.put(uuid,result1); //向外网发送数据 @@ -91,7 +139,7 @@ * 用户校验 * @param user */ private static Result userCheckOut(User user) { public static Result userCheckOut(User user) { //1. 校验是否有重复导入 User user1 = new User(); user1.setCardid(user.getCardid()); @@ -101,18 +149,146 @@ if (null!=one){ //判断单位是否一致 if (!one.getDeptId().equals(user.getDeptId())){ //判断是否为机读身份证录入 if (null!=user.getCell() && !user.getCell().equals("")){ if (user.getCell().equals("2")){ // cell 2为机读录入 //先将原有人员离职 one.setStatus(2); one.setUpdateTime(new Date()); //离职 hanlder.userService.updateById(one); //内网同步 String s1 = "update blade_user set status = " + one.getStatus() + ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(one.getUpdateTime()) + "'" + " where id = " + "'" + one.getId() + "'"; hanlder.myAsyncService.FTP(s1); //人员离职后修改派遣记录,修改从业记录 hanlder.updateUserDispatcherExp(one); } } return new Result(400,null,user.getRealName() + "已在其他单位导入"); }else { return new Result(201,"已在本单位导入",one); } } //2.保安证编号校验 return new Result(200,null,""); } /** * 修改派遣记录,修改从业记录 * * @param user */ private void updateUserDispatcherExp(User user) { //修改派遣状态 user.setDispatch("1"); //同时将派遣记录中的派遣状态修改 //查询派遣记录(还在派遣中的) Dispatcher dispatcher = new Dispatcher(); dispatcher.setUserIds(user.getId().toString()); dispatcher.setStatus(0); List<Dispatcher> dispatcherList = dispatcherService.list(Condition.getQueryWrapper(dispatcher)); if (dispatcherList.size() > 0) { dispatcherList.forEach(dispatcher1 -> { dispatcher1.setStatus(1); dispatcher1.setUpdateTime(new Date()); String s1 = "update sys_dispatcher set status = " + "'" + dispatcher1.getStatus() + "'" + ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher1.getUpdateTime()) + "'" + " " + "where id = " + "'" + dispatcher1.getId() + "'"; myAsyncService.FTP(s1); }); } //查询当前用户是否有从业记录,没有的话新增,有就更新 //根据公司名查询单位 Dept dept = iDeptService.getById(user.getDeptId()); Experience experience = new Experience(); experience.setCompanyname(dept.getDeptName()); //按id降序 List<Experience> list = experienceService.list(Condition.getQueryWrapper(experience).orderByDesc("id")); if (list.size() > 0) { //如果有多条取第一条更新 Experience experience1 = list.get(0); //设置离职时间 experience1.setDeparturetime(new Date()); //更新从业记录信息 experienceService.updateById(experience1); //数据同步 String s1 = "update sys_experience set departureTime = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience1.getDeparturetime()) + "'" + " " + "where id = " + "'" + experience1.getId() + "'"; myAsyncService.FTP(s1); } else { //新增 if (null != user.getRtime()) { experience.setEntrytime(user.getRtime()); } else { experience.setEntrytime(new Date()); } experience.setDeparturetime(new Date()); experience.setName(user.getRealName()); if (null != user.getReasonForLeav() && !user.getReasonForLeav().equals("")) { experience.setLeaving(user.getReasonForLeav()); } experience.setCardid(user.getCardid()); experience.setSecurityid(user.getId().toString()); //新增 experienceService.save(experience); //内网同步 String s = "insert into sys_experience(id,name,entryTime,departureTime,leaving,cardId,companyname,securityId) " + "values(" + "'" + experience.getId() + "'" + "," + "'" + experience.getName() + "'" + "," + "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getDeparturetime()) + "'" + "," + "'" + experience.getLeaving() + "'" + "," + "'" + experience.getCardid() + "'" + "," + "'" + experience.getCompanyname() + "'" + "," + "'" + experience.getSecurityid() + "'" + ")"; myAsyncService.FTP(s); } } /** * 保安员证编号校验 * @param user * @return */ public Result checkSecurityNumber(User user){ //2.保安证编号校验 //判断是否持证 boolean states = false; if (user.getHold().equals("1") && null!=user.getSecuritynumber() && !user.getSecuritynumber().equals("")){ //持证,校验保安证编号是否合法 SecurityPaper securityPaper = new SecurityPaper(); securityPaper.setIdCardNo(user.getCardid()); List<SecurityPaper> securityPaperList = hanlder.securityPaperService.list(Condition.getQueryWrapper(securityPaper)); if (securityPaperList.size()>0){ //遍历 for (SecurityPaper paper : securityPaperList) { if (paper.getNumber().equals(user.getSecuritynumber())){ states = true; } } if (!states){ user.setHold("2"); } }else { states = false; user.setHold("2"); } } if (!states) { return new Result(201,null,"保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!",user); } return new Result(200,null,"",user); } } src/main/java/org/springblade/modules/FTP/MyAsyncService.java
New file @@ -0,0 +1,18 @@ package org.springblade.modules.FTP; import org.springframework.stereotype.Service; /** * @author Administrator */ @Service public class MyAsyncService { /** * FTP * @param s sql语句 */ public void FTP(String s) { FtpUtil.sqlFileUpload(s); } } src/main/java/org/springblade/modules/FTP/Result.java
@@ -32,4 +32,11 @@ this.userId = userId; this.msg = msg; } public Result(Integer code, Long userId, String msg, User user) { this.code = code; this.userId = userId; this.msg = msg; this.user = user; } } src/main/java/org/springblade/modules/experience/entity/Experience.java
@@ -102,5 +102,9 @@ @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 保安员id */ @TableField("securityId") private String securityid; } src/main/java/org/springblade/modules/securitypaper/controller/SecurityPaperController.java
New file @@ -0,0 +1,101 @@ package org.springblade.modules.securitypaper.controller; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.excel.util.ExcelUtil; import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.modules.securitypaper.entity.SecurityPaper; import org.springblade.modules.securitypaper.excel.SecurityPaperExcel; import org.springblade.modules.securitypaper.excel.SecurityPaperImporter; import org.springblade.modules.securitypaper.service.SecurityPaperService; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; /** * @author zhongrj * @time 2021-12-25 * @desc 保安员证管理控制层 */ @RestController @AllArgsConstructor @RequestMapping("/securityPaper") public class SecurityPaperController { private final SecurityPaperService securityPaperService; // /** // * 自定义分页 // * @param query page,size // * @param securityPaper 保安员证管理信息对象 // */ // @GetMapping("/page") // public R<IPage<SecurityPaperVo>> page(SecurityPaperVo securityPaper, Query query) { // IPage<SecurityPaperVo> pages = securityPaperService.selectSecurityPaperPage(Condition.getPage(query), securityPaper); // return R.data(pages); // } /** * 新增 * @param securityPaper 保安员证管理信息对象 */ @PostMapping("/save") @ApiOperation(value = "新增", notes = "传入securityPaper") public R save(@RequestBody SecurityPaper securityPaper){ return R.data(securityPaperService.save(securityPaper)); } /** * 修改 * @param securityPaper 保安员证管理信息对象 */ @PostMapping("/update") public R update(@RequestBody SecurityPaper securityPaper){ return R.status(securityPaperService.updateById(securityPaper)); } /** * 新增或修改 * @param securityPaper 保安员证管理信息对象 */ @PostMapping("/submit") public R submit(@RequestBody SecurityPaper securityPaper){ return R.data(securityPaperService.saveOrUpdate(securityPaper)); } /** * 删除 * @param ids 保安员证管理信息ids 数组 */ @PostMapping("/remove") public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) { return R.status(securityPaperService.removeByIds(Func.toLongList(ids))); } /** * 详情 * @param securityPaper 保安员证管理信息对象 */ @GetMapping("/detail") @ApiOperation(value = "详情", notes = "传入securityPaper") public R<SecurityPaper> detail(SecurityPaper securityPaper) { SecurityPaper detail = securityPaperService.getOne(Condition.getQueryWrapper(securityPaper)); return R.data(detail); } /** * 导入保安员证数据 */ @PostMapping("import-security-paper") public R importSecurityPaper(MultipartFile file, Integer isCovered, String deptId) { SecurityPaperImporter securityImporter = new SecurityPaperImporter(securityPaperService, false,deptId); ExcelUtil.save(file, securityImporter, SecurityPaperExcel.class); return R.success("操作成功"); } } src/main/java/org/springblade/modules/securitypaper/entity/SecurityPaper.java
New file @@ -0,0 +1,81 @@ package org.springblade.modules.securitypaper.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.util.Date; /** * 保安员证管理实体类 * @author zhongrj * @time 2021-12-25 */ @Data @TableName("sys_security_paper") public class SecurityPaper implements Serializable { private static final long serialVersionUID = 1L; /** * 制证记录主键id,非自增 */ @TableId(value = "id",type = IdType.AUTO) private Integer id; /** * 保安证编号 */ private String number; /** * 创建时间 */ @TableField("create_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; /** * 人员姓名 */ @TableField("people_name") private String peopleName; /** * 人员身份证号码 */ @TableField("id_card_no") private String idCardNo; /** * user_id */ @TableField("user_id") private Long userId; /** * 报名id */ @TableField("apply_id") private Long applyId; /** * 考试id / 核查申请 id */ @TableField("exam_id") private Long examId; /** * 来源 1:考试通过生成 2:核查申请通过插入 3:其他 */ private Integer source; } src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java
New file @@ -0,0 +1,75 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.securitypaper.excel; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight; import lombok.Data; import java.io.Serializable; /** * UserExcel * * @author Chill */ @Data @ColumnWidth(25) @HeadRowHeight(20) @ContentRowHeight(18) public class SecurityPaperExcel implements Serializable { private static final long serialVersionUID = 1L; @ExcelProperty("企业名称*") @ColumnWidth(30) private String deptId; @ColumnWidth(10) @ExcelProperty("姓名*") private String realName; @ColumnWidth(15) @ExcelProperty("联系电话*") private String phone; @ExcelProperty("性别*") @ColumnWidth(10) private String sex; @ExcelProperty("身份证号*") @ColumnWidth(20) private String cardid; @ExcelProperty("民族") @ColumnWidth(10) private String nation; @ExcelProperty("身份证住址*") private String registered; @ExcelProperty("是否持证*") @ColumnWidth(15) private String hold; @ExcelProperty("保安员证编码") @ColumnWidth(20) private String securitynumber; } src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperImporter.java
New file @@ -0,0 +1,41 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.securitypaper.excel; import lombok.RequiredArgsConstructor; import org.springblade.core.excel.support.ExcelImporter; import org.springblade.modules.securitypaper.service.SecurityPaperService; import java.util.List; /** * 保安员证数据数据导入类 * * @author zhongrj */ @RequiredArgsConstructor public class SecurityPaperImporter implements ExcelImporter<SecurityPaperExcel> { private final SecurityPaperService service; private final Boolean isCovered; private final String deptId; @Override public void save(List<SecurityPaperExcel> data) { service.importSecurityPaper(data, isCovered,deptId); } } src/main/java/org/springblade/modules/securitypaper/mapper/SecurityPaperMapper.java
New file @@ -0,0 +1,13 @@ package org.springblade.modules.securitypaper.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.springblade.modules.securitypaper.entity.SecurityPaper; /** * 保安员证管理Mapper 接口 * @author zhongrj */ public interface SecurityPaperMapper extends BaseMapper<SecurityPaper> { } src/main/java/org/springblade/modules/securitypaper/mapper/SecurityPaperMapper.xml
New file @@ -0,0 +1,5 @@ <?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="org.springblade.modules.securitypaper.mapper.SecurityPaperMapper"> </mapper> src/main/java/org/springblade/modules/securitypaper/service/SecurityPaperService.java
New file @@ -0,0 +1,22 @@ package org.springblade.modules.securitypaper.service; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.modules.securitypaper.entity.SecurityPaper; import org.springblade.modules.securitypaper.excel.SecurityPaperExcel; import java.util.List; /** * 保安员证管理服务类 * @author zhongrj */ public interface SecurityPaperService extends IService<SecurityPaper> { /** * 导入保安员证数据 * @param data * @param isCovered * @param deptId */ void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId); } src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java
New file @@ -0,0 +1,42 @@ package org.springblade.modules.securitypaper.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springblade.modules.securitypaper.entity.SecurityPaper; import org.springblade.modules.securitypaper.excel.SecurityPaperExcel; import org.springblade.modules.securitypaper.mapper.SecurityPaperMapper; import org.springblade.modules.securitypaper.service.SecurityPaperService; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; /** * 保安员证管理服务实现类 * @author zhongrj * @since 2021-12-25 */ @Service @AllArgsConstructor public class SecurityPaperServiceImpl extends ServiceImpl<SecurityPaperMapper, SecurityPaper> implements SecurityPaperService { /** * 导入保安员证数据 * @param data * @param isCovered * @param deptId */ @Override public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) { data.forEach(securityPaperExcel -> { SecurityPaper securityPaper = new SecurityPaper(); securityPaper.setIdCardNo(securityPaperExcel.getCardid()); securityPaper.setPeopleName(securityPaperExcel.getRealName()); securityPaper.setNumber(securityPaperExcel.getSecuritynumber()); securityPaper.setCreateTime(new Date()); securityPaper.setSource(3); //新增 this.save(securityPaper); }); } } src/main/java/org/springblade/modules/securitypaper/vo/SecurityPaperVo.java
New file @@ -0,0 +1,17 @@ package org.springblade.modules.securitypaper.vo; import lombok.Data; import org.springblade.modules.securitypaper.entity.SecurityPaper; import java.io.Serializable; /** * 保安员证管理vo * @author zhongrj * @since 2021-12-15 */ @Data public class SecurityPaperVo extends SecurityPaper implements Serializable { }