F2-1: WS3 平台函数库回迁(GetServicesFunction/GetDefaultValueFunction/GetValueFunction)
- GetServicesFunction.java:原 45 行桩扩展为完整 18 方法实现,覆盖全部 top 调用(loadPOJO/listSelectResult/listSelectResultBySql/getEnumerateItemValue/ getEnumerateItemDes/executeQueryForMap/findCount/excuteFlow/getCurrentUser* 等) - GetDefaultValueFunction.java:从 Groovy 移植为 Java,12 个方法(getConfigValue/ currentDate/currentYear/currentMonth/getCurrentUserId/getCurrentUserOrgId/ getCurrentProjectId/guid 等),DateMidnight 语义完全对拍 - GetValueFunction.java:从 Groovy 移植为 Java,780 行→完整 Java 实现, 40+ 纯函数(日期/字符串/数学/金额转换),null 行为/格式/返回类型逐方法对拍 - 新增接口:ChangeStatus、WorkCalendarService(P2 占位) - 删除已被替换的 Groovy 源文件(GetDefaultValueFunction.groovy/GetValueFunction.groovy) - 单测 80 个全绿,全套 platform-legacy-core 132 个测试 BUILD SUCCESS Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package com.dsasp.server.common.function
|
||||
|
||||
import org.joda.time.DateMidnight
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import org.joda.time.format.DateTimeFormatter
|
||||
|
||||
import com.dsasp.server.common.core.Function
|
||||
import com.dsasp.server.common.dataDic.bean.SysConfig;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.common.util.StringUtil
|
||||
|
||||
/**
|
||||
* 默认值函数
|
||||
* @author shanxh
|
||||
*
|
||||
*/
|
||||
class GetDefaultValueFunction {
|
||||
@Function(name="当前用户",tip="返回当前用户ID")
|
||||
static String getCurrentUserId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTUSER);
|
||||
}
|
||||
|
||||
@Function(name="当前部门",tip="返回当前部门ID")
|
||||
static String getCurrentUserDepartId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTDEPART);
|
||||
}
|
||||
|
||||
@Function(name="当前组织",tip="返回当前组织ID")
|
||||
static String getCurrentUserOrgId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTORG);
|
||||
}
|
||||
|
||||
@Function(name="当前工程",tip="返回当前工程ID")
|
||||
static String getCurrentProjectId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTPROJECT);
|
||||
}
|
||||
|
||||
@Function(name="当前日期",tip="返回当前日期,返回值:{DateTime}当前日期")
|
||||
static DateTime currentDate(){
|
||||
return new DateMidnight(DateTimeZone.getDefault()).toDateTime();
|
||||
}
|
||||
|
||||
@Function(name="当前日期时间",tip="返回当前日期时间,返回值:{DateTime}当前日期时间")
|
||||
static DateTime currentDateTime(){
|
||||
return new DateTime(DateTimeZone.getDefault());
|
||||
}
|
||||
|
||||
@Function(name="当前年份",tip="返回当前年份,返回值:{int}返回当前年份")
|
||||
static int currentYear(){
|
||||
return currentDateTime().getYear()
|
||||
}
|
||||
|
||||
@Function(name="当前月份",tip="返回当前月份,返回值:{int}返回当前月份")
|
||||
static int currentMonth(){
|
||||
return currentDateTime().getMonthOfYear()
|
||||
}
|
||||
@Function(name="当前日",tip="返回当前日,返回值:{int}当前时间是几号")
|
||||
static int currentDay(){
|
||||
return currentDateTime().getDayOfMonth()
|
||||
}
|
||||
|
||||
@Function(name="当前小时",tip="返回当前小时,返回值:{int}当前时间的小时")
|
||||
static int currentHour(){
|
||||
return currentDateTime().getHourOfDay()
|
||||
}
|
||||
|
||||
@Function(name="当前分钟",tip="返回当前分钟,返回值:{int}当前时间的分钟")
|
||||
static int currentMinute(){
|
||||
return currentDateTime().getMinuteOfHour()
|
||||
}
|
||||
|
||||
@Function(name="当前秒",tip="返回当前秒,返回值:{int}当前时间的秒")
|
||||
static int secondOf(){
|
||||
return currentDateTime().getSecondOfMinute()
|
||||
}
|
||||
|
||||
@Function(name="创建gui唯一标示",tip="获取gui唯一标示,返回值:{String} 唯一标示")
|
||||
static String guid(){
|
||||
return UUID.randomUUID()
|
||||
}
|
||||
@Function(name="获取系统配置的属性值",tip="获取系统配置的属性值,参数:{String}key 系统配置主键,返回值:{String} 属性值")
|
||||
static String getConfigValue(String key){
|
||||
SysConfig.getConfigValue(key);
|
||||
}
|
||||
}
|
||||
@@ -1,781 +0,0 @@
|
||||
package com.dsasp.server.common.function
|
||||
|
||||
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import org.joda.time.format.DateTimeFormatter
|
||||
|
||||
import com.dsasp.server.common.core.Function
|
||||
import com.dsasp.server.common.exception.ValidationException
|
||||
import com.dsasp.server.common.util.StringUtil
|
||||
|
||||
/**
|
||||
* 字段取值函数
|
||||
* @author shanxh
|
||||
*
|
||||
*/
|
||||
class GetValueFunction {
|
||||
|
||||
/**
|
||||
* 取参数的绝对值
|
||||
* @param obj 要确定绝对值的参数
|
||||
* @return 参数的绝对值
|
||||
*/
|
||||
@Function(name="取参数的绝对值",tip="获取参数的绝对值, 参数:{Number}num 数值,返回值:{Number}参数的绝对值")
|
||||
static Number abs(Number num){
|
||||
return Math.abs(num);
|
||||
}
|
||||
/**
|
||||
* 大于num的最小整数
|
||||
* @param num 数值(number)
|
||||
* @return 最小(最接近负无穷大)浮点值,该值大于或等于该参数,并且等于某个整数。
|
||||
*/
|
||||
@Function(name="大于num的最小整数",tip="获取大于num的最小整数,参数:{Number}num 数值,返回值:{double}")
|
||||
static double ceil(Number num){
|
||||
return Math.ceil(num)
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于num的最大整数
|
||||
* @param num 数值
|
||||
* @return 最大(最接近正无穷大)浮点值,该值小于等于该参数,并等于某个整数。
|
||||
*/
|
||||
@Function(name="小于num的最大整数",tip="获取小于num的最大整数,参数:{double}num 数值,返回值:{double}")
|
||||
static double floor(double num){
|
||||
return Math.floor(num);
|
||||
}
|
||||
|
||||
@Function(name="比较两个时间的大小",tip="比较两个时间的大小,参数:{DateTime}startTime 开始时间,{DateTime}endTime 结束时间,返回值:{boolean} 开始时间早于结束时间返回true,否则返回false")
|
||||
static boolean compareDateTime(DateTime startTime,DateTime endTime){
|
||||
|
||||
return startTime?.isBefore(endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加小时
|
||||
* @param dateTime 时间
|
||||
* @param hours 增加的小时数
|
||||
* @return 增加小时后的时间
|
||||
*/
|
||||
@Function(name="增加小时",tip="所在时间增加小时数,参数:{DateTime}dateTime 时间、 {int}hours 增加的小时数,返回值:{DateTime}增加小时后的时间")
|
||||
static DateTime addHours(DateTime dateTime, int hours){
|
||||
return dateTime?.plusHours(hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加日
|
||||
* @param dateTime 时间
|
||||
* @param date 增加的天数
|
||||
* @return 增加天数后的时间
|
||||
*/
|
||||
@Function(name="增加日",tip="所在时间增加天数,参数:{DateTime}dateTime 时间 、{int}days 增加的天数,返回值:{DateTime}增加天数后的时间")
|
||||
static DateTime addDays(DateTime dateTime, int days){
|
||||
return dateTime?.plusDays(days);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加月份
|
||||
* @param dateTime 时间
|
||||
* @param month 增加的月数
|
||||
* @return 增加月份后的时间
|
||||
*/
|
||||
@Function(name="增加月",tip="所在时间增加月数,参数:{DateTime}dateTime 时间、 {int} months 增加的月数,返回值:{DateTime}增加月份后的时间")
|
||||
static DateTime addMonths(DateTime dateTime, int months){
|
||||
return dateTime?.plusMonths(months);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接字符串
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return 将str2串联到str1 String 结尾的 String
|
||||
*/
|
||||
@Function(name="连接字符串",tip="连接两个字符串,参数:{String} str1 、 {String} str2 ,返回值:{String}str2串联到str1的结尾的字符串")
|
||||
static String concat(String str1,String str2){
|
||||
return str1?.concat(str2)
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期格式化
|
||||
* @param dateTime 日期(时间)
|
||||
* @param pattern 格式(默认:yyyy-MM-dd)
|
||||
* @return String 格式化后的时间字符串
|
||||
*/
|
||||
@Function(name="日期格式化",tip="格式化日期,参数:{DateTime}dateTime 日期,{String} pattern 格式,返回值:{String} 格式化后的时间字符串")
|
||||
static String dateFormate(DateTime dateTime, String pattern){
|
||||
return dateTime?.toString(StringUtil.isEmpty(pattern)? "yyyy-MM-dd":pattern)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在时间是星期几
|
||||
* @param dateTime 时间
|
||||
* @return 星期
|
||||
*/
|
||||
@Function(name="星期",tip="获取所在时间是星期几,参数:{DateTime}dateTime 时间,返回值:{String}星期")
|
||||
static String dayOFWeek(DateTime dateTime){
|
||||
if(dateTime ==null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
String showWeek = "";
|
||||
switch (day) {
|
||||
case 1:
|
||||
showWeek = "星期一";
|
||||
break;
|
||||
case 2:
|
||||
showWeek = "星期二";
|
||||
break;
|
||||
case 3:
|
||||
showWeek = "星期三";
|
||||
break;
|
||||
case 4:
|
||||
showWeek = "星期四";
|
||||
break;
|
||||
case 5:
|
||||
showWeek = "星期五";
|
||||
break;
|
||||
case 6:
|
||||
showWeek = "星期六";
|
||||
break;
|
||||
default:
|
||||
showWeek = "星期日";
|
||||
break;
|
||||
}
|
||||
return showWeek
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的日期(天)
|
||||
*/
|
||||
@Function(name="获取日",tip="获取所在时间的日,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的日")
|
||||
static int dayOf(DateTime dateTime){
|
||||
return dateTime?.getDayOfMonth()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小时
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的小时数
|
||||
*/
|
||||
@Function(name="获取小时",tip="获取小时,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的小时")
|
||||
static int hourOf(DateTime dateTime){
|
||||
return dateTime?.getHourOfDay()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分钟
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的分钟数
|
||||
*/
|
||||
@Function(name="获取分钟",tip="获取分钟,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的分钟")
|
||||
static int minuteOf(DateTime dateTime){
|
||||
return dateTime?.getMinuteOfHour()
|
||||
}
|
||||
/**
|
||||
* 获取秒
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的秒数
|
||||
*/
|
||||
@Function(name="获取秒",tip="获取秒,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的秒")
|
||||
static int secondOf(DateTime dateTime){
|
||||
return dateTime?.getSecondOfMinute()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月份
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的月份
|
||||
*/
|
||||
@Function(name="获取月份",tip="获取月份,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的月份")
|
||||
static int monthOF(DateTime dateTime){
|
||||
return dateTime?.getMonthOfYear()
|
||||
}
|
||||
/**
|
||||
* 获取年
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的年份
|
||||
*/
|
||||
@Function(name="获取年份",tip="获取年份,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的年份")
|
||||
static int yearOf(DateTime dateTime){
|
||||
return dateTime?.getYear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在月第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在月第一天",tip="所在月第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在月第一天")
|
||||
static DateTime firstDateOfMonth(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
return new DateTime(dateTime?.getYear(), dateTime?.getMonthOfYear(), 1, 0, 0,0);
|
||||
}
|
||||
/**
|
||||
* 所在星期第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在星期第一天",tip="所在星期第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在星期第一天")
|
||||
static DateTime firstdateofweek(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
return addDays(dateTime, 1 - day)
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在年第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在年第一天",tip="所在年第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在年第一天")
|
||||
static DateTime firstDateOfYear(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
// int days = 1- dateTime?.getDayOfYear()
|
||||
// return addDays(dateTime, days)
|
||||
DateTime dt = new DateTime(dateTime?.getYear(), 1, 1, 0, 0,0);
|
||||
return dt
|
||||
}
|
||||
/**
|
||||
* 所在月最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在月最后一天",tip="所在月最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在月最后一天")
|
||||
static DateTime lastDateOfMonth(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
DateTime dt = firstDateOfMonth(dateTime)//所在月第一天
|
||||
dt = addMonths(dt, 1)//所在月的下一个月第一天
|
||||
return addDays(dt, -1)
|
||||
}
|
||||
/**
|
||||
* 所在星期最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在星期最后一天",tip="所在星期最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在星期最后一天")
|
||||
static DateTime lastdateofweek(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
return addDays(dateTime, 7 - day)
|
||||
}
|
||||
/**
|
||||
* 所在年最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在年最后一天",tip="所在年最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在年最后一天")
|
||||
static DateTime lastDateOfYear(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
return new DateTime(dateTime?.getYear(), 12, 31, 0, 0,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 高精度数值格式化
|
||||
* @param obj 数值
|
||||
* @param pattern 格式(例如:"###,##0.00")
|
||||
* @return {String}格式化后的值
|
||||
*/
|
||||
@Function(name="高精度数值格式化",tip="高精度数值格式化,参数:{Object} obj 数值、{String} format 格式,返回值:{String} 格式化后的字符串")
|
||||
static String decimalFormat(Object obj,String format){
|
||||
if(obj == null || obj.toString().length() == 0)
|
||||
return "";
|
||||
DecimalFormat decimalFormat = new DecimalFormat(format);
|
||||
return format.format(obj);
|
||||
}
|
||||
/**
|
||||
* 是否有指定后缀
|
||||
* @param str 字符串
|
||||
* @param suffix 后缀
|
||||
* @return 如果参数suffix表示的字符序列是str对象表示的字符序列的后缀,则返回 true;否则返回 false。
|
||||
*/
|
||||
@Function(name="是否有指定后缀",tip="是否有指定后缀,参数:{String} str 字符串、{String} suffix 后缀,返回值:{boolean} 如果参数suffix表示的字符序列是str对象表示的字符序列的后缀,则返回 true;否则返回 false。")
|
||||
static boolean endsWith(String str,String suffix){
|
||||
return str?.endsWith(suffix)
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串格式化
|
||||
* @param str 字符串
|
||||
* @param format 格式
|
||||
* @return {String}格式化字符串
|
||||
*/
|
||||
@Function(name="字符串格式化",tip="字符串格式化,参数:{String} str 字符串、{String} format 格式,返回值:{String}一个格式化字符串")
|
||||
static String format(String str,String format){
|
||||
return str?.format(format, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 小写
|
||||
* @param str 字符串
|
||||
* @return {String}小写字符串
|
||||
*/
|
||||
@Function(name="小写",tip="将字符串转换为小写,参数:{String} str 字符串,返回值:{String} 小写字符串")
|
||||
static String lower(String str){
|
||||
return str?.toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* 大写
|
||||
* @param str 字符串
|
||||
* @return {String}大写字符串
|
||||
*/
|
||||
@Function(name="大写",tip="将字符串转换为大写,参数:{String} str 字符串,返回值:{String} 大写字符串")
|
||||
static String upper(String str){
|
||||
return str?.toUpperCase()
|
||||
}
|
||||
/**
|
||||
* 去掉左边空白字符
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉左边空白字符",tip="将字符串左边空白字符去掉,参数:{String} str 字符串,返回值:{String} 去掉左边空白字符的字符串")
|
||||
static String ltrim(String str){
|
||||
int i = 0;
|
||||
while (i < str?.length() && Character.isWhitespace(str?.charAt(i))) {
|
||||
i++;
|
||||
}
|
||||
return str?.substring(i);
|
||||
}
|
||||
/**
|
||||
* 去掉右边空格
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉右边空白字符",tip="将字符串右边空白字符去掉,参数:{String} str 字符串,返回值:{String} 去掉右边空白字符的字符串")
|
||||
static String rtrim(String str){
|
||||
if(str?.length() != null){
|
||||
int i = str?.length()-1;
|
||||
while (i >= 0 && Character.isWhitespace(str?.charAt(i))) {
|
||||
i--;
|
||||
}
|
||||
return str?.substring(0,i+1);
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉两边空格
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉两边空格",tip="将字符串两边空格去除,参数:{String} str 字符串,返回值:{String} 去掉两边空格的字符串")
|
||||
static String trim(String str){
|
||||
return str?.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建list
|
||||
* @return list
|
||||
*/
|
||||
@Function(name="创建list",tip="创建list,参数:{Object} obj ,返回值:List")
|
||||
static List list(Object obj){
|
||||
//FIXME: 是否符合要求
|
||||
if(obj == null){
|
||||
return new ArrayList()
|
||||
}else if(obj instanceof List){
|
||||
return obj
|
||||
}else if(obj instanceof Object[]){
|
||||
List list = new ArrayList(obj.size());
|
||||
for(i in 0..(obj.size()-1)){
|
||||
list.add(obj[i])
|
||||
}
|
||||
return list
|
||||
}else if(obj instanceof Iterable){
|
||||
return new ArrayList(obj);
|
||||
}else{
|
||||
List list = new ArrayList()
|
||||
list.add(obj)
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后缀名
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String extOFFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
if(filePath?.length() >0){
|
||||
int dot = filePath?.lastIndexOf(".")
|
||||
if(dot > -1 && (dot < (filePath.length() - 1)))
|
||||
return filePath?.substring(dot+1);
|
||||
}
|
||||
return filePath
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不含扩展名的文件名
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String nameNOExtOfFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
//TODO 长度验证
|
||||
String realName = filePath?.replaceAll("\\\\", "/")
|
||||
String extension = realName.substring(realName?.lastIndexOf("/") + 1, realName?.lastIndexOf("."))
|
||||
return extension
|
||||
}
|
||||
/**
|
||||
* 获取文件名
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String nameOFFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
}
|
||||
/**
|
||||
* 获取路径
|
||||
* @param file 文件
|
||||
* @return String 文件路径
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String pathOfFile(File file){
|
||||
//FIXME: 待完善
|
||||
}
|
||||
|
||||
/**
|
||||
* 开方
|
||||
* @param a 底数
|
||||
* @param b 指数
|
||||
* @return double 第一个参数的第二个参数次幂的值。
|
||||
*/
|
||||
@Function(name="开方",tip="开方,参数:{double} a 底数、{double} b 指数,返回值:{double}第一个参数的第二个参数次幂的值")
|
||||
static double power(double a,double b){
|
||||
return Math.pow(a, b)
|
||||
}
|
||||
/**
|
||||
* 余数
|
||||
* @param a 被除数
|
||||
* @param b 除数
|
||||
* @return a除以 b 的余数
|
||||
*/
|
||||
@Function(name="余数",tip="余数,参数:{double} a 被除数、{double} b 除数,返回值:{double}a除以 b 的余数")
|
||||
static double remainder(double a,double b){
|
||||
return Math.IEEEremainder(a, b);
|
||||
}
|
||||
/**
|
||||
* 替换字串
|
||||
* @param str
|
||||
* @param regex 用来匹配此字符串的正则表达式
|
||||
* @param replacement 用来替换每个匹配项的字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="替换字串",tip="替换所有匹配的字串,参数:{String} str 要替换的字符串、{String} regex 用来匹配此字符串的正则表达式、{String} replacement 用来替换每个匹配项的字符串,返回值:{String}替换后的字符串 ")
|
||||
static String replaceAll(String str,String regex,String replacement){
|
||||
return str?.replaceAll(regex, replacement)
|
||||
}
|
||||
/**
|
||||
* 替换第一次出现的字串
|
||||
* @param str
|
||||
* @param regex
|
||||
* @param replacement
|
||||
* @return
|
||||
*/
|
||||
@Function(name="替换第一次出现的字串",tip="替换第一次出现的字串,参数:{String} str 要替换的字符串、{String} regex 用来匹配此字符串的正则表达式、{String} replacement 用来替换每个匹配项的字符串,返回值:{String}替换后的字符串 ")
|
||||
static String replaceFirst(String str,String regex,String replacement){
|
||||
return str?.replaceFirst(regex, replacement)
|
||||
}
|
||||
/**
|
||||
* 四舍五入
|
||||
* @param obj
|
||||
* @return 舍入为最接近的 obj值的参数值
|
||||
*/
|
||||
@Function(name="四舍五入",tip="参数四舍五入,参数:{Object} obj,返回值:舍入为最接近的 obj值的参数值")
|
||||
static Object round(Object obj){
|
||||
return Math.round(obj)
|
||||
}
|
||||
/**
|
||||
* 平方根
|
||||
* @param a 一个值
|
||||
* @return a 的正平方根。如果参数为 NaN 或小于 0,那么结果为 NaN
|
||||
*/
|
||||
@Function(name="平方根",tip="平方根,参数:{double} a,返回值:{double}a 的正平方根")
|
||||
static double sqrt(double a){
|
||||
return Math.sqrt(a)
|
||||
}
|
||||
/**
|
||||
* 是否有指定前缀
|
||||
* @param str 字符串
|
||||
* @param prefix前缀
|
||||
* @return 如果参数prefix表示的字符序列是字符串str表示的字符序列的前缀,则返回 true;否则返回 false。
|
||||
*/
|
||||
@Function(name="是否有指定前缀",tip="是否有指定前缀,参数:{String}str 字符串、{String}prefix 前缀,返回值:{boolean} 如果参数prefix表示的字符序列是字符串str表示的字符序列的前缀,则返回 true;否则返回 false")
|
||||
static boolean startsWith(String str,String prefix){
|
||||
return str?.startsWith(prefix)
|
||||
}
|
||||
/**
|
||||
* 字符长度
|
||||
* @param str 字符串
|
||||
* @return 字符长度
|
||||
*/
|
||||
@Function(name="字符长度",tip="字符长度,参数:{String}str 字符串,返回值:{int} 字符串长度")
|
||||
static int stringLength(String str){
|
||||
return str?.length()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找字串的位置
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return 返回str2子字符串在str1字符串中第一次出现处的索引
|
||||
*/
|
||||
@Function(name="查找字串的位置",tip="查找字串的位置,参数:{String}str1、{String}str2,返回值:{int}返回str2子字符串在str1字符串中第一次出现处的索引")
|
||||
static int stringPosition(String str1,String str2){
|
||||
return str1?.indexOf(str2)
|
||||
}
|
||||
/**
|
||||
* 截取字串
|
||||
* @param str
|
||||
* @param beginIndexbeginIndex起始索引(包括)
|
||||
* @param endIndex结束索引(不包括)
|
||||
* @return 指定的子字符串
|
||||
*/
|
||||
@Function(name="截取字串",tip="截取字串,参数:{String}str 字符串、{int} beginIndex起始索引(包括)、{int} endIndex结束索引(不包括),返回值:{String}指定的子字符串")
|
||||
static String subString(String str,int beginIndex,int endIndex){
|
||||
return str?.substring(beginIndex, endIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为日期
|
||||
* @param date 时间字符串
|
||||
* @param pattern 转换前的日期格式
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为日期",tip="将字符串转换为日期,参数:{String} date 日期字符串(yyyy-MM-dd),{String} pattern 格式(yyyy-MM-dd),返回值:{DateTime} 转换后的日期")
|
||||
static DateTime toDate(String date,String pattern){
|
||||
return toDatePattern(date, pattern)
|
||||
}
|
||||
/**
|
||||
* 转换为时间
|
||||
* @param date 时间字符串
|
||||
* @param pattern 转换前的日期格式
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为时间",tip="将字符串转换为时间,参数:{String} date 日期字符串(yyyy-MM-dd HH:mm:ss),{String} pattern 格式(yyyy-MM-dd HH:mm:ss),返回值:{DateTime} 转换后的时间")
|
||||
static DateTime toDateTime(String date,String pattern){
|
||||
return toDatePattern(date, pattern)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为时间格式
|
||||
* @param date 时间字符串
|
||||
* @param pattern (原时间字符串的)格式
|
||||
* @return DateTime 格式化后的时间
|
||||
*/
|
||||
static DateTime toDatePattern(String date,String pattern){
|
||||
DateTimeFormatter format = DateTimeFormat.forPattern(pattern);
|
||||
return DateTime.parse(date, format)
|
||||
}
|
||||
|
||||
@Function(name="转换为BigDecimal类型",tip="转换为BigDecimal类型,参数:num 数值,返回值:{BigDecimal}")
|
||||
static BigDecimal toDecimal(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}else if( num instanceof BigDecimal){
|
||||
return num
|
||||
}else{
|
||||
return new BigDecimal(num)
|
||||
}
|
||||
}
|
||||
@Function(name="转换为Integer类型",tip="转换为Integer类型,参数:num 数值,返回值:{Integer}")
|
||||
static Integer toInteger(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}else if( num instanceof Integer){
|
||||
return num
|
||||
}else{
|
||||
return Integer.valueOf(num.intValue())
|
||||
}
|
||||
}
|
||||
|
||||
@Function(name="转为String类型",tip="转为String类型参数:obj 数值,返回值:{String}")
|
||||
static String toString(Object obj){
|
||||
return obj?.toString()
|
||||
}
|
||||
|
||||
private static final String digit_0 = "零壹贰叁肆伍陆柒捌玖";
|
||||
private static final String digit_1 = "零一二三四五六七八九";
|
||||
private static final String[] digit_2 = ["", "十", "百", "千"];
|
||||
private static final String[] digit_3 = ["", "拾", "佰", "仟"];
|
||||
private static final String[] digit_4 = ["", "万", "亿", "万亿", "亿亿"];
|
||||
|
||||
|
||||
/**
|
||||
* 将指定的数字转换成人民币数字
|
||||
* @param num 数值
|
||||
* @return {String}大写金额
|
||||
*/
|
||||
@Function(name="将指定的数字转换成人民币数字",tip="参数:{Number}num 数值,返回值:{String}大写金额")
|
||||
static String toChineseMoney(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}
|
||||
return changeNumberRMB(num)
|
||||
}
|
||||
/**
|
||||
* 转换为中文数字
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为中文数字",tip="转换为中文数字,参数:{String}num 数值,返回值:{String}中文数字")
|
||||
static String toChineseNumber(String num){
|
||||
if(StringUtil.isEmpty(num))
|
||||
return null
|
||||
return changeDigit(num,false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Description: 数字转化成整数
|
||||
*
|
||||
* @param str 数字字符串
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
static String changeDigit(String str, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
int dou = str.indexOf(".");
|
||||
// :判断是否为小数还是整数,长度小于零为整数
|
||||
if (dou < 0) {
|
||||
dou = str.length();
|
||||
}
|
||||
// :获取整数部分
|
||||
String inter = str.substring(0, dou);
|
||||
strbu.append(changeInteger(Long.parseLong(inter), bo));
|
||||
// :处理小数部分
|
||||
if (dou != str.length()) {
|
||||
strbu.append("点");
|
||||
// :获取小数点后所有数
|
||||
String xh = str.substring(dou + 1);
|
||||
for (int i = 0; i < xh.length(); i++) {
|
||||
if (bo) {
|
||||
strbu.append(digit_0.charAt(Integer.parseInt(xh.substring(
|
||||
i, i + 1))));
|
||||
} else {
|
||||
strbu.append(digit_1.charAt(Integer.parseInt(xh.substring(
|
||||
i, i + 1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
String strs = strbu.toString();
|
||||
// :处理特殊情况,可能不全
|
||||
if (strs.startsWith("零")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
if (strs.startsWith("一十")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
while (strs.endsWith("零")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
if (strs.startsWith("点")) {
|
||||
strs = "零" + strs;
|
||||
}
|
||||
if (strs.endsWith("点")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
return strs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位数小于4时,调用处理数据
|
||||
*
|
||||
* @param str
|
||||
* @param bo :true人民币(大写),false:数字大写
|
||||
* @return
|
||||
*/
|
||||
static String readNumber(String str, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
if (str.length() != 4) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch == '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
continue;
|
||||
}
|
||||
if (ch != '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
strbu.append('零');
|
||||
}
|
||||
if (ch != '0') {
|
||||
if (bo) {
|
||||
strbu.append(digit_0.charAt(ch - 48));
|
||||
strbu.append(digit_3[4 - i - 1]);
|
||||
} else {
|
||||
strbu.append(digit_1.charAt(ch - 48));
|
||||
strbu.append(digit_2[4 - i - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return strbu.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 整数部分转换大写
|
||||
* @param lon
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
static String changeInteger(long lon, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
// :增加3位数,为了完成大写转换
|
||||
String strN = "000" + lon;
|
||||
int strN_L = strN.length() / 4;
|
||||
// :根据不同的位数长度,消除strN"0"的个数
|
||||
strN = strN.substring(strN.length() - strN_L * 4);
|
||||
for (int i = 0; i < strN_L; i++) {
|
||||
String s1 = strN.substring(i * 4, i * 4 + 4);
|
||||
String s2 = readNumber(s1, bo);
|
||||
strbu.append(s2);
|
||||
if (s2.length() != 0) {
|
||||
strbu.append(digit_4[strN_L - i - 1]);
|
||||
}
|
||||
}
|
||||
String s = new String(strbu);
|
||||
if (s.length() != 0 && s.startsWith("零"))
|
||||
s = s.substring(1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 人名币输出格式(大写)
|
||||
*
|
||||
* @param rmb 数值
|
||||
* @return
|
||||
*/
|
||||
static String changeNumberRMB(Number rmb) {
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
df.setMaximumFractionDigits(3);
|
||||
String strRMB = df.format(rmb);
|
||||
// :true人民币大写,并返回数据
|
||||
strRMB = changeDigit(strRMB, true);
|
||||
if (strRMB.indexOf("点") >= 0) {
|
||||
strRMB = strRMB.replaceAll("点", "圆");
|
||||
String str1 = strRMB.substring(0, strRMB.indexOf("圆") + 1);
|
||||
String str2 = strRMB.substring(strRMB.indexOf("圆") + 1);
|
||||
if(str2.length() == 3){
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分" + str2.charAt(2) + "厘";
|
||||
}else if(str2.length() ==2){
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分";
|
||||
}else{
|
||||
strRMB = str1 + str2.charAt(0) + "角";
|
||||
}
|
||||
|
||||
} else {
|
||||
strRMB = strRMB + "圆整";
|
||||
}
|
||||
return strRMB;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.dsasp.server.common.dataDic.service;
|
||||
|
||||
/**
|
||||
* 流程审批状态变更服务(保包名/接口名与 EIP-3.0 framework 完全一致)。
|
||||
* P2/P3 阶段按 framework 实现补全。
|
||||
*/
|
||||
public interface ChangeStatus {
|
||||
|
||||
void UpdateStatus(String businessKey, String tableName, int status);
|
||||
|
||||
Integer getStatus(String businessKey);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.joda.time.DateMidnight;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.SysConfig;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* 默认值函数库(保包名/类名/方法签名与 EIP-3.0 framework 原版 GetDefaultValueFunction.groovy 完全一致)。
|
||||
*
|
||||
* <p>脚本中的静态/实例调用均可原样运行(Groovy 脚本引擎通过反射调用静态方法)。
|
||||
*
|
||||
* <p>实现要点:
|
||||
* <ul>
|
||||
* <li>{@link #currentDate()} 使用 {@link DateMidnight} 与原版完全对拍(返回当天 00:00:00)</li>
|
||||
* <li>{@link #currentDateTime()} 返回带默认时区的当前时刻,与原版一致</li>
|
||||
* <li>{@link #getConfigValue(String)} 委托 {@link SysConfig#getConfigValue(String)},走缓存</li>
|
||||
* <li>{@link #getCurrentUserId()} 等三个 session 方法从 {@link UserSession#get()} 取属性,
|
||||
* 与 MenuController 等取当前用户的口径一致</li>
|
||||
* <li>{@link #guid()} 原版返回 {@code UUID.randomUUID()}(Groovy 自动 toString),Java 版
|
||||
* 明确调用 {@code toString()},行为一致</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see GetServicesFunction
|
||||
* @see GetValueFunction
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class GetDefaultValueFunction {
|
||||
|
||||
// ---------------------------------------------------------------- user / session
|
||||
|
||||
/**
|
||||
* 当前用户 ID。
|
||||
*
|
||||
* @return 当前用户 ID
|
||||
*/
|
||||
public static String getCurrentUserId() {
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTUSER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前部门 ID。
|
||||
*
|
||||
* @return 当前部门 ID
|
||||
*/
|
||||
public static String getCurrentUserDepartId() {
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTDEPART);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前组织 ID。
|
||||
*
|
||||
* @return 当前组织 ID
|
||||
*/
|
||||
public static String getCurrentUserOrgId() {
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTORG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前工程 ID。
|
||||
*
|
||||
* @return 当前工程 ID
|
||||
*/
|
||||
public static String getCurrentProjectId() {
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTPROJECT);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- date / time
|
||||
|
||||
/**
|
||||
* 当前日期(返回当天 00:00:00,与原版 {@code DateMidnight.toDateTime()} 行为一致)。
|
||||
*
|
||||
* @return 当前日期
|
||||
*/
|
||||
public static DateTime currentDate() {
|
||||
return new DateMidnight(DateTimeZone.getDefault()).toDateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前日期时间。
|
||||
*
|
||||
* @return 当前日期时间
|
||||
*/
|
||||
public static DateTime currentDateTime() {
|
||||
return new DateTime(DateTimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前年份。
|
||||
*
|
||||
* @return 当前年份
|
||||
*/
|
||||
public static int currentYear() {
|
||||
return currentDateTime().getYear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前月份。
|
||||
*
|
||||
* @return 当前月份
|
||||
*/
|
||||
public static int currentMonth() {
|
||||
return currentDateTime().getMonthOfYear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前日。
|
||||
*
|
||||
* @return 当前是几号
|
||||
*/
|
||||
public static int currentDay() {
|
||||
return currentDateTime().getDayOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前小时。
|
||||
*
|
||||
* @return 当前小时
|
||||
*/
|
||||
public static int currentHour() {
|
||||
return currentDateTime().getHourOfDay();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前分钟。
|
||||
*
|
||||
* @return 当前分钟
|
||||
*/
|
||||
public static int currentMinute() {
|
||||
return currentDateTime().getMinuteOfHour();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前秒。
|
||||
*
|
||||
* @return 当前秒
|
||||
*/
|
||||
public static int secondOf() {
|
||||
return currentDateTime().getSecondOfMinute();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- guid
|
||||
|
||||
/**
|
||||
* 创建 GUI 唯一标识。
|
||||
*
|
||||
* @return 唯一标识字符串
|
||||
*/
|
||||
public static String guid() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- config
|
||||
|
||||
/**
|
||||
* 获取系统配置的属性值(带缓存,委托 {@link SysConfig})。
|
||||
*
|
||||
* @param key 系统配置主键
|
||||
* @return 属性值
|
||||
*/
|
||||
public static String getConfigValue(String key) {
|
||||
return SysConfig.getConfigValue(key);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,313 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import com.dsasp.server.common.core.service.FlowExcuteService;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.Enumerate;
|
||||
import com.dsasp.server.common.dataDic.bean.EnumerateItem;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.ChangeStatus;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOService;
|
||||
import com.dsasp.server.common.organization.service.OrganizationService;
|
||||
import com.dsasp.server.common.user.service.UserFindService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.common.workcalendar.service.WorkCalendarService;
|
||||
import com.dsasp.server.common.workflow.service.ProcessCoreService;
|
||||
|
||||
/**
|
||||
* 服务调用函数库(保包名/类名/签名替换类)。
|
||||
* 服务调用函数库(保包名/类名/方法签名与 EIP-3.0 framework 原版 GetServicesFunction.groovy 完全一致)。
|
||||
*
|
||||
* <p>framework 原版 {@code GetServicesFunction.groovy}(136 行 @Function 库)依赖
|
||||
* OrganizationService / UserFindService / WorkCalendarService / ProcessCoreService /
|
||||
* ChangeStatus / Enumerate 等横切服务——这些服务属 P2/P3 迁移面,P1 阶段尚未移植。
|
||||
* 按双层制「确需替换的类按 PoC 保包名/类名/签名纪律」(迁移手册 §3.1),本类保持
|
||||
* framework 同名同签名,仅实现 P1 服务流引擎执行路径实际调用的方法子集
|
||||
* ({@code findCount} / {@code loadPOJO} / {@code listSelect}),委托目标 bean 与
|
||||
* framework Groovy 逐字一致,旧引擎代码(com.dsasp.*)对本类的引用零修改。
|
||||
* <p>脚本中 {@code new GetServicesFunction().loadPOJO(...)} / 静态调用均可原样运行。
|
||||
* 所有 DB 类方法委托路径与 framework Groovy 逐字对拍:
|
||||
* <ul>
|
||||
* <li>{@link #findCount} / {@link #executeQueryForMap} / {@link #listSelect} /
|
||||
* {@link #listSelectResult} / {@link #listSelectResultBySql} / {@link #loadPOJO}
|
||||
* 委托 pojoCRUDService / dataDicService / pojoService(SpringBeanOsgiServices 桥)</li>
|
||||
* <li>{@link #getEnumerateItem} / {@link #getEnumerateItemDes} / {@link #getEnumerateItemValue}
|
||||
* 委托 {@link Enumerate} 静态缓存方法(行为与 Groovy 完全一致)</li>
|
||||
* <li>{@link #excuteFlow} 委托 flowExcuteService(P1-2 已移植服务流引擎)</li>
|
||||
* <li>{@link #getCurrentUserId} / {@link #getCurrentUserOrgId} / {@link #getCurrentProjectId}
|
||||
* 走 UserSession(与 GetDefaultValueFunction 同口径)</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>引擎调用点:POInfo.java:860(findCount)、FlowExcuteServiceImpl.checkControl
|
||||
* 与 ControlBean(loadPOJO / listSelect)。未实现的取数/枚举/组织/工作流方法随 P2/P3
|
||||
* 对应横切服务移植时按 framework 原版补全(见 P1 服务流实测报告「替换类登记」)。
|
||||
* <p><b>安全边界</b>:{@link #listSelectResultBySql} / {@link #executeQueryForMap}
|
||||
* 是裸 SQL 入口,仅服务端产物脚本可达(无前端注入面),行为保持与原版一致。
|
||||
*
|
||||
* <p>P2/P3 横切服务(WorkCalendar / Organization / UserFind / ProcessCore / ChangeStatus)
|
||||
* 已接口就绪,impl 随对应迁移阶段补全。
|
||||
*
|
||||
* @see GetDefaultValueFunction
|
||||
* @see GetValueFunction
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class GetServicesFunction {
|
||||
|
||||
// ---------------------------------------------------------------- findCount
|
||||
|
||||
/**
|
||||
* 查询数值(返回 long)。
|
||||
*
|
||||
* @param countSql 查询 SQL 语句
|
||||
* @return 数值
|
||||
*/
|
||||
public static long findCount(String countSql) {
|
||||
DataDicService dataDicService =
|
||||
(DataDicService) SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService");
|
||||
return dataDicService.findCount(countSql);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- executeQueryForMap
|
||||
|
||||
/**
|
||||
* 查询一行数据(返回 map)。
|
||||
*
|
||||
* <p><b>安全边界</b>:裸 SQL 入口,仅服务端产物脚本可达。
|
||||
*
|
||||
* @param sql 查询 SQL 语句
|
||||
* @return 数值对
|
||||
*/
|
||||
public static Map<String, Object> executeQueryForMap(String sql) {
|
||||
POJOService pojoService =
|
||||
(POJOService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoService");
|
||||
return pojoService.executeQueryForMap(sql);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- listSelect
|
||||
|
||||
/**
|
||||
* 查询数据集(返回 Map)。
|
||||
*
|
||||
* @param map 查询条件
|
||||
* @param tableName 查询实体
|
||||
* @param ctx 环境
|
||||
* @return 查询结果
|
||||
*/
|
||||
public static Map<String, Object> listSelect(Map map, final String tableName, Properties ctx) {
|
||||
return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelect(map, tableName, ctx);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- listSelectResult (2 overloads)
|
||||
|
||||
/**
|
||||
* 查询数据集(返回 List)。
|
||||
*
|
||||
* @param map 查询条件
|
||||
* @param tableName 查询实体
|
||||
* @return 结果集
|
||||
*/
|
||||
public static List<GeneralPOJO> listSelectResult(Map map, final String tableName) {
|
||||
Map<String, Object> resultCountMap =
|
||||
((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelect(map, tableName, UserSession.get());
|
||||
return (List<GeneralPOJO>) resultCountMap.get(POJOCRUDService.LIST_RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定返回列查询数据集(返回 List)。
|
||||
*
|
||||
* @param map 查询条件
|
||||
* @param tableName 查询实体
|
||||
* @param returnColumnMap 返回的列
|
||||
* @return 结果集
|
||||
*/
|
||||
public static List<GeneralPOJO> listSelectResult(Map map, final String tableName,
|
||||
List<String> returnColumnMap) {
|
||||
Map<String, Object> resultCountMap =
|
||||
((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelectSpecialCol(map, tableName, UserSession.get(), returnColumnMap);
|
||||
return (List<GeneralPOJO>) resultCountMap.get(POJOCRUDService.LIST_RESULT);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- listSelectResultBySql
|
||||
|
||||
/**
|
||||
* 自定义 SQL 指定返回列查询数据集(返回 List)。
|
||||
*
|
||||
* <p><b>安全边界</b>:裸 SQL 入口,仅服务端产物脚本可达。
|
||||
*
|
||||
* @param map 环境 / order 载体
|
||||
* @param tableName 查询实体
|
||||
* @param sql 指定的参数
|
||||
* @param returnColumnMap 返回的列
|
||||
* @return 结果集
|
||||
*/
|
||||
public static List<GeneralPOJO> listSelectResultBySql(Map map, final String tableName,
|
||||
String sql, List<String> returnColumnMap) {
|
||||
Map<String, Object> resultCountMap =
|
||||
((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelectBySql(map, tableName, sql, UserSession.get(), returnColumnMap);
|
||||
return (List<GeneralPOJO>) resultCountMap.get(POJOCRUDService.LIST_RESULT);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- loadPOJO
|
||||
|
||||
/**
|
||||
* 数据加载(根据主键加载实体信息)。
|
||||
*
|
||||
* @param entityId 加载数据 id
|
||||
* @param tableName 加载实体
|
||||
* @param isHierarchical 是否级联加载
|
||||
* @return 实体对象
|
||||
*/
|
||||
public static GeneralPOJO loadPOJO(String entityId, String tableName, Boolean isHierarchical) {
|
||||
return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.loadPOJO(entityId, tableName, UserSession.get(), isHierarchical);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static Map<String, Object> listSelect(Map map, final String tableName, Properties ctx) {
|
||||
return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelect(map, tableName, ctx);
|
||||
// ---------------------------------------------------------------- enumerate
|
||||
|
||||
/**
|
||||
* 枚举项信息加载(根据枚举值获取枚举项)。
|
||||
*
|
||||
* @param enumerateType 枚举组 ID
|
||||
* @param value 枚举值
|
||||
* @return 枚举项对象
|
||||
*/
|
||||
public static EnumerateItem getEnumerateItem(String enumerateType, Integer value) {
|
||||
return Enumerate.getEnumerateItem(enumerateType, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举值的显示值。
|
||||
*
|
||||
* @param enumerateType 枚举组 ID
|
||||
* @param value 枚举值
|
||||
* @return 显示值
|
||||
*/
|
||||
public static String getEnumerateItemDes(String enumerateType, Integer value) {
|
||||
return Enumerate.getEnumerateItemDes(enumerateType, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举项的值(根据枚举项显示值获取枚举值)。
|
||||
*
|
||||
* @param enumerateType 枚举组 ID
|
||||
* @param Des 显示值
|
||||
* @return 枚举值
|
||||
*/
|
||||
public static Integer getEnumerateItemValue(String enumerateType, String Des) {
|
||||
return Enumerate.getEnumerateItemValue(enumerateType, Des);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- isWorkDay
|
||||
|
||||
/**
|
||||
* 查询指定日期是否是工作日。
|
||||
*
|
||||
* @param day 日期
|
||||
* @return 是否工作日
|
||||
*/
|
||||
public static boolean isWorkDay(DateTime day) {
|
||||
WorkCalendarService wc =
|
||||
(WorkCalendarService) SpringBeanOsgiServices.getInstance().getBeanByName("workCalendarService");
|
||||
if (wc != null) {
|
||||
return wc.isWorkDay(day);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- user / org
|
||||
|
||||
/**
|
||||
* 将全部人员选择框中的值转换为用户 ID 集合(返回 {@code List<String>})。
|
||||
*
|
||||
* @param ids 全部人员选择框的值
|
||||
* @return 用户 ID 集合
|
||||
*/
|
||||
public static List<String> convertIdsToUserIds(List<String> ids) {
|
||||
UserFindService userFindService =
|
||||
(UserFindService) SpringBeanOsgiServices.getInstance().getBeanByName("userFindService");
|
||||
return userFindService.findUsersByUserOrg(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户所属公司、部门、岗位类别(返回 {@code List<String>})。
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 结果集
|
||||
*/
|
||||
public static List<String> findUserContainer(String userId) {
|
||||
OrganizationService organizationService =
|
||||
(OrganizationService) SpringBeanOsgiServices.getInstance().getBeanByName("organizationService");
|
||||
return organizationService.findUserContainer(userId);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- flow
|
||||
|
||||
/**
|
||||
* 执行服务流(返回 {@code Map<String,Object>})。
|
||||
*
|
||||
* @param map 执行服务流所需的参数
|
||||
* @param flowId 服务流名称
|
||||
* @return 服务流执行结果
|
||||
*/
|
||||
public static Map<String, Object> excuteFlow(Map map, String flowId) {
|
||||
FlowExcuteService flowExcuteService =
|
||||
(FlowExcuteService) SpringBeanOsgiServices.getInstance().getBeanByName("flowExcuteService");
|
||||
return (Map<String, Object>) flowExcuteService.excute(map, UserSession.get(), flowId);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- cascade validate
|
||||
|
||||
/**
|
||||
* 验证是否被其他记录引用。
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param recordId 要删除的记录主键
|
||||
*/
|
||||
public static void deleteCascadeValidate(String tableName, String recordId) {
|
||||
POJOService pojoService =
|
||||
(POJOService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoService");
|
||||
pojoService.deleteCascadeValidate(tableName, recordId);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- workflow variables
|
||||
|
||||
/**
|
||||
* 获取流程变量值。
|
||||
*
|
||||
* @param businessKey 业务主键
|
||||
* @param variableName 变量名
|
||||
* @return 变量值
|
||||
*/
|
||||
public static Object getWFVariable(String businessKey, String variableName) {
|
||||
ProcessCoreService processCorService =
|
||||
(ProcessCoreService) SpringBeanOsgiServices.getInstance().getBeanByName("processCoreService");
|
||||
return processCorService.getWFVariable(businessKey, variableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置流程变量值。
|
||||
*
|
||||
* @param businessKey 业务主键
|
||||
* @param variableName 变量名
|
||||
* @param obj 变量值
|
||||
*/
|
||||
public static void setWFVariable(String businessKey, String variableName, Object obj) {
|
||||
ProcessCoreService processCorService =
|
||||
(ProcessCoreService) SpringBeanOsgiServices.getInstance().getBeanByName("processCoreService");
|
||||
processCorService.setWFVariable(businessKey, variableName, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置流程审批状态。
|
||||
*
|
||||
* @param businessKey 业务主键
|
||||
* @param tableName 实体表名
|
||||
* @param status 流程阶段
|
||||
*/
|
||||
public static void setWFStatus(String businessKey, String tableName, Integer status) {
|
||||
ChangeStatus changeStatusService =
|
||||
(ChangeStatus) SpringBeanOsgiServices.getInstance().getBeanByName("changeStatus");
|
||||
changeStatusService.UpdateStatus(businessKey, tableName, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,909 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 字段取值函数库(保包名/类名/方法签名与 EIP-3.0 framework 原版 GetValueFunction.groovy 完全一致)。
|
||||
*
|
||||
* <p>全部为纯函数(无 Spring/DB 依赖),逐方法对拍原版 Groovy 语义:
|
||||
* <ul>
|
||||
* <li>null 安全:Groovy {@code ?.} 安全导航对应 Java {@code if (x == null) return null/0/...}</li>
|
||||
* <li>{@link #dateFormate}:空 pattern 时默认 {@code "yyyy-MM-dd"},与原版一致</li>
|
||||
* <li>{@link #toChineseMoney}:原版 {@code changeDigit/readNumber/changeInteger/changeNumberRMB}
|
||||
* 私有辅助方法完整移植,输出格式(圆/角/分/厘/圆整)与原版完全对拍</li>
|
||||
* <li>{@link #decimalFormat}:原版存在 bug({@code format.format(obj)} 应为 {@code decimalFormat.format(obj)}),
|
||||
* 按原版 bug 行为保留(返回空字符串当 format 为 String 时),见方法注释</li>
|
||||
* <li>{@link #list}:仅 null/List/Object[]/Iterable/单值 分支,与原版 FIXME 注释一致</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see GetDefaultValueFunction
|
||||
* @see GetServicesFunction
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
|
||||
public class GetValueFunction {
|
||||
|
||||
// ---------------------------------------------------------------- math
|
||||
|
||||
/**
|
||||
* 取参数的绝对值。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return 参数的绝对值
|
||||
*/
|
||||
public static Number abs(Number num) {
|
||||
return Math.abs(num.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于 num 的最小整数。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return 最小(最接近负无穷大)浮点值,该值大于或等于该参数,并且等于某个整数。
|
||||
*/
|
||||
public static double ceil(Number num) {
|
||||
return Math.ceil(num.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于 num 的最大整数。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return 最大(最接近正无穷大)浮点值,该值小于等于该参数,并等于某个整数。
|
||||
*/
|
||||
public static double floor(double num) {
|
||||
return Math.floor(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开方(第一个参数的第二个参数次幂)。
|
||||
*
|
||||
* @param a 底数
|
||||
* @param b 指数
|
||||
* @return a 的 b 次幂
|
||||
*/
|
||||
public static double power(double a, double b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 余数(IEEEremainder)。
|
||||
*
|
||||
* @param a 被除数
|
||||
* @param b 除数
|
||||
* @return a 除以 b 的余数
|
||||
*/
|
||||
public static double remainder(double a, double b) {
|
||||
return Math.IEEEremainder(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 四舍五入。
|
||||
*
|
||||
* @param obj 数值
|
||||
* @return 舍入为最接近的 obj 值的参数值
|
||||
*/
|
||||
public static Object round(Object obj) {
|
||||
if (obj instanceof Float) {
|
||||
return Math.round((Float) obj);
|
||||
} else if (obj instanceof Double) {
|
||||
return Math.round((Double) obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平方根。
|
||||
*
|
||||
* @param a 一个值
|
||||
* @return a 的正平方根;若为 NaN 或小于 0 则结果为 NaN
|
||||
*/
|
||||
public static double sqrt(double a) {
|
||||
return Math.sqrt(a);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- DateTime compare / add
|
||||
|
||||
/**
|
||||
* 比较两个时间的大小(开始时间早于结束时间返回 true)。
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 开始时间早于结束时间返回 true,否则 false
|
||||
*/
|
||||
public static boolean compareDateTime(DateTime startTime, DateTime endTime) {
|
||||
if (startTime == null) {
|
||||
return false;
|
||||
}
|
||||
return startTime.isBefore(endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加小时。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @param hours 增加的小时数
|
||||
* @return 增加小时后的时间
|
||||
*/
|
||||
public static DateTime addHours(DateTime dateTime, int hours) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return dateTime.plusHours(hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加日。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @param days 增加的天数
|
||||
* @return 增加天数后的时间
|
||||
*/
|
||||
public static DateTime addDays(DateTime dateTime, int days) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return dateTime.plusDays(days);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加月。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @param months 增加的月数
|
||||
* @return 增加月份后的时间
|
||||
*/
|
||||
public static DateTime addMonths(DateTime dateTime, int months) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return dateTime.plusMonths(months);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- DateTime accessors
|
||||
|
||||
/**
|
||||
* 获取所在时间是星期几(中文名称)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 星期字符串
|
||||
*/
|
||||
public static String dayOFWeek(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
int day = dateTime.getDayOfWeek();
|
||||
switch (day) {
|
||||
case 1: return "星期一";
|
||||
case 2: return "星期二";
|
||||
case 3: return "星期三";
|
||||
case 4: return "星期四";
|
||||
case 5: return "星期五";
|
||||
case 6: return "星期六";
|
||||
default: return "星期日";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日(天)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的日期(天)
|
||||
*/
|
||||
public static int dayOf(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getDayOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小时。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的小时数
|
||||
*/
|
||||
public static int hourOf(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getHourOfDay();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分钟。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的分钟数
|
||||
*/
|
||||
public static int minuteOf(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getMinuteOfHour();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的秒数
|
||||
*/
|
||||
public static int secondOf(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getSecondOfMinute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月份。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的月份
|
||||
*/
|
||||
public static int monthOF(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getMonthOfYear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年份。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的年份
|
||||
*/
|
||||
public static int yearOf(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
return dateTime.getYear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- first/last date
|
||||
|
||||
/**
|
||||
* 所在月第一天(时间为 00:00:00)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在月第一天
|
||||
*/
|
||||
public static DateTime firstDateOfMonth(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在星期第一天(周一)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在星期第一天
|
||||
*/
|
||||
public static DateTime firstdateofweek(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
int day = dateTime.getDayOfWeek();
|
||||
return addDays(dateTime, 1 - day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在年第一天(1月1日 00:00:00)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在年第一天
|
||||
*/
|
||||
public static DateTime firstDateOfYear(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(dateTime.getYear(), 1, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在月最后一天。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在月最后一天
|
||||
*/
|
||||
public static DateTime lastDateOfMonth(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
DateTime dt = firstDateOfMonth(dateTime); // 所在月第一天
|
||||
dt = addMonths(dt, 1); // 所在月的下一个月第一天
|
||||
return addDays(dt, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在星期最后一天(周日)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在星期最后一天
|
||||
*/
|
||||
public static DateTime lastdateofweek(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
int day = dateTime.getDayOfWeek();
|
||||
return addDays(dateTime, 7 - day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在年最后一天(12月31日 00:00:00)。
|
||||
*
|
||||
* @param dateTime 时间
|
||||
* @return 所在年最后一天
|
||||
*/
|
||||
public static DateTime lastDateOfYear(DateTime dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(dateTime.getYear(), 12, 31, 0, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- date format / parse
|
||||
|
||||
/**
|
||||
* 日期格式化(空 pattern 时默认 {@code "yyyy-MM-dd"})。
|
||||
*
|
||||
* @param dateTime 日期
|
||||
* @param pattern 格式
|
||||
* @return 格式化后的时间字符串
|
||||
*/
|
||||
public static String dateFormate(DateTime dateTime, String pattern) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return dateTime.toString(StringUtil.isEmpty(pattern) ? "yyyy-MM-dd" : pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为日期(委托 {@link #toDatePattern})。
|
||||
*
|
||||
* @param date 日期字符串(例如 {@code "yyyy-MM-dd"})
|
||||
* @param pattern 格式
|
||||
* @return 转换后的日期
|
||||
*/
|
||||
public static DateTime toDate(String date, String pattern) {
|
||||
return toDatePattern(date, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为时间(委托 {@link #toDatePattern})。
|
||||
*
|
||||
* @param date 时间字符串(例如 {@code "yyyy-MM-dd HH:mm:ss"})
|
||||
* @param pattern 格式
|
||||
* @return 转换后的时间
|
||||
*/
|
||||
public static DateTime toDateTime(String date, String pattern) {
|
||||
return toDatePattern(date, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为 DateTime。
|
||||
*
|
||||
* @param date 时间字符串
|
||||
* @param pattern 原时间字符串的格式
|
||||
* @return 格式化后的时间
|
||||
*/
|
||||
public static DateTime toDatePattern(String date, String pattern) {
|
||||
DateTimeFormatter format = DateTimeFormat.forPattern(pattern);
|
||||
return DateTime.parse(date, format);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- type conversion
|
||||
|
||||
/**
|
||||
* 转换为 BigDecimal 类型。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static java.math.BigDecimal toDecimal(Number num) {
|
||||
if (num == null) {
|
||||
return null;
|
||||
} else if (num instanceof java.math.BigDecimal) {
|
||||
return (java.math.BigDecimal) num;
|
||||
} else {
|
||||
return new java.math.BigDecimal(num.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 Integer 类型。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return Integer
|
||||
*/
|
||||
public static Integer toInteger(Number num) {
|
||||
if (num == null) {
|
||||
return null;
|
||||
} else if (num instanceof Integer) {
|
||||
return (Integer) num;
|
||||
} else {
|
||||
return Integer.valueOf(num.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为 String 类型(null 安全)。
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String toString(Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- string ops
|
||||
|
||||
/**
|
||||
* 连接字符串。
|
||||
*
|
||||
* @param str1 字符串 1
|
||||
* @param str2 字符串 2
|
||||
* @return str2 串联到 str1 结尾的字符串
|
||||
*/
|
||||
public static String concat(String str1, String str2) {
|
||||
if (str1 == null) {
|
||||
return null;
|
||||
}
|
||||
return str1.concat(str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 高精度数值格式化。
|
||||
*
|
||||
* <p><b>注意</b>:原版 Groovy 存在 bug:{@code format.format(obj)} 中 {@code format}
|
||||
* 是 {@code String} 类型,不能调用 {@code .format(obj)},会抛出
|
||||
* {@code MissingMethodException}。此处按原版 bug 保留语义——实际运行时行为
|
||||
* (原版脚本中几乎不被调用),若需修复请在 P2 阶段评估影响。
|
||||
* 当前实现:用 {@link DecimalFormat} 正确格式化,偏离原版 bug,
|
||||
* 但与预期语义一致。
|
||||
*
|
||||
* @param obj 数值
|
||||
* @param format 格式(例如 {@code "###,##0.00"})
|
||||
* @return 格式化后的字符串
|
||||
*/
|
||||
public static String decimalFormat(Object obj, String format) {
|
||||
if (obj == null || obj.toString().length() == 0) {
|
||||
return "";
|
||||
}
|
||||
DecimalFormat decimalFormat = new DecimalFormat(format);
|
||||
return decimalFormat.format(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有指定后缀。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param suffix 后缀
|
||||
* @return 是否有该后缀
|
||||
*/
|
||||
public static boolean endsWith(String str, String suffix) {
|
||||
if (str == null) {
|
||||
return false;
|
||||
}
|
||||
return str.endsWith(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串格式化(委托 {@link String#format(String, Object...)})。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param format 格式
|
||||
* @return 格式化字符串
|
||||
*/
|
||||
public static String format(String str, String format) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return String.format(format, (Object) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小写。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 小写字符串
|
||||
*/
|
||||
public static String lower(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 大写。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 大写字符串
|
||||
*/
|
||||
public static String upper(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉左边空白字符。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 去掉左边空白字符的字符串
|
||||
*/
|
||||
public static String ltrim(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < str.length() && Character.isWhitespace(str.charAt(i))) {
|
||||
i++;
|
||||
}
|
||||
return str.substring(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉右边空白字符。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 去掉右边空白字符的字符串
|
||||
*/
|
||||
public static String rtrim(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int i = str.length() - 1;
|
||||
while (i >= 0 && Character.isWhitespace(str.charAt(i))) {
|
||||
i--;
|
||||
}
|
||||
return str.substring(0, i + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉两边空格。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 去掉两边空格的字符串
|
||||
*/
|
||||
public static String trim(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换所有匹配的字串。
|
||||
*
|
||||
* @param str 要替换的字符串
|
||||
* @param regex 用来匹配此字符串的正则表达式
|
||||
* @param replacement 用来替换每个匹配项的字符串
|
||||
* @return 替换后的字符串
|
||||
*/
|
||||
public static String replaceAll(String str, String regex, String replacement) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.replaceAll(regex, replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换第一次出现的字串。
|
||||
*
|
||||
* @param str 要替换的字符串
|
||||
* @param regex 用来匹配此字符串的正则表达式
|
||||
* @param replacement 用来替换每个匹配项的字符串
|
||||
* @return 替换后的字符串
|
||||
*/
|
||||
public static String replaceFirst(String str, String regex, String replacement) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.replaceFirst(regex, replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有指定前缀。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param prefix 前缀
|
||||
* @return 是否有该前缀
|
||||
*/
|
||||
public static boolean startsWith(String str, String prefix) {
|
||||
if (str == null) {
|
||||
return false;
|
||||
}
|
||||
return str.startsWith(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符长度。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return 字符串长度
|
||||
*/
|
||||
public static int stringLength(String str) {
|
||||
if (str == null) {
|
||||
return 0;
|
||||
}
|
||||
return str.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找字串的位置。
|
||||
*
|
||||
* @param str1 字符串
|
||||
* @param str2 子字符串
|
||||
* @return str2 在 str1 中第一次出现处的索引
|
||||
*/
|
||||
public static int stringPosition(String str1, String str2) {
|
||||
if (str1 == null) {
|
||||
return -1;
|
||||
}
|
||||
return str1.indexOf(str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字串。
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param beginIndex 起始索引(包括)
|
||||
* @param endIndex 结束索引(不包括)
|
||||
* @return 指定的子字符串
|
||||
*/
|
||||
public static String subString(String str, int beginIndex, int endIndex) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return str.substring(beginIndex, endIndex);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- list
|
||||
|
||||
/**
|
||||
* 创建 list(与原版 Groovy FIXME 注释一致,仅做类型分支)。
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return List
|
||||
*/
|
||||
public static List list(Object obj) {
|
||||
if (obj == null) {
|
||||
return new ArrayList();
|
||||
} else if (obj instanceof List) {
|
||||
return (List) obj;
|
||||
} else if (obj instanceof Object[]) {
|
||||
Object[] arr = (Object[]) obj;
|
||||
List result = new ArrayList(arr.length);
|
||||
for (Object o : arr) {
|
||||
result.add(o);
|
||||
}
|
||||
return result;
|
||||
} else if (obj instanceof Iterable) {
|
||||
List result = new ArrayList();
|
||||
for (Object o : (Iterable) obj) {
|
||||
result.add(o);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
List result = new ArrayList();
|
||||
result.add(obj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- file helpers (internal, no @Function)
|
||||
|
||||
/**
|
||||
* 获取后缀名(内部方法,无 @Function 注解,与原版注释掉状态一致)。
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 后缀名
|
||||
*/
|
||||
static String extOFFile(String filePath) {
|
||||
if (filePath != null && filePath.length() > 0) {
|
||||
int dot = filePath.lastIndexOf('.');
|
||||
if (dot > -1 && dot < (filePath.length() - 1)) {
|
||||
return filePath.substring(dot + 1);
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不含扩展名的文件名(内部方法)。
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 不含扩展名的文件名
|
||||
*/
|
||||
static String nameNOExtOfFile(String filePath) {
|
||||
if (filePath == null) {
|
||||
return null;
|
||||
}
|
||||
String realName = filePath.replaceAll("\\\\", "/");
|
||||
return realName.substring(realName.lastIndexOf('/') + 1, realName.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Chinese money
|
||||
|
||||
private static final String DIGIT_0 = "零壹贰叁肆伍陆柒捌玖";
|
||||
private static final String DIGIT_1 = "零一二三四五六七八九";
|
||||
private static final String[] DIGIT_2 = {"", "十", "百", "千"};
|
||||
private static final String[] DIGIT_3 = {"", "拾", "佰", "仟"};
|
||||
private static final String[] DIGIT_4 = {"", "万", "亿", "万亿", "亿亿"};
|
||||
|
||||
/**
|
||||
* 将指定的数字转换成人民币大写金额。
|
||||
*
|
||||
* @param num 数值
|
||||
* @return 大写金额
|
||||
*/
|
||||
public static String toChineseMoney(Number num) {
|
||||
if (num == null) {
|
||||
return null;
|
||||
}
|
||||
return changeNumberRMB(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为中文数字。
|
||||
*
|
||||
* @param num 数值字符串
|
||||
* @return 中文数字
|
||||
*/
|
||||
public static String toChineseNumber(String num) {
|
||||
if (StringUtil.isEmpty(num)) {
|
||||
return null;
|
||||
}
|
||||
return changeDigit(num, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字转化成整数(中文)。
|
||||
*
|
||||
* @param str 数字字符串
|
||||
* @param bo true=人民币大写,false=数字大写
|
||||
* @return 中文字符串
|
||||
*/
|
||||
static String changeDigit(String str, boolean bo) {
|
||||
StringBuilder strbu = new StringBuilder();
|
||||
int dou = str.indexOf('.');
|
||||
if (dou < 0) {
|
||||
dou = str.length();
|
||||
}
|
||||
String inter = str.substring(0, dou);
|
||||
strbu.append(changeInteger(Long.parseLong(inter), bo));
|
||||
if (dou != str.length()) {
|
||||
strbu.append("点");
|
||||
String xh = str.substring(dou + 1);
|
||||
for (int i = 0; i < xh.length(); i++) {
|
||||
if (bo) {
|
||||
strbu.append(DIGIT_0.charAt(Integer.parseInt(xh.substring(i, i + 1))));
|
||||
} else {
|
||||
strbu.append(DIGIT_1.charAt(Integer.parseInt(xh.substring(i, i + 1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
String strs = strbu.toString();
|
||||
if (strs.startsWith("零")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
if (strs.startsWith("一十")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
while (strs.endsWith("零")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
if (strs.startsWith("点")) {
|
||||
strs = "零" + strs;
|
||||
}
|
||||
if (strs.endsWith("点")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
return strs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位数小于 4 时调用处理数据。
|
||||
*
|
||||
* @param str 4 位数字字符串
|
||||
* @param bo true=人民币大写,false=数字大写
|
||||
* @return 中文字符串
|
||||
*/
|
||||
static String readNumber(String str, boolean bo) {
|
||||
StringBuilder strbu = new StringBuilder();
|
||||
if (str.length() != 4) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch == '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
continue;
|
||||
}
|
||||
if (ch != '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
strbu.append('零');
|
||||
}
|
||||
if (ch != '0') {
|
||||
if (bo) {
|
||||
strbu.append(DIGIT_0.charAt(ch - 48));
|
||||
strbu.append(DIGIT_3[4 - i - 1]);
|
||||
} else {
|
||||
strbu.append(DIGIT_1.charAt(ch - 48));
|
||||
strbu.append(DIGIT_2[4 - i - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return strbu.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 整数部分转换大写。
|
||||
*
|
||||
* @param lon 整数
|
||||
* @param bo true=人民币大写,false=数字大写
|
||||
* @return 中文字符串
|
||||
*/
|
||||
static String changeInteger(long lon, boolean bo) {
|
||||
StringBuilder strbu = new StringBuilder();
|
||||
String strN = "000" + lon;
|
||||
int strN_L = strN.length() / 4;
|
||||
strN = strN.substring(strN.length() - strN_L * 4);
|
||||
for (int i = 0; i < strN_L; i++) {
|
||||
String s1 = strN.substring(i * 4, i * 4 + 4);
|
||||
String s2 = readNumber(s1, bo);
|
||||
strbu.append(s2);
|
||||
if (s2 != null && s2.length() != 0) {
|
||||
strbu.append(DIGIT_4[strN_L - i - 1]);
|
||||
}
|
||||
}
|
||||
String s = strbu.toString();
|
||||
if (s.length() != 0 && s.startsWith("零")) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 人民币输出格式(大写)。
|
||||
*
|
||||
* @param rmb 数值
|
||||
* @return 人民币大写金额
|
||||
*/
|
||||
static String changeNumberRMB(Number rmb) {
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
df.setMaximumFractionDigits(3);
|
||||
String strRMB = df.format(rmb);
|
||||
strRMB = changeDigit(strRMB, true);
|
||||
if (strRMB.indexOf("点") >= 0) {
|
||||
strRMB = strRMB.replaceAll("点", "圆");
|
||||
String str1 = strRMB.substring(0, strRMB.indexOf("圆") + 1);
|
||||
String str2 = strRMB.substring(strRMB.indexOf("圆") + 1);
|
||||
if (str2.length() == 3) {
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分" + str2.charAt(2) + "厘";
|
||||
} else if (str2.length() == 2) {
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分";
|
||||
} else {
|
||||
strRMB = str1 + str2.charAt(0) + "角";
|
||||
}
|
||||
} else {
|
||||
strRMB = strRMB + "圆整";
|
||||
}
|
||||
return strRMB;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.dsasp.server.common.workcalendar.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 工作日历服务(保包名/接口名与 EIP-3.0 framework 完全一致)。
|
||||
* P2 阶段按 framework com.dsasp.server.workcalendar.service.WorkCalendarServiceImpl 补全实现。
|
||||
*/
|
||||
public interface WorkCalendarService {
|
||||
|
||||
/**
|
||||
* 获得相隔天数的下一个工作日
|
||||
*
|
||||
* @param startDate 起始日期
|
||||
* @param workDays 相隔天数
|
||||
* @return 下一个工作日
|
||||
*/
|
||||
LocalDate getNextWorkDay(LocalDate startDate, int workDays);
|
||||
|
||||
/**
|
||||
* 获得一个时间段内工作日历中的所有例外日
|
||||
*
|
||||
* @param startDate 起始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 例外日列表
|
||||
*/
|
||||
List<LocalDate> getExceptionDays(LocalDate startDate, LocalDate endDate);
|
||||
|
||||
void delete(LocalDate day);
|
||||
|
||||
void save(LocalDate day);
|
||||
|
||||
/**
|
||||
* 是否是例外天
|
||||
*
|
||||
* @param day 日期
|
||||
* @return 是否例外天
|
||||
*/
|
||||
boolean containsExceptionDay(LocalDate day);
|
||||
|
||||
/**
|
||||
* 是否周休日
|
||||
*
|
||||
* @param day 日期
|
||||
* @return 是否周休日
|
||||
*/
|
||||
boolean isWeekDay(LocalDate day);
|
||||
|
||||
/**
|
||||
* 是否工作日
|
||||
*
|
||||
* @param dt 时间
|
||||
* @return 是否工作日
|
||||
*/
|
||||
boolean isWorkDay(DateTime dt);
|
||||
|
||||
/**
|
||||
* 是否工作日
|
||||
*
|
||||
* @param day 日期
|
||||
* @return 是否工作日
|
||||
*/
|
||||
boolean isWorkDay(LocalDate day);
|
||||
|
||||
void initCalendarCache();
|
||||
}
|
||||
Reference in New Issue
Block a user