hz-zhhq-app-service/greenH5modul/.svn/pristine/03/03e5c5302bb811c119e39950b94...

405 lines
16 KiB
Plaintext
Raw Normal View History

2025-01-21 13:12:35 +08:00
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.JSONException;
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.bizc.IGreenUserInfoBizc;
import com.nationalelectric.greenH5.po.GreenRentHouseApply;
import com.nationalelectric.greenH5.po.GreenUserInfo;
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.DateTime;
import com.nationalelectric.greenH5.utils.DateTimeHelper;
import com.nationalelectric.greenH5.utils.DateUtil;
import com.sgcc.isc.service.adapter.utils.JsonUtil;
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;
@Resource
private IGreenUserInfoBizc greenuserinfoBizc;
public static void main(String[] args) {
String startTime = "2024-09-24 12:00:00";
String endTime = "2024-09-24 12:09:00";
Long timestamp = DateTimeHelper.convertDateStringToTimestamp(startTime, "yyyy-MM-dd HH:mm:ss");
Long timestamp2 = DateTimeHelper.convertDateStringToTimestamp(endTime, "yyyy-MM-dd HH:mm:ss");
System.err.println("时间戳1:"+timestamp);
System.err.println("时间戳2:"+timestamp2);
System.err.println("差值:"+(timestamp2 - timestamp));
if((timestamp2 - timestamp) <= 60 * 10 * 1000){
String time = startTime.substring(0,10);
System.err.println(time + " 23:59:59");
}
}
/**
* 添加来访记录
*
* @param entity
* 数据
* @return 响应数据
*/
public RestResult addVisitor(GreenVisitor entity) {
try {
if (StringUtils.isBlank(entity.getType())) {
entity.setType("1");
}
// 拜访与离开时间差值小于10分钟 离开时间默认到当天23:59:59
Long timestamp = DateTimeHelper.convertDateStringToTimestamp(entity.getVisitingTime(), "yyyy-MM-dd HH:mm:ss");
Long timestamp2 = DateTimeHelper.convertDateStringToTimestamp(entity.getLeaveTime(), "yyyy-MM-dd HH:mm:ss");
if((timestamp2 - timestamp) <= 60 * 10 * 1000){
String time = entity.getVisitingTime().substring(0,10);
entity.setLeaveTime(time + " 23:59:59");
}
// 获取最低审核批次
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 = '52103' ";// 生产:52103 开发15102
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 RestResult addVisitorEventNotify(String result) {
try {
VisitorEventNotify entity = JsonUtil.jsonToObject(result, VisitorEventNotify.class);
GreenVisitor visitor = new GreenVisitor();
for (EventsDTO eventsDTO : entity.getParams().getEvents()) {
if (eventsDTO.getEventType() != 1392513025) {
return new RestResult(Constant.FAILED,"操作失败");
}
DataDTO dataDTO = eventsDTO.getData();
String sql = "SELECT * FROM GREEN_USER_HK WHERE HK_ID=?";
List<Map<String, String>> list = iHibernateDao.queryForListWithSql(sql,
new Object[] { dataDTO.getBeVisitedPersonId() });
if (list.size() < 0) {
return new RestResult(Constant.FAILED,"操作失败");
}
String userId = list.get(0).get("USER_ID").toString();
GreenUserInfo info = greenuserinfoBizc.get(userId);
if (info == null) {
return new RestResult(Constant.FAILED,"操作失败");
}
visitor.setPersonnelName(dataDTO.getPersonName());
visitor.setPersonnelCard(dataDTO.getIdNo());
visitor.setReason(dataDTO.getPurpose());
visitor.setVisitingTime(DateUtil.getISO8601Timestamp(dataDTO.getStartTime()));
visitor.setLeaveTime(DateTimeHelper.getNowDate1() + " 23:59:59");
visitor.setPersonnelPhone(dataDTO.getPhone());
visitor.setPersonnelPhoto(dataDTO.getPhotoUrl());
visitor.setUserId(info.getId());
visitor.setUserName(info.getRealName());
visitor.setPhone(info.getMobile());
visitor.setOrgId(info.getOrgId().toString());
visitor.setOrgName(info.getOrgName());
visitor.setType("0");
visitor.setExaminePersonId(info.getId());
visitor.setExaminePersonName(info.getRealName());
addVisitor(visitor);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return new RestResult(Constant.FAILED,"操作失败");
}
return new RestResult(Constant.SUCCESS, "操作成功");
}
/**
* @MethodName: getHisInvitationByUserId
* @Description: 历史邀约人员
* @author cwchen
* @param entity
* @return RestResult
* @date 2024-05-12 11:41:59
*/
@SuppressWarnings("unchecked")
public RestResult getHisInvitationByUserId(GreenVisitor entity) {
try {
System.err.println("用户ID:"+entity.getUserId());
String sql = "SELECT DISTINCT PERSONNEL_NAME AS \"PERSONNELNAME\",PERSONNEL_CARD AS \"PERSONNELCARD\",PERSONNEL_PHONE AS \"PERSONNELPHONE\" from GREEN_VISITOR WHERE IS_PUSH = ? AND TYPE = ? AND TO_CHAR(USER_ID) = ? ";
List<Map<String, String>> list = iHibernateDao.queryForListWithSql(sql, new Object[] { "1","1",entity.getUserId()});
return new RestResult(Constant.SUCCESS, "操作成功", list);
} catch (Exception e) {
e.printStackTrace();
return new RestResult(Constant.FAILED, "操作失败");
}
}
}