package pkubatis.common.utils;
import com.pkusoft.agxt.model.*;
import com.pkusoft.agxt.req.FileInfoParam;
import com.pkusoft.lesp.model.KeAgAjztxx;
import com.pkusoft.lesp.model.KeAjjbxx;
import com.pkusoft.usercenter.po.SysDept;
import com.pkusoft.usercenter.po.SysRole;
import com.pkusoft.usercenter.po.SysUser;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import pkubatis.constants.JobConstant;
import sun.misc.BASE64Encoder;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
public class JobUtil {
public final static String IDDEFAULT="00000000-0000-0000-0000-000000000000";
public static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static Date getDate(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date=sdf.parse("1970-1-1 00:00:00");
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return new Date(0);
}
public static String getBase64(byte[] b){
BASE64Encoder enc = new BASE64Encoder();
return enc.encode(b);
}
public static boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
public static String stringisNull(Object data){
if(data == null){
return null;
}
return data+"";
}
/**
*
* 得到当前日期时间
* @return yyyy-MM-dd HH:mm:ss字符串
*/
public static String getDateTime() {
SimpleDateFormat sdf = new SimpleDateFormat(TIME_PATTERN);
return sdf.format(new Date());
}
//向文件追加数据
public static void method1(String str) {
FileWriter fw = null;
try {
File f=new File("D:\\dd.txt");
fw = new FileWriter(f, true);
} catch (IOException e) {
e.printStackTrace();
}
PrintWriter pw = new PrintWriter(fw);
pw.println(getDateTime()+":"+str);
pw.flush();
try {
fw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//java 生成8位数字作为UID
public static String generateUID(){
Random random = new Random();
String result="";
for(int i=0;i<8;i++){
//首字母不能为0
result += (random.nextInt(9)+1);
}
return result;
}
/**
* 使用JobFileStore的信息创建案卷轨迹信息(每次要更换track.setOperType("0010");和track.setOperReson("新建案卷");的信息)
* @param
* @return
*/
public static FileTrack establishTrack(FileInfo jobFileInfo, UserInfo userInfo){
FileTrack track=new FileTrack();
track.setId(UUID.randomUUID().toString());
track.setFileId(jobFileInfo.getId());
track.setFileCode(jobFileInfo.getCode());
track.setFileName(jobFileInfo.getName());
track.setOperTime(new Date());
track.setOperId(userInfo.getIdCard());
track.setOperCode(userInfo.getPoliceCode());
track.setOperName(userInfo.getName());
// track.setOperType("0010");//0010
track.setOperDetail("");//新建案卷
track.setTagOrgCode("");
track.setTagOrgName("");
track.setTagUserCode("");
track.setTagUserName("");
track.setIsOpened(0);
track.setStatus(jobFileInfo.getStatus());
// track.setReserve1();
// track.setReserve2();
// track.setReserve3();
// track.setMemo(store.getMemo());
track.setRowStatus(3);
track.setCreaterId(userInfo.getIdCard());
track.setCreaterName(userInfo.getName());
track.setCreateTime(new Date());
track.setModerId(userInfo.getIdCard());
track.setModerName(userInfo.getName());
track.setModTime(new Date());
track.setOrgC(jobFileInfo.getOrgC());
track.setOrgS(jobFileInfo.getOrgS());
track.setOrgT(jobFileInfo.getOrgT());
track.setOrgCData(jobFileInfo.getOrgCData());
track.setOrgSData(jobFileInfo.getOrgSData());
track.setOrgTData(jobFileInfo.getOrgTData());
track.setCurOrg(jobFileInfo.getCurOrg());
track.setCurOrgData(jobFileInfo.getCurOrgData());
track.setLoginType(userInfo.getLoginType());
track.setOperdeptCode(userInfo.getDeptCode());
track.setOperdeptName(userInfo.getDeptName());
return track;
}
public static FileTrack establishTrackByMetal(FileMetal jobFileMetal){
FileTrack track=new FileTrack();
track.setId(UUID.randomUUID().toString());
track.setFileId(jobFileMetal.getFileId());
track.setFileCode(jobFileMetal.getFileCode());
track.setFileName(jobFileMetal.getFileName());
track.setOperTime(new Date());
// track.setOperType("0010");//0010
track.setOperDetail("");//新建案卷
track.setTagOrgCode("");
track.setTagOrgName("");
track.setTagUserCode("");
track.setTagUserName("");
track.setIsOpened(0);
track.setStatus(jobFileMetal.getStatus());
// track.setReserve1();
// track.setReserve2();
// track.setReserve3();
// track.setMemo(store.getMemo());
track.setRowStatus(3);
track.setCreateTime(new Date());
track.setModTime(new Date());
track.setOrgC(jobFileMetal.getOrgC());
track.setOrgS(jobFileMetal.getOrgS());
track.setOrgT(jobFileMetal.getOrgT());
track.setOrgCData(jobFileMetal.getOrgCData());
track.setOrgSData(jobFileMetal.getOrgSData());
track.setOrgTData(jobFileMetal.getOrgTData());
track.setCurOrg(jobFileMetal.getCurOrg());
track.setCurOrgData(jobFileMetal.getCurOrgData());
// track.setLoginType(userInfo.getLoginType());
return track;
}
/*
* JobFileInfo 不能有空的字段 否则解析不了
*/
public static FileInfo notNull(FileInfo fileinfo){
if(fileinfo == null){
return new FileInfo();
}
if (null == fileinfo.getId() || false == inspectId(fileinfo.getId()) ){
fileinfo.setId(UUID.fromString("00000000-0000-0000-0000-000000000000").toString());
}
if(null == fileinfo.getCode()){
fileinfo.setCode("");
}
if(null == fileinfo.getName()){
fileinfo.setName("");
}
if (null == fileinfo.getCaseId() || false == inspectId(fileinfo.getCaseId()) ){
fileinfo.setCaseId(UUID.fromString("00000000-0000-0000-0000-000000000000").toString());
}
if(null == fileinfo.getCaseName()){
fileinfo.setCaseName("");
}
if(null == fileinfo.getHosterId()){
fileinfo.setHosterId("");
}
if(null == fileinfo.getHosterPcode()){
fileinfo.setHosterPcode("");
}
if(null == fileinfo.getHosterName()){
fileinfo.setHosterName("");
}
if(null == fileinfo.getType()){
fileinfo.setType("");
}
if(null == fileinfo.getSn()){
fileinfo.setSn(0.0);
}
if(null == fileinfo.getPlaceId() || false == inspectId(fileinfo.getPlaceId())){
fileinfo.setPlaceId(UUID.fromString("00000000-0000-0000-0000-000000000000").toString());
}
if(null == fileinfo.getPlaceName()){
fileinfo.setPlaceName("");
}
if(null == fileinfo.getAreaId() || false == inspectId(fileinfo.getAreaId())){
fileinfo.setAreaId(UUID.fromString("00000000-0000-0000-0000-000000000000").toString());
}
if(null == fileinfo.getAreaName()){
fileinfo.setAreaName("");
}
if(null == fileinfo.getSpaceId() || false == inspectId(fileinfo.getSpaceId())){
fileinfo.setSpaceId(UUID.fromString("00000000-0000-0000-0000-000000000000").toString());
}
if(null == fileinfo.getSpaceName()){
fileinfo.setSpaceName("");
}
if(null == fileinfo.getCellId()){
fileinfo.setCellId("");
}
if(null == fileinfo.getCellName()){
fileinfo.setCellName("");
}
if(null == fileinfo.getDiskPath()){
fileinfo.setDiskPath("");
}
if(null == fileinfo.getIsScan()){
fileinfo.setIsScan(0);
}
if(null == fileinfo.getPageCount()){
fileinfo.setPageCount(0);
}
if(null == fileinfo.getPrintCode()){
fileinfo.setPrintCod