|
|
package weaver.interfaces.mingfeng.cron;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import weaver.conn.RecordSet;
|
|
|
import weaver.formmode.setup.ModeRightInfo;
|
|
|
import weaver.general.BaseBean;
|
|
|
import weaver.general.Util;
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class BirthdayWishesCronJob extends BaseCronJob
|
|
|
{
|
|
|
/**
|
|
|
*
|
|
|
* 计划任务的入口,五任何输入参数
|
|
|
*/
|
|
|
@Override
|
|
|
public void execute()
|
|
|
{
|
|
|
updateBirthdayWishes();
|
|
|
}
|
|
|
|
|
|
public void updateBirthdayWishes(){
|
|
|
|
|
|
BaseBean log = new BaseBean();
|
|
|
log.writeLog("updateAnniversaryWishes! ");
|
|
|
|
|
|
String uftable = "uf_srzf";
|
|
|
RecordSet rs = new RecordSet();
|
|
|
int days = 30 ;
|
|
|
|
|
|
List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();
|
|
|
Map<String,String> dataMap = null;
|
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd" ) ;
|
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy" ) ;
|
|
|
|
|
|
try{
|
|
|
for(int i=0;i<days;i++) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, 0 - i);
|
|
|
String currentDay = sdf.format(calendar.getTime());
|
|
|
bb.writeLog("currentDay:" + currentDay);
|
|
|
|
|
|
String currentYear = sdf2.format(calendar.getTime());
|
|
|
bb.writeLog("currentYear:" + currentYear);
|
|
|
|
|
|
String sql = " select h.id,h.lastname,h.sex,d.departmentname,s.subcompanyname from hrmresource h\n" +
|
|
|
" inner join HrmDepartment d on d.id = h.departmentid\n" +
|
|
|
" inner join HrmSubCompany s on s.id = h.subcompanyid1\n" +
|
|
|
" where birthday like '%" + currentDay + "'\n" +
|
|
|
" and h.status in(0,1,2,3) " +
|
|
|
" and h.belongto is null ";
|
|
|
bb.writeLog("sql:" + sql);
|
|
|
rs.executeQuery(sql);
|
|
|
while (rs.next()) {
|
|
|
String userid = Util.null2String(rs.getString("id"));
|
|
|
String lastname = Util.null2String(rs.getString("lastname"));
|
|
|
String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
|
|
|
String departmentid = Util.null2String(rs.getString("departmentid"));
|
|
|
String birthday = Util.null2String(rs.getString("birthday"));
|
|
|
|
|
|
String zfy = getZfy(lastname);
|
|
|
|
|
|
dataMap = new HashMap<String, String>();
|
|
|
dataMap.put("ry", userid);
|
|
|
dataMap.put("rymc", lastname);
|
|
|
dataMap.put("ryid", userid);
|
|
|
dataMap.put("zfy", zfy);
|
|
|
dataMap.put("bm", departmentid);
|
|
|
dataMap.put("sr", birthday);
|
|
|
dataMap.put("fb", subcompanyid1);
|
|
|
dataMap.put("nf", currentYear);
|
|
|
dataList.add(dataMap);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int k = 0; k < dataList.size(); k++) {
|
|
|
Map<String, String> dMap = dataList.get(k);
|
|
|
String ry = dMap.get("ry");
|
|
|
String nf = dMap.get("nf");
|
|
|
String ufid = "";
|
|
|
sql = " select id from " + uftable + " where ry='" + ry + "' and nf = '" + nf + "'";
|
|
|
rs.executeQuery(sql);
|
|
|
if (rs.next()) {
|
|
|
ufid = Util.null2String(rs.getString("id"));
|
|
|
}
|
|
|
if (StringUtils.isBlank(ufid)) {
|
|
|
updateBrithdayInfo(uftable, dMap);
|
|
|
} else {
|
|
|
String zfy = dMap.get("zfy");
|
|
|
String sr = dMap.get("sr");
|
|
|
sql = " update " + uftable + " set zfy='" + zfy + "',sr='" + sr + "' where id = " + ufid;
|
|
|
boolean isTrue = rs.executeUpdate(sql);
|
|
|
bb.writeLog("isTrue:" + isTrue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
bb.writeLog("AnniversaryWishesCronJob--updateAnniversaryWishes:e"+e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public int updateBrithdayInfo(String fromtable,Map<String,String> datas){
|
|
|
RecordSet rs = new RecordSet();
|
|
|
BaseBean bb = new BaseBean();
|
|
|
int count = 0;
|
|
|
ModeRightInfo modeRightInfo = new ModeRightInfo();
|
|
|
String uuid = UUID.randomUUID().toString().replace("-","");
|
|
|
bb.writeLog("uuid:"+uuid);
|
|
|
|
|
|
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
|
|
|
String currentdate = formatter1.format(new Date());
|
|
|
String currenttime = formatter2.format(new Date());
|
|
|
String modedatacreater = "1";
|
|
|
String modedatacreatertype = "0";
|
|
|
|
|
|
String formmodeid = "" ;
|
|
|
String sql =" select k.id from modeinfo k \n" +
|
|
|
" inner join workflow_bill l on formid = l.id\n" +
|
|
|
" where l.tablename = '"+fromtable+"' " ;
|
|
|
rs.execute(sql);
|
|
|
if(rs.next()){
|
|
|
formmodeid = Util.null2String(rs.getString("id"));
|
|
|
}
|
|
|
|
|
|
bb.writeLog("formmodeid:"+formmodeid);
|
|
|
datas.put("formmodeid", formmodeid);
|
|
|
datas.put("modedatacreater", modedatacreater);
|
|
|
datas.put("modedatacreatertype", modedatacreatertype);
|
|
|
datas.put("modedatacreatedate", currentdate);
|
|
|
datas.put("modedatacreatetime", currenttime);
|
|
|
datas.put("uuid", uuid);
|
|
|
|
|
|
String tablenvalue = "";
|
|
|
String tablename = "";
|
|
|
for (Map.Entry<String, String> entry : datas.entrySet()) {
|
|
|
String fieldname = Util.null2String(entry.getKey()).trim();
|
|
|
String fieldvalue = Util.null2String(entry.getValue()).replace("'", "''").trim();
|
|
|
tablename += tablename == "" ? fieldname : "," + fieldname;
|
|
|
tablenvalue += tablenvalue == "" ? "'" + fieldvalue + "'" : ",'" + fieldvalue + "'";
|
|
|
}
|
|
|
if (tablename != "" && tablenvalue != "") {
|
|
|
|
|
|
sql = " insert into " + fromtable + "(" + tablename + ") values (" + tablenvalue + ")";
|
|
|
bb.writeLog("sql:" + sql);
|
|
|
boolean boo = rs.executeUpdate(sql);
|
|
|
if (boo) {
|
|
|
count++;
|
|
|
}
|
|
|
bb.writeLog("count:" + count);
|
|
|
if (count > 0) {
|
|
|
String dataid = "";
|
|
|
sql = " select id from " + fromtable + " where uuid='" + uuid + "'";
|
|
|
bb.writeLog("sql:" + sql);
|
|
|
rs.execute(sql);
|
|
|
if (rs.next()) {
|
|
|
dataid = Util.null2String(rs.getString("id"));
|
|
|
}
|
|
|
if (!"".equals(dataid)) {
|
|
|
modeRightInfo.editModeDataShare(Integer.valueOf(modedatacreater), Util.getIntValue(formmodeid), Integer.parseInt(dataid));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/***
|
|
|
*
|
|
|
* @param lastname
|
|
|
* @return
|
|
|
*/
|
|
|
public String getZfy(String lastname){
|
|
|
|
|
|
String zfy =" <div style=\"width: 500px;font-size: 14px !important;text-align: left;\">\n" +
|
|
|
" <p class=\"p1\" style=\"color: #202e7f;font-size: 18px;font-weight: 600;\">亲爱的<span class=\"s1\">"+lastname+"</span>:</p>\n" +
|
|
|
" <p class=\"p2\"> </p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">时光是一把神奇的钥匙,让每个脚印都坚实而有力量;</p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">岁月是看不见的年轮,让每次付出都收获希望与果实;</p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">感谢您的全力奔跑,感恩您的笃定前行;</p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">今天是您的生日!</p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">在这个没有流星也可以许愿的日子里,祝您生日快乐!</p>\n" +
|
|
|
" <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">愿您心之所向,光芒万丈,所盼皆所成,所思终所拥!</p>\n" +
|
|
|
" <p class=\"p2\"> </p>\n" +
|
|
|
" <p class=\"p2\"> </p>\n" +
|
|
|
" <p class=\"p4\" style=\"float: right;color: #202e7f;font-size: 18px;font-weight: 600;\"> MATFRON</p>\n" +
|
|
|
"</div>";
|
|
|
return zfy;
|
|
|
}
|
|
|
|
|
|
}
|