319 lines
12 KiB
Plaintext
319 lines
12 KiB
Plaintext
package com.jysoft.card.service;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Calendar;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.UUID;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.hibernate.util.StringHelper;
|
||
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.DateUtils;
|
||
import com.sgcc.uap.utils.StringUtils;
|
||
|
||
/**
|
||
* @author bonus
|
||
* @date 2023-06-12
|
||
* @功能 访客管理
|
||
*/
|
||
@Service
|
||
public class CardService {
|
||
|
||
@Autowired
|
||
private IHibernateDao iHibernateDao;
|
||
|
||
@Resource
|
||
private AliasManageController aliasManageController;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
/**
|
||
* 添加来访记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult addCard(GreenCard entity) {
|
||
StringBuilder sqlString = new StringBuilder();
|
||
try {
|
||
String batchSql = "SELECT * FROM GREEN_DICTIONARY_INFO WHERE DATA_TYPE = 'cardExamSwitch' 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");
|
||
}
|
||
if (StringUtils.isBlank(entity.getExaminePersonId())) {
|
||
return new RestResult(Constant.FAILED, "请选择审核人");
|
||
}
|
||
sqlString.append(
|
||
"INSERT INTO GREEN_CARD (ID, USER_ID, USER_NAME, PHONE, ORG_ID, ORG_NAME, TYPE, UNIT, PERSONNEL, PERSONNEL_PHONE, MATTER, ACCESS_AREA, START_TIME, END_TIME, APPLY_TIME, EXAMINE_BATCH, EXAMINE_STATE, EXAMINE_PERSON_ID, EXAMINE_PERSON_NAME,CARD_CODE,CARD_TYPE ,TYPE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?,?)");
|
||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||
iHibernateDao.executeSqlUpdate(sqlString.toString(),
|
||
new Object[] { uuid, entity.getUserId(), entity.getUserName(), entity.getPhone(), entity.getOrgId(),
|
||
entity.getOrgName(), entity.getType(), entity.getUnit(), entity.getPersonnel(),
|
||
entity.getPersonnelPhone(), entity.getMatter(), entity.getAccessArea(),
|
||
entity.getStartTime(), entity.getEndTime(), DateTimeHelper.getNowDate(), examineBatch,
|
||
"0", entity.getExaminePersonId(), entity.getExaminePersonName(),
|
||
entity.getCardCode(), entity.getCardType() ,entity.getTypeName()});
|
||
String title = "办卡申请";
|
||
String text = "您好,您有新的办卡申请需要审批,请点击查看。";
|
||
String url = "/pages/access-card/card-record?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 getCard(GreenCard entity) {
|
||
try {
|
||
List<Object> params = new ArrayList<Object>();
|
||
String sql = "SELECT * FROM GREEN_CARD WHERE ID = ? ORDER BY APPLY_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_CARD_EXAMINE where DEL_FLAG = 0 and CARD_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 updateCard(GreenCard 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 = 'cardExamSwitch' "
|
||
+ "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_CARD SET EXAMINE_BATCH = ? WHERE ID = ? ";
|
||
iHibernateDao.executeSqlUpdate(updateBatchSql, new Object[] { lastExamineBatch, entity.getId() });
|
||
} else if ("2".equals(entity.getExamineState())) {
|
||
String updateStateSql = "UPDATE GREEN_CARD SET EXAMINE_STATE = ? WHERE ID = ? ";
|
||
iHibernateDao.executeSqlUpdate(updateStateSql,
|
||
new Object[] { entity.getExamineState(), entity.getId() });
|
||
}
|
||
} else {
|
||
String updateStateSql = "UPDATE GREEN_CARD 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 = 'cardExamSwitch' 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_CARD_EXAMINE(ID,CARD_ID,USER_ID,USER_NAME,EXAMINE_STATE,EXAMINE_OPINION,"
|
||
+ "EXAMINE_TIME,DEL_FLAG,EXAMINE_BATCH,BATCH_DESCRIPTION) " + "VALUES(?,?,?,?,?,?,?,0,?,?) ";
|
||
iHibernateDao.executeSqlUpdate(sql,
|
||
new Object[] { uuid, entity.getId(), entity.getUserId(), entity.getUserName(),
|
||
entity.getExamineState(), entity.getExamineOpinion(),DateTimeHelper.getNowDate(), entity.getExamineBatch(),
|
||
description });
|
||
return new RestResult(Constant.SUCCESS, "操作成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "操作失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 审核记录
|
||
*
|
||
* @param entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult getCardByUserId(GreenCard 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 = 'cardExamSwitch' 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 rn.*,rownum rn from ( " + " SELECT DISTINCT A.*" + " FROM GREEN_CARD A "
|
||
+ " LEFT JOIN (select * from GREEN_CARD_EXAMINE where EXAMINE_BATCH in (?) and DEL_FLAG=0) E ON A.ID = E.CARD_ID "
|
||
+ " WHERE 1=1 ";
|
||
|
||
paramList.add(entity.getExamineBatch());
|
||
|
||
// 当查询审核批次为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.APPLY_TIME DESC " + " ) rn )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 getIssueCardByUserId(GreenCard entity) {
|
||
String sql = "SELECT * FROM (SELECT ROWNUM num,A.* FROM (SELECT gc.* FROM GREEN_CARD gc WHERE gc.USER_ID =? ORDER BY gc.APPLY_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(), 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(GreenCard 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 = '10303' ";
|
||
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 entity
|
||
* 数据
|
||
* @return 响应数据
|
||
*/
|
||
public RestResult getCardType(GreenCard entity) {
|
||
String sql = "SELECT * FROM GREEN_DICTIONARY_INFO WHERE DATA_TYPE ='cardType' and DATA_CODE = ?";
|
||
try {
|
||
List<Map<String, Object>> list = iHibernateDao.queryForListWithSql(sql, new Object[] { entity.getType() });
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
} catch (Exception e) {
|
||
System.err.println(e.getMessage());
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
}
|