372 lines
14 KiB
Plaintext
372 lines
14 KiB
Plaintext
package com.jysoft.visitor.service;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.UUID;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.json.JSONArray;
|
||
import org.json.JSONObject;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import com.jysoft.visitor.util.ArtemisPost;
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.AliasManageController;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.po.GreenRentHouseApply;
|
||
import com.nationalelectric.greenH5.po.GreenVisitor;
|
||
import com.nationalelectric.greenH5.po.VisitorEventNotify;
|
||
import com.nationalelectric.greenH5.po.VisitorEventNotify.ParamsDTO.EventsDTO;
|
||
import com.nationalelectric.greenH5.po.VisitorEventNotify.ParamsDTO.EventsDTO.DataDTO;
|
||
import com.nationalelectric.greenH5.utils.Base64Utils;
|
||
import com.nationalelectric.greenH5.utils.DateTimeHelper;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
import com.sgcc.uap.utils.StringUtils;
|
||
|
||
/**
|
||
* @author bonus
|
||
* @date 2023-06-12
|
||
* @功能 访客管理
|
||
*/
|
||
@Service
|
||
public class VisitorService {
|
||
|
||
@Autowired
|
||
private IHibernateDao iHibernateDao;
|
||
|
||
@Resource
|
||
private AliasManageController aliasManageController;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
/**
|
||
* 添加来访记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult addVisitor(GreenVisitor entity) {
|
||
try {
|
||
if (StringUtils.isBlank(entity.getType())) {
|
||
entity.setType("1");
|
||
}
|
||
// 获取最低审核批次
|
||
String batchSql = "SELECT * FROM GREEN_DICTIONARY_INFO WHERE DATA_TYPE = 'visitorExamSwitch' AND IS_DELETED = 'N' AND DATA_VALUE = 1 ORDER BY DATA_CODE ASC ";
|
||
List<Map<String, String>> list = iHibernateDao.queryForListWithSql(batchSql);
|
||
String examineBatch = "0";
|
||
if (list.size() > 0) {
|
||
examineBatch = list.get(0).get("DATA_CODE");
|
||
}
|
||
String sqlString = "INSERT INTO GREEN_VISITOR (ID, PERSONNEL_NAME, PERSONNEL_CARD, VISITING_TIME, LEAVE_TIME,"
|
||
+ " REASON, PERSONNEL_PHONE, PERSONNEL_PHOTO, STATE, CREATE_TIME, ENTOURAGE, "
|
||
+ "EXAMINE_BATCH, EXAMINE_STATE, EXAMINE_PERSON_ID, EXAMINE_PERSON_NAME, USER_ID, USER_NAME, PHONE, ORG_ID, ORG_NAME,TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?)";
|
||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||
iHibernateDao.executeSqlUpdate(sqlString,
|
||
new Object[] { uuid, entity.getPersonnelName(), entity.getPersonnelCard(), entity.getVisitingTime(),
|
||
entity.getLeaveTime(), entity.getReason(), entity.getPersonnelPhone(),
|
||
entity.getPersonnelPhoto(), entity.getState(), DateTimeHelper.getNowDate(),
|
||
entity.getEntourage(), examineBatch, "0", entity.getExaminePersonId(),
|
||
entity.getExaminePersonName(), entity.getUserId(), entity.getUserName(), entity.getPhone(),
|
||
entity.getOrgId(), entity.getOrgName(), entity.getType() });
|
||
|
||
artPersonInfo(entity);
|
||
String title = "访客审批";
|
||
String text = "您好,您有新的访客信息需要审批,请点击查看。";
|
||
String url = "/pages/visitor-management/visitor-invite-exam?examineBatch=" + examineBatch;
|
||
aliasManageController.pushToSingle(entity.getExaminePersonId(), title, text, url);
|
||
return new RestResult(Constant.SUCCESS, "添加成功");
|
||
} catch (Exception e) {
|
||
System.err.println(e.getMessage());
|
||
return new RestResult(Constant.FAILED, "添加失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通过id获取来访记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult getVisitor(GreenVisitor entity) {
|
||
try {
|
||
List<Object> params = new ArrayList<Object>();
|
||
String sql = "SELECT * FROM GREEN_VISITOR WHERE ID = ? ORDER BY CREATE_TIME desc ";
|
||
params.add(entity.getId());
|
||
List<Map<String, Object>> list = iHibernateDao.queryForListWithSql(sql, params.toArray());
|
||
if (list.size() > 0) {
|
||
String pictureString = list.get(0).get("PERSONNEL_PHOTO") == null ? ""
|
||
: list.get(0).get("PERSONNEL_PHOTO").toString();
|
||
list.get(0).put("PERSONNEL_PHOTO", baseService.getImageBase64(pictureString));
|
||
|
||
// 获取审核详情
|
||
String sqls = "SELECT * from GREEN_VISITOR_EXAMINE where DEL_FLAG = 0 and VISITOR_ID = ? order by EXAMINE_BATCH asc ";
|
||
List<Map<String, String>> lists = iHibernateDao.queryForListWithSql(sqls,
|
||
new Object[] { list.get(0).get("ID").toString() });
|
||
if (lists.size() > 0) {
|
||
list.get(0).put("detail", lists.toArray());
|
||
}
|
||
}
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
} catch (Exception e) {
|
||
System.err.println(e.getMessage());
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修改访客信息状态
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult updateVisitor(GreenVisitor entity) {
|
||
try {
|
||
|
||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||
if (StringUtils.isBlank(entity.getExamineState())) {
|
||
return new RestResult(Constant.FAILED, "审核状态不能为空");
|
||
}
|
||
if (StringUtils.isBlank(entity.getExamineBatch())) {
|
||
return new RestResult(Constant.FAILED, "审核批次不能为空");
|
||
}
|
||
|
||
// 查询下一审核批次
|
||
String batchSql = "SELECT * FROM GREEN_DICTIONARY_INFO WHERE DATA_TYPE = 'visitorExamSwitch' "
|
||
+ "AND IS_DELETED = 'N' AND DATA_VALUE = 1 AND DATA_CODE > ? ORDER BY DATA_CODE ASC ";
|
||
List<Map<String, String>> list = iHibernateDao.queryForListWithSql(batchSql,
|
||
new Object[] { entity.getExamineBatch() });
|
||
// 不为空则更改审核批次,否则更改申请单的审核状态
|
||
if (list.size() > 0) {
|
||
if ("1".equals(entity.getExamineState())) {
|
||
String lastExamineBatch = list.get(0).get("DATA_CODE");
|
||
String updateBatchSql = "UPDATE GREEN_VISITOR SET EXAMINE_BATCH = ? WHERE ID = ? ";
|
||
iHibernateDao.executeSqlUpdate(updateBatchSql, new Object[] { lastExamineBatch, entity.getId() });
|
||
} else if ("2".equals(entity.getExamineState())) {
|
||
String updateStateSql = "UPDATE GREEN_VISITOR SET EXAMINE_STATE = ? WHERE ID = ? ";
|
||
iHibernateDao.executeSqlUpdate(updateStateSql,
|
||
new Object[] { entity.getExamineState(), entity.getId() });
|
||
}
|
||
} else {
|
||
String updateStateSql = "UPDATE GREEN_VISITOR SET EXAMINE_STATE = ? WHERE ID = ? ";
|
||
iHibernateDao.executeSqlUpdate(updateStateSql,
|
||
new Object[] { entity.getExamineState(), entity.getId() });
|
||
}
|
||
|
||
// 查询当前批次描述
|
||
String description = "";
|
||
String sqls = "SELECT DATA_CODE as \"id\",DATA_VALUE as \"name\",DESCRIPTION as \"description\" FROM GREEN_DICTIONARY_INFO "
|
||
+ "WHERE DATA_TYPE = 'visitorExamSwitch' AND IS_DELETED = 'N' and DATA_CODE = ? ";
|
||
List<Map<String, String>> lists = iHibernateDao.queryForListWithSql(sqls,
|
||
new Object[] { entity.getExamineBatch() });
|
||
if (lists.size() > 0) {
|
||
description = lists.get(0).get("description");
|
||
}
|
||
|
||
// 插入数据
|
||
String sql = "INSERT INTO GREEN_VISITOR_EXAMINE(ID,VISITOR_ID,USER_ID,USER_NAME,EXAMINE_STATE,EXAMINE_OPINION,"
|
||
+ "EXAMINE_TIME,DEL_FLAG,EXAMINE_BATCH,BATCH_DESCRIPTION) " + "VALUES(?,?,?,?,?,?,SYSDATE,0,?,?) ";
|
||
iHibernateDao.executeSqlUpdate(sql,
|
||
new Object[] { uuid, entity.getId(), entity.getUserId(), entity.getUserName(),
|
||
entity.getExamineState(), entity.getExamineOpinion(), entity.getExamineBatch(),
|
||
description });
|
||
return new RestResult(Constant.SUCCESS, "操作成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "操作失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 审核记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult getReceiveVisitorByUserId(GreenVisitor entity) {
|
||
try {
|
||
ArrayList<Object> paramList = new ArrayList<Object>();
|
||
int pageSize = entity.getPageSize();
|
||
int pageNum = entity.getPageNum();
|
||
int page = (pageNum - 1) * pageSize;
|
||
int limit = pageNum * pageSize;
|
||
|
||
if (StringUtils.isBlank(entity.getExamineState())) {
|
||
return new RestResult(Constant.FAILED, "审核状态不能为空");
|
||
}
|
||
if (StringUtils.isBlank(entity.getExamineBatch())) {
|
||
return new RestResult(Constant.FAILED, "审核批次不能为空");
|
||
}
|
||
|
||
if ("0".equals(entity.getExamineState())) {
|
||
String sqlState = "select count(*) from GREEN_DICTIONARY_INFO where data_type = 'visitorExamSwitch' and data_code in (?) and data_value = 1 ";
|
||
int count = iHibernateDao.queryForIntWithSql(sqlState, new Object[] { entity.getExamineBatch() });
|
||
if (count == 0) {
|
||
return new RestResult(Constant.SUCCESS, "操作成功", new ArrayList<Map<String, String>>());
|
||
}
|
||
}
|
||
|
||
String sql = "select * from (select B.*,ROWNUM rn from ( " + " SELECT DISTINCT A.*"
|
||
+ " FROM GREEN_VISITOR A "
|
||
+ " LEFT JOIN (select * from GREEN_VISITOR_EXAMINE where EXAMINE_BATCH in (?) and DEL_FLAG=0) E ON A.ID = E.VISITOR_ID "
|
||
+ " WHERE A.TYPE =? ";
|
||
|
||
paramList.add(entity.getExamineBatch());
|
||
paramList.add(entity.getType());
|
||
// 当查询审核批次为1时,只查询审核人为当前userid的数据
|
||
if ("1".equals(entity.getExamineBatch())) {
|
||
sql += "AND A.EXAMINE_PERSON_ID = ? ";
|
||
paramList.add(entity.getUserId());
|
||
}
|
||
if ("1".equals(entity.getExamineState())) {// 已审核
|
||
sql += "and e.ID is not NULL ";
|
||
} else if ("0".equals(entity.getExamineState())) {// 待审核
|
||
sql += "AND A.EXAMINE_STATE = 0 AND A.EXAMINE_BATCH in (?) ";
|
||
paramList.add(entity.getExamineBatch());
|
||
}
|
||
|
||
sql += " ORDER BY A.CREATE_TIME DESC " + " ) B )where rn>? and rn<=? ";
|
||
paramList.add(page);
|
||
paramList.add(limit);
|
||
System.err.println(sql);
|
||
List<Map<String, Object>> list = iHibernateDao.queryForListWithSql(sql, paramList.toArray());
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
|
||
} catch (Exception e) {
|
||
System.err.println(e.getMessage());
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取个人发出的访客记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult getIssueVisitorByUserId(GreenVisitor entity) {
|
||
String sql = "SELECT * FROM (SELECT ROWNUM num ,A.* FROM (SELECT ID, PERSONNEL_NAME, PERSONNEL_CARD, VISITING_TIME, LEAVE_TIME, REASON, PERSONNEL_PHONE, PERSONNEL_PHOTO, STATE, CREATE_TIME, ENTOURAGE, EXAMINE_BATCH, EXAMINE_STATE, EXAMINE_PERSON_ID, EXAMINE_PERSON_NAME, USER_ID, USER_NAME, PHONE, ORG_ID, ORG_NAME FROM GREEN_VISITOR WHERE USER_ID =? AND TYPE=? order by CREATE_TIME desc) A WHERE ROWNUM<=?) WHERE num > ?";
|
||
try {
|
||
int pageSize = entity.getPageSize();
|
||
int pageNum = entity.getPageNum();
|
||
int page = (pageNum - 1) * pageSize;
|
||
int limit = pageNum * pageSize;
|
||
List<Map<String, Object>> list = iHibernateDao.queryForListWithSql(sql,
|
||
new Object[] { entity.getUserId(), entity.getType(), limit ,page });
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
} catch (Exception e) {
|
||
System.err.println(e.getMessage());
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询出行报备部门拥有审核权限人员
|
||
*
|
||
* @param map
|
||
* @return
|
||
*/
|
||
public RestResult getDeptExamineAuth(GreenVisitor entity) {
|
||
try {
|
||
String depts[] = entity.getDepartmentId().split("/");
|
||
String dept = "";
|
||
for (String string : depts) {
|
||
dept = dept + string + "/";
|
||
}
|
||
int lastIndex = dept.lastIndexOf("/");
|
||
dept = dept.substring(0, lastIndex);
|
||
String sql = "SELECT u.id as \"id\",u.REAL_NAME as \"name\" from GREEN_USER_INFO u "
|
||
+ "LEFT JOIN GREEN_USER_ROLE_REL urr ON u.ID = urr.USER_ID AND u.IS_DELETED = 'N' "
|
||
+ "LEFT JOIN GREEN_ROLE_PERMISSION rp ON urr.ROLE_ID = rp.ROLE_ID AND urr.IS_DELETED = 'N' "
|
||
+ "WHERE u.DEPt_ID_url like '%" + dept + "%' AND rp.PERMISSION_ID = '15002' ";
|
||
System.err.println(sql);
|
||
List<Map<String, Object>> list = iHibernateDao.queryForListWithSql(sql);
|
||
return new RestResult(Constant.SUCCESS, "操作成功", list);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "操作失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 访客机事件订阅
|
||
*
|
||
* @param map
|
||
* @return
|
||
*/
|
||
|
||
public void addVisitorEventNotify(VisitorEventNotify entity) {
|
||
GreenVisitor visitor = new GreenVisitor();
|
||
for (EventsDTO eventsDTO : entity.getParams().getEvents()) {
|
||
DataDTO dataDTO = eventsDTO.getData();
|
||
visitor.setPersonnelName(dataDTO.getPersonName());
|
||
visitor.setPersonnelCard(dataDTO.getIdNo());
|
||
visitor.setReason(dataDTO.getPurpose());
|
||
visitor.setVisitingTime(DateUtil.getISO8601Timestamp(dataDTO.getStartTime()));
|
||
visitor.setLeaveTime(DateUtil.getISO8601Timestamp(dataDTO.getEndTime()));
|
||
visitor.setPersonnelPhone(dataDTO.getPhone());
|
||
visitor.setPersonnelPhoto(dataDTO.getPhotoUrl());
|
||
visitor.setUserId(dataDTO.getBeVisitedPersonId());
|
||
visitor.setUserName(dataDTO.getBeVisitedPersonName());
|
||
visitor.setOrgId(dataDTO.getBeVisitedPersonOrgId());
|
||
visitor.setOrgName(dataDTO.getBeVisitedPersonOrg());
|
||
visitor.setType("0");
|
||
visitor.setExaminePersonId(dataDTO.getBeVisitedPersonId());
|
||
visitor.setExaminePersonName(dataDTO.getBeVisitedPersonName());
|
||
}
|
||
addVisitor(visitor);
|
||
}
|
||
|
||
/**
|
||
* 人脸权限下发
|
||
*
|
||
* @param staffNo
|
||
* @param staffName
|
||
* @param orgId
|
||
* @param picture
|
||
* @param cardId
|
||
* @return
|
||
*/
|
||
public RestResult artPersonInfo(GreenVisitor entity) {
|
||
try {
|
||
JSONObject jobj = new JSONObject();
|
||
JSONObject resourceInfo = new JSONObject();
|
||
resourceInfo.put("resourceIndexCode", "1");
|
||
resourceInfo.put("resourceType", "door");
|
||
JSONObject personInfo = new JSONObject();
|
||
personInfo.put("personId", entity.getPersonnelCard());
|
||
personInfo.put("operatorType", 0);// 0添加 1修改 2删除
|
||
personInfo.put("startTime", "");
|
||
personInfo.put("endTime", "");
|
||
JSONObject face = new JSONObject();
|
||
JSONObject data = new JSONObject();
|
||
data.put("f1", baseService.getImageBase64(entity.getPersonnelPhoto()));
|
||
face.put("card", entity.getPersonnelCard());
|
||
face.put("data", data);
|
||
personInfo.put("face", face);
|
||
jobj.put("taskType", 5);
|
||
jobj.put("resourceInfo", resourceInfo);
|
||
jobj.put("personInfo", personInfo);
|
||
String body = jobj.toString();
|
||
String result = ArtemisPost.syncRole(body);
|
||
return new RestResult(Constant.SUCCESS, "操作成功!", result);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "操作失败");
|
||
}
|
||
|
||
}
|
||
}
|