罗德自行二开文件

This commit is contained in:
钱涛 2025-11-17 16:03:12 +08:00
parent 3511c18e31
commit 77c43e78ea
8 changed files with 941 additions and 12 deletions

View File

@ -0,0 +1,3 @@
ALTER TABLE hrsa_add_up_deduction
ADD hiredate VARCHAR(255);

View File

@ -45,7 +45,6 @@ public class AddUpDeduction {
*/
@ElogTransform(name = "申报月份")
private Date declareMonth;
/**
* 累计子女教育
*/
@ -132,6 +131,11 @@ public class AddUpDeduction {
@ElogTransform(name = "租户ID")
private String tenantKey;
/**
* 入职日期
*/
@ElogTransform(name = "入职日期")
private String hiredate;
List<Long> employeeIds;
Collection<Long> taxAgentIds;

View File

@ -1,5 +1,6 @@
package com.engine.salary.entity.salarysob.bo;
import com.alibaba.fastjson.JSONObject;
import com.engine.salary.annotation.SalaryFormulaVar;
import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.dto.SalaryFormulaEmployeeDTO;
@ -18,7 +19,9 @@ import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.lang.reflect.Field;
import java.util.*;
@ -87,6 +90,10 @@ public class SalarySobItemAggregateBO {
* @return
*/
public SalarySobItemAggregateDTO convert2AggregateDTO() {
// 2025-09-11 获取薪资项目若存在于账套则无法删除配置
JSONObject itemConfig = getItemConfig();
new BaseBean().writeLog("INFO","薪资账套id==>"+salarySob.getId());
new BaseBean().writeLog("INFO","获取薪资项目若存在于账套则无法删除配置==>"+itemConfig);
List<SalarySobItemDTO> itemsWithoutGroup = Lists.newArrayList();
// 薪资账套的薪资项目分类po转换成dto
List<SalarySobItemGroupDTO> salarySobItemGroupDTOS = salarySobItemGroups.stream()
@ -110,6 +117,7 @@ public class SalarySobItemAggregateBO {
}
}
});
new BaseBean().writeLog("INFO","薪资账套的薪资项目副本所关联的薪资项目,处理后==>"+salaryItems);
Map<Long, SalaryItemPO> salaryItemMap = SalaryEntityUtil.convert2Map(salaryItems, SalaryItemPO::getId);
Map<Long, List<SalarySobItemPO>> salarySobItemMap = SalaryEntityUtil.group2Map(salarySobItems, SalarySobItemPO::getSalarySobItemGroupId);
@ -148,11 +156,32 @@ public class SalarySobItemAggregateBO {
.build());
}
}
new BaseBean().writeLog("INFO","薪资账套的薪资项目副本所关联的薪资项目,处理前==>"+items);
List<SalarySobItemDTO> itemsNew = Lists.newArrayList();
for (int i = 0; i < items.size(); i++) {
SalarySobItemDTO item = items.get(i);
// 2025-09-11 获取薪资项目若存在于账套则无法删除配置
String itemName = item.getName();
boolean deleteMark = false;
new BaseBean().writeLog("INFO","薪资项目名称==>"+itemName);
if (itemConfig.containsKey(itemName)){
String rczyztzwfsc = itemConfig.getString(itemName);
if ("0".equals(rczyztzwfsc)){
deleteMark = true;
new BaseBean().writeLog("INFO","薪资项目名称,符合不可删除==>");
}
}
if (deleteMark){
item.setCanDelete(false);
}
itemsNew.add(item);
}
new BaseBean().writeLog("INFO","薪资账套的薪资项目副本所关联的薪资项目,处理后==>"+itemsNew);
if (!salarySobItemGroupDTOMap.containsKey(k)) {
itemsWithoutGroup.addAll(items);
itemsWithoutGroup.addAll(itemsNew);
} else {
SalarySobItemGroupDTO salarySobItemGroupDTO = salarySobItemGroupDTOMap.get(k);
salarySobItemGroupDTO.setItems(sortItem(items));
salarySobItemGroupDTO.setItems(sortItem(itemsNew));
}
});
// 薪资账套的员工信息字段po转换成dto
@ -265,4 +294,23 @@ public class SalarySobItemAggregateBO {
return group;
}).sorted(Comparator.comparingInt(SalarySobItemGroupDTO::getSortedIndex)).collect(Collectors.toList());
}
/**
* 2025-09-11 获取薪资项目若存在于账套则无法删除配置
* @return
*/
public JSONObject getItemConfig(){
RecordSet rs = new RecordSet();
JSONObject data = new JSONObject();
String sql = "select * from uf_xzxmpzb";
rs.executeQuery(sql);
while (rs.next()){
String name = Util.null2String(rs.getString("xzxmmc"));
String rczyztzwfsc = Util.null2String(rs.getString("rczyztzwfsc"));
if (!"".equals(name) && !"".equals(rczyztzwfsc)){
data.put(name,rczyztzwfsc);
}
}
return data;
}
}

View File

@ -115,7 +115,7 @@
d.departmentname AS departmentName,
e.mobile,
e.workcode as job_num,
e.companystartdate as hiredate,
t1.hiredate as hiredate,
t2.name AS taxAgentName,
t2.id AS taxAgentId,
t1.add_up_child_education,
@ -182,7 +182,7 @@
</if>
<!-- 入职日期 -->
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
AND (t1.hiredate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<!-- 手机号 -->
<if test="param.mobile != null and param.mobile != ''">
@ -245,7 +245,7 @@
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
AND (t1.hiredate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
@ -306,7 +306,7 @@
</if>
<if test="param.hiredate != null and param.hiredate.size() == 2">
AND (e.companystartdate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
AND (t1.hiredate BETWEEN #{param.hiredate[0]} AND #{param.hiredate[1]})
</if>
<if test="param.mobile != null and param.mobile != ''">
@ -414,7 +414,8 @@
create_time,
update_time,
creator,
tenant_key
tenant_key,
hiredate
)
VALUES
<foreach collection="collection" item="item" separator=",">
@ -432,7 +433,8 @@
#{item.createTime},
#{item.updateTime},
#{item.creator},
#{item.tenantKey}
#{item.tenantKey},
#{item.hiredate}
)
</foreach>
</insert>
@ -489,7 +491,8 @@
create_time,
update_time,
creator,
tenant_key
tenant_key,
hiredate
)
VALUES
(
@ -506,7 +509,8 @@
#{item.createTime},
#{item.updateTime},
#{item.creator},
#{item.tenantKey}
#{item.tenantKey},
#{item.hiredate}
)
</foreach>
</insert>
@ -563,6 +567,13 @@
</if>
</foreach>
</trim>
<trim prefix="hiredate =case" suffix="end,">
<foreach collection="collection" item="item" index="index">
<if test="item.hiredate!=null">
when id=#{item.id} then #{item.hiredate}
</if>
</foreach>
</trim>
</trim>
where
id in

View File

@ -56,6 +56,7 @@ import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ydh.ldkj.utils.CommonUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
@ -245,6 +246,12 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
String mobile = dto.getMobile();
String workcode = dto.getJobNum();
String idNo = dto.getIdNo();
// 2025-09-03 入职日期通过模板导入
String hiredate = Util.null2String(dto.getHiredate());
if (!StringUtils.isBlank(hiredate)) {
hiredate = CommonUtils.dateFormart(hiredate,"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd");
}
addUpDeduction.setHiredate(hiredate);
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
List<DataCollectionEmployee> employeeSameIds = getSalaryEmployeeService(user).matchImportEmployee(confValue, employees, userName, deparmentName, mobile, workcode, idNo, null);
@ -297,7 +304,8 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
} else {
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
if (StringUtils.isNotEmpty(taxAgentId) && !optionalTemp.get().getTaxAgentId().equals(Long.valueOf(taxAgentId))) {
// 2025-10-09 个税扣缴义务人选择全部时不校验
if (StringUtils.isNotEmpty(taxAgentId) && !"-999".equals(taxAgentId)&& !optionalTemp.get().getTaxAgentId().equals(Long.valueOf(taxAgentId))) {
//个税扣缴义务人与导入时选择的不一致
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人与导入时选择的不一致");

View File

@ -0,0 +1,113 @@
package com.ydh.ldkj.sync;
import com.ydh.ldkj.utils.ThreadPoolUtils;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 建模权限重构
* @author YDH
* CreateTime 2022年5月13日 下午12:16:57
* @Description
*
*/
public class ModeRightDataThreadSync extends ModeRightInfo implements Runnable{
private List<Map> dataList = null;
private int threadCount = 6;
private int currentCount = 0;
@Override
public void run() {
writeLog("线程启动了");
ModeRightInfo localModeRightInfo = new ModeRightInfo();
while (true) {
Map localObject1 = new HashMap();
synchronized (this) {
this.currentCount += 1;
if (this.currentCount > this.dataList.size()) {
this.currentCount -= 1;
break;
}
localObject1 = (Map)this.dataList.get(this.currentCount - 1);
}
String billId = Util.null2String(localObject1.get("billid"));
String creator = Util.null2String(localObject1.get("creator"));
recreateNewModeRightByBillId(localModeRightInfo, Util.getIntValue(creator), getModeId(), Util.getIntValue(billId));
rebuildModeRightByBillId(localModeRightInfo, Util.getIntValue(creator), getModeId(), Util.getIntValue(billId));
}
}
/**
* 新数据权限重构
* @author YDH
* CreateTime 2022年5月11日 上午10:02:07
* @param paraModeRightInfo
* @param paramInt1
* @param paramInt2
* @param paramInt3
*/
public void recreateNewModeRightByBillId(ModeRightInfo paraModeRightInfo,int paramInt1,int paramInt2,int paramInt3) {
paraModeRightInfo.setNewRight(true);
paraModeRightInfo.editModeDataShare(paramInt1, paramInt2, paramInt3);
}
/**
* 旧数据权限重构
* @author YDH
* CreateTime 2022年5月11日 上午10:02:07
* @param paraModeRightInfo
* @param paramInt1
* @param paramInt2
* @param paramInt3
*/
public void recreateOldModeRightByBillId(ModeRightInfo paraModeRightInfo,int paramInt1,int paramInt2,int paramInt3) {
paraModeRightInfo.setNewRight(true);
paraModeRightInfo.rebuildModeDataShareByEdit(paramInt1, paramInt2, paramInt3);
}
/**
* 旧数据权限重构
* @author YDH
* CreateTime 2022年5月13日 下午12:16:13
* @param paraModeRightInfo
* @param paramInt1
* @param paramInt2
* @param paramInt3
*/
public void rebuildModeRightByBillId(ModeRightInfo paraModeRightInfo,int paramInt1,int paramInt2,int paramInt3) {
paraModeRightInfo.rebuildModeDataShareByEdit(paramInt1, paramInt2, paramInt3);
}
public void resetModeRightThread() {
try {
List<Map> maps = this.getDataList();
if (maps == null || maps.size() == 0) {
return;
}
ModeRightDataThreadSync rightDataObject = new ModeRightDataThreadSync();
rightDataObject.setModeId(this.getModeId());
rightDataObject.setDataList(maps);
ThreadPoolUtils.getInstance().fixThreadPoolExecute((Runnable)rightDataObject);
} catch (Exception e) {
writeLog("resetModeRight:", e);
}
}
/**
* @return dataList
*/
public List<Map> getDataList() {
return dataList;
}
/**
* @param dataList 要设置的dataList
*/
public void setDataList(List<Map> dataList) {
this.dataList = dataList;
}
}

View File

@ -0,0 +1,669 @@
package com.ydh.ldkj.utils;
import com.ydh.ldkj.sync.ModeRightDataThreadSync;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.docs.docs.DocManagerNoRequest;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.soa.workflow.request.Property;
import weaver.wechat.util.Utils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
/**
* 通用工具类
*
* @author ydh
*/
public class CommonUtils {
private static BaseBean basebean = new BaseBean();
/**
* 获取下拉框值
*
* @param selectvalue 下拉框值
* @param billid 流程表单
* @param fieldname 数据库字段名
* @return
*/
public static String getSelectItme(Integer selectvalue, Integer billid, String fieldname) {
RecordSet rs = new RecordSet();
String sql = "select selectname from workflow_selectitem where selectvalue = ? and fieldid in (select id from workflow_billfield where billid=? and fieldname=?)";
rs.executeQuery(sql, selectvalue, billid, fieldname);
rs.next();
return "" + rs.getString("selectname");
}
/**
* 新建流程字段赋值
*
* @param fieldName
* @param value
* @return
*/
public static Property setField(String fieldName, String value) {
Property p = new Property();
p.setName(fieldName);
p.setValue(value);
return p;
}
/**
* 获取流程wfid
*
* @param requestId 流程请求id
* @return
*/
public static String getWorkflowidByRequestId(String requestId) {
String workflowId = "";
String sql = " select workflowid from workflow_requestbase where requestid = ? ";
RecordSet rs = new RecordSet();
rs.executeQuery(sql, requestId);
if (rs.next()) {
workflowId = Util.null2String(rs.getString("workflowid"));
}
return workflowId;
}
/**
* 获取流程表名
*
* @param workflowid 流程id
* @return
*/
public static String getTableNameByWorkflowid(String workflowid) {
String formid = "";
String sql = "select formid from workflow_base where id =?";
RecordSet rs = new RecordSet();
rs.executeQuery(sql, workflowid);
if (rs.next()) {
formid = rs.getString("formid");
}
formid = formid.replaceAll("-", "");
String tablename = "formtable_main_" + formid;
return tablename;
}
/**
* 字符串判断为空
*
* @param str
* @return
*/
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return false;
}
}
return true;
}
/**
* 根据建模表名获取建模模块id
*
* @param tableName
* @return
* @author YDH CreateTime 2022年5月11日 上午9:48:52
*/
public static int getModeId(String tableName) {
RecordSet rs = new RecordSet();
String sql = " select id from modeinfo where formid = (select id from workflow_bill where tablename = ?) ";
rs.executeQuery(sql, tableName);
rs.next();
int modeId = rs.getInt(1);
return modeId;
}
/**
* 根据人员id获取上级
*
* @param id
* @return
*/
public static Integer getManagerByUserid(Integer id) {
RecordSet rs = new RecordSet();
String sql = "select managerid from hrmresource where id = ?";
rs.executeQuery(sql, id);
rs.next();
return Utils.getIntValue(rs.getString("managerid"), 0);
}
/**
* 获取人员名称
* @param id
* @return
*/
public static String getUserNameByUserId(Integer id) {
String name = "";
if (id == 1){
name = "系统管理员";
} else {
RecordSet rs = new RecordSet();
String sql = " select lastname from HrmResource where id = ?";
rs.executeQuery(sql, id);
if (rs.next()){
name = Util.null2String(rs.getString("lastname"));
}
}
return name;
}
/**
* 获取人员id
* @param workCode
* @return
*/
public static int getUserIdByWorkCode(String workCode) {
int userId = -1;
RecordSet rs = new RecordSet();
String sql = " select id from HrmResource where workcode = ?";
rs.executeQuery(sql, workCode);
if (rs.next()){
userId = Util.getIntValue(rs.getString("id"),-1);
}
return userId;
}
/**
* 获取人员id
* @param userId
* @return
*/
public static String getWorkCodeByUserId(int userId) {
String workCode = "";
RecordSet rs = new RecordSet();
String sql = " select workCode from HrmResource where id = ?";
rs.executeQuery(sql, userId);
if (rs.next()){
workCode = Util.null2String(rs.getString("workCode"));
}
return workCode;
}
/**
* 批量执行
*
* @param parameters
* @param sql
* @param rs
*/
public static void batchSql(List<List<Object>> parameters, String sql, RecordSet rs) {
RecordSetTrans rst = new RecordSetTrans();
rst.setAutoCommit(false);
try {
rst.executeBatchSql(sql, parameters);
rst.commit();
} catch (Exception e) {
rs.writeLog(CommonUtils.class.getName() + ",执行批量操作异常:", e);
rst.rollback();
}
}
/**
* 数据权限重置
* @author YDH
* CreateTime 2022年5月11日 上午10:32:18
* @param uuid
* @param rs
* @param creator
* @param modeId
*/
public static void authorityReconfiguration(String uuid,RecordSet rs,String creator,int modeId,String tableName) {
List<Map> dataList = new ArrayList<Map>();
StringBuilder sql = new StringBuilder();
sql.append("select ID from ").append(tableName).append(" where modeUUID = ?");
rs.executeQuery(sql.toString(), uuid);
while(rs.next()) {
HashMap localHashMap = new HashMap();
localHashMap.put("billid", rs.getInt(1));
localHashMap.put("creator", creator);
dataList.add(localHashMap);
}
if (!dataList.isEmpty()) {
ModeRightDataThreadSync sync = new ModeRightDataThreadSync();
sync.setModeId(modeId);
sync.setDataList(dataList);
sync.resetModeRightThread();
}
}
/**
* MD5加密
* @param str
* @return
*/
public static String codeMD5(String str) {
try {
// 生成一个MD5加密计算摘要
MessageDigest md = MessageDigest.getInstance("MD5");
// 计算md5函数
md.update(str.getBytes());
// digest()最后确定返回md5 hash值返回值为8位字符串因为md5 hash值是16位的hex值实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值用字符串来表示得到字符串形式的hash值
// 一个byte是八位二进制也就是2位十六进制字符2的8次方等于16的2次方
return new BigInteger(1, md.digest()).toString(16);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* sha256加密
* @param originalString
* @return
*/
public static String codeSha256(String originalString) {
try {
// 获取SHA-256 MessageDigest 实例
MessageDigest digest = MessageDigest.getInstance("SHA-256");
// 对字符串进行编码
byte[] encodedhash = digest.digest(originalString.getBytes(java.nio.charset.StandardCharsets.UTF_8));
// 将字节转换为十六进制字符串
StringBuilder hexString = new StringBuilder();
for (byte b : encodedhash) {
String hex = Integer.toHexString(0xff & b);
if(hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* base64转文件
* @param base64
* @param fileName
* @param savePath
*/
public static boolean base64ToFile(String base64, String fileName, String savePath) {
boolean mark = false;
File file = null;
//创建文件目录
String filePath = savePath;
File dir = new File(filePath);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
BufferedOutputStream bos = null;
java.io.FileOutputStream fos = null;
try {
byte[] bytes = Base64.getDecoder().decode(base64);
file = new File(filePath + fileName);
fos = new java.io.FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bytes);
} catch (Exception e) {
basebean.writeLog("ERROR","base64转文件异常");
basebean.writeLog("ERROR",e);
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
basebean.writeLog("ERROR","base64转文件关闭bos异常");
basebean.writeLog("ERROR",e);
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
basebean.writeLog("ERROR","base64转文件关闭fos异常");
basebean.writeLog("ERROR",e);
}
}
}
File file2 = new File(filePath + fileName);
if (file2.exists()){
mark = true;
}
return mark;
}
/**
* 附件id转文档id
* @param modeid 模块id
* @param userid
* @param imageid 附件id
* @return
*/
public static int buildFileForFile(int modeid,int userid,int imageid){
RecordSet rs = new RecordSet();
int retDocid = 0;
try {
int maincategory = 0;
int subcategory = 0;
int seccategory = 0;
if(modeid > 0){
rs.executeQuery("select * from modeinfo where id="+modeid);
if(rs.next()){
maincategory = Util.getIntValue(rs.getString("maincategory"),0);
subcategory = Util.getIntValue(rs.getString("subcategory"),0);
seccategory = Util.getIntValue(rs.getString("seccategory"),0);
}
}
String docsubject="";
rs.executeQuery("select imagefilename from ImageFile if2 where imagefileid = ?",imageid);
if (rs.next()){
docsubject = Util.null2String(rs.getString("imagefilename"));
}
Map dataMap=new HashMap();
dataMap.put("docsubject",docsubject);
dataMap.put("doccreaterid",""+userid);
dataMap.put("docCreaterType","1");
dataMap.put("maincategory",""+maincategory);
dataMap.put("subcategory",""+subcategory);
dataMap.put("seccategory",""+seccategory);
dataMap.put("fileids",""+imageid);
//文件FILEID处理
DocManagerNoRequest docManagerNoRequest = new DocManagerNoRequest();
docManagerNoRequest.UploadDocNoRequest(dataMap);
//文档ID
retDocid = docManagerNoRequest.getId();
} catch (Exception e) {
basebean.writeLog("ERROR","附件id转文档异常");
basebean.writeLog("ERROR",e);
}
return retDocid;
}
/**
* 获取其他月份
* @param ny
* @param i
* @return
*/
public static String getLastMonth(String ny,int i){
String lastMonth = "";
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
Date newdate = simpleDateFormat.parse(ny);
Calendar calendar = Calendar.getInstance();
calendar.setTime(newdate);
calendar.add(Calendar.MONTH,i);
lastMonth = simpleDateFormat.format(calendar.getTime());
} catch (ParseException e) {
basebean.writeLog("ERROR","获取上月异常!");
basebean.writeLog("ERROR",e);
}
return lastMonth;
}
/**
* 获取随机正整数
* @param offset
* @return
*/
public static int getRandomPositiveNumber(int offset) {
Random random = new Random();
int randomNumber = random.nextInt();
int positiveNumber = Math.abs(randomNumber);
int finalNumber = positiveNumber + offset;
return finalNumber;
}
/**
* 日期格式化
* @param date
* @return
*/
public static String dateFormart(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMM");
Calendar gCalendar = Calendar.getInstance();
try {
Date dateTime = sdf.parse(date);
gCalendar.setTime(dateTime);
} catch (ParseException e) {
basebean.writeLog("ERROR","日期格式化异常!");
basebean.writeLog("ERROR",e);
}
return sdf2.format(gCalendar.getTime());
}
/**
* 获取当前系统日期及时间yyyy-MM-dd
* @return
*/
public static String getCurrentDate() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(new Date());
}
/**
* 获取当前系统年月yyyy-MM
* @return
*/
public static String getCurrentMonth() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
return sdf.format(new Date());
}
/**
* 获取当前系统年份 yyyy
* @return
*/
public static String getCurrentYear() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
return sdf.format(new Date());
}
/**
* 计算2个日期月份差
* @param dateString1
* @param dateString2
* @return
*/
public static int monthDiff(String dateString1, String dateString2){
// 将字符串转换为 LocalDate 对象
LocalDate date1 = LocalDate.parse(dateString1);
LocalDate date2 = LocalDate.parse(dateString2);
// 获软时间1的年份和月份
int year1 = date1.getYear();
int month1 = date1.getMonthValue();
// 获取时间2的年份和月份
int year2 = date2.getYear();
int month2 = date2.getMonthValue();
// 计算时间1的总月数
int totalMonths1 = year1 * 12 + month1;
// 计算时间2的总月数
int totalMonths2 = year2 * 12 + month2;
// 计算总月数差
int monthsDiff = totalMonths2 - totalMonths1;
return monthsDiff;
}
/**
* 获取上一天
* @param date
* @return
*/
public static String getLastDate(String date){
String lastMonth = "";
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date newdate = simpleDateFormat.parse(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(newdate);
calendar.add(Calendar.DAY_OF_MONTH,-1);
lastMonth = simpleDateFormat.format(calendar.getTime());
} catch (ParseException e) {
basebean.writeLog("ERROR","获取前一天异常!");
basebean.writeLog("ERROR",e);
}
return lastMonth;
}
/**
* 日期格式化
* @param date
* @return
*/
public static String dateFormart2(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
Calendar gCalendar = Calendar.getInstance();
try {
Date dateTime = sdf.parse(date);
gCalendar.setTime(dateTime);
} catch (ParseException e) {
basebean.writeLog("ERROR","日期格式化异常!");
basebean.writeLog("ERROR",e);
}
return sdf2.format(gCalendar.getTime());
}
/**
* 比较日期是在区间内
*
* @param orginDate 年月
* @param startDate 开始日期
* @param endDate 结束日期
* @return
*/
public static boolean compareDate(String orginDate, String startDate, String endDate) {
boolean mark = false;
// 起始缴纳年月为空
if (CommonUtils.isBlank(startDate)) {
// 停止缴纳年月为空
if (CommonUtils.isBlank(endDate)) {
mark = true;
} else {
// 年月早于停止缴纳年月
if (orginDate.compareTo(endDate) <= 0) {
mark = true;
} else {
mark = false;
}
}
} else {
// 起始缴纳年月为空
if (CommonUtils.isBlank(endDate)) {
// 年月晚于起始缴纳年月
if (orginDate.compareTo(startDate) >= 0) {
mark = true;
} else {
mark = false;
}
} else {
// 年月早于停止缴纳年月&&年月晚于起始缴纳年月
if (orginDate.compareTo(startDate) >= 0 && orginDate.compareTo(endDate) <= 0) {
mark = true;
} else {
mark = false;
}
}
}
return mark;
}
/**
* 四舍五入
* @param orginData
* @return
*/
public static double mathRound(double orginData){
double result1 = BigDecimal.valueOf(orginData).setScale(3, RoundingMode.HALF_UP).doubleValue();
double result2 = BigDecimal.valueOf(result1).setScale(2, RoundingMode.HALF_UP).doubleValue();
return result2;
}
/**
* 四舍五入
* @param orginData
* @return
*/
public static double bigDecimalMultiply(double orginData,double orginData2){
BigDecimal a = new BigDecimal(String.valueOf(orginData));
BigDecimal b = new BigDecimal(String.valueOf(orginData2));
BigDecimal result = a.multiply(b).setScale(2, RoundingMode.HALF_UP);
return result.doubleValue();
}
/**
* 见角进元
* @param orginData
* @return
*/
public static double roundUpToYuan(double orginData){
if (orginData < 0) {
throw new IllegalArgumentException("金额不能为负数");
}
// 使用BigDecimal精确处理
BigDecimal bd = BigDecimal.valueOf(orginData);
// 获取元的整数部分
BigInteger integerPart = bd.toBigInteger();
// 计算小数部分分等
BigDecimal fractional = bd.subtract(new BigDecimal(integerPart));
// 小数部分乘以10得到角并截断分以下部分
int jiao = fractional.multiply(BigDecimal.TEN).intValue();
// 若角1则进位
if (jiao >= 1) {
return integerPart.longValue() + 1;
} else {
return integerPart.longValue();
}
}
/**
* 获取前几天
* @param dateString
* @param dateFormat
* @param days
* @return
*/
public static String getDaysBefore(String dateString, String dateFormat,int days) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date = sdf.parse(dateString);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, days);
return sdf.format(calendar.getTime());
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
/**
* 日期格式化
* @param date
* @param pattern1
* @param pattern2
* @return
*/
public static String dateFormart(String date,String pattern1,String pattern2) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern1);
SimpleDateFormat sdf2 = new SimpleDateFormat(pattern2);
Calendar gCalendar = Calendar.getInstance();
try {
Date dateTime = sdf.parse(date);
gCalendar.setTime(dateTime);
} catch (ParseException e) {
basebean.writeLog("ERROR","日期格式化异常!");
basebean.writeLog("ERROR",e);
}
return sdf2.format(gCalendar.getTime());
}
}

View File

@ -0,0 +1,73 @@
package com.ydh.ldkj.utils;
import weaver.conn.RecordSet;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author yuandonghui
*/
public class ThreadPoolUtils {
/** 线程池保持alive状态线程数 */
public static final int CORE_POOL_SIZE = 10;
/** 线程池最大线程数 */
public static final int MAX_POOL_SIZE = 40;
/** 空闲线程回收时间 */
public static final int KEEP_ALIVE_TIME = 1000;
private final static ThreadPoolUtils threadPoolUtils = new ThreadPoolUtils();
/** 业务请求异步处理线程池 */
private static final ThreadPoolExecutor processExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,MAX_POOL_SIZE,KEEP_ALIVE_TIME,
TimeUnit.MICROSECONDS,new LinkedBlockingQueue<Runnable>(),new NameThreadFactory(),new MyIgnorePolicy());
/** 业务请求异步处理线程池 */
private static final ExecutorService newFixExecutor = Executors.newFixedThreadPool(CORE_POOL_SIZE);
private ThreadPoolUtils() {};
public static ThreadPoolUtils getInstance() {
return threadPoolUtils;
}
static class NameThreadFactory implements ThreadFactory {
private final AtomicInteger mThreadNum = new AtomicInteger(1);
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r,"my-thread-"+mThreadNum.getAndIncrement());
return t;
}
}
public static class MyIgnorePolicy implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
dolog(r,e);
}
private void dolog(Runnable r, ThreadPoolExecutor e) {
RecordSet rs = new RecordSet();
rs.writeLog("INFO", "com.hw.utils.ThreadPoolUtils"+r.toString()+" rejected");
}
}
/**
* 异步任务处理 线程池不需要关闭
* @author YDH
* CreateTime 2022年5月11日 上午10:23:38
* @param task
*/
public void execute(Runnable task) {
processExecutor.submit(task);
}
/**
*
* @author YDH
* CreateTime 2022年5月11日 上午10:23:56
* @param task
*/
public void fixThreadPoolExecute(Runnable task) {
newFixExecutor.submit(task);
}
}