Ecology-Dev-chaofa/ShangHaiShuZhi/interface/shsz/do.jsp

269 lines
9.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="org.apache.http.client.methods.CloseableHttpResponse" %>
<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %>
<%@ page import="org.apache.http.impl.client.HttpClients" %>
<%@ page import="org.apache.http.client.methods.HttpPost" %>
<%@ page import="org.apache.http.entity.StringEntity" %>
<%@ page import="org.apache.http.HttpEntity" %>
<%@ page import="org.apache.http.util.EntityUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.io.IOException" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.YearMonth" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.wbi.util.Util" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.MD5" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rst" class="weaver.conn.RecordSet" scope="page" />
<%
int sum = 0;
String path = "/v2.0/employee/delete";
String url = "http://v2-api.delicloud.com"+path;
int formmodeid = getFormModeIdByCubeName("uf_tbdljlb");
int creater = 1;
String key = rs.getPropValue("deliCloud","key");
String secret = rs.getPropValue("deliCloud","secret");
String fbid = rs.getPropValue("hrm_deliinfo","fbid");
String currentdate = TimeUtil.getCurrentDateString();
String currenttime = TimeUtil.getOnlyCurrentTimeString();
String yesterDate = addDateMonth(currentdate,-1);
String yearmonth = yesterDate.substring(0,7);
String lastFromDate = yearmonth + "-01";
String lastToDate = getLastDayByDate(yesterDate);
String where = " and lzrq >= '"+ lastFromDate +"' and lzrq <= '"+ lastToDate +"' ";
if(fbid != null && !"".equals(fbid)){
where += " and gzdw in ("+ fbid +") ";
}
int errorcount = 0;
rs.executeQuery("select * from uf_rzgljmb where ygzt='3' "+ where);
rs.writeLog("select * from uf_rzgljmb where ygzt='3' "+ where);
while(rs.next()){
String usercode = Util.null2String(rs.getString("gh"));
//同步删除得力人员信息
String sjc = String.valueOf(Calendar.getInstance().getTimeInMillis());
String appSig = getAppSigData(path,key,secret,sjc);
Map<String, String> heads = new HashMap<String, String>();
heads.put("App-Key", key);
heads.put("App-Timestamp", sjc);
heads.put("App-Sig", appSig);
heads.put("Api-Module", "CHECKIN");
heads.put("Api-Cmd", "checkin_query");
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("employee_ext_id", usercode);
String back = httpPostJson(url, JSON.toJSONString(dataMap), heads, "utf-8");
rs.writeLog("response:" + back);
JSONObject backObj = JSONObject.parseObject(back);
String code = backObj.getString("code");
String fhzt = "0";
String data = backObj.getString("msg");
rs.writeLog("employee-code:" + code + "</br>");
if (!"0".equals(code)) {
fhzt = "1";
errorcount++;
}
rs.writeLog(usercode + " ======== syn delete user to deli errorcount ======== "+ errorcount);
String uuid = UUID.randomUUID().toString();
String insertSql = " insert into uf_tbdljlb(qqjk,qqcs,fhzt,fhjg,cjrq,cjsj,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid,modeuuid) " +
"values(?,?,?,?,?,?,?,?,?,?,?) ";
boolean exeRes = rst.executeUpdate(insertSql,new Object[]{url,JSON.toJSONString(dataMap),fhzt,data,currentdate,currenttime,creater, currentdate, currenttime, formmodeid, uuid});
int billid = -1;
if (exeRes) {
//重构权限
rs1.executeQuery(" select id from uf_tbdljlb where modeuuid=? ",new Object[]{uuid});
rs1.next();
billid = rs1.getInt("id");
ModeRightInfo moderight = new ModeRightInfo();
moderight.editModeDataShare(creater, formmodeid, billid);
}
}
sum++;
%>
<%!
public String getAppSigData(String path,String key,String sercet,String sjc){
String appSig = "";
BaseBean bb = new BaseBean();
try{
MD5 md5 = new MD5();
String all = path + sjc + key + sercet;
String sig = md5.getMD5ofStr(all);
bb.writeLog("sig:" + sig);
Scanner sc = new Scanner(md5.getMD5ofStr(all));
String str = sc.next();
char[] arrays = str.toCharArray();
for (int i = 0; i < arrays.length; i++) {
char c1 = arrays[i];
if (c1 >= 65 && c1 <= 90) {
char c2 = toLowerCase(c1);//如果输入是大写 ,则调用toLowerCase方法
appSig = appSig + c2;
} else {
appSig = appSig + c1;
}
}
bb.writeLog("appSig:" + appSig);
}catch (Exception e){
}
return appSig;
}
/***
*
* @param c1
* @return
*/
public static char toLowerCase(char c1){
int a = (int) c1;//将接收到的小写字符c1转换成int类型的数据给a
int b =a+32; //a+32得出大写写对应小写的ascll数值
char bb = (char)b;//最后将b转换成char类型字符给bb
return bb; //返回bb就是返回字母小写的字符
}
/**
* 对时间的月份进行加减
* @param daytime 时间的格式yyyy-MM-dd HH:mm:ss
* @param month 月数 -1则代表减一月
* @return
*/
public static String addDateMonth(String daytime, int month){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = format.parse(daytime);
if (date == null){
return "";
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, month);// 加一月
date = cal.getTime();
cal = null;
return format.format(date);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
public String getLastDayByDate(String dateString){
String result = "";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(dateString); // 解析为LocalDate
// 获取年份和月份
int year = date.getYear();
int month = date.getMonthValue();
// 使用YearMonth来找到该月的最后一天
YearMonth yearMonthObject = YearMonth.of(year, month);
LocalDate lastDayOfMonth = yearMonthObject.atEndOfMonth();
// 输出结果
System.out.println("当月最后一天是: " + lastDayOfMonth);
result = lastDayOfMonth.format(formatter);
return result;
}
private static int getFormModeIdByCubeName(String cubeName) {
RecordSet rs = new RecordSet();
rs.executeQuery("select t1.id from modeinfo t1 " +
" left join workflow_bill t2 " +
" on t1.formid=t2.id " +
" where t2.tablename='" + cubeName + "'");
rs.next();
return rs.getInt("id");
}
/**
* 发送 http post 请求,参数以原生字符串进行提交
* @param url
* @param encode
* @return
*/
public static String httpPostJson(String url, String stringJson, Map<String,String> headers, String encode){
if(encode == null){
encode = "utf-8";
}
String result = "";
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
try {
//HttpClients.createDefault()等价于 HttpClientBuilder.create().build();
closeableHttpClient = HttpClients.createDefault();
HttpPost httpost = new HttpPost(url);
//设置header
httpost.setHeader("Content-type", "application/json; charset=UTF-8");
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(),entry.getValue());
}
}
//组织请求参数
StringEntity stringEntity = new StringEntity(stringJson, encode);
httpost.setEntity(stringEntity);
//响应信息
httpResponse = closeableHttpClient.execute(httpost);
HttpEntity entity = httpResponse.getEntity();
String content = EntityUtils.toString(entity, encode);
if(content != null && !"".equals(content)){
JSONObject jsonObject = JSONObject.parseObject(content);
result = jsonObject.toString();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
%>
<HEAD>
</HEAD>
<BODY>
<h1>Congratulation Mode 666666 !</h1>
<h1> sum <%=sum%> </h1>
</BODY>