package org.springblade.modules.FTP;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import liquibase.pro.packaged.M;
|
import org.springblade.common.utils.DesensitizedUtil;
|
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.text.SimpleDateFormat;
|
import java.util.*;
|
|
@Component
|
public class DataHanlder {
|
|
@Autowired
|
private IUserService userService;
|
|
//声明对象
|
private static DataHanlder hanlder;
|
|
@Autowired
|
private SecurityPaperService securityPaperService;
|
|
@Autowired
|
private IExperienceService experienceService;
|
|
@Autowired
|
private IDispatcherService dispatcherService;
|
|
@Autowired
|
private MyAsyncService myAsyncService;
|
|
@Autowired
|
private IDeptService iDeptService;
|
|
/**
|
* 初始化
|
*/
|
@PostConstruct
|
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;
|
}
|
|
|
/**
|
* 数据处理
|
* @param json
|
*/
|
public static void handler(String json){
|
//以分号分割
|
List<String> list = Arrays.asList(json.split(";"));
|
//对象转换
|
for (String s : list) {
|
Map map = JSON.parseObject(s, Map.class);
|
Object user = map.get("user");
|
User user1 = JSON.parseObject(user.toString(), User.class);
|
//获取 uuid
|
String uuid = user1.getReasonForLeav();
|
//用户数据校验
|
Result result = userCheckOut(user1);
|
//创建返回对象
|
Result result1 = new Result();
|
if (result.getCode()==200){
|
user1.setReasonForLeav("");
|
//校验保安员证编号
|
Result result2 = hanlder.checkSecurityNumber(user1);
|
User user2 = result2.getUser();
|
//去新增
|
boolean save = hanlder.userService.save(user2);
|
if (save){
|
//异步审查
|
hanlder.myAsyncService.checkUserExamineByCardNo(user2);
|
}
|
|
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());
|
//校验保安员证编号
|
Result result2 = hanlder.checkSecurityNumber(user1);
|
User user2 = result2.getUser();
|
user2.setId(data.getId());
|
|
hanlder.userService.updateById(user2);
|
//设置返回结果
|
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 {
|
//不新增,不修改
|
//设置返回结果
|
result1.setCode(400);
|
result1.setUserId(null);
|
result1.setMsg(result.getMsg());
|
}
|
Map<String, Object> map1 = new HashMap<>(1);
|
map1.put(uuid,result1);
|
//向外网发送数据
|
FtpUtil.objectFileUpload(map1);
|
}
|
}
|
|
/**
|
* 用户校验
|
* @param user
|
*/
|
public static Result userCheckOut(User user) {
|
//1. 校验是否有重复导入
|
User user1 = new User();
|
user1.setCardid(user.getCardid());
|
user1.setStatus(1);
|
user1.setIsDeleted(0);
|
User one = hanlder.userService.getOne(Condition.getQueryWrapper(user1));
|
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);
|
}
|
}
|
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 cardid = DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid());
|
|
//内网同步
|
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() + "'" +
|
"," + "'" + cardid + "'" +
|
"," + "'" + 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);
|
}
|
|
|
}
|