@@ -4,7 +4,7 @@ import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.util.Consts; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.spring.config.FileConfigProperties; | |||
import cc.smtweb.system.bpm.spring.file.attach.AttachHelper; | |||
import cc.smtweb.system.bpm.spring.file.attach.AttachUtil; | |||
@@ -96,7 +96,7 @@ public class AttachController { | |||
} | |||
attach.setPath(path);//附件路径 | |||
attach.setPartyId(-1l); | |||
attach.setTime(PubUtil.getLastTime()); | |||
attach.setTime(DateUtil.nowDateTimeLong()); | |||
attach.setUserId(-1l); | |||
attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 | |||
// 上传文件名 | |||
@@ -104,7 +104,7 @@ public class AttachController { | |||
if (i >= 0) { | |||
attach.setSuffix(file.getOriginalFilename().substring(i)); | |||
} | |||
if (PubUtil.isEmptyStr(attachName)) { | |||
if (StringUtil.isEmpty(attachName)) { | |||
attachName = file.getOriginalFilename(); | |||
} | |||
else { | |||
@@ -116,7 +116,7 @@ public class AttachController { | |||
// 上传文件域对象 | |||
File upload = new File(attachHelper.getAttachTmpPath() + attach.getId() + attach.getSuffix()); | |||
attach.setSize((long) FileCopyUtils.copy(file.getInputStream(), new BufferedOutputStream(new FileOutputStream(upload)))); | |||
if (PubUtil.isEmpty(savePath)) { | |||
if (StringUtil.isEmpty(savePath)) { | |||
localSaveAttach(attach, upload); | |||
} else {//复制到指定目录 | |||
String filePath; | |||
@@ -176,7 +176,7 @@ public class AttachController { | |||
// 上传文件类型 | |||
//String uploadContentType = file.getContentType(); | |||
AttachInfo attach = null; | |||
boolean isNew = PubUtil.isEmpty(attachId+""); | |||
boolean isNew = StringUtil.isEmpty(attachId+""); | |||
if (isNew) { | |||
attach = new AttachInfo(); | |||
} | |||
@@ -188,7 +188,7 @@ public class AttachController { | |||
} else isNew = attach.isNew(); | |||
} | |||
attach.setId(attachId); | |||
if (PubUtil.isEmpty(attachId+"")) attach.setId(dbEngine.nextId()); | |||
if (StringUtil.isEmpty(attachId+"")) attach.setId(dbEngine.nextId()); | |||
attach.setType(type);//附件类别 | |||
if(null !=ownerId) { | |||
@@ -196,7 +196,7 @@ public class AttachController { | |||
} | |||
attach.setPath(path);//附件路径 | |||
attach.setPartyId(-1l); | |||
attach.setTime(PubUtil.getLastTime()); | |||
attach.setTime(DateUtil.nowDateTimeLong()); | |||
attach.setUserId(-1l); | |||
attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 | |||
attach.setTime(DateUtil.nowDateTimeLong()); | |||
@@ -219,7 +219,7 @@ public class AttachController { | |||
File upload = new File(attachHelper.getAttachTmpPath() + attach.getId() + attach.getSuffix()); | |||
FileUtils.writeByteArrayToFile(upload, byt); | |||
attach.setSize(upload.length()); | |||
if (PubUtil.isEmpty(savePath)) { | |||
if (StringUtil.isEmpty(savePath)) { | |||
localSaveAttach(attach, upload); | |||
} else {//复制到指定目录 | |||
String filePath; | |||
@@ -239,7 +239,7 @@ public class AttachController { | |||
public R copyupload(HttpServletRequest request) throws Exception { | |||
String type=request.getParameter("type"); | |||
String attachId=request.getParameter("attachId"); | |||
if(PubUtil.isEmpty(attachId)){ | |||
if(StringUtil.isEmpty(attachId)){ | |||
return R.success(""); | |||
} | |||
AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); | |||
@@ -259,7 +259,7 @@ public class AttachController { | |||
attach.setType(type);//附件类别 | |||
attach.setOwnerId(-1l);//附件拥有者id | |||
attach.setPartyId(-1l); | |||
attach.setTime(PubUtil.getLastTime()); | |||
attach.setTime(DateUtil.nowDateTimeLong()); | |||
attach.setUserId(-1l); | |||
attach.setName(attach.getId()+attach.getSuffix()); | |||
// 上传文件域对象 | |||
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.spring.file.attach; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.spring.config.FileConfigProperties; | |||
import cc.smtweb.system.bpm.util.UtilDownloadFile; | |||
import cc.smtweb.system.bpm.util.UtilFile; | |||
@@ -21,7 +21,7 @@ public final class AttachFileWork implements IAttachWorkIntf { | |||
private FileConfigProperties properties; | |||
private String getPath(String remoteFolderPath) { | |||
String path =properties.getAttachPath(); | |||
if (PubUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) | |||
if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) | |||
path = path + "/" + remoteFolderPath; | |||
else path = path + remoteFolderPath; | |||
path = path.replaceAll("-",""); | |||
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.spring.file.attach; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.spring.config.FileConfigProperties; | |||
import cc.smtweb.system.bpm.util.UtilDownloadFile; | |||
import cc.smtweb.system.bpm.util.UtilFile; | |||
@@ -33,7 +33,7 @@ public final class AttachFtpWork implements IAttachWorkIntf { | |||
private FileConfigProperties properties; | |||
private String getPath(String remoteFolderPath) { | |||
String path = properties.getAttachPath(); | |||
if (PubUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) | |||
if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) | |||
path = path + "/" + remoteFolderPath; | |||
else path = path + remoteFolderPath; | |||
path = path.replaceAll("-", ""); | |||
@@ -1,7 +1,9 @@ | |||
package cc.smtweb.system.bpm.spring.file.attach; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.spring.config.FileConfigProperties; | |||
import cc.smtweb.system.bpm.util.UtilFile; | |||
import cc.smtweb.system.bpm.util.UtilMath; | |||
@@ -42,7 +44,7 @@ public final class AttachHelper { | |||
//删除ftp服务器的文件 | |||
public boolean deleteOneAttach(String attachId) throws Exception { | |||
if (PubUtil.isEmpty(attachId)) return true; | |||
if (StringUtil.isEmpty(attachId)) return true; | |||
AttachInfo attachInfo = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); | |||
if(null == attachInfo){ | |||
return true; | |||
@@ -93,8 +95,8 @@ public final class AttachHelper { | |||
//批量删除 | |||
public boolean deleteAttachList(List<String> attachIdList) throws Exception { | |||
if (PubUtil.isEmpty(attachIdList)) return false; | |||
dbEngine.update("delete from "+AttachInfo.ENTITY_NAME+" where attach_id in(" + PubUtil.getSqlInIds(attachIdList) + ")"); | |||
if (CommUtil.isEmpty(attachIdList)) return false; | |||
dbEngine.update("delete from "+AttachInfo.ENTITY_NAME+" where attach_id in(" + CommUtil.getSqlInStr(attachIdList) + ")"); | |||
return true; | |||
} | |||
@@ -201,7 +203,7 @@ public final class AttachHelper { | |||
*/ | |||
public List<String> getAttachsFromFtp(final List<String> attachIds, final String ownerType) throws Exception { | |||
List<Object> paras = new ArrayList<Object>(); | |||
if (PubUtil.isNotEmpty(attachIds)) { | |||
if (!CommUtil.isEmpty(attachIds)) { | |||
StringBuilder sb = new StringBuilder(128); | |||
for(int i=0;i<attachIds.size();i++){ | |||
if(i==0){ | |||
@@ -259,7 +261,7 @@ public final class AttachHelper { | |||
attach.setType(type);//附件类别 | |||
attach.setOwnerId(-1l);//附件拥有者id | |||
attach.setPartyId(-1l); | |||
attach.setTime(PubUtil.getLastTime()); | |||
attach.setTime(DateUtil.nowDateTimeLong()); | |||
attach.setUserId(-1l); | |||
attach.setName(attach.getId()+attach.getSuffix()); | |||
// 上传文件域对象 | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.spring.file.attach; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.spring.config.FileConfigProperties; | |||
import cc.smtweb.system.bpm.spring.dataCacheInit.AttachFolderEntityBuffer; | |||
import cc.smtweb.system.bpm.web.sys.base.attach.AttachInfo; | |||
@@ -40,7 +40,7 @@ public final class AttachUtil { | |||
} | |||
public void init() { | |||
final String at = PubUtil.checkNull(properties.getAttachType()).toLowerCase(); | |||
final String at = StringUtil.checkNull(properties.getAttachType()).toLowerCase(); | |||
if ("ftp".equals(at) || "sftp".equals(at)) | |||
worker = attachFtpWork; | |||
else worker = attachFileWork; | |||
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.util; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import com.aliyuncs.utils.IOUtils; | |||
import org.springframework.util.FileCopyUtils; | |||
import sun.misc.BASE64Decoder; | |||
@@ -898,7 +898,7 @@ public class UtilFile { | |||
} else { | |||
//String filePath = child.getAbsolutePath(); | |||
String filePath = child.getName(); | |||
if (PubUtil.isEmpty(suffix)) { | |||
if (StringUtil.isEmpty(suffix)) { | |||
//后缀名为null则为所有文件 | |||
fileList.add(filePath); | |||
} else { | |||
@@ -951,7 +951,7 @@ public class UtilFile { | |||
getFiles(fileList, child, suffix, level + 1, max_level); | |||
} else { | |||
String filePath = child.getName(); | |||
if (PubUtil.isEmpty(suffix)) { | |||
if (StringUtil.isEmpty(suffix)) { | |||
//后缀名为null则为所有文件 | |||
fileList.add(child); | |||
} else { | |||
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.util; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -12,7 +12,7 @@ public class UtilLogger { | |||
private static String getOrigMsg(String message, Throwable e) { | |||
if (message != null) return message; | |||
return PubUtil.getOrigMsg(e); | |||
return CommUtil.getOrigMsg(e); | |||
} | |||
public static void debug(String message) { | |||
@@ -60,7 +60,7 @@ public class UtilLogger { | |||
} | |||
public static void error(String message, Throwable e) { | |||
if (e instanceof Exception) logger.info(message + PubUtil.getOrigMsg(e)); | |||
if (e instanceof Exception) logger.info(message + CommUtil.getOrigMsg(e)); | |||
else logger.error(getOrigMsg(message, e), e); | |||
} | |||
} |
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.util; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import java.math.BigDecimal; | |||
import java.math.RoundingMode; | |||
@@ -54,7 +54,7 @@ public class UtilMath { | |||
public static double roundDouble(Object src, int scale) { | |||
if (src == null) return 0.0; | |||
String v = src.toString(); | |||
if (PubUtil.isEmpty(v)) return 0.0; | |||
if (StringUtil.isEmpty(v)) return 0.0; | |||
if (scale < 0) scale = 2; | |||
BigDecimal src_b = new BigDecimal(v); | |||
@@ -181,7 +181,7 @@ public class UtilMath { | |||
* @return boolean | |||
*/ | |||
public static boolean isBigThanZero(String value) { | |||
return !PubUtil.isEmpty(value) && isBigThanZero(toDouble(value)); | |||
return !StringUtil.isEmpty(value) && isBigThanZero(toDouble(value)); | |||
} | |||
/** | |||
@@ -201,7 +201,7 @@ public class UtilMath { | |||
* @return boolean | |||
*/ | |||
public static boolean isEqualsZero(String value) { | |||
return PubUtil.isEmpty(value) || isEqualsZero(toDouble(value)); | |||
return StringUtil.isEmpty(value) || isEqualsZero(toDouble(value)); | |||
} | |||
/** | |||
@@ -254,7 +254,7 @@ public class UtilMath { | |||
* @return String 去掉逗号后的串,如果amount为空,则返回0.00 | |||
*/ | |||
public static String toStdNumberString(String s) { | |||
if (PubUtil.isEmpty(s)) | |||
if (StringUtil.isEmpty(s)) | |||
return "0.00"; | |||
return stdNumberFormat.format(UtilMath.todouble(s)); | |||
} | |||
@@ -341,7 +341,7 @@ public class UtilMath { | |||
* @return String 转换结果 | |||
*/ | |||
public static String toCapsAmountString(String s) { | |||
if (PubUtil.isEmpty(s)) return ""; | |||
if (StringUtil.isEmpty(s)) return ""; | |||
return toCapsAmountString(todouble(s)); | |||
} | |||
@@ -1,7 +1,8 @@ | |||
package cc.smtweb.system.bpm.util; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import java.text.Collator; | |||
import java.util.*; | |||
@@ -13,6 +14,7 @@ import java.util.*; | |||
* To change this template use File | Settings | File Templates. | |||
*/ | |||
@SuppressWarnings("UnusedDeclaration") | |||
@Deprecated | |||
public class UtilString { | |||
private static Collator chineseCollator = Collator.getInstance(Locale.CHINA); | |||
@@ -24,9 +26,9 @@ public class UtilString { | |||
* @return String 返回 | |||
*/ | |||
public static String getLeft(String strSrc, String strSe) { | |||
if (PubUtil.isEmpty(strSrc)) | |||
if (StringUtil.isEmpty(strSrc)) | |||
return ""; | |||
if (PubUtil.isEmpty(strSe)) | |||
if (StringUtil.isEmpty(strSe)) | |||
strSe = " "; | |||
String result = ""; | |||
@@ -44,7 +46,7 @@ public class UtilString { | |||
* @return String return | |||
*/ | |||
public static String getLeft(String strSrc, int count) { | |||
if (PubUtil.isEmpty(strSrc) || count <= 0) { | |||
if (StringUtil.isEmpty(strSrc) || count <= 0) { | |||
return ""; | |||
} | |||
if (strSrc.length() < count) { | |||
@@ -62,9 +64,9 @@ public class UtilString { | |||
* @return String right部分 | |||
*/ | |||
public static String getRight(String strSrc, String strSe) { | |||
if (PubUtil.isEmpty(strSrc)) | |||
if (StringUtil.isEmpty(strSrc)) | |||
return ""; | |||
if (PubUtil.isEmpty(strSe)) | |||
if (StringUtil.isEmpty(strSe)) | |||
strSe = " "; | |||
String result = strSrc; | |||
@@ -82,7 +84,7 @@ public class UtilString { | |||
* @return String return | |||
*/ | |||
public static String getRight(String strSrc, int count) { | |||
if (PubUtil.isEmpty(strSrc) || count <= 0) { | |||
if (StringUtil.isEmpty(strSrc) || count <= 0) { | |||
return ""; | |||
} | |||
int l = strSrc.length(); | |||
@@ -195,7 +197,7 @@ public class UtilString { | |||
* @return 处理结果 | |||
*/ | |||
public static String cutStringLeft(String src, String cut) { | |||
if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { | |||
if (StringUtil.isEmpty(src) || StringUtil.isEmpty(cut)) { | |||
return ""; | |||
} | |||
if (src.startsWith(cut)) { | |||
@@ -206,7 +208,7 @@ public class UtilString { | |||
} | |||
public static String cutStringRight(String src, String cut) { | |||
if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { | |||
if (StringUtil.isEmpty(src) || StringUtil.isEmpty(cut)) { | |||
return ""; | |||
} | |||
while (src.endsWith(cut)) | |||
@@ -446,7 +448,7 @@ public class UtilString { | |||
return myReplaceStrEx(express, b, e, new IStrHanlder() { | |||
@Override | |||
public String work(String src) { | |||
return PubUtil.checkNull(mapVals.get(src)); | |||
return StringUtil.checkNull(mapVals.get(src)); | |||
} | |||
}); | |||
} | |||
@@ -485,7 +487,7 @@ public class UtilString { | |||
String[] ss = src.split(ch); | |||
int[] ret = new int[ss.length]; | |||
for (int i = 0, len = ss.length; i < len; i++) { | |||
ret[i] = PubUtil.getIntIgnoreErr(ss[i]); | |||
ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); | |||
} | |||
return ret; | |||
} | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.util.ftp; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.util.UtilLogger; | |||
import java.io.File; | |||
@@ -118,7 +118,7 @@ public class FtpTaskManager { | |||
} | |||
private String getBakPath(String path) { | |||
path = PubUtil.isEmpty(path) ? DateUtil.getNowYm() : path; | |||
path = StringUtil.isEmpty(path) ? DateUtil.getNowYm() : path; | |||
return "bak/" + path + "/"; | |||
} | |||
@@ -190,7 +190,7 @@ public class FtpTaskManager { | |||
public Object execute(IFtpUtil ftp) throws Exception { | |||
for (String file : files) { | |||
if (worker != null && !worker.isDownload(file, fileNamePrefix)) continue; | |||
if (PubUtil.isNotEmptyId(fileNamePrefix) && !file.startsWith(fileNamePrefix)) continue; | |||
if (StringUtil.isNotEmpty(fileNamePrefix) && !file.startsWith(fileNamePrefix)) continue; | |||
ftp.downloadFileEx(remotePath, file, localPath + "/" + file); | |||
if (isDelLocal) { | |||
ftp.setRemoteDir("/"); | |||
@@ -1,6 +1,6 @@ | |||
package cc.smtweb.system.bpm.util.ftp; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.system.bpm.util.UtilFile; | |||
import cc.smtweb.system.bpm.util.UtilLogger; | |||
import org.apache.commons.net.ftp.FTPClient; | |||
@@ -243,7 +243,7 @@ public class FtpUtil implements IFtpUtil { | |||
ftpClient.enterLocalPassiveMode();//设置被动模式 | |||
setRemoteDir(path); | |||
String[] files = ftpClient.listNames(gbktoiso8859(filename)); | |||
return PubUtil.isNotEmpty(files); | |||
return !CommUtil.isEmpty(files); | |||
} catch (IOException e) { | |||
logError("判断文件是否存在失败", e); | |||
return false; | |||
@@ -1,6 +1,7 @@ | |||
package cc.smtweb.system.bpm.util.ftp; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.util.UtilFile; | |||
import cc.smtweb.system.bpm.util.UtilLogger; | |||
import com.jcraft.jsch.*; | |||
@@ -63,7 +64,7 @@ public class SFtpUtil implements IFtpUtil { | |||
UtilLogger.debug("已连接到 " + ftpConf.getServerIp() + ";"); | |||
return true; | |||
} catch (Exception e) { | |||
UtilLogger.debug("connect fail[" + count + "/3]:" + PubUtil.getOrigMsg(e)); | |||
UtilLogger.debug("connect fail[" + count + "/3]:" + CommUtil.getOrigMsg(e)); | |||
} | |||
} | |||
UtilLogger.debug("sftp登录失败:3次连接超时..."); | |||
@@ -135,7 +136,7 @@ public class SFtpUtil implements IFtpUtil { | |||
try { | |||
String now = sftp.pwd(); | |||
for (int i = 0; i < dirs.length; i++) { | |||
if (PubUtil.isEmpty(dirs[i])) continue; | |||
if (StringUtil.isEmpty(dirs[i])) continue; | |||
boolean dirExists = openRemoteDir(dirs[i]); | |||
if (!dirExists) { | |||
sftp.mkdir(dirs[i]); | |||
@@ -387,7 +388,7 @@ public class SFtpUtil implements IFtpUtil { | |||
setRemoteDir(path); | |||
Vector<ChannelSftp.LsEntry> files = sftp.ls(filename); | |||
sftp.cd(now); | |||
return PubUtil.isNotEmpty(files); | |||
return !CommUtil.isEmpty(files); | |||
} catch (SftpException e) { | |||
logError("判断文件是否存在失败", e); | |||
return false; | |||
@@ -11,7 +11,6 @@ import cc.smtweb.framework.core.db.vo.ModelField; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.mvc.service.AbstractCompService; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; | |||
import cc.smtweb.framework.core.mvc.service.DefaultListHandler; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.SqlUtil; | |||
@@ -9,7 +9,7 @@ import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.util.TreeDataUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache; | |||
@@ -34,7 +34,7 @@ public class PreviewMenuTreeService { | |||
String prj_id = ModelProjectCache.getInstance().getIdByModule(module); | |||
if(!SwConsts.SysParam.SYS_DEBUG){ | |||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us); | |||
if (PubUtil.isNotEmpty(menuVOList)) { | |||
if (!CommUtil.isEmpty(menuVOList)) { | |||
return R.success(menuVOList); | |||
} | |||
} | |||
@@ -79,7 +79,7 @@ public class PreviewMenuTreeService { | |||
public List<MenuVO> buildMenu(String prj_id, String module, UserSession us) { | |||
Set<MenuPlan> set = MenuPlanCache.getInstance().getByP(prj_id); | |||
if (PubUtil.isEmpty(set)) { | |||
if (CommUtil.isEmpty(set)) { | |||
return new ArrayList<>(); | |||
} | |||
MenuPlan menuPlan = set.iterator().next(); | |||
@@ -107,7 +107,7 @@ public class PreviewMenuTreeService { | |||
menu.setPath(MenuCache.getInstance().getPath(mp.getMenu())); | |||
menu.setParentId(parent_id); | |||
List<MenuVO> child = new ArrayList<>(); | |||
if (PubUtil.isNotEmpty(mp.getChildren())) { | |||
if (!CommUtil.isEmpty(mp.getChildren())) { | |||
for (MenuPlanItem cmp : mp.getChildren()) { | |||
List<MenuVO> m = buildMenu(menu.getId(), cmp); | |||
if (m == null) continue; | |||
@@ -14,10 +14,9 @@ import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.framework.core.mvc.service.SqlNamedPara; | |||
import cc.smtweb.framework.core.util.MapUtil; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.form.define.*; | |||
import org.apache.commons.lang3.StringUtils; | |||
import reactor.util.annotation.Nullable; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
@@ -321,13 +320,13 @@ public class DynPageHelper { | |||
}); | |||
mapBuilder.put(SwEnum.OptType.IN.value, (opt, field, name, value, args) -> { | |||
if (PubUtil.isEmpty(value.toString())) return ""; | |||
if (StringUtil.isEmpty(value.toString())) return ""; | |||
args.put(name, value); | |||
return field + " in (:" + name + ") "; | |||
}); | |||
mapBuilder.put(SwEnum.OptType.NOT_IN.value, (opt, field, name, value, args) -> { | |||
if (PubUtil.isEmpty(value.toString())) return ""; | |||
if (StringUtil.isEmpty(value.toString())) return ""; | |||
args.put(name, value); | |||
return field + " not in (:" + name + ") "; | |||
}); | |||
@@ -10,7 +10,6 @@ import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.MathUtil; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.system.bpm.web.design.flow.FlowConst; | |||
import cc.smtweb.system.bpm.web.design.flow.ModelProc; | |||
@@ -18,7 +17,6 @@ import cc.smtweb.system.bpm.web.design.flow.ModelProcHelper; | |||
import cc.smtweb.system.bpm.web.design.flow.define.Activity; | |||
import cc.smtweb.system.bpm.web.design.flow.define.ProcInfo; | |||
import cc.smtweb.system.bpm.web.engine.flow.entity.*; | |||
import cc.smtweb.system.bpm.web.sys.base.billFlow.BillFlow; | |||
import cc.smtweb.system.bpm.web.sys.user.dept.Dept; | |||
import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; | |||
import cc.smtweb.system.bpm.web.sys.user.party.Party; | |||
@@ -5,7 +5,7 @@ import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.mvc.service.SqlPara; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
import cc.smtweb.system.bpm.web.design.form.ModelFormCache; | |||
@@ -67,7 +67,7 @@ public class ComboHandler { | |||
@Override | |||
public SwListData buildListData() { | |||
String cls = params.readMap("filter").readString("cls"); | |||
if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); | |||
if (StringUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); | |||
List<SwMap> list = new ArrayList<>(); | |||
try { | |||
AbstractEnum e; | |||
@@ -8,7 +8,7 @@ import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean; | |||
import org.springframework.util.Assert; | |||
@@ -37,7 +37,7 @@ public class EnumComboService extends DynPageService { | |||
} | |||
private SwListData buildListData(String cls) { | |||
if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); | |||
if (StringUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); | |||
List<SwMap> list = new ArrayList<>(); | |||
try { | |||
Class tempClass ; | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.menu; | |||
import cc.smtweb.framework.core.annotation.SwTable; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import java.util.ArrayList; | |||
import java.util.HashSet; | |||
@@ -164,18 +164,18 @@ public class Menu extends DefaultEntity { | |||
public final String getPath() { | |||
if (PubUtil.isEmpty(getContent())) return ""; | |||
if (StringUtil.isEmpty(getContent())) return ""; | |||
return JsonUtil.parseMap(getContent()).get("path").toString(); | |||
} | |||
public final String getPageId() { | |||
if (PubUtil.isEmpty(getContent())) return ""; | |||
if (StringUtil.isEmpty(getContent())) return ""; | |||
return JsonUtil.parseMap(getContent()).get("pageId").toString(); | |||
} | |||
public final List<String> getRightList(String type) { | |||
List<String> set = new ArrayList<>(); | |||
if (PubUtil.isEmpty(getRight())) return set; | |||
if (StringUtil.isEmpty(getRight())) return set; | |||
return (List<String>) JsonUtil.parseMap(getRight()).get(type); | |||
} | |||
@@ -5,8 +5,8 @@ import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | |||
import cc.smtweb.framework.core.db.vo.ModelProject; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; | |||
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; | |||
@@ -49,16 +49,16 @@ public class MenuHandler { | |||
super.afterLoadBean(dataset, bean); | |||
Menu menu = new Menu(); | |||
menu.setData(bean); | |||
if (PubUtil.isNotEmptyStr(menu.getContent())) { | |||
if (StringUtil.isNotEmpty(menu.getContent())) { | |||
Map<String, String> urlMap = JsonUtil.parseMap(menu.getContent()); | |||
bean.put("sm_page_id", urlMap.get("pageId")); | |||
bean.put("sm_page_url", urlMap.get("path")); | |||
} | |||
if (PubUtil.isNotEmptyStr(menu.getRight())) { | |||
if (StringUtil.isNotEmpty(menu.getRight())) { | |||
Map<String, List<String>> rightMap = JsonUtil.parseMap(menu.getRight()); | |||
bean.put("sm_right_data", PubUtil.getSqlInIds(rightMap.get("data"))); | |||
bean.put("sm_right_func", PubUtil.getSqlInIds(rightMap.get("func"))); | |||
bean.put("sm_right_field", PubUtil.getSqlInIds(rightMap.get("field"))); | |||
bean.put("sm_right_data", CommUtil.getSqlInStr(rightMap.get("data"))); | |||
bean.put("sm_right_func", CommUtil.getSqlInStr(rightMap.get("func"))); | |||
bean.put("sm_right_field", CommUtil.getSqlInStr(rightMap.get("field"))); | |||
} | |||
} | |||
} | |||
@@ -117,7 +117,7 @@ public class MenuHandler { | |||
ModelProject mp = ModelProjectCache.getInstance().get(id); | |||
if (mp != null) { | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(0, mp.getId(), true, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isEmpty(mcList)) return; | |||
if (CommUtil.isEmpty(mcList)) return; | |||
for (ModelCatalog mc : mcList) { | |||
SwMap row = new SwMap(); | |||
row.put("mc_id", mc.getId()); | |||
@@ -131,7 +131,7 @@ public class MenuHandler { | |||
return; | |||
} | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isEmpty(mcList)) return; | |||
if (CommUtil.isEmpty(mcList)) return; | |||
for (ModelCatalog mc : mcList) { | |||
SwMap row = new SwMap(); | |||
row.put("mc_id", mc.getId()); | |||
@@ -175,10 +175,10 @@ public class MenuHandler { | |||
private List<SwMap> buildTreeData(long prj_id, long id) { | |||
List<SwMap> list = new ArrayList<>(); | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, prj_id, false, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isNotEmpty(mcList)) { | |||
if (!CommUtil.isEmpty(mcList)) { | |||
for (ModelCatalog mc : mcList) { | |||
List<SwMap> children = buildTreeData(prj_id, mc.getId()); | |||
if (PubUtil.isNotEmpty(children)) { | |||
if (!CommUtil.isEmpty(children)) { | |||
MenuNode menuNode = new MenuNode(); | |||
menuNode.setMenu(mc.getId()); | |||
menuNode.setLabel(mc.getName()); | |||
@@ -186,7 +186,7 @@ public class MenuHandler { | |||
list.add(menuNode.getData()); | |||
} | |||
Set<Menu> menus = MenuCache.getInstance().getByM(String.valueOf(mc.getId())); | |||
if (PubUtil.isNotEmpty(menus)) { | |||
if (!CommUtil.isEmpty(menus)) { | |||
for (Menu m : menus) { | |||
MenuNode menu = new MenuNode(); | |||
menu.setMenu(m.getId()); | |||
@@ -2,8 +2,8 @@ package cc.smtweb.system.bpm.web.sys.user.menuPlan; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
@@ -87,7 +87,7 @@ public class MenuPlanContent { | |||
removeById(id, list); | |||
} else { | |||
List<MenuPlanItem> children = parent.getChildren(); | |||
if (PubUtil.isNotEmpty(children)) { | |||
if (!CommUtil.isEmpty(children)) { | |||
removeById(id, children); | |||
} | |||
} | |||
@@ -123,7 +123,7 @@ public class MenuPlanContent { | |||
} | |||
private MenuPlanItem findById(long id, List<MenuPlanItem> itemList) { | |||
if (PubUtil.isEmpty(itemList)) { | |||
if (CommUtil.isEmpty(itemList)) { | |||
return null; | |||
} | |||
for (MenuPlanItem item : itemList) { | |||
@@ -132,7 +132,7 @@ public class MenuPlanContent { | |||
} | |||
} | |||
for (MenuPlanItem item : itemList) { | |||
if(PubUtil.isNotEmpty(item.getChildren())){ | |||
if(!CommUtil.isEmpty(item.getChildren())){ | |||
MenuPlanItem rt = findById(id,item.getChildren()); | |||
if(rt!=null){ | |||
return rt; | |||
@@ -143,17 +143,17 @@ public class MenuPlanContent { | |||
} | |||
private MenuPlanItem findParentById(long id, List<MenuPlanItem> itemList) { | |||
if (PubUtil.isEmpty(itemList)) { | |||
if (CommUtil.isEmpty(itemList)) { | |||
return null; | |||
} | |||
for (MenuPlanItem item : itemList) { | |||
List<MenuPlanItem> children = item.getChildren(); | |||
if (PubUtil.isNotEmpty(children)) { | |||
if (!CommUtil.isEmpty(children)) { | |||
for (MenuPlanItem i : children) { | |||
if (i.getId() == id) { | |||
return item; | |||
} | |||
if (PubUtil.isNotEmpty(i.getChildren())) { | |||
if (!CommUtil.isEmpty(i.getChildren())) { | |||
return findParentById(id, i.getChildren()); | |||
} | |||
} | |||
@@ -7,8 +7,8 @@ import cc.smtweb.framework.core.db.jdbc.IDbWorker; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; | |||
@@ -136,7 +136,7 @@ public class MenuPlanHandler { | |||
List<MenuPlanItem> children = getChildren(); | |||
List<SwMap> list = new ArrayList<>(); | |||
int total = 0; | |||
if (PubUtil.isNotEmpty(children)) { | |||
if (!CommUtil.isEmpty(children)) { | |||
total = children.size(); | |||
for (MenuPlanItem bean : children) { | |||
SwMap map = bean.getData(); | |||
@@ -219,7 +219,7 @@ public class MenuPlanHandler { | |||
boolean exc_menu = params.readBool("exc_menu"); | |||
List<SwMap> list = new ArrayList<>(); | |||
List<MenuPlanItem> temList = menuPlanContent.getChildren(id); | |||
if (PubUtil.isNotEmpty(temList)) { | |||
if (!CommUtil.isEmpty(temList)) { | |||
temList.forEach(bean -> { | |||
if (exc_menu && bean.getMenu() > 0) { | |||
return; | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.party; | |||
import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import java.util.Set; | |||
@@ -46,6 +46,6 @@ public class PartyCache extends AbstractEntityCache<Party> { | |||
//是否末级 | |||
public final boolean isLeaf(Long key) { | |||
Set<Party> children = getChildren(key); | |||
return PubUtil.isEmpty(children); | |||
return CommUtil.isEmpty(children); | |||
} | |||
} |
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.role; | |||
import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
@@ -36,6 +36,6 @@ public class RoleCache extends AbstractEntityCache<Role> { | |||
key.forEach(k -> { | |||
names.add(get(k).getName()); | |||
}); | |||
return PubUtil.getSqlInIds(names); | |||
return CommUtil.getSqlInStr(names); | |||
} | |||
} |
@@ -6,7 +6,8 @@ import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
import cc.smtweb.system.bpm.web.design.form.ModelFormCache; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
@@ -56,10 +57,9 @@ public class RoleHandler { | |||
if (role_id <= 0) return R.error("未指定角色!"); | |||
SwMap formData = data.readMap("form"); | |||
Set<Long> set = formData.readLongSet("menu"); | |||
//if (PubUtil.isEmpty(set)) return R.error("未选择菜单!"); | |||
//if (CommUtil.isEmpty(set)) return R.error("未选择菜单!"); | |||
Role role = RoleCache.getInstance().get(role_id); | |||
RoleRightContent rc = new RoleRightContent(role.getPrivilege()); | |||
rc.resetItem(); | |||
for (Long menu_id : set) { | |||
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), menu_id); | |||
RoleRight right = rc.getRoleRight(item.getId()); | |||
@@ -203,7 +203,7 @@ public class RoleHandler { | |||
Menu menu = MenuCache.getInstance().get(item.getMenu()); | |||
if (menu == null) return SwListData.create(list, 0); | |||
for (String f : menu.getRightSet(SwEnum.MenuRightType.FUNC.value)) { | |||
if (PubUtil.isEmpty(f)) continue; | |||
if (StringUtil.isEmpty(f)) continue; | |||
SwMap row = new SwMap(); | |||
row.put("f_id", f); | |||
row.put("f_name", SwEnum.MenuFuncRight.instance.getName(f)); | |||
@@ -239,7 +239,7 @@ public class RoleHandler { | |||
Map<String, Object> data = rc.getDataRight(item.getId()); | |||
for (String f : menu.getRightSet(SwEnum.MenuRightType.DATA.value)) { | |||
if (PubUtil.isEmpty(f)) continue; | |||
if (StringUtil.isEmpty(f)) continue; | |||
SwMap row = new SwMap(); | |||
row.put("key", f); | |||
row.put("key_text", DataRightDefineCache.getInstance().get(f).getName()); | |||
@@ -2,8 +2,9 @@ package cc.smtweb.system.bpm.web.sys.user.role; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import java.util.*; | |||
@@ -18,10 +19,10 @@ public class RoleRightContent { | |||
public RoleRightContent(String content) { | |||
List<RoleRight> tempList = JsonUtil.parseList(content, RoleRight.class); | |||
if (PubUtil.isNotEmpty(content) && tempList == null) { | |||
if (StringUtil.isNotEmpty(content) && tempList == null) { | |||
throw new BizException("角色权限转换失败!"); | |||
} | |||
if (PubUtil.isEmpty(tempList)) return; | |||
if (CommUtil.isEmpty(tempList)) return; | |||
tempList.forEach(bean -> { | |||
map.put(bean.getId(), bean); | |||
}); | |||
@@ -60,7 +61,7 @@ public class RoleRightContent { | |||
public String getFuncRight(long key) { | |||
RoleRight right = getRoleRight(key); | |||
if (right == null) return ""; | |||
return PubUtil.getSqlInIds(right.getRightFunc()); | |||
return CommUtil.getSqlInStr(right.getRightFunc()); | |||
} | |||
public String getMenuRight() { | |||
@@ -69,7 +70,7 @@ public class RoleRightContent { | |||
map.values().forEach(roleRight -> { | |||
if (roleRight.getMenu() == 1) menus.add(roleRight.getId() + ""); | |||
}); | |||
return PubUtil.getSqlInIds(menus); | |||
return CommUtil.getSqlInStr(menus); | |||
} | |||
public String getFieldRight(long key, int type) { | |||
@@ -81,7 +82,7 @@ public class RoleRightContent { | |||
cache.forEach((k, v) -> { | |||
if (v == type) fields.add(k); | |||
}); | |||
return PubUtil.getSqlInIds(fields); | |||
return CommUtil.getSqlInStr(fields); | |||
} | |||
public Map<String, Object> getDataRight(long key) { | |||
@@ -10,7 +10,9 @@ import cc.smtweb.framework.core.db.jdbc.IDbWorker; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageDelHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; | |||
@@ -60,7 +62,7 @@ public class UserHandler { | |||
roleList = new ArrayList<>(); | |||
partyList = new ArrayList<>(); | |||
List<Map<String, Object>> rows = data.readListMap("partyData"); | |||
if (PubUtil.isEmpty(rows)) throw new BizException("用户所属机构为空"); | |||
if (CommUtil.isEmpty(rows)) throw new BizException("用户所属机构为空"); | |||
for (Map<String, Object> row : rows) { | |||
UserParty userParty = new UserParty(); | |||
userParty.init(); | |||
@@ -70,7 +72,7 @@ public class UserHandler { | |||
partyList.add(userParty); | |||
String roles = row.get("sup_roles").toString(); | |||
if (PubUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空"); | |||
if (StringUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空"); | |||
for (String role_id : roles.split(",")) { | |||
UserRole userRole = new UserRole(); | |||
userRole.init(); | |||
@@ -97,7 +99,7 @@ public class UserHandler { | |||
UserStatuCache.getInstance().put(userStatu); | |||
} | |||
if (bean.isNew()) { | |||
((User) bean).setCreate(PubUtil.getLastTime()); | |||
((User) bean).setCreate(DateUtil.nowDateTimeLong()); | |||
((User) bean).setPwd(LoginHelper.encodePwd(bean.getEntityId(), SwConsts.DEF_PWD)); | |||
} | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.user; | |||
import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
@@ -46,7 +46,7 @@ public class UserPartyCache extends AbstractEntityCache<UserParty> { | |||
public final Set<Long> getIdByUser(Long key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserParty> set = getByUser(String.valueOf(key)); | |||
if (PubUtil.isEmpty(set)) return ids; | |||
if (CommUtil.isEmpty(set)) return ids; | |||
set.forEach(bean -> { | |||
ids.add(bean.getEntityId()); | |||
}); | |||
@@ -57,7 +57,7 @@ public class UserPartyCache extends AbstractEntityCache<UserParty> { | |||
public final Set<Long> getUserByDept(Long key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserParty> set = getByDept(String.valueOf(key)); | |||
if (PubUtil.isEmpty(set)) return ids; | |||
if (CommUtil.isEmpty(set)) return ids; | |||
set.forEach(bean -> { | |||
ids.add(bean.getUserId()); | |||
}); | |||
@@ -67,7 +67,7 @@ public class UserPartyCache extends AbstractEntityCache<UserParty> { | |||
public final Set<Long> getUserByParty(Long key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserParty> set = getByParty(String.valueOf(key)); | |||
if (PubUtil.isEmpty(set)) return ids; | |||
if (CommUtil.isEmpty(set)) return ids; | |||
set.forEach(bean -> { | |||
ids.add(bean.getUserId()); | |||
}); | |||
@@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.user; | |||
import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
@@ -34,7 +34,7 @@ public class UserRoleCache extends AbstractEntityCache<UserRole> { | |||
public final Set<Long> getByParty(Long key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserRole> set = getByParty(String.valueOf(key)); | |||
if (PubUtil.isEmpty(set)) return ids; | |||
if (CommUtil.isEmpty(set)) return ids; | |||
set.forEach(bean -> { | |||
ids.add(bean.getEntityId()); | |||
}); | |||
@@ -50,7 +50,7 @@ public class UserRoleCache extends AbstractEntityCache<UserRole> { | |||
public final Set<Long> getRoleByParty(Long key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserRole> set = getByParty(String.valueOf(key)); | |||
if (PubUtil.isEmpty(set)) return ids; | |||
if (CommUtil.isEmpty(set)) return ids; | |||
set.forEach(bean -> { | |||
ids.add(bean.getRoleId()); | |||
}); | |||
@@ -75,11 +75,11 @@ public class UserRoleCache extends AbstractEntityCache<UserRole> { | |||
public final Set<Long> getRoleIdByUP(Long user_id, Long party_id) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<UserParty> upSet = UserPartyCache.getInstance().getListByKey(UserPartyCache.mk_u, String.valueOf(user_id)); | |||
if (PubUtil.isEmpty(upSet)) return ids; | |||
if (CommUtil.isEmpty(upSet)) return ids; | |||
upSet.forEach(up -> { | |||
if (up.getPartyId() != party_id) return; | |||
Set<UserRole> urSet = getListByKey(mk_s, String.valueOf(up.getId())); | |||
if (PubUtil.isEmpty(urSet)) return; | |||
if (CommUtil.isEmpty(urSet)) return; | |||
for (UserRole userRole : urSet) { | |||
ids.add(userRole.getRoleId()); | |||
} | |||
@@ -94,10 +94,10 @@ public class UserRoleCache extends AbstractEntityCache<UserRole> { | |||
public final Set<Long> getIdByUser(String key) { | |||
Set<Long> ids = new HashSet<>(); | |||
Set<Long> upSet = UserPartyCache.getInstance().getListIdByKey(UserPartyCache.mk_u, key); | |||
if (PubUtil.isEmpty(upSet)) return ids; | |||
if (CommUtil.isEmpty(upSet)) return ids; | |||
upSet.forEach(k -> { | |||
Set<UserRole> urSet = getListByKey(mk_s, String.valueOf(k)); | |||
if (PubUtil.isEmpty(urSet)) return; | |||
if (CommUtil.isEmpty(urSet)) return; | |||
for (UserRole userRole : urSet) { | |||
ids.add(userRole.getEntityId()); | |||
} | |||
@@ -5,7 +5,6 @@ import cc.smtweb.framework.core.cache.redis.RedisBroadcastEvent; | |||
import cc.smtweb.framework.core.cache.redis.RedisManager; | |||
import cc.smtweb.framework.core.common.SwConsts; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import com.github.benmanes.caffeine.cache.Caffeine; | |||
import com.github.benmanes.caffeine.cache.LoadingCache; | |||
import com.github.benmanes.caffeine.cache.Scheduler; | |||
@@ -452,7 +451,7 @@ public abstract class AbstractCache<T extends Serializable> implements ISwCache< | |||
} | |||
public void removeList(Collection<Long> key) { | |||
if (PubUtil.isEmpty(key)) return; | |||
if (CommUtil.isEmpty(key)) return; | |||
key.forEach(k -> { | |||
remove(k); | |||
}); | |||
@@ -4,7 +4,7 @@ import cc.smtweb.framework.core.common.SwConsts; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityDao; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
@@ -59,7 +59,7 @@ public class AbstractEntityCache<T extends DefaultEntity> extends AbstractCache< | |||
public final Set<Long> getListIdByKey(String rk, String key) { | |||
Set<Long> idSet = new HashSet<>(); | |||
Set<T> beanSet = getListByKey(rk, key); | |||
if (PubUtil.isEmpty(beanSet)) return idSet; | |||
if (CommUtil.isEmpty(beanSet)) return idSet; | |||
beanSet.forEach(bean -> { | |||
idSet.add(bean.getEntityId()); | |||
}); | |||
@@ -1,7 +1,6 @@ | |||
package cc.smtweb.framework.core.common; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.sql.Types; | |||
@@ -14,7 +14,6 @@ import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import org.apache.commons.lang3.StringUtils; | |||
@@ -64,7 +63,7 @@ public class EntityHelper { | |||
String value = v != null ? v.toString() : ""; | |||
final ModelField field = modelEntity.findField(fname); | |||
if (field != null) { | |||
if (PubUtil.isEmpty(value) && PubUtil.isNotEmpty(field.getDefaultValue())) { | |||
if (StringUtil.isEmpty(value) && StringUtil.isNotEmpty(field.getDefaultValue())) { | |||
value = field.getDefaultValue(); | |||
} | |||
args[i++] = SwEnum.DataType.getDataValue(field.getDataType(), value); | |||
@@ -38,7 +38,7 @@ public class ModelDatabaseCache extends AbstractCache<ModelDatabase> { | |||
EntityDao<ModelDatabase> dao = DbEngine.getInstance().findDao(ModelDatabase.class); | |||
if (StringUtils.isEmpty(SwConsts.SysParam.RUN_PROJECTS)) | |||
return dao.query(); | |||
return dao.queryEx(" inner join " + ModelProject.ENTITY_NAME + " on db_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStrs(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"); | |||
return dao.queryEx(" inner join " + ModelProject.ENTITY_NAME + " on db_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStr(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"); | |||
} | |||
public final ModelDatabase getByName(String key) { | |||
@@ -54,7 +54,7 @@ public class ModelTableCache extends AbstractCache<ModelTable> { | |||
protected List<ModelTable> loadAll() { | |||
String sql; | |||
if (!StringUtils.isEmpty(SwConsts.SysParam.RUN_PROJECTS)) { | |||
sql = " inner join " + ModelProject.ENTITY_NAME + " on tb_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStrs(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"; | |||
sql = " inner join " + ModelProject.ENTITY_NAME + " on tb_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStr(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"; | |||
} else sql = ""; | |||
return DbEngine.getInstance().query("SELECT\n" + | |||
"t.tb_id,\n" + | |||
@@ -9,10 +9,8 @@ import org.apache.commons.lang3.StringUtils; | |||
import java.io.Serializable; | |||
import java.lang.reflect.ParameterizedType; | |||
import java.lang.reflect.Type; | |||
import java.text.Collator; | |||
import java.util.Collection; | |||
import java.util.HashSet; | |||
import java.util.Locale; | |||
import java.util.Set; | |||
/** | |||
@@ -68,6 +66,10 @@ public class CommUtil { | |||
return c == null || c.isEmpty(); | |||
} | |||
public static boolean isEmpty(Object[] c) { | |||
return c == null || c.length == 0; | |||
} | |||
/** | |||
* 从DefaultEntity实体转成自己的对象类 | |||
* @param bean | |||
@@ -114,7 +116,7 @@ public class CommUtil { | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static String getSqlInStrs(Collection<String> ids) { | |||
public static String getSqlInStr(Collection<String> ids) { | |||
if (null == ids || ids.isEmpty()) return ""; | |||
StringBuilder s = new StringBuilder(128); | |||
Set<String> set = new HashSet<>(); | |||
@@ -128,7 +130,7 @@ public class CommUtil { | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static String getSqlInStrs(String[] ids) { | |||
public static String getSqlInStr(String[] ids) { | |||
if (null == ids || ids.length == 0) return ""; | |||
StringBuilder s = new StringBuilder(128); | |||
Set<String> set = new HashSet<>(); | |||
@@ -141,4 +143,14 @@ public class CommUtil { | |||
if (s.length() == 0) return ""; | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static String getOrigMsg(Throwable e) { | |||
String s = e.getMessage(); | |||
Throwable t = e.getCause(); | |||
while (t != null) { | |||
s = t.getMessage(); | |||
t = t.getCause(); | |||
} | |||
return s; | |||
} | |||
} |
@@ -1,7 +1,6 @@ | |||
package cc.smtweb.framework.core.util; | |||
import org.apache.commons.lang3.time.DateUtils; | |||
import org.springframework.util.unit.DataUnit; | |||
import java.sql.Timestamp; | |||
import java.text.DateFormat; | |||
@@ -101,7 +100,7 @@ public class DateUtil { | |||
* @return yyyy-mm-dd | |||
*/ | |||
public static String toStdDateString(String s) { | |||
if (PubUtil.isEmptyId(s)) return ""; | |||
if (StringUtil.isEmpty(s)) return ""; | |||
if (s.contains("-")) return s; | |||
return toStdDateString(s, "-", false); | |||
} | |||
@@ -114,7 +113,7 @@ public class DateUtil { | |||
* @return 用分隔符,如“-”,“.”进行分割后的日期串; | |||
*/ | |||
public static String toStdDateString(String s, String split, boolean returnEmptyIfErrDate) { | |||
if (PubUtil.isEmptyId(s)) return ""; | |||
if (StringUtil.isEmpty(s)) return ""; | |||
try { | |||
if (s == null || s.length() < 8) { | |||
return returnEmptyIfErrDate ? "" : s; | |||
@@ -714,10 +713,10 @@ public class DateUtil { | |||
* @return boolean 如果为日期格式则返回=true; | |||
*/ | |||
public static boolean isDateFormat(String strDate, String format) { | |||
if (PubUtil.isEmpty(strDate)) { | |||
if (StringUtil.isEmpty(strDate)) { | |||
return false; | |||
} | |||
if (PubUtil.isEmpty(format)) { | |||
if (StringUtil.isEmpty(format)) { | |||
format = "YYYY-MM-DD"; | |||
} | |||
switch (format) { | |||
@@ -812,12 +811,14 @@ public class DateUtil { | |||
*/ | |||
public static java.sql.Date toDate(String src) { | |||
try { | |||
if (PubUtil.isEmpty(src)) return null; | |||
if (StringUtil.isEmpty(src)) return null; | |||
return java.sql.Date.valueOf(src); | |||
} catch (Exception e) { | |||
return null; | |||
} | |||
} | |||
/** | |||
* 得到长日期时间字符[yyyyMMddHHmmss] | |||
* | |||
@@ -877,7 +878,7 @@ public class DateUtil { | |||
* @param yearMonth YYYYMM | |||
*/ | |||
public static String fmtCNYearMonth(String yearMonth) { | |||
if (PubUtil.getIntIgnoreErr(yearMonth) > 190000) | |||
if (NumberUtil.getIntIgnoreErr(yearMonth) > 190000) | |||
return String.format("%s年%s月", yearMonth.substring(0, 4), yearMonth.substring(4)); | |||
return ""; | |||
} | |||
@@ -887,7 +888,7 @@ public class DateUtil { | |||
* @param yearMonth YYYYMMDD | |||
*/ | |||
public static String fmtCNYearMonthDay(String yearMonth) { | |||
if (PubUtil.isEmptyId(yearMonth) || yearMonth.length() != 8) return yearMonth; | |||
if (StringUtil.isEmpty(yearMonth) || yearMonth.length() != 8) return yearMonth; | |||
return String.format("%s年%s月%s日", yearMonth.substring(0, 4), yearMonth.substring(4, 6), yearMonth.substring(6)); | |||
} | |||
@@ -1077,7 +1078,7 @@ public class DateUtil { | |||
return getDateYm(nowTimestamp()); | |||
} | |||
public static String getNextYear(String year, int add) { | |||
if (PubUtil.isEmptyId(year)) return year; | |||
if (StringUtil.isEmpty(year)) return year; | |||
int curYear = Integer.parseInt(year) - 1; | |||
return curYear + ""; | |||
} | |||
@@ -1110,7 +1111,7 @@ public class DateUtil { | |||
return getNextYm(getNowYm()); | |||
} | |||
public static String getNextYm(String period_id, int add) { | |||
if (PubUtil.isEmptyId(period_id)) return period_id; | |||
if (StringUtil.isEmpty(period_id)) return period_id; | |||
int curYear = Integer.parseInt(period_id.substring(0, 4)); | |||
int curMonth = Integer.parseInt(period_id.substring(4)) + add; | |||
if (curMonth > 12) { | |||
@@ -1226,4 +1227,43 @@ public class DateUtil { | |||
public static void main(String[] args) { | |||
System.out.println(getTimesmorning()); | |||
} | |||
/** | |||
* 转日期时间long | |||
* | |||
* @param dateStr | |||
* @return | |||
*/ | |||
public static long getDateTimeLong(String dateStr) { | |||
if (StringUtil.isEmpty(dateStr)) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); | |||
_dateTime = StringUtil.getLeft(_dateTime + "00000000000000", 14); | |||
return NumberUtil.getLongIgnoreErr(_dateTime); | |||
} | |||
public static long getDateLong(String dateStr) { | |||
if (StringUtil.isEmpty(dateStr) || dateStr.length() != 10) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", ""); | |||
return NumberUtil.getLongIgnoreErr(_dateTime); | |||
} | |||
/** | |||
* 转日期时间long | |||
* | |||
* @param dateStr | |||
* @return | |||
*/ | |||
public static long getEndDateTimeLong(String dateStr) { | |||
if (StringUtil.isEmpty(dateStr)) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); | |||
_dateTime = StringUtil.getLeft(_dateTime + "00000000", 8) + "235959"; | |||
return NumberUtil.getLongIgnoreErr(_dateTime); | |||
} | |||
} |
@@ -13,7 +13,7 @@ public class EmojiFilter { | |||
* @return | |||
*/ | |||
public static String filterEmoji(String source) { | |||
if(PubUtil.isEmpty(source)){ | |||
if(StringUtil.isEmpty(source)){ | |||
return ""; | |||
} | |||
if (!containsEmoji(source)) { | |||
@@ -1,781 +0,0 @@ | |||
package cc.smtweb.framework.core.util; | |||
import cc.smtweb.framework.core.common.AbstractEnum; | |||
import cc.smtweb.framework.core.common.IntEnum; | |||
import cc.smtweb.framework.core.common.StrEnum; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.List; | |||
/** | |||
* 注意:where参数表示是否已经加入了where关键字 | |||
* | |||
* @author : AKzz | |||
* @version : $Revision:$ | |||
*/ | |||
@SuppressWarnings("UnusedDeclaration") | |||
@Deprecated | |||
public abstract class ListSQLParaHelper { | |||
/** | |||
* 补充SQL的字符串的==条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, int condition_value) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" = ? \n"); | |||
args.add(condition_value); | |||
return true; | |||
} | |||
/** | |||
* 补充SQL的字符串的==条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" = ? \n"); | |||
args.add(condition_value); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_lesser(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" <= ? \n"); | |||
args.add(condition_value); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_greater(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" >= ? \n"); | |||
args.add(condition_value); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(仅后匹配) %s | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_EX(boolean where_is_exist, StringBuilder sql, List<Object> args, String condition_value, String... db_field_name) { | |||
if (db_field_name == null || db_field_name.length == 0) return where_is_exist; | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
if (db_field_name.length == 1) { | |||
sql.append(db_field_name[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
return where_is_exist; | |||
} | |||
sql.append(" ("); | |||
for (String db_filed : db_field_name) { | |||
sql.append(" ").append(db_filed).append(" LIKE ? \nOR"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
sql.delete(sql.length() - 2, sql.length()); | |||
sql.append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(仅后匹配) s% | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(全模糊) %s% | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (PubUtil.isNotEmptyStr(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? "); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" OR ").append(db_field_names[i]).append(" LIKE ? "); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL字符串的IN条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_IN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { | |||
if (expr != null && expr.length > 0) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" IN (").append(StringUtils.join(expr, ',')).append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL字符串的not IN条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_NOTIN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { | |||
if (expr != null && expr.length > 0) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" NOT IN (").append(StringUtils.join(expr, ',')).append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 增加字符串字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值,包含','为多选 | |||
* @param sql sql | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConMulti(String field, String value, StringBuilder sql, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
if (value.contains(",")) {//多选 | |||
sql.append(" and ").append(field).append(" in ('").append(value.replaceAll(",", "','")).append("')"); | |||
} else if (!Consts.NULL_STRING.equals(value)) {//单 | |||
sql.append(" and ").append(field).append("=?"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件,不判断多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingle(String field, String value, StringBuilder sb, List<Object> paras) { | |||
addStrConSingle(field, "=", value, sb, paras); | |||
} | |||
/** | |||
* 增加字符串字段条件,不判断多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param opt 逻辑运算符 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingle(String field, String opt, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append(" ").append(opt).append(" ? \n"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件,包含 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingleLike(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append(" like ? \n"); | |||
paras.add("%" + value + "%"); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件并且不区分大小写,包含 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingleLikeIgnoreCase(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) { | |||
String valueLower = value.toLowerCase(); | |||
sb.append(" and ").append("lower(").append(field).append(")").append(" like ? \n"); | |||
paras.add("%" + valueLower + "%"); | |||
} | |||
} | |||
/** | |||
* 增加数字字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值,包含','为多选 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumberConMulti(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmptyId(value)) | |||
return; | |||
if (value.contains(",")) {//多选 | |||
sb.append(" and ").append(field).append(" in (").append(value).append(") \n"); | |||
} else if (!Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append("=? \n"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加数字字段条件,单选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumConSingle(String field, Number value, StringBuilder sb, List<Object> paras) { | |||
addNumConSingle(field, "=", value, sb, paras); | |||
} | |||
/** | |||
* 增加数字字段条件,单选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param opt 运算符 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumConSingle(String field, String opt, Number value, StringBuilder sb, List<Object> paras) { | |||
sb.append(" and ").append(field).append(opt).append("? \n"); | |||
paras.add(value); | |||
} | |||
/** | |||
* 增加日期字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
@Deprecated | |||
public static void addDateCon(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = PubUtil.getCurDateStr(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 考虑日期时间的情况 | |||
sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 1)).append("' \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 8)).append("' \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getMonthStart()).append("' and ").append(field).append("<='").append(DateUtil.getMonthEnd()).append(" 23:59:59' \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getSeasonFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getSeasonLastDay()).append(" 23:59:59' \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getYearFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getYearLastDay()).append(" 23:59:59' \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) | |||
return; | |||
if (PubUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(de); | |||
} else if (PubUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(df); | |||
} else { | |||
sb.append(" and ").append(field).append(">=? and ").append(field).append("<=? \n"); | |||
paras.add(df); | |||
paras.add(de); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 增加日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addDateConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = PubUtil.getCurDateStr(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 | |||
sb.append(" and ").append(field).append("=").append(PubUtil.getDateLong(s)).append(" \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(s)).append(" and ").append(PubUtil.getDateLong(DateUtil.getAfterDays(s, 7))).append(" \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getMonthStart())).append(" and ").append(PubUtil.getDateLong(DateUtil.getMonthEnd())).append(" \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getSeasonFirstDay())).append(" and ").append(PubUtil.getDateLong(DateUtil.getSeasonLastDay())).append(" \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getYearFirstDay())).append(" and ").append(PubUtil.getDateLong(DateUtil.getYearLastDay())).append(" \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) | |||
return; | |||
if (PubUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(PubUtil.getDateLong(de)); | |||
} else if (PubUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(PubUtil.getDateLong(df)); | |||
} else { | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(PubUtil.getDateLong(df)); | |||
paras.add(PubUtil.getDateLong(de)); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 增加期间查询日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addPeriodDateConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(df + "01"); | |||
paras.add(de + "31"); | |||
} | |||
/** | |||
* 增加日期时间字段条件 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addDateTimeConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = PubUtil.getCurDateStr(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(s)).append(" and ").append(PubUtil.getEndDateTimeLong(s)).append(" \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(s)).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getAfterDays(s, 6))).append(" \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getMonthStart())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getMonthEnd())).append(" \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getSeasonFirstDay())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getSeasonLastDay())).append(" \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getYearFirstDay())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getYearLastDay())).append(" \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) | |||
return; | |||
if (PubUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(PubUtil.getEndDateTimeLong(de)); | |||
} else if (PubUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(PubUtil.getDateTimeLong(df)); | |||
} else { | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(PubUtil.getDateTimeLong(df)); | |||
paras.add(PubUtil.getEndDateTimeLong(de)); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 枚举状态字段,in方式 | |||
* | |||
* @param where_is_exist sql是否已包括where | |||
* @param field sql字段名 | |||
* @param value 前端传回来的查询值,格式:1,1,1,1 | |||
* @param intEnum 枚举类型 | |||
* @param sql 待构建的sql | |||
*/ | |||
public static void addIntEnumCon(boolean where_is_exist, String field, String value, IntEnum intEnum, StringBuilder sql) { | |||
if (PubUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
String s = ""; | |||
String[] ss = value.split(","); | |||
int i = 0; | |||
for (AbstractEnum.IntEnumBean b : intEnum.values()) { | |||
if (ss.length > i && "1".equals(ss[i])) s += "," + b.value; | |||
i++; | |||
} | |||
sql.append(field + " in (" + s.substring(1) + ")"); | |||
} | |||
} | |||
/** | |||
* 枚举状态字段,in方式 | |||
* | |||
* @param where_is_exist sql是否已包括where | |||
* @param field sql字段名 | |||
* @param value 前端传回来的查询值,格式:1,1,1,1 | |||
* @param intEnum 枚举类型 | |||
* @param sql 待构建的sql | |||
*/ | |||
public static void addStrEnumCon(boolean where_is_exist, String field, String value, StrEnum intEnum, StringBuilder sql) { | |||
if (PubUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
String s = ""; | |||
String[] ss = value.split(","); | |||
int i = 0; | |||
for (AbstractEnum.StrEnumBean b : intEnum.values()) { | |||
if (ss.length > i && "1".equals(ss[i])) s += ",'" + b.value + "'"; | |||
i++; | |||
} | |||
sql.append(field + " in (" + s.substring(1) + ")"); | |||
} | |||
} | |||
public static void addTreeStateCon(String curPrefix, String value, String tableName, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value) && !value.contains(",")) { | |||
int v = PubUtil.getIntIgnoreErr(value); | |||
if (v == 0) {//查启用 自己启用,且父亲未停用 | |||
sb.append(" and ").append(curPrefix).append(".f_status=0 and not exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%')"); | |||
} else {//查停用 自己停用 或父亲被停用 | |||
sb.append(" and (").append(curPrefix).append(".f_status=1 or exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%'))"); | |||
} | |||
} | |||
} | |||
/** | |||
* 增加年月字段条件 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addYmCon(String field, String value, StringBuilder sb, List<Object> paras) { | |||
addYmConEx(field, field, value, sb, paras); | |||
} | |||
public static void addYmConEx(String field_begin, String field_end, String value, StringBuilder sb, List<Object> paras) { | |||
if (PubUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = PubUtil.getCurDateStr(); | |||
if (st.length > 1) { | |||
switch (st[0]) { | |||
case "M": //本月 | |||
String nowYm = DateUtil.getNowYm(); | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) | |||
return; | |||
if (PubUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field_begin).append("<=?"); | |||
paras.add(de); | |||
} else if (PubUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field_end).append(">=?"); | |||
paras.add(df); | |||
} else { | |||
sb.append(" and ").append(field_end).append(">=? and ").append(field_begin).append("<=?"); | |||
paras.add(df); | |||
paras.add(de); | |||
} | |||
break; | |||
} | |||
} else if (st.length == 1) { | |||
sb.append(" and ").append(field_end).append(">='").append(value).append("' and ").append(field_begin).append("<='").append(value).append("'"); | |||
} | |||
} | |||
//构建年月范围的sql | |||
public static String getYmConSql(String field, String value) { | |||
return getYmConSqlEx(field, field, value); | |||
} | |||
public static String getYmConSqlEx(String field_begin, String field_end, String value) { | |||
if (PubUtil.isEmpty(value)) return ""; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) return ""; | |||
String s = PubUtil.getCurDateStr(); | |||
StringBuilder sb = new StringBuilder(128); | |||
switch (st[0]) { | |||
case "M": //本月 | |||
String nowYm = DateUtil.getNowYm(); | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) | |||
return ""; | |||
if (PubUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field_begin).append("<='").append(de).append("'"); | |||
} else if (PubUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field_end).append(">='").append(df).append("'"); | |||
} else { | |||
sb.append(" and ").append(field_end).append(">='").append(df).append("' and ").append(field_begin).append("<='").append(de).append("'"); | |||
} | |||
break; | |||
} | |||
return sb.substring(5); | |||
} | |||
} |
@@ -216,7 +216,7 @@ public class MapUtil { | |||
public static List<String> readStringList(SwMap swMap, String name) { | |||
Object value = swMap.get(name); | |||
if (value != null && PubUtil.isNotEmpty(value.toString())) { | |||
if (value != null && StringUtil.isNotEmpty(value.toString())) { | |||
return Arrays.asList(value.toString().split(",")); | |||
} | |||
return null; | |||
@@ -1,464 +0,0 @@ | |||
package cc.smtweb.framework.core.util; | |||
import java.math.BigDecimal; | |||
import java.math.RoundingMode; | |||
import java.text.DecimalFormat; | |||
/** | |||
* Created with IntelliJ IDEA. | |||
* User: AKhh | |||
* Date: 12-12-25 下午1:02 | |||
* To change this template use File | Settings | File Templates. | |||
*/ | |||
@Deprecated | |||
public class MathUtil { | |||
//整数 | |||
private static DecimalFormat dfLng = new DecimalFormat("##############0"); | |||
private static DecimalFormat dfLong = new DecimalFormat("###,###,###,###,##0"); | |||
//一位小数 | |||
private static DecimalFormat df1 = new DecimalFormat("##############0.0"); | |||
private static DecimalFormat df1Format = new DecimalFormat("###,###,###,###,##0.0"); | |||
//两位小数 | |||
private static DecimalFormat df2 = new DecimalFormat("##############0.00"); | |||
private static DecimalFormat df2Format = new DecimalFormat("###,###,###,###,##0.00"); | |||
//四位小数 | |||
private static DecimalFormat df4 = new DecimalFormat("###,###,###,###,##0.0000"); | |||
//六位小数 | |||
private static DecimalFormat df6Number = new DecimalFormat("#######################0.000000"); | |||
private static DecimalFormat df6NumberF = new DecimalFormat("#,###,###,###,###,###,##0.000000"); | |||
public final static DecimalFormat stdAmountFormat = new DecimalFormat("###,###,###,###,##0.00"); | |||
public final static DecimalFormat stdNumberFormat = new DecimalFormat("#0.00"); | |||
public final static String DEF_NUM_TEN_THOUSAND = "10000";//万 | |||
public static final double MAX_VALUE = 9999999999999.99D; | |||
public static final double MIN_VALUE = -9999999999999.99D; | |||
private final static BigDecimal ONE_BIG = new BigDecimal(1.00D); | |||
private static final String UNIT = "万仟佰拾亿仟佰拾万仟佰拾元角分"; | |||
private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖"; | |||
/** | |||
* 4舍5入double,2位小数 | |||
*/ | |||
public static double roundDouble(double src) { | |||
return roundDouble(src, 2); | |||
} | |||
/** | |||
* 4舍5入double,N 位小数 | |||
* @param src | |||
* @param scale 小数位数 | |||
* @return | |||
*/ | |||
public static double roundDouble(Object src, int scale) { | |||
if (src == null) return 0.0; | |||
String v = src.toString(); | |||
if (PubUtil.isEmpty(v)) return 0.0; | |||
if (scale < 0) scale = 2; | |||
BigDecimal src_b = new BigDecimal(v); | |||
BigDecimal src_v = src_b.divide(ONE_BIG, scale + 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 | |||
src_v = src_v.divide(ONE_BIG, scale, BigDecimal.ROUND_HALF_UP);// 4舍5入 | |||
return src_v.doubleValue(); | |||
} | |||
/** | |||
* 舍位处理,原生floor有坑,部分浮点数记录为.99999999999形式,导致floor结果错误 | |||
* @param d | |||
* @return | |||
*/ | |||
public static double floor(double d) { | |||
return Math.floor(roundDouble(d, 2)); | |||
} | |||
/** | |||
* 比较两Double是否相等,将会吧他们专程BigDecimal进行比较; | |||
* | |||
* @param src double1 | |||
* @param tag double2 | |||
* @return src > tag 返回1, src < tag 返回-1, 否则返回0 | |||
*/ | |||
public static int compare(double src, double tag) { | |||
BigDecimal src_b = new BigDecimal(src); | |||
BigDecimal src_v = src_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 | |||
BigDecimal tag_b = new BigDecimal(tag); | |||
BigDecimal tag_v = tag_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 | |||
return src_v.compareTo(tag_v); | |||
} | |||
/** | |||
* 自动过滤金额中的逗号转换为double,如果出错,则返回0 | |||
* | |||
* @param s 源串,可能为带逗号的金额串; | |||
* @return double | |||
*/ | |||
public static Double toDouble(String s) { | |||
return todouble(s); | |||
} | |||
/** | |||
* 自动过滤金额中的逗号转换为double,如果出错,则返回0 | |||
* | |||
* @param s 源串,可能为带逗号的金额串; | |||
* @return double | |||
*/ | |||
public static double todouble(String s) { | |||
try { | |||
return Double.parseDouble(s.replaceAll(",", "")); | |||
} catch (Exception e) { | |||
return 0.00; | |||
} | |||
} | |||
/** | |||
* 获取double,主要过滤d为null的情况; | |||
* | |||
* @param d Double对象; | |||
* @return double | |||
*/ | |||
public static double todouble(Double d) { | |||
if (d == null) return 0.0d; | |||
return d.doubleValue(); | |||
} | |||
/** | |||
* 自动过滤金额中的逗号转换为float,如果出错,则返回0 | |||
* | |||
* @param s 源串,可能为带逗号的金额串; | |||
* @return Float | |||
*/ | |||
public static Float toFloat(String s) { | |||
return tofloat(s); | |||
} | |||
/** | |||
* 自动过滤金额中的逗号转换为float,如果出错,则返回0 | |||
* | |||
* @param s 源串,可能为带逗号的金额串; | |||
* @return Float | |||
*/ | |||
public static float tofloat(String s) { | |||
try { | |||
return Float.parseFloat(s.replaceAll(",", "")); | |||
} catch (Exception e) { | |||
return 0.0f; | |||
} | |||
} | |||
public static long tolong(String src, long defaultvalue) { | |||
try { | |||
return Long.parseLong(src); | |||
} catch (Exception e) { | |||
return defaultvalue; | |||
} | |||
} | |||
public static int toint(String src, int defaultvalue) { | |||
try { | |||
return Integer.parseInt(src); | |||
} catch (Exception e) { | |||
return defaultvalue; | |||
} | |||
} | |||
/** | |||
* 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 | |||
* | |||
* @param value double类型 | |||
* @return boolean | |||
*/ | |||
public static boolean isBigThanZero(double value) { | |||
return (value > 0.00001); | |||
} | |||
/** | |||
* 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 | |||
* | |||
* @param value String类型 | |||
* @return boolean | |||
*/ | |||
public static boolean isBigThanZero(String value) { | |||
return !PubUtil.isEmpty(value) && isBigThanZero(toDouble(value)); | |||
} | |||
/** | |||
* 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 | |||
* | |||
* @param value double类型 | |||
* @return boolean | |||
*/ | |||
public static boolean isEqualsZero(double value) { | |||
return (-0.00001 < value && value < 0.00001); | |||
} | |||
/** | |||
* 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 | |||
* | |||
* @param value String类型 | |||
* @return boolean | |||
*/ | |||
public static boolean isEqualsZero(String value) { | |||
return PubUtil.isEmpty(value) || isEqualsZero(toDouble(value)); | |||
} | |||
/** | |||
* 是否是负数 | |||
* | |||
* @param db_val 要判断的double | |||
* @return 负数则返回true; | |||
*/ | |||
public static boolean isNegative(double db_val) { | |||
return (compare(db_val, 0.00D) == -1); | |||
} | |||
/** | |||
* 是否是正数 | |||
* | |||
* @param db_val 要判断的double | |||
* @return 正数则返回true; | |||
*/ | |||
public static boolean isPlus(double db_val) { | |||
return (compare(db_val, 0.00D) == 1); | |||
} | |||
/** | |||
* 得到金额字符串,保持小数点2位 | |||
* | |||
* @param db 将double转换为金额字符串; | |||
* @return 金额字符串#0.00; | |||
*/ | |||
public static String toStdNumberString(double db) { | |||
try { | |||
return stdNumberFormat.format(db); | |||
} catch (Exception e) { | |||
return "0.00"; | |||
} | |||
} | |||
public static String toStdNumberStringEx(double db) { | |||
try { | |||
if (compare(db, -1d) == 0) return "-"; | |||
return stdNumberFormat.format(db); | |||
} catch (Exception e) { | |||
return "0.00"; | |||
} | |||
} | |||
/** | |||
* 将金额格式字符串,如23,333,093.01 去掉逗号 | |||
* | |||
* @param s 金额串 | |||
* @return String 去掉逗号后的串,如果amount为空,则返回0.00 | |||
*/ | |||
public static String toStdNumberString(String s) { | |||
if (PubUtil.isEmpty(s)) | |||
return "0.00"; | |||
return stdNumberFormat.format(todouble(s)); | |||
} | |||
/** | |||
* 将数据转换为两位小数的数字格式; | |||
* | |||
* @param d 数据 | |||
* @param isZeroToEmpty 如果未0,是否返回“”; | |||
* @return 两位小数的字符串; | |||
*/ | |||
public static String toStdNumberString(double d, boolean isZeroToEmpty) { | |||
if (isEqualsZero(d)) { | |||
return isZeroToEmpty ? "": "0.00"; | |||
} | |||
return stdNumberFormat.format(d); | |||
} | |||
public static String toStdNumberString(String s, boolean isZeroToEmpty) { | |||
return toStdNumberString(todouble(s), isZeroToEmpty); | |||
} | |||
public static String toStdNumberString(double d, int scale) { | |||
DecimalFormat dfn = null; | |||
if (scale == 1) dfn = df1Format; | |||
if (scale == 2) dfn = df2Format; | |||
else if (scale == 4) dfn = df4; | |||
else if (scale == 6) dfn = df6NumberF; | |||
else if (scale <= 0) dfn = dfLong; | |||
else { | |||
StringBuilder sb = new StringBuilder("###,###,###,###,##0."); | |||
for (int i = 0; i < scale; i++) sb.append("0"); | |||
dfn = new DecimalFormat(sb.toString()); | |||
} | |||
return dfn.format(d); | |||
} | |||
/** | |||
* 将数字乘100,保留小数点后两位, 然后后面添加% | |||
* | |||
* @param d 值 | |||
* @param isZeroToEmpty,如果值为0,是否返回空; | |||
* @return 字符串; | |||
*/ | |||
public static String toStdPercentNumberStr(double d, boolean isZeroToEmpty) { | |||
if (d > -0.00000000001 && d < 0.00000000001) { | |||
return isZeroToEmpty ? "": "0.00%"; | |||
} | |||
return toStdNumberString(d * 100) + "%"; | |||
} | |||
public static String toStdAmountString(double d) { | |||
return toStdAmountString(d, false); | |||
} | |||
/** | |||
* 将数据转换为两位小数的金额格式,带逗号; | |||
* | |||
* @param d 数据 | |||
* @param isZeroToEmpty 如果未0,是否返回“”; | |||
* @return 金额格式的字符串; | |||
*/ | |||
public static String toStdAmountString(double d, boolean isZeroToEmpty) { | |||
if (isEqualsZero(d)) { | |||
return isZeroToEmpty ? "": "0.00"; | |||
} | |||
return stdAmountFormat.format(d); | |||
} | |||
public static String toStdAmountString(String s) { | |||
return toStdAmountString(todouble(s), false); | |||
} | |||
public static String toStdAmountString(String s, boolean isZeroToEmpty) { | |||
return toStdAmountString(todouble(s), isZeroToEmpty); | |||
} | |||
/** | |||
* 将小写金额转换为人民币大写金额 | |||
* | |||
* @param s 金额格式的串 | |||
* @return String 转换结果 | |||
*/ | |||
public static String toCapsAmountString(String s) { | |||
if (PubUtil.isEmpty(s)) return ""; | |||
return toCapsAmountString(todouble(s)); | |||
} | |||
/** | |||
* 将小写金额转换为人民币大写金额 | |||
* | |||
* @param v double | |||
* @return String 转换结果 | |||
*/ | |||
public static String toCapsAmountString(double v) { | |||
if (v < MIN_VALUE || v > MAX_VALUE) return "参数非法!"; | |||
boolean negative = isNegative(v); | |||
if (negative) v = Math.abs(v); | |||
long l = Math.round(v * 100); | |||
if (l == 0) return "零元整"; | |||
String strValue = String.valueOf(l); | |||
// i用来控制数 | |||
int i = 0; | |||
// j用来控制单位 | |||
int j = UNIT.length() - strValue.length(); | |||
StringBuilder rs = new StringBuilder(32); | |||
boolean isZero = false; | |||
for (; i < strValue.length(); i++, j++) { | |||
char ch = strValue.charAt(i); | |||
if (ch == '0') { | |||
isZero = true; | |||
if (UNIT.charAt(j) == '亿' || UNIT.charAt(j) == '万' || UNIT.charAt(j) == '元') { | |||
rs.append(UNIT.charAt(j)); | |||
isZero = false; | |||
} | |||
} else { | |||
if (isZero) { | |||
rs.append('零'); | |||
isZero = false; | |||
} | |||
rs.append(DIGIT.charAt(ch - '0')).append(UNIT.charAt(j)); | |||
} | |||
} | |||
if (rs.charAt(rs.length() - 1) != '分') | |||
rs.append('整'); | |||
i = rs.indexOf("亿万"); | |||
if (i > 0) rs.delete(i + 1, i + 2); // i+1 ->万 | |||
if (negative) | |||
return rs.insert(0, '负').toString(); | |||
else | |||
return rs.toString(); | |||
} | |||
/** | |||
* 返回0 到 maxvalue的随机数 | |||
* | |||
* @param maxvalue 随机数的最大值 | |||
* @return int | |||
*/ | |||
public static int rnd(int maxvalue) { | |||
return (int) (Math.random() * (maxvalue + 1)); | |||
} | |||
public static double chkDbNull(Double v) { | |||
return v == null ? 0: v; | |||
} | |||
public static double max(double d1, double d2) { | |||
return compare(d1, d2) < 0 ? d2 : d1; | |||
} | |||
public static double min(double d1, double d2) { | |||
return compare(d1, d2) < 0 ? d1 : d2; | |||
} | |||
public static void main(String[] args) { | |||
double aa=123456789.345678900005; | |||
System.out.println("args0 = " + upDouble(aa,0)); | |||
System.out.println("args1 = " + upDouble(aa,1)); | |||
System.out.println("args2 = " + upDouble(aa,2)); | |||
System.out.println("args3 = " + upDouble(aa,3)); | |||
System.out.println("args4 = " + upDouble(aa,4)); | |||
System.out.println("args5 = " + upDouble(aa,5)); | |||
System.out.println("args5 = " + upDouble(aa,6)); | |||
System.out.println("args5 = " + upDouble(aa,7)); | |||
System.out.println("args5 = " + upDouble(aa,8)); | |||
} | |||
/** | |||
* double 去尾法 | |||
* @param src 待处理数据 | |||
* @param scale 保留小数位数 | |||
* @return | |||
*/ | |||
public static double cutDouble(double src, int scale){ | |||
String v = toStdNumberString(src, 6);//先到6位小数,再去计算,否则容易出错,如8.3成8.29999999999,舍位就成了8.29了 | |||
DecimalFormat formater = new DecimalFormat(); | |||
formater.setMaximumFractionDigits(scale); | |||
formater.setGroupingSize(0); | |||
formater.setRoundingMode(RoundingMode.FLOOR); | |||
return new BigDecimal(formater.format(toDouble(v))).doubleValue(); | |||
} | |||
/** | |||
* double 进位法 | |||
* @param src 待处理数据 | |||
* @param scale 保留小数位数 | |||
* @return | |||
*/ | |||
public static double upDouble(double src, int scale){ | |||
String v = toStdNumberString(src, 6);//先到6位小数,再去计算 | |||
DecimalFormat formater = new DecimalFormat(); | |||
formater.setMaximumFractionDigits(scale); | |||
formater.setGroupingSize(0); | |||
formater.setRoundingMode(RoundingMode.UP); | |||
return new BigDecimal(formater.format(toDouble(v))).doubleValue(); | |||
} | |||
} |
@@ -1,780 +0,0 @@ | |||
package cc.smtweb.framework.core.util; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.lang3.ArrayUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.io.UnsupportedEncodingException; | |||
import java.sql.Date; | |||
import java.sql.Timestamp; | |||
import java.text.Collator; | |||
import java.text.DecimalFormat; | |||
import java.text.SimpleDateFormat; | |||
import java.util.*; | |||
import java.util.function.Function; | |||
import java.util.regex.Matcher; | |||
import java.util.regex.Pattern; | |||
/** | |||
* Created with IntelliJ IDEA. | |||
* User: AKhh | |||
* Date: 12-12-26 下午11:55 | |||
* 基础工具类; | |||
*/ | |||
@SuppressWarnings("UnusedDeclaration") | |||
@Slf4j | |||
@Deprecated | |||
public class PubUtil { | |||
private static SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd"); | |||
private static SimpleDateFormat tFormat = new SimpleDateFormat("HH:mm:ss"); | |||
private static SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
private static SimpleDateFormat dLFormat = new SimpleDateFormat("yyyyMMddHHmmss"); | |||
private static SimpleDateFormat dLFormat2 = new SimpleDateFormat("yyyyMMdd"); | |||
private static DecimalFormat df2Format = new DecimalFormat("###,###,###,###,##0.00"); | |||
private static DecimalFormat df2 = new DecimalFormat("##############0.00"); | |||
private static DecimalFormat df = new DecimalFormat("#.##"); | |||
public static boolean isEmpty(String str) { | |||
return str == null || str.trim().length() == 0; | |||
} | |||
//判断 是否支持GBK | |||
public static boolean supportGBK(String str){ | |||
if(str == null){ | |||
return true; | |||
} | |||
try { | |||
return str.equals ( new String (str.getBytes ("gbk"),"gbk") ); | |||
}catch (Exception e){ | |||
log.error ( "判断【"+str+"】是否支持GBK时出现异常:"+e.getMessage () ); | |||
e.printStackTrace (); | |||
return false; | |||
} | |||
} | |||
public static boolean isEmpty(Collection collection) { | |||
return collection == null || collection.size() == 0; | |||
} | |||
public static boolean isEmpty(Object[] o) { | |||
return o == null || o.length == 0; | |||
} | |||
public static boolean isEmptyStr(String str) { | |||
return str == null || str.trim().length() == 0 || "-".equals(str) || "-1".equals(str); | |||
} | |||
//判断Id是否为空id,有可能是"-","-1" | |||
public static boolean isEmptyId(String id) { | |||
return id == null || id.trim().length() == 0 || "-".equals(id) || "-1".equals(id) || "null".equals(id) || "(无)".equals(id); | |||
} | |||
public static boolean isNotEmpty(String str) { | |||
return !isEmpty(str); | |||
} | |||
public static boolean isNotEmptyId(String str) { | |||
return !isEmptyId(str); | |||
} | |||
public static boolean isNotEmptyStr(String str) { | |||
return !isEmptyStr(str); | |||
} | |||
public static boolean isNotEmpty(Collection collection) { | |||
return !isEmpty(collection); | |||
} | |||
public static boolean isNotEmpty(Object[] o) { | |||
return !isEmpty(o); | |||
} | |||
/** | |||
* 获取浮点数(有错误默认为0),可以识别金额中的逗号格式 | |||
* | |||
* @param str 带转换的字符串 | |||
* @return 浮点数 | |||
*/ | |||
public static double getDoubleIgnoreErr(String str) { | |||
if (str == null) | |||
return 0.0; | |||
str = str.trim(); | |||
if (str.equals("")) | |||
return 0.0; | |||
str = str.replaceAll(",", "").replaceAll(",", ""); | |||
try { | |||
return Double.valueOf(str); | |||
} catch (Exception e) { | |||
return 0.0; | |||
} | |||
} | |||
/** | |||
* 得到int 获取转换的int值,有错返回0 | |||
* | |||
* @param str 带转换的字符串 | |||
* @return int | |||
*/ | |||
public static int getIntIgnoreErr(String str) { | |||
return getIntIgnoreErr(str, 0); | |||
} | |||
public static int getIntIgnoreErr(String str, int defValue) { | |||
if (str == null) | |||
return defValue; | |||
str = str.trim(); | |||
if (str.equals("")) | |||
return defValue; | |||
str = str.replaceAll(",", "").replaceAll(",", ""); | |||
if (str.contains(".")) | |||
str = str.substring(0, str.indexOf('.')); | |||
try { | |||
return Integer.valueOf(str); | |||
} catch (Exception e) { | |||
return defValue; | |||
} | |||
} | |||
/** | |||
* 得到Long 获取转换的Long值,有错返回0 | |||
* | |||
* @param str 带转换的字符串 | |||
* @return long | |||
*/ | |||
public static long getLongIgnoreErr(String str) { | |||
return getLongIgnoreErr(str, 0L); | |||
} | |||
public static long getLongIgnoreErr(String str, long defValue) { | |||
if (str == null) | |||
return defValue; | |||
str = str.trim(); | |||
if (str.equals("")) | |||
return defValue; | |||
str = str.replaceAll(",", "").replaceAll(",", ""); | |||
try { | |||
return Long.valueOf(str); | |||
} catch (Exception e) { | |||
return defValue; | |||
} | |||
} | |||
public static String getDateStrIgnoreNull(Timestamp obj) { | |||
if (obj == null) | |||
return ""; | |||
return dFormat.format(obj); | |||
} | |||
public static String getTimeStrIgnoreNull(Timestamp obj) { | |||
if (obj == null) | |||
return ""; | |||
return tFormat.format(obj); | |||
} | |||
public static Date getCurDate() { | |||
return new Date(System.currentTimeMillis()); | |||
} | |||
public static String getCurDateStr() { | |||
return dFormat.format(new Date(System.currentTimeMillis())); | |||
} | |||
public static Timestamp getCurDatetime() { | |||
return new Timestamp(System.currentTimeMillis()); | |||
} | |||
public static String getCurDatetimeStr() { | |||
return dtFormat.format(new Timestamp(System.currentTimeMillis())); | |||
} | |||
public static String getCurDatetimeShortStr() { | |||
return dLFormat.format(new Timestamp(System.currentTimeMillis())); | |||
} | |||
/** | |||
* Func:为空,返回"" | |||
* | |||
* @param str 带检查的字符串 | |||
* @return "" | |||
*/ | |||
public static String checkNull(String str) { | |||
if (isEmpty(str)) | |||
return ""; | |||
return str.trim(); | |||
} | |||
/** | |||
* 功能:null过滤,返回默认值 | |||
* | |||
* @param strValue 带检查的字符串 | |||
* @param defaultValue 为空返回的字符串 | |||
* @return str | |||
*/ | |||
public static String checkNull(String strValue, String defaultValue) { | |||
return strValue == null ? defaultValue : strValue; | |||
} | |||
public static String checkNull(Integer n) { | |||
return checkNull(n, true); | |||
} | |||
public static String checkNull(Integer n, boolean zeroToEmpty) { | |||
int v; | |||
if (n == null || n == 0) | |||
v = 0; | |||
else | |||
v = n; | |||
return v != 0 ? String.valueOf(v) : zeroToEmpty ? "" : "0"; | |||
} | |||
public static String checkNull(Long n) { | |||
return checkNull(n, 0L); | |||
} | |||
public static String checkNull(Long n, long defValue) { | |||
return n != null ? String.valueOf(n) : String.valueOf(defValue); | |||
} | |||
public static String checkNull(Double n) { | |||
return checkNull(n, 0d); | |||
} | |||
public static String checkNull(Double n, boolean zeroToEmpty) { | |||
double v; | |||
if (n == null || n == 0) | |||
v = 0; | |||
else | |||
v = n; | |||
return v != 0 ? String.valueOf(v) : zeroToEmpty ? "" : "0"; | |||
} | |||
public static String checkNull(Double n, double defValue) { | |||
double d = n != null ? n : defValue; | |||
return getDoubleStr(d); | |||
} | |||
//字符串清洗 | |||
public static String clearStr(String str) { | |||
if (str == null) return ""; | |||
else | |||
str = str.replaceAll("\u3000", "").replaceAll("\n", "").replaceAll("\b", "").replaceAll("\r", "").replaceAll("\t", "").replaceAll("\\s", "").replaceAll(" ", "").trim(); | |||
return str; | |||
} | |||
/** | |||
* Func:取当前年 | |||
* | |||
* @return "" | |||
*/ | |||
public static String getThisYear() { | |||
Calendar tlpDate = new GregorianCalendar(); | |||
tlpDate.setTime(getCurDate()); | |||
return String.valueOf(tlpDate.get(Calendar.YEAR)); | |||
} | |||
/** | |||
* Func:取当前月 | |||
* | |||
* @return "" | |||
*/ | |||
public static String getThisMonth() { | |||
Calendar tlpDate = new GregorianCalendar(); | |||
tlpDate.setTime(getCurDate()); | |||
return String.valueOf(tlpDate.get(Calendar.MONTH)); | |||
} | |||
/** | |||
* 功能:空值过滤,返回默认值 | |||
* | |||
* @param strValue 待检查的字符串 | |||
* @param defaultValue 为空返回的字符串 | |||
* @return str | |||
*/ | |||
public static String checkEmpty(String strValue, String defaultValue) { | |||
return isEmpty(strValue) ? defaultValue : strValue; | |||
} | |||
/** | |||
* 功能:空值过滤,返回默认值 | |||
* | |||
* @param strValue 待检查的字符串 | |||
* @return str | |||
*/ | |||
public static String checkEmptyId(String strValue, String defaultValue) { | |||
return isEmptyId(strValue) ? defaultValue : strValue; | |||
} | |||
public static String checkEmptyId(String strValue) { | |||
return isEmptyId(strValue) ? "" : strValue; | |||
} | |||
public static String getOrigMsg(Throwable e) { | |||
String s = e.getMessage(); | |||
Throwable t = e.getCause(); | |||
while (t != null) { | |||
s = t.getMessage(); | |||
t = t.getCause(); | |||
} | |||
return s; | |||
} | |||
//计算一个字符串source的长度(英文和数字占一个长度,其他字符(中文和特殊符号等)占2个长度) | |||
public static int strLength(String source) { | |||
int totalLength = source.length();// 总长度 | |||
String otherStr = source.replaceAll("\\d|\\w", "");// 去掉字符串中的数字和英文字符 | |||
int otherLength = otherStr.length();// 占2个长度的字符 | |||
return (totalLength - otherLength) + otherLength * 2; | |||
} | |||
/** | |||
* 格式化最后修改时间 | |||
* | |||
* @param strTime YYYYMMDDhhmmss | |||
* @return YYYY-MM-DD hh:mm:ss | |||
*/ | |||
public static String checkLastTime(String strTime) { | |||
if (isEmpty(strTime)) | |||
return ""; | |||
return checkLastTime(getLongIgnoreErr(strTime)); | |||
} | |||
public static String checkLastTime(long lngTime) { | |||
if (0 >= lngTime) | |||
return ""; | |||
String s1 = String.valueOf(lngTime + "").trim(); | |||
if (s1.length() != 14) | |||
return ""; | |||
return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)).concat(" ").concat(s1.substring(8, 10)).concat(":").concat(s1.substring(10, 12)).concat(":").concat(s1.substring(12)); | |||
} | |||
/** | |||
* 格式化最后修改时间 | |||
* | |||
* @param strTime YYYYMMDDhhmmss | |||
* @return YYYY-MM-DD hh:mm:ss | |||
*/ | |||
public static String getTimeFormatValue(String strTime) { | |||
if (isEmpty(strTime)) | |||
return ""; | |||
return getTimeFormatValue(getTimeDbValue(strTime)); | |||
} | |||
/** | |||
* 日期格式化 YYYYMMDDHHMMSS 转 YYYY-MM-DD- HH:MM:SS | |||
* | |||
* @param lngTime | |||
* @return | |||
*/ | |||
public static String getTimeFormatValue(long lngTime) { | |||
if (lngTime <= 0L) return ""; | |||
String s1 = String.valueOf(lngTime + "").trim(); | |||
if (s1.length() == 8) {//日期 | |||
return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)); | |||
} | |||
if (s1.length() == 6) {//时间 | |||
return s1.substring(0, 2).concat(":").concat(s1.substring(2, 4)).concat(":").concat(s1.substring(4, 6)); | |||
} | |||
if (s1.length() == 14) {//日期 | |||
return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)).concat(" ").concat(s1.substring(8, 10)).concat(":").concat(s1.substring(10, 12)).concat(":").concat(s1.substring(12)); | |||
} | |||
return ""; | |||
} | |||
/** | |||
* 日期格式化 YYYY-MM-DD- HH:MM:SS 转 YYYYMMDDHHMMSS | |||
* | |||
* @param strTime | |||
* @return | |||
*/ | |||
public static long getTimeDbValue(String strTime) { | |||
if (isEmptyId(strTime)) return -1L; | |||
return getLongIgnoreErr(strTime.replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "")); | |||
} | |||
/** | |||
* 取最后修改时间 | |||
* | |||
* @return Long | |||
*/ | |||
public static Long getLastTime() { | |||
return DateUtil.nowDateTimeNumber(); | |||
} | |||
/** | |||
* 取最后修改日期 | |||
* | |||
* @return | |||
*/ | |||
public static Long getLastDate() { | |||
return Long.valueOf(dLFormat2.format(new Timestamp(System.currentTimeMillis()))); | |||
} | |||
public static String getAmountStr(double amount) { | |||
return df2Format.format(amount); | |||
} | |||
public static String getAmountStrEx(double amount) { | |||
return df.format(amount); | |||
} | |||
public static String getSingleAmountStr(double amount) { | |||
return df2.format(amount); | |||
} | |||
public static String getIntStr(int d) { | |||
if (d == 0) | |||
return ""; | |||
else | |||
return String.valueOf(d); | |||
} | |||
/** | |||
* 截取右边的0串 | |||
* | |||
* @param codeStr | |||
* @return | |||
*/ | |||
public static String cutZero(String codeStr) { | |||
int j = 0; | |||
int len = codeStr.length() - 1; | |||
for (int i = len; i > -1; i--) { | |||
if ('0' == codeStr.charAt(i)) { | |||
j++; | |||
} else { | |||
break; | |||
} | |||
} | |||
return codeStr.substring(0, len - j + 1); | |||
} | |||
/** | |||
* 右边补0串 | |||
* | |||
* @param codeLen | |||
* @param cutedCode | |||
* @return | |||
*/ | |||
public static String fillZero(int codeLen, String cutedCode) { | |||
StringBuilder codeStr = new StringBuilder(20).append(cutedCode); | |||
for (int len = cutedCode.length(), i = 0; i < codeLen - len; i++) { | |||
codeStr.append("0"); | |||
} | |||
return codeStr.toString(); | |||
} | |||
/** | |||
* 转换为boolean | |||
*/ | |||
public static boolean toBoolean(String v, boolean b) { | |||
if (v == null) return b; | |||
return "1".equals(v) || "true".equalsIgnoreCase(v) || "Y".equalsIgnoreCase(v) || "yes".equalsIgnoreCase(v); | |||
} | |||
public static String getDateStr(Object _dateTime) { //yyyymmddhhMMss | |||
if (_dateTime == null) return ""; | |||
String dateTime = String.valueOf(_dateTime); | |||
if (PubUtil.isEmpty(dateTime) || dateTime.length() < 8) { | |||
return ""; | |||
} else { | |||
String s1 = String.valueOf(dateTime); | |||
return s1.substring(0, 4) + "-" + s1.substring(4, 6) + "-" + s1.substring(6, 8); | |||
} | |||
} | |||
/** | |||
* 日期转long | |||
* | |||
* @param dateStr YYYY-MM-DD | |||
* @return YYYYmmDD | |||
*/ | |||
public static long getDateLong(String dateStr) { | |||
if (PubUtil.isEmpty(dateStr) || dateStr.length() != 10) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", ""); | |||
return getLongIgnoreErr(_dateTime); | |||
} | |||
/** | |||
* 转日期时间long | |||
* | |||
* @param dateStr | |||
* @return | |||
*/ | |||
public static long getDateTimeLong(String dateStr) { | |||
if (PubUtil.isEmpty(dateStr)) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); | |||
_dateTime = StringUtil.getLeft(_dateTime + "00000000000000", 14); | |||
return getLongIgnoreErr(_dateTime); | |||
} | |||
/** | |||
* 转日期时间long | |||
* | |||
* @param dateStr | |||
* @return | |||
*/ | |||
public static long getEndDateTimeLong(String dateStr) { | |||
if (PubUtil.isEmpty(dateStr)) { | |||
return -1L; | |||
} | |||
String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); | |||
_dateTime = StringUtil.getLeft(_dateTime + "00000000", 8) + "235959"; | |||
return getLongIgnoreErr(_dateTime); | |||
} | |||
public static String getDateTimeStr(Object _dateTime) { //yyyymmddhhMMss | |||
String dateTime = String.valueOf(_dateTime); | |||
if (PubUtil.isEmpty(dateTime) || dateTime.length() < 14) { | |||
return ""; | |||
} else { | |||
String s1 = String.valueOf(dateTime); | |||
return s1.substring(0, 4) + "-" + s1.substring(4, 6) + "-" + s1.substring(6, 8);// + " " + s1.substr(8, 10) + ":" + s1.substr(10, 12) + ":" + s1.substr(12); | |||
} | |||
} | |||
//删除除 {"0","1","2","3","4","5","6","7","8","9",".","/","-"}以外的字符 | |||
public static String remove(String str) { | |||
if (isEmpty(str)) return ""; | |||
char[] charArray = str.toCharArray(); | |||
char[] strArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '/', '-'}; | |||
for (char c : charArray) { | |||
if (!ArrayUtils.contains(strArray, c)) { | |||
str = StringUtils.remove(str, c); | |||
} | |||
} | |||
return str; | |||
} | |||
//数字转字符串,如无小数,则去掉.00 | |||
public static String getDoubleStr(double d) { | |||
return getAmountStr(d).replaceAll(",", "").replaceAll("\\.00", ""); | |||
} | |||
//将List转为sql语句in后面的常量,'XXX','XXX'格式 | |||
public static String getSqlInstr(List<String> list) { | |||
if (PubUtil.isEmpty(list)) return ""; | |||
StringBuilder sb = new StringBuilder(256); | |||
for (String s : list) { | |||
if (PubUtil.isEmptyId(s)) continue; | |||
sb.append(",'").append(s).append("'"); | |||
} | |||
if (sb.length() == 0) return ""; | |||
return sb.substring(1); | |||
} | |||
/** | |||
* 将数组ID转为sql语句in后面的常量 | |||
* | |||
* @param ids ID数组 | |||
* @return 返回格式:110,1002 | |||
*/ | |||
public static String getSqlInIds(String[] ids) { | |||
if (null == ids || ids.length < 1) return ""; | |||
StringBuilder s = new StringBuilder(128); | |||
for (String id : ids) { | |||
if (PubUtil.isEmptyId(id)) continue; | |||
s.append(id.trim()).append(","); | |||
} | |||
if (s.length() == 0) return ""; | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static String getSqlInIds(Collection<String> ids) { | |||
if (null == ids || ids.size() < 1) return ""; | |||
StringBuilder s = new StringBuilder(128); | |||
for (String id : ids) { | |||
if (PubUtil.isEmptyId(id)) continue; | |||
s.append(id).append(","); | |||
} | |||
if (s.length() == 0) return ""; | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static String getSqlInStrIds(Collection<String> ids) { | |||
if (null == ids || ids.size() < 1) return ""; | |||
StringBuilder s = new StringBuilder(128); | |||
for (String id : ids) { | |||
if (PubUtil.isEmptyId(id)) continue; | |||
s.append("'" + id + "'").append(","); | |||
} | |||
if (s.length() == 0) return ""; | |||
return s.substring(0, s.length() - 1); | |||
} | |||
public static List<String> buildSqlIds(Collection<String> ids, int size) { | |||
List<String> l = new ArrayList<>(); | |||
StringBuilder sb = new StringBuilder(); | |||
int count = 0; | |||
for (String id : ids) { | |||
if (count >= size) { | |||
l.add(sb.substring(1)); | |||
sb.setLength(0); | |||
count = 0; | |||
} | |||
sb.append(",").append(id); | |||
count++; | |||
} | |||
if (sb.length() > 0) l.add(sb.substring(1)); | |||
return l; | |||
} | |||
/** | |||
* 判断字符串是否只包含unicode数字。 | |||
* <p/> | |||
* <p> | |||
* <code>null</code>将返回<code>false</code>,空字符串<code>""</code>将返回 | |||
* <code>true</code>。 | |||
* </p> | |||
* <p/> | |||
* <p> | |||
* <pre> | |||
* StringUtil.isNumeric(null) = false | |||
* StringUtil.isNumeric("") = true | |||
* StringUtil.isNumeric(" ") = false | |||
* StringUtil.isNumeric("123") = true | |||
* StringUtil.isNumeric("12 3") = false | |||
* StringUtil.isNumeric("ab2c") = false | |||
* StringUtil.isNumeric("12-3") = false | |||
* StringUtil.isNumeric("12.3") = false | |||
* </pre> | |||
* | |||
* @param str 要检查的字符串 | |||
* @return 如果字符串非<code>null</code>并且全由unicode数字组成,则返回<code>true</code> | |||
*/ | |||
public static boolean isNumeric(String str) { | |||
if (PubUtil.isEmpty(str)) { | |||
return false; | |||
} | |||
int length = str.length(); | |||
for (int i = 0; i < length; i++) { | |||
if (!Character.isDigit(str.charAt(i))) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
public static boolean isDouble(String str) { | |||
if (null == str || "".equals(str)) { | |||
return false; | |||
} | |||
Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$"); | |||
return pattern.matcher(str).matches(); | |||
} | |||
/** | |||
* 获得某个字符在 字符串中 出现第n次时的 下标 | |||
* | |||
* @param res | |||
* @param _c | |||
* @param index | |||
* @return | |||
*/ | |||
public static int getIndexChar(String res, String _c, int index) { | |||
Matcher mh = Pattern.compile(_c).matcher(res); | |||
int i = 0; | |||
while (mh.find()) { | |||
i++; | |||
if (i == index) { | |||
break; | |||
} | |||
} | |||
return mh.start(); | |||
} | |||
/** | |||
* 将字符串转为指定字符集 | |||
* @param str | |||
* @param charSet | |||
* @return | |||
*/ | |||
public static String changeStrCharSet(String str, String charSet) { | |||
if (isEmptyId(str)) return str; | |||
String newStr = str; | |||
try { | |||
newStr = new String(str.getBytes(charSet), charSet); | |||
} catch (UnsupportedEncodingException e) { | |||
return newStr; | |||
} | |||
return newStr; | |||
} | |||
/** | |||
* 转布尔 | |||
* | |||
* @param o | |||
* @return | |||
*/ | |||
public static boolean getBool(Object o) { | |||
if (o == null) return false; | |||
String v = o.toString(); | |||
return "1".equals(v) || "t".equalsIgnoreCase(v) || "true".equalsIgnoreCase(v); | |||
} | |||
/** | |||
* 返回当恰能操作系统是否为Linux | |||
* | |||
* @return boolean | |||
*/ | |||
public static boolean osIsLinux() { | |||
String s = System.getProperty("os.name"); | |||
return s != null && s.equalsIgnoreCase("linux"); | |||
} | |||
public static boolean strAllEqual(String str) { | |||
if (PubUtil.isEmptyId(str)) return true; | |||
for (int i = 1; i < str.length(); i++) | |||
if (str.charAt(i) != str.charAt(0)) return false; | |||
return true; | |||
} | |||
/** | |||
* 对中文字段 list排序 | |||
* | |||
* @param list | |||
* @param fun 获取排序的值 | |||
* @param desc 降序 | |||
* @throws Exception | |||
*/ | |||
public static <T, R> void sortChineseStrList(List<T> list, Function<T, R> fun, boolean desc) { | |||
list.sort((T o1, T o2) -> { | |||
int rt = Collator.getInstance(Locale.CHINESE).compare(fun.apply(o1), fun.apply(o2)); | |||
if (rt < 0) { | |||
if (desc) { | |||
return 1; | |||
} | |||
return -1; | |||
} | |||
if (rt > 0) { | |||
if (desc) { | |||
return -1; | |||
} | |||
return 1; | |||
} | |||
return 0; | |||
}); | |||
} | |||
//遍历map | |||
public static <K, V> void doForMap(Map<K, V> map, IMapEntryReader<K, V> reader) throws Exception { | |||
if (map == null) return; | |||
for (Map.Entry<K, V> entry : map.entrySet()) { | |||
reader.readEntry(entry.getKey(), entry.getValue()); | |||
} | |||
} | |||
public interface IMapEntryReader<K, V> { | |||
void readEntry(K key, V value) throws Exception; | |||
} | |||
} |
@@ -1,10 +1,20 @@ | |||
package cc.smtweb.framework.core.util; | |||
import cc.smtweb.framework.core.common.AbstractEnum; | |||
import cc.smtweb.framework.core.common.IntEnum; | |||
import cc.smtweb.framework.core.common.StrEnum; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.List; | |||
/** | |||
* Created by Akmm at 2022/5/20 16:57 | |||
* sql工具类 | |||
* 注意:where参数表示是否已经加入了where关键字 | |||
* | |||
* @author : AKzz | |||
* @version : $Revision:$ | |||
*/ | |||
public class SqlUtil { | |||
@SuppressWarnings("UnusedDeclaration") | |||
public abstract class SqlUtil { | |||
/** | |||
* 将sql中的表名替换成schema.table的格式 | |||
* @param sql | |||
@@ -14,5 +24,758 @@ public class SqlUtil { | |||
return sql; | |||
} | |||
/** | |||
* 补充SQL的字符串的==条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, int condition_value) { | |||
return addSql_EQUALE_Expr(where_is_exist, sql, args, db_field_name, String.valueOf(condition_value)); | |||
} | |||
public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, long condition_value) { | |||
return addSql_EQUALE_Expr(where_is_exist, sql, args, db_field_name, String.valueOf(condition_value)); | |||
} | |||
/** | |||
* 补充SQL的字符串的==条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" = ? \n"); | |||
args.add(condition_value); | |||
} | |||
return true; | |||
} | |||
public static boolean addSql_lesser(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" <= ? \n"); | |||
args.add(condition_value); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_greater(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" >= ? \n"); | |||
args.add(condition_value); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(仅后匹配) %s | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_EX(boolean where_is_exist, StringBuilder sql, List<Object> args, String condition_value, String... db_field_name) { | |||
if (db_field_name == null || db_field_name.length == 0) return where_is_exist; | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
if (db_field_name.length == 1) { | |||
sql.append(db_field_name[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
return where_is_exist; | |||
} | |||
sql.append(" ("); | |||
for (String db_filed : db_field_name) { | |||
sql.append(" ").append(db_filed).append(" LIKE ? \nOR"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
sql.delete(sql.length() - 2, sql.length()); | |||
sql.append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(仅后匹配) s% | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); | |||
args.add(String.format("%s%%", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL的字符串Like条件(全模糊) %s% | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List<Object> args, String db_field_name, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" LIKE ? \n"); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
return where_is_exist; | |||
} | |||
public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List<Object> args, String[] db_field_names, String condition_value) { | |||
if (StringUtil.isNotEmpty(condition_value)) { | |||
//mysq _ 是一个占位符需要加\进行处理 | |||
condition_value = condition_value.replaceAll("_", "\\\\_"); | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append("(").append(db_field_names[0]).append(" LIKE ? "); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
for (int i = 1; i < db_field_names.length; ++i) { | |||
sql.append(" OR ").append(db_field_names[i]).append(" LIKE ? "); | |||
args.add(String.format("%%%s%%", condition_value)); | |||
} | |||
sql.append(")"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL字符串的IN条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_IN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { | |||
if (expr != null && expr.length > 0) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" IN (").append(StringUtils.join(expr, ',')).append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 补充SQL字符串的not IN条件 | |||
* | |||
* @param where_is_exist 是否已经加入了where关键字 | |||
*/ | |||
public static boolean addSql_NOTIN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { | |||
if (expr != null && expr.length > 0) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
sql.append(db_field_name).append(" NOT IN (").append(StringUtils.join(expr, ',')).append(")\n"); | |||
} | |||
return where_is_exist; | |||
} | |||
/** | |||
* 增加字符串字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值,包含','为多选 | |||
* @param sql sql | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConMulti(String field, String value, StringBuilder sql, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
if (value.contains(",")) {//多选 | |||
sql.append(" and ").append(field).append(" in ('").append(value.replaceAll(",", "','")).append("')"); | |||
} else if (!Consts.NULL_STRING.equals(value)) {//单 | |||
sql.append(" and ").append(field).append("=?"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件,不判断多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingle(String field, String value, StringBuilder sb, List<Object> paras) { | |||
addStrConSingle(field, "=", value, sb, paras); | |||
} | |||
/** | |||
* 增加字符串字段条件,不判断多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param opt 逻辑运算符 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingle(String field, String opt, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append(" ").append(opt).append(" ? \n"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件,包含 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingleLike(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append(" like ? \n"); | |||
paras.add("%" + value + "%"); | |||
} | |||
} | |||
/** | |||
* 增加字符串字段条件并且不区分大小写,包含 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addStrConSingleLikeIgnoreCase(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) { | |||
String valueLower = value.toLowerCase(); | |||
sb.append(" and ").append("lower(").append(field).append(")").append(" like ? \n"); | |||
paras.add("%" + valueLower + "%"); | |||
} | |||
} | |||
/** | |||
* 增加数字字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值,包含','为多选 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumberConMulti(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
if (value.contains(",")) {//多选 | |||
sb.append(" and ").append(field).append(" in (").append(value).append(") \n"); | |||
} else if (!Consts.NULL_STRING.equals(value)) {//单 | |||
sb.append(" and ").append(field).append("=? \n"); | |||
paras.add(value); | |||
} | |||
} | |||
/** | |||
* 增加数字字段条件,单选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumConSingle(String field, Number value, StringBuilder sb, List<Object> paras) { | |||
addNumConSingle(field, "=", value, sb, paras); | |||
} | |||
/** | |||
* 增加数字字段条件,单选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param opt 运算符 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addNumConSingle(String field, String opt, Number value, StringBuilder sb, List<Object> paras) { | |||
sb.append(" and ").append(field).append(opt).append("? \n"); | |||
paras.add(value); | |||
} | |||
/** | |||
* 增加日期字段条件,可能多选 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
@Deprecated | |||
public static void addDateCon(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = DateUtil.nowDateString(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 考虑日期时间的情况 | |||
sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 1)).append("' \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 8)).append("' \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getMonthStart()).append("' and ").append(field).append("<='").append(DateUtil.getMonthEnd()).append(" 23:59:59' \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getSeasonFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getSeasonLastDay()).append(" 23:59:59' \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(">='").append(DateUtil.getYearFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getYearLastDay()).append(" 23:59:59' \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) | |||
return; | |||
if (StringUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(de); | |||
} else if (StringUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(df); | |||
} else { | |||
sb.append(" and ").append(field).append(">=? and ").append(field).append("<=? \n"); | |||
paras.add(df); | |||
paras.add(de); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 增加日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addDateConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = DateUtil.nowDateString(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 | |||
sb.append(" and ").append(field).append("=").append(DateUtil.getDateLong(s)).append(" \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(s)).append(" and ").append(DateUtil.getDateLong(DateUtil.getAfterDays(s, 7))).append(" \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getMonthStart())).append(" and ").append(DateUtil.getDateLong(DateUtil.getMonthEnd())).append(" \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getSeasonFirstDay())).append(" and ").append(DateUtil.getDateLong(DateUtil.getSeasonLastDay())).append(" \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getYearFirstDay())).append(" and ").append(DateUtil.getDateLong(DateUtil.getYearLastDay())).append(" \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) | |||
return; | |||
if (StringUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(DateUtil.getDateLong(de)); | |||
} else if (StringUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(DateUtil.getDateLong(df)); | |||
} else { | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(DateUtil.getDateLong(df)); | |||
paras.add(DateUtil.getDateLong(de)); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 增加期间查询日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addPeriodDateConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(df + "01"); | |||
paras.add(de + "31"); | |||
} | |||
/** | |||
* 增加日期时间字段条件 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addDateTimeConEx(String field, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
String s = DateUtil.nowDateString(); | |||
if (st.length > 0) { | |||
switch (st[0]) { | |||
case "D": //当天 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(s)).append(" and ").append(DateUtil.getEndDateTimeLong(s)).append(" \n"); | |||
break; | |||
case "W": //本周 | |||
s = DateUtil.toStdDateString(DateUtil.getWeekStart()); | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(s)).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getAfterDays(s, 6))).append(" \n"); | |||
break; | |||
case "M": //本月 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getMonthStart())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getMonthEnd())).append(" \n"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getSeasonFirstDay())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getSeasonLastDay())).append(" \n"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getYearFirstDay())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getYearLastDay())).append(" \n"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) | |||
return; | |||
if (StringUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field).append("<=?"); | |||
paras.add(DateUtil.getEndDateTimeLong(de)); | |||
} else if (StringUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field).append(">=?"); | |||
paras.add(DateUtil.getDateTimeLong(df)); | |||
} else { | |||
sb.append(" and ").append(field).append(" between ? and ? \n"); | |||
paras.add(DateUtil.getDateTimeLong(df)); | |||
paras.add(DateUtil.getEndDateTimeLong(de)); | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 枚举状态字段,in方式 | |||
* | |||
* @param where_is_exist sql是否已包括where | |||
* @param field sql字段名 | |||
* @param value 前端传回来的查询值,格式:1,1,1,1 | |||
* @param intEnum 枚举类型 | |||
* @param sql 待构建的sql | |||
*/ | |||
public static void addIntEnumCon(boolean where_is_exist, String field, String value, IntEnum intEnum, StringBuilder sql) { | |||
if (StringUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
String s = ""; | |||
String[] ss = value.split(","); | |||
int i = 0; | |||
for (AbstractEnum.IntEnumBean b : intEnum.values()) { | |||
if (ss.length > i && "1".equals(ss[i])) s += "," + b.value; | |||
i++; | |||
} | |||
sql.append(field + " in (" + s.substring(1) + ")"); | |||
} | |||
} | |||
/** | |||
* 枚举状态字段,in方式 | |||
* | |||
* @param where_is_exist sql是否已包括where | |||
* @param field sql字段名 | |||
* @param value 前端传回来的查询值,格式:1,1,1,1 | |||
* @param intEnum 枚举类型 | |||
* @param sql 待构建的sql | |||
*/ | |||
public static void addStrEnumCon(boolean where_is_exist, String field, String value, StrEnum intEnum, StringBuilder sql) { | |||
if (StringUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { | |||
if (!where_is_exist) { | |||
sql.append(" WHERE "); | |||
where_is_exist = true; | |||
} else { | |||
sql.append(" AND "); | |||
} | |||
String s = ""; | |||
String[] ss = value.split(","); | |||
int i = 0; | |||
for (AbstractEnum.StrEnumBean b : intEnum.values()) { | |||
if (ss.length > i && "1".equals(ss[i])) s += ",'" + b.value + "'"; | |||
i++; | |||
} | |||
sql.append(field + " in (" + s.substring(1) + ")"); | |||
} | |||
} | |||
public static void addTreeStateCon(String curPrefix, String value, String tableName, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value) && !value.contains(",")) { | |||
int v = NumberUtil.getIntIgnoreErr(value); | |||
if (v == 0) {//查启用 自己启用,且父亲未停用 | |||
sb.append(" and ").append(curPrefix).append(".f_status=0 and not exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%')"); | |||
} else {//查停用 自己停用 或父亲被停用 | |||
sb.append(" and (").append(curPrefix).append(".f_status=1 or exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%'))"); | |||
} | |||
} | |||
} | |||
/** | |||
* 增加年月字段条件 | |||
* | |||
* @param field 查询的字段名 | |||
* @param value 值 | |||
* @param paras 参数 | |||
*/ | |||
public static void addYmCon(String field, String value, StringBuilder sb, List<Object> paras) { | |||
addYmConEx(field, field, value, sb, paras); | |||
} | |||
public static void addYmConEx(String field_begin, String field_end, String value, StringBuilder sb, List<Object> paras) { | |||
if (StringUtil.isEmpty(value)) | |||
return; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 | |||
return; | |||
} | |||
if (st.length > 1) { | |||
switch (st[0]) { | |||
case "M": //本月 | |||
String nowYm = DateUtil.getNowYm(); | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) | |||
return; | |||
if (StringUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field_begin).append("<=?"); | |||
paras.add(de); | |||
} else if (StringUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field_end).append(">=?"); | |||
paras.add(df); | |||
} else { | |||
sb.append(" and ").append(field_end).append(">=? and ").append(field_begin).append("<=?"); | |||
paras.add(df); | |||
paras.add(de); | |||
} | |||
break; | |||
} | |||
} else if (st.length == 1) { | |||
sb.append(" and ").append(field_end).append(">='").append(value).append("' and ").append(field_begin).append("<='").append(value).append("'"); | |||
} | |||
} | |||
//构建年月范围的sql | |||
public static String getYmConSql(String field, String value) { | |||
return getYmConSqlEx(field, field, value); | |||
} | |||
public static String getYmConSqlEx(String field_begin, String field_end, String value) { | |||
if (StringUtil.isEmpty(value)) return ""; | |||
String[] st = value.split(","); | |||
if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) return ""; | |||
StringBuilder sb = new StringBuilder(128); | |||
switch (st[0]) { | |||
case "M": //本月 | |||
String nowYm = DateUtil.getNowYm(); | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); | |||
break; | |||
case "Q": //本季度 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); | |||
break; | |||
case "Y": //本年 | |||
sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); | |||
break; | |||
default: //自定义 | |||
String df, de; | |||
if (st.length > 1) | |||
df = st[1]; | |||
else | |||
df = ""; | |||
if (st.length > 2) | |||
de = st[2]; | |||
else | |||
de = ""; | |||
if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) | |||
return ""; | |||
if (StringUtil.isEmpty(df)) { | |||
sb.append(" and ").append(field_begin).append("<='").append(de).append("'"); | |||
} else if (StringUtil.isEmpty(de)) { | |||
sb.append(" and ").append(field_end).append(">='").append(df).append("'"); | |||
} else { | |||
sb.append(" and ").append(field_end).append(">='").append(df).append("' and ").append(field_begin).append("<='").append(de).append("'"); | |||
} | |||
break; | |||
} | |||
return sb.substring(5); | |||
} | |||
} |
@@ -17,6 +17,15 @@ import java.util.*; | |||
public class StringUtil { | |||
private static Collator chineseCollator = Collator.getInstance(Locale.CHINA); | |||
public static boolean isEmpty(String str) { | |||
return str == null || str.trim().length() == 0 || "-".equals(str); | |||
} | |||
public static boolean isNotEmpty(String cs) { | |||
return !isEmpty(cs); | |||
} | |||
/** | |||
* strSrc中寻找第一个strSe并且返回以其分隔的Left部分,汉字长度也为1 | |||
* | |||
@@ -25,9 +34,9 @@ public class StringUtil { | |||
* @return String 返回 | |||
*/ | |||
public static String getLeft(String strSrc, String strSe) { | |||
if (PubUtil.isEmpty(strSrc)) | |||
if (isEmpty(strSrc)) | |||
return ""; | |||
if (PubUtil.isEmpty(strSe)) | |||
if (isEmpty(strSe)) | |||
strSe = " "; | |||
String result = ""; | |||
@@ -45,7 +54,7 @@ public class StringUtil { | |||
* @return String return | |||
*/ | |||
public static String getLeft(String strSrc, int count) { | |||
if (PubUtil.isEmpty(strSrc) || count <= 0) { | |||
if (isEmpty(strSrc) || count <= 0) { | |||
return ""; | |||
} | |||
if (strSrc.length() < count) { | |||
@@ -63,9 +72,9 @@ public class StringUtil { | |||
* @return String right部分 | |||
*/ | |||
public static String getRight(String strSrc, String strSe) { | |||
if (PubUtil.isEmpty(strSrc)) | |||
if (isEmpty(strSrc)) | |||
return ""; | |||
if (PubUtil.isEmpty(strSe)) | |||
if (isEmpty(strSe)) | |||
strSe = " "; | |||
String result = strSrc; | |||
@@ -83,7 +92,7 @@ public class StringUtil { | |||
* @return String return | |||
*/ | |||
public static String getRight(String strSrc, int count) { | |||
if (PubUtil.isEmpty(strSrc) || count <= 0) { | |||
if (isEmpty(strSrc) || count <= 0) { | |||
return ""; | |||
} | |||
int l = strSrc.length(); | |||
@@ -196,7 +205,7 @@ public class StringUtil { | |||
* @return 处理结果 | |||
*/ | |||
public static String cutStringLeft(String src, String cut) { | |||
if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { | |||
if (isEmpty(src) || isEmpty(cut)) { | |||
return ""; | |||
} | |||
if (src.startsWith(cut)) { | |||
@@ -207,7 +216,7 @@ public class StringUtil { | |||
} | |||
public static String cutStringRight(String src, String cut) { | |||
if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { | |||
if (isEmpty(src) || isEmpty(cut)) { | |||
return ""; | |||
} | |||
while (src.endsWith(cut)) | |||
@@ -447,7 +456,7 @@ public class StringUtil { | |||
return myReplaceStrEx(express, b, e, new IStrHanlder() { | |||
@Override | |||
public String work(String src) { | |||
return PubUtil.checkNull(mapVals.get(src)); | |||
return checkNull(mapVals.get(src)); | |||
} | |||
}); | |||
} | |||
@@ -473,6 +482,29 @@ public class StringUtil { | |||
return "true".equalsIgnoreCase(s) || "1".equals(s) || "y".equalsIgnoreCase(s); | |||
} | |||
/** | |||
* 功能:null过滤,返回默认值 | |||
* | |||
* @param strValue 带检查的字符串 | |||
* @param defaultValue 为空返回的字符串 | |||
* @return str | |||
*/ | |||
public static String checkNull(String strValue, String defaultValue) { | |||
return strValue == null ? defaultValue : strValue; | |||
} | |||
/** | |||
* Func:为空,返回"" | |||
* | |||
* @param str 带检查的字符串 | |||
* @return "" | |||
*/ | |||
public static String checkNull(String str) { | |||
if (isEmpty(str)) | |||
return ""; | |||
return str.trim(); | |||
} | |||
/*Blob转String*/ | |||
// public static String blob2Str(Blob blob) { | |||
// if (blob == null) return ""; | |||
@@ -507,7 +539,7 @@ public class StringUtil { | |||
String[] ss = src.split(ch); | |||
int[] ret = new int[ss.length]; | |||
for (int i = 0, len = ss.length; i < len; i++) { | |||
ret[i] = PubUtil.getIntIgnoreErr(ss[i]); | |||
ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); | |||
} | |||
return ret; | |||
} | |||
@@ -124,7 +124,7 @@ public class XmlUtil { | |||
//获取节点属性,转为字符串数组 | |||
public static String[] getAttrStrArray(Element e, String attrName) { | |||
String s = getAttribute(e, attrName); | |||
if (PubUtil.isNotEmptyStr(s)) return StringUtil.split(s, ",").toArray(new String[]{}); | |||
if (StringUtil.isNotEmpty(s)) return StringUtil.split(s, ",").toArray(new String[]{}); | |||
return new String[0]; | |||
} | |||
@@ -133,17 +133,17 @@ public class XmlUtil { | |||
String[] ss = getAttrStrArray(e, attrName); | |||
int[] ret = new int[ss.length]; | |||
for (int i = 0, len = ss.length; i < len; i++) { | |||
ret[i] = PubUtil.getIntIgnoreErr(ss[i]); | |||
ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); | |||
} | |||
return ret; | |||
} | |||
public static int getAttributeInt(Element e, String attrName) { | |||
return PubUtil.getIntIgnoreErr(getAttribute(e, attrName)); | |||
return NumberUtil.getIntIgnoreErr(getAttribute(e, attrName)); | |||
} | |||
public static double getAttributeDbl(Element e, String attrName) { | |||
return PubUtil.getDoubleIgnoreErr(getAttribute(e, attrName)); | |||
return NumberUtil.getDoubleIgnoreErr(getAttribute(e, attrName)); | |||
} | |||
public static boolean getAttributeBool(Element e, String attrName) { | |||
@@ -153,7 +153,7 @@ public class XmlUtil { | |||
//获取节点属性 | |||
public static String getAttributeIgnoreNull(Element e, String attrName) { | |||
return PubUtil.checkNull(getAttribute(e, attrName)); | |||
return StringUtil.checkNull(getAttribute(e, attrName)); | |||
} | |||
//读取节点所有属性,返回map | |||
@@ -173,7 +173,7 @@ public class XmlUtil { | |||
//设置节点属性 | |||
public static void setAttribute(Element e, String attrName, String attrValue) { | |||
if (PubUtil.isNotEmpty(attrValue)) e.addAttribute(attrName, attrValue); | |||
if (StringUtil.isNotEmpty(attrValue)) e.addAttribute(attrName, attrValue); | |||
else removeAttribute(e, attrName); | |||
} | |||
@@ -185,7 +185,7 @@ public class XmlUtil { | |||
//设置节点属性 | |||
public static void setAttribute(Element e, String attrName, double attrValue) { | |||
if (!MathUtil.isEqualsZero(attrValue)) e.addAttribute(attrName, String.valueOf(attrValue)); | |||
if (!NumberUtil.isEqualsZero(attrValue)) e.addAttribute(attrName, String.valueOf(attrValue)); | |||
else removeAttribute(e, attrName); | |||
} | |||