#chabaodao-6# 代码提交
This commit is contained in:
parent
835a39c4b5
commit
8c50718c53
|
|
@ -240,6 +240,7 @@ public class HrmInformationFilesController {
|
|||
if(StringUtils.isNotBlank(fileId)){
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
|
||||
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(fileId));
|
||||
FileObj fileObj = fileData.getFileObj();
|
||||
// 获取文件的输入流
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.seconddev.chapanda.hrm.service.HrmShiftQueryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -68,7 +70,4 @@ public class HrmShiftQueryController {
|
|||
List<Map<String,Object>> dataList = hrmShiftQueryService.operateScheduling(paramJson);
|
||||
return WeaResult.success(dataList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.seconddev.chapanda.hrm.service.HrmShiftQueryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -64,9 +66,24 @@ public class HrmShiftQueryOpenController {
|
|||
public WeaResult<Object> operateScheduling(@RequestBody JSONObject paramJson){
|
||||
log.error("paramJson:{}",paramJson.toJSONString());
|
||||
List<Map<String,Object>> dataList = hrmShiftQueryService.operateScheduling(paramJson);
|
||||
return WeaResult.success(dataList);
|
||||
|
||||
String schedulingids = "";
|
||||
for(int i= 0 ;i<dataList.size();i++){
|
||||
Map<String,Object> dataMap = dataList.get(i);
|
||||
if(dataMap.containsKey("schedulingid")){
|
||||
String schedulingid = dataMap.get("schedulingid").toString();
|
||||
schedulingids += StringUtils.isBlank(schedulingids) ? schedulingid : ","+schedulingid;
|
||||
}
|
||||
}
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("schedulingid",schedulingids);
|
||||
return WeaResult.success(result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class HrmShiftQueryDao {
|
||||
|
|
@ -263,9 +261,10 @@ public class HrmShiftQueryDao {
|
|||
}
|
||||
|
||||
|
||||
public void insertAttendConfigRange(Long id,String employeeId,String attendConfig,String sort_num){
|
||||
public Map<String,Object> insertAttendConfigRange(Long id,String employeeId,String attendConfig,String sort_num){
|
||||
String sourceType = "LOGIC";
|
||||
String groupId = "weaver-hr-service";
|
||||
Map<String,Object> result = new HashMap<String,Object>();
|
||||
try{
|
||||
String create_time = DateUtils.getCurrentDateString() + " " + DateUtils.getOnlyCurrentTimeString();
|
||||
String dataSql =" insert into attend_config_range(id,target_id,entry_type,attend_config,tenant_key,create_time,update_time,delete_type,include_sub_dept,min_sec_level,max_sec_level,sort_num,creator) " +
|
||||
|
|
@ -283,7 +282,7 @@ public class HrmShiftQueryDao {
|
|||
paramList.add(Constants.SysUserId);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
|
|
@ -293,13 +292,16 @@ public class HrmShiftQueryDao {
|
|||
e.printStackTrace();
|
||||
log.error("e:" + e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void insertAttendScheduling(Long id,String attendConfig,String attend_date,String range_id,String shift_id){
|
||||
public Map<String, Object> insertAttendScheduling(Long id,String attendConfig,String attend_date,String range_id,String shift_id){
|
||||
String sourceType = "LOGIC";
|
||||
String groupId = "weaver-hr-service";
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try{
|
||||
String create_time = DateUtils.getCurrentDateString() + " " + DateUtils.getOnlyCurrentTimeString();
|
||||
String dataSql =" insert into attend_scheduling\n" +
|
||||
|
|
@ -322,7 +324,7 @@ public class HrmShiftQueryDao {
|
|||
paramList.add(Constants.SysUserId);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
|
|
@ -332,18 +334,19 @@ public class HrmShiftQueryDao {
|
|||
e.printStackTrace();
|
||||
log.error("e:" + e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void deleteAttendScheduling(String attendDate,String shiftId,String attendConfig,String rangeId){
|
||||
public Map<String, Object> deleteAttendScheduling(String attendDate,String shiftId,String attendConfig,String rangeId){
|
||||
String sourceType = "LOGIC";
|
||||
String groupId = "weaver-hr-service";
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try{
|
||||
|
||||
String update_time = DateUtils.getCurrentDateString() + " " + DateUtils.getOnlyCurrentTimeString();
|
||||
String dataSql =" update attend_scheduling\n" +
|
||||
" set delete_type = 1,update_time = ? \n" +
|
||||
" set delete_type = 3,update_time = ? \n" +
|
||||
" where ATTEND_DATE = ? \n" +
|
||||
" and SHIFT_ID=? \n" +
|
||||
" and ATTEND_CONFIG_ID=? \n" +
|
||||
" and RANGE_ID=? and tenant_key = ? " ;
|
||||
|
||||
|
|
@ -351,13 +354,12 @@ public class HrmShiftQueryDao {
|
|||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(update_time);
|
||||
paramList.add(attendDate);
|
||||
paramList.add(shiftId);
|
||||
paramList.add(attendConfig);
|
||||
paramList.add(rangeId);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
|
|
@ -367,6 +369,7 @@ public class HrmShiftQueryDao {
|
|||
e.printStackTrace();
|
||||
log.error("e:" + e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,22 +8,22 @@ package com.weaver.seconddev.chapanda.hrm.entity;
|
|||
*/
|
||||
|
||||
public class CustomShiftTimePo {
|
||||
private String attendStartTime;
|
||||
private String attendEndTime;
|
||||
private String beginTime;
|
||||
private String endTime;
|
||||
|
||||
public String getAttendStartTime() {
|
||||
return attendStartTime;
|
||||
public String getBeginTime() {
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
public void setAttendStartTime(String attendStartTime) {
|
||||
this.attendStartTime = attendStartTime;
|
||||
public void setBeginTime(String beginTime) {
|
||||
this.beginTime = beginTime;
|
||||
}
|
||||
|
||||
public String getAttendEndTime() {
|
||||
return attendEndTime;
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setAttendEndTime(String attendEndTime) {
|
||||
this.attendEndTime = attendEndTime;
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,9 +61,16 @@ public class HrmShiftQueryServiceImpl implements HrmShiftQueryService {
|
|||
shiftMap.put("type",fdjjrbc);
|
||||
shiftMap.put("isStore",sfmdbc);
|
||||
|
||||
log.error("id:{}",dataList.size());
|
||||
log.error("id:{}",id);
|
||||
String beginTime = "";
|
||||
String endTime = "";
|
||||
List<CustomShiftTimePo> attendList = hrmShiftQueryMapper.queryShiftTimeList(id,Constants.TENANT_KEY);
|
||||
shiftMap.put("attend",attendList);
|
||||
if(attendList.size()>0){
|
||||
beginTime = attendList.get(0).getBeginTime();
|
||||
endTime = attendList.get(0).getEndTime();
|
||||
}
|
||||
shiftMap.put("beginTime",beginTime);
|
||||
shiftMap.put("endTime",endTime);
|
||||
shiftList.add(shiftMap);
|
||||
}
|
||||
return shiftList;
|
||||
|
|
@ -77,8 +84,17 @@ public class HrmShiftQueryServiceImpl implements HrmShiftQueryService {
|
|||
@Override
|
||||
public List<Map<String,Object>> querySchedulingList(JSONObject paramJson) {
|
||||
List<Map<String,Object>> shiftList = new ArrayList<Map<String,Object>>();
|
||||
String beginDate = paramJson.getString("beginDate");
|
||||
String endDate = paramJson.getString("endDate");
|
||||
String beginDate = "";
|
||||
if(paramJson.containsKey("beginDate")){
|
||||
beginDate = paramJson.getString("beginDate");
|
||||
}
|
||||
String endDate = "";
|
||||
if(paramJson.containsKey("endDate")){
|
||||
endDate = paramJson.getString("endDate");
|
||||
}
|
||||
if(StringUtils.isBlank(endDate)){
|
||||
endDate = beginDate;
|
||||
}
|
||||
log.error("beginDate:{}",beginDate);
|
||||
log.error("endDate:{}",endDate);
|
||||
String empCodeStr = paramJson.getString("empCode");
|
||||
|
|
@ -112,18 +128,20 @@ public class HrmShiftQueryServiceImpl implements HrmShiftQueryService {
|
|||
shiftMap.put("empName",empName);
|
||||
|
||||
List<CustomShiftTimePo> attendList = hrmShiftQueryMapper.queryShiftTimeList(scID,Constants.TENANT_KEY);
|
||||
shiftMap.put("attend",attendList);
|
||||
shiftMap.put("scTimes",attendList);
|
||||
shiftList.add(shiftMap);
|
||||
}
|
||||
}
|
||||
return shiftList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map<String,Object>> operateScheduling(JSONObject paramJson) {
|
||||
|
||||
log.error("paramJson:{}",paramJson.toJSONString());
|
||||
List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
List<Map<String,Object>> shiftList = new ArrayList<Map<String,Object>>();
|
||||
|
||||
// List<Map<String,Object>> shiftList = new ArrayList<Map<String,Object>>();
|
||||
String operType = paramJson.getString("operType");
|
||||
JSONArray dataArray = paramJson.getJSONArray("data");
|
||||
|
||||
|
|
@ -133,36 +151,79 @@ public class HrmShiftQueryServiceImpl implements HrmShiftQueryService {
|
|||
String scID = dataJson.getString("scID");
|
||||
String scDate = dataJson.getString("scDate");
|
||||
String employeeId = hrmShiftQueryDao.queryEmployeeIdByCode(empCode);
|
||||
log.error("employeeId:{}",employeeId);
|
||||
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
String attendId = "";
|
||||
String datacode = "";
|
||||
if(StringUtils.isNotBlank(employeeId)){
|
||||
if(StringUtils.isNotBlank(scID)){
|
||||
String attendConfig = hrmShiftQueryDao.queryAttendConfig(scID);
|
||||
log.error("attendConfig:{}",attendConfig);
|
||||
if(StringUtils.isNotBlank(attendConfig)){
|
||||
String sort_num = hrmShiftQueryDao.queryRangeCount();
|
||||
log.error("sort_num:{}",sort_num);
|
||||
if(StringUtils.isNotBlank(sort_num)){
|
||||
Long attend_config_rangeId = IdGenerator.generate();
|
||||
hrmShiftQueryDao.insertAttendConfigRange(attend_config_rangeId,employeeId,attendConfig,sort_num);
|
||||
|
||||
String rangeId = hrmShiftQueryDao.queryRangeIdByconfigId(employeeId,attendConfig);
|
||||
log.error("rangeId:{}",rangeId);
|
||||
if(StringUtils.isBlank(rangeId)){
|
||||
Long attend_config_rangeId = IdGenerator.generate();
|
||||
log.error("attend_config_rangeId:{}",attend_config_rangeId);
|
||||
Map<String,Object> result2 = hrmShiftQueryDao.insertAttendConfigRange(attend_config_rangeId,employeeId,attendConfig,sort_num);
|
||||
if(result2.containsKey("code")){
|
||||
String code2 = result2.get("code").toString();
|
||||
if("200".equals(code2)){
|
||||
rangeId = String.valueOf(attend_config_rangeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("rangeId2:{}",rangeId);
|
||||
if(StringUtils.isNotBlank(rangeId)){
|
||||
// 添加排班
|
||||
if("1".equals(operType)){
|
||||
Long attendSchedulingId = IdGenerator.generate();
|
||||
hrmShiftQueryDao.insertAttendScheduling(attendSchedulingId,attendConfig,scDate,rangeId,scID);
|
||||
log.error("attendSchedulingId:{}",attendSchedulingId);
|
||||
Map<String,Object> result = hrmShiftQueryDao.insertAttendScheduling(attendSchedulingId,attendConfig,scDate,rangeId,scID);
|
||||
if(result.containsKey("code")){
|
||||
datacode = result.get("code").toString();
|
||||
if("200".equals(datacode)){
|
||||
attendId = String.valueOf(attendSchedulingId);
|
||||
}
|
||||
}
|
||||
}else if("2".equals(operType)){ // 修改排班
|
||||
hrmShiftQueryDao.deleteAttendScheduling(scDate,scID,attendConfig,rangeId);
|
||||
Long attendSchedulingId = IdGenerator.generate();
|
||||
hrmShiftQueryDao.insertAttendScheduling(attendSchedulingId,attendConfig,scDate,rangeId,scID);
|
||||
Map<String,Object> result = hrmShiftQueryDao.deleteAttendScheduling(scDate,scID,attendConfig,rangeId);
|
||||
if(result.containsKey("code")){
|
||||
String code = result.get("code").toString();
|
||||
if("200".equals(code)){
|
||||
Long attendSchedulingId = IdGenerator.generate();
|
||||
Map<String,Object> result2 = hrmShiftQueryDao.insertAttendScheduling(attendSchedulingId,attendConfig,scDate,rangeId,scID);
|
||||
if(result2.containsKey("code")){
|
||||
datacode = result.get("code").toString();
|
||||
}
|
||||
if("200".equals(datacode)){
|
||||
attendId = String.valueOf(attendSchedulingId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if("3".equals(operType)){ // 删除排班
|
||||
hrmShiftQueryDao.deleteAttendScheduling(scDate,scID,attendConfig,rangeId);
|
||||
Map<String,Object> result = hrmShiftQueryDao.deleteAttendScheduling(scDate,scID,attendConfig,rangeId);
|
||||
if(result.containsKey("code")){
|
||||
datacode = result.get("code").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataMap.put("schedulingid",attendId);
|
||||
dataMap.put("empCode",empCode);
|
||||
dataMap.put("scDate",scDate);
|
||||
dataMap.put("operType",operType);
|
||||
dataMap.put("code",datacode);
|
||||
dataList.add(dataMap);
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.test;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -23,5 +24,9 @@ public class test99 {
|
|||
System.out.println(period_time);
|
||||
}
|
||||
|
||||
String data = "[\"10000065971\"]";
|
||||
JSONArray jsonArray = JSONArray.parseArray(data);
|
||||
System.out.println(jsonArray.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,18 @@
|
|||
select b.id,b.name,a.sfmdbc,a.fdjjrbc
|
||||
from e10_common.uf_kq_mdbcdy a
|
||||
inner join (select * from e10_other_business.attend_shift where delete_type=0 and tenant_key = #{tenantKey}) b on a.bc=b.id
|
||||
where a.sfmdbc = #{isStore}
|
||||
and a.fdjjrbc = #{type}
|
||||
and a.delete_type = 0
|
||||
where a.delete_type = 0
|
||||
and a.tenant_key= #{tenantKey}
|
||||
<if test="isStore != null">
|
||||
and a.sfmdbc = #{isStore}
|
||||
</if>
|
||||
<if test="type != null">
|
||||
and a.fdjjrbc = #{type}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="queryShiftTimeList" resultType="com.weaver.seconddev.chapanda.hrm.entity.CustomShiftTimePo">
|
||||
select attend_start_time as attendStartTime,attend_end_time as attendEndTime
|
||||
select attend_start_time as beginTime,attend_end_time as endTime
|
||||
from e10_other_business.attend_period
|
||||
where delete_type=0
|
||||
and attend_shift_id = #{shiftId}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package com.weaver.seconddev.chapanda.prop.constant;
|
||||
|
||||
|
||||
public class Constants {
|
||||
public static String TENANT_KEY = "t024j0gfn0";
|
||||
public static String SysUserId = "1167276462243069953";
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.weaver.seconddev.chapanda.prop.dao;
|
||||
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.seconddev.chapanda.prop.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.prop.util.DatabaseUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ParamConfigDao {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ParamConfigDao.class);
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String queryEnvironmentValue(String pkey,String envType){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
String value = "";
|
||||
try{
|
||||
String dataSql =" select uatvalue,devvalue,prodvalue from uf_config where pkey=? " +
|
||||
" and tenant_key=? \n" +
|
||||
" and delete_type=0" ;
|
||||
|
||||
log.error("dataSql:" + dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(pkey);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("recordList:{}",recordList.size());
|
||||
if(recordList.size() > 0){
|
||||
Map<String, Object> recordMap = recordList.get(0);
|
||||
value = String.valueOf(recordMap.get(envType+"value"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("e:{}", e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,422 @@
|
|||
package com.weaver.seconddev.chapanda.prop.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class CommonUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(CommonUtils.class);
|
||||
|
||||
public static JSONObject toJSON(String data){
|
||||
if(!StringUtils.isEmpty(data)){
|
||||
try {
|
||||
return JSONObject.parseObject(data);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Long getJSONLong(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getLong(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getJSONInteger(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getInteger(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String getJSONString(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return null2String(json.getString(key));
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONObject(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONArray getJSONArray(JSONObject json, String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONArray(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONArray json, int idx){
|
||||
if(json != null && json.size() > idx){
|
||||
try {
|
||||
return json.getJSONObject(idx);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String mapToStrData(Map<String, Object> para){
|
||||
if(para != null) {
|
||||
return JSONObject.toJSON(para).toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs){
|
||||
strToLongList(list,strs,true);
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs,boolean isDist){
|
||||
if(list == null){
|
||||
return;
|
||||
}
|
||||
if(StringUtils.isEmpty(strs)){
|
||||
return;
|
||||
}
|
||||
|
||||
String[] strList = StringUtils.split(strs, ",");
|
||||
for(String str:strList){
|
||||
if(StringUtils.isEmpty(str)){
|
||||
continue;
|
||||
}
|
||||
|
||||
long id = getLongValue(str);
|
||||
if(id > 0l && (isDist == false || !list.contains(id))){
|
||||
list.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLongValue(Object v){
|
||||
return getLongValue(null2String(v));
|
||||
}
|
||||
|
||||
public static long getLongValue(String v) {
|
||||
return getLongValue(v, -1);
|
||||
}
|
||||
|
||||
public static long getLongValue(String v, long def) {
|
||||
try {
|
||||
return Long.parseLong(v);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntValue(Object o){
|
||||
return getIntValue(null2String(o));
|
||||
}
|
||||
|
||||
public static int getIntValue(String s){
|
||||
return getIntValue(s,-1);
|
||||
}
|
||||
|
||||
public static int getIntValue(String s, int def){
|
||||
try {
|
||||
return NumberUtils.toInt(s);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String null2String(Object s) {
|
||||
return s == null ? "" : s.toString();
|
||||
}
|
||||
|
||||
public static String null2String(Object s, String def) {
|
||||
return s == null ? (def == null ? "" : def) : s.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String stringReplace(String sou, String s1, String s2) {
|
||||
//int idx = sou.indexOf(s1);
|
||||
//if (idx < 0) {
|
||||
// return sou;
|
||||
//}
|
||||
//return sou.substring(0, idx) + s2 + StringReplace(sou.substring(idx + s1.length()), s1, s2);
|
||||
sou = null2String(sou);
|
||||
s1 = null2String(s1);
|
||||
s2 = null2String(s2);
|
||||
try{
|
||||
sou = sou.replace(s1, s2);
|
||||
}catch(Exception e){
|
||||
//System.out.println(e);//将未知异常打印出来,便于检查错误。
|
||||
}
|
||||
return sou;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toScreen(String s) {
|
||||
char c[] = s.toCharArray();
|
||||
char ch;
|
||||
int i = 0;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (i < c.length) {
|
||||
ch = c[i++];
|
||||
|
||||
if (ch == '\r')
|
||||
buf.append("");
|
||||
else if (ch == '\n')
|
||||
buf.append("");
|
||||
else
|
||||
buf.append(ch);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toExcel(String s) {
|
||||
if (s == null) return "";
|
||||
//因本方法会将字符串 &符号转换,故先将欧元符号转义符转换为其Unicode码
|
||||
s = s.replaceAll("€", "\u20AC");
|
||||
String str = toScreen(s);
|
||||
str = stringReplace(str, "∠", "∠");
|
||||
str = stringReplace(str, "φ", "φ");
|
||||
str = stringReplace(str, """, "\"");
|
||||
str = stringReplace(str, " ", "%nbsp");
|
||||
//str=Util.StringReplace(str,"'","‘");
|
||||
str = stringReplace(str, "<", "<");
|
||||
str = stringReplace(str, ">", ">");
|
||||
str = stringReplace(str, "&dt;&at;", "<br>");
|
||||
str = stringReplace(str, "&", "&");
|
||||
str = stringReplace(str, "<br>", "&dt;&at;");
|
||||
if ("&dt;&at;".equals(str)) {
|
||||
str = "";
|
||||
}
|
||||
//在方法最后,又将欧元符号置换为转义符
|
||||
str = str.replaceAll("\u20AC", "€");
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String delHtml(final String inputString) {
|
||||
String htmlStr = toExcel(inputString); // 含html标签的字符串
|
||||
|
||||
String textStr = "";
|
||||
java.util.regex.Pattern p_script;
|
||||
java.util.regex.Matcher m_script;
|
||||
java.util.regex.Pattern p_html;
|
||||
java.util.regex.Matcher m_html;
|
||||
|
||||
try {
|
||||
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
|
||||
|
||||
String regEx_script = "<[/s]*?script[^>]*?>[/s/S]*?<[/s]*?//[/s]*?script[/s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[/s/S]*?<//script>
|
||||
|
||||
p_script = java.util.regex.Pattern.compile(regEx_script, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_script = p_script.matcher(htmlStr);
|
||||
htmlStr = m_script.replaceAll(""); // 过滤script标签
|
||||
|
||||
p_html = java.util.regex.Pattern.compile(regEx_html, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_html = p_html.matcher(htmlStr);
|
||||
htmlStr = m_html.replaceAll(""); // 过滤html标签
|
||||
|
||||
textStr = htmlStr;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Html2Text: " + e.getMessage());
|
||||
}
|
||||
|
||||
return htmlToTxt(textStr).trim();// 返回文本字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字符串中的html格式
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static String htmlToTxt(String input) {
|
||||
if (input == null || input.trim().equals("")) {
|
||||
return "";
|
||||
}
|
||||
// 去掉所有html元素,
|
||||
String str = input.replaceAll("<[a-zA-Z]+[1-9]?[^><]*>", "");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
//==new=
|
||||
|
||||
public static int getIntValue(Object s, int def){
|
||||
return getIntValue(null2String(s));
|
||||
}
|
||||
|
||||
public static List<Long> strToLongList(String strs){
|
||||
List<Long> list = new ArrayList<Long>();
|
||||
strToLongList(list,strs,true);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static int dateInterval(String fromdate, String todate) {
|
||||
Calendar fromcalendar = getCalendar(fromdate);
|
||||
Calendar tocalendar = getCalendar(todate);
|
||||
|
||||
if (fromcalendar == null || tocalendar == null)
|
||||
return 0;
|
||||
|
||||
return (int) ((tocalendar.getTimeInMillis() - fromcalendar.getTimeInMillis()) / 3600 / 24 / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间,格式为 '2004-05-12 12:00:23' 或者 '2004-05-12'
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime) {
|
||||
int datetimelength = datetime.length() ;
|
||||
|
||||
switch(datetimelength) {
|
||||
case 19 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd' 'HH:mm:ss") ;
|
||||
case 10 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd") ;
|
||||
default :
|
||||
return null ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间
|
||||
* @param formart - 给定的日期时间的格式
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime, String formart) {
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(formart) ;
|
||||
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
try {
|
||||
calendar.setTime(SDF.parse(datetime)) ;
|
||||
} catch (ParseException e) {
|
||||
return null ;
|
||||
}
|
||||
|
||||
return calendar ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回当前时间字符,格式为 yyyy'-'MM'-'dd
|
||||
*
|
||||
* 返回当前时间字符,默认格式为yyyy'-'MM'-'dd
|
||||
*
|
||||
* 如 2004-09-07
|
||||
*/
|
||||
public static String getCurrentDateString() {
|
||||
String timestrformart = "yyyy'-'MM'-'dd" ;
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(timestrformart) ;
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
|
||||
return SDF.format(calendar.getTime()) ;
|
||||
}
|
||||
|
||||
public static String getMessage(String msgMode,String key,String val){
|
||||
key = null2String(key).trim();
|
||||
val = null2String(val).trim();
|
||||
msgMode = null2String(msgMode).trim();
|
||||
if(!"".equals(msgMode) && !"".equals(key)) {
|
||||
msgMode = msgMode.replaceAll(key, val);
|
||||
}
|
||||
return msgMode;
|
||||
}
|
||||
|
||||
public static List<Long> tranStrToLongList(Object idListObj){
|
||||
List<Long> docIds = new ArrayList<Long>();
|
||||
if(idListObj != null) {
|
||||
try {
|
||||
JSONArray idObjs = JSONArray.parseArray(null2String(idListObj));
|
||||
for (Object idObj : idObjs) {
|
||||
long id = getLongValue(idObj);
|
||||
if (id > 0l) {
|
||||
docIds.add(id);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("trans error :{}", idListObj);
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return docIds;
|
||||
}
|
||||
|
||||
public Map<String, Object> requestToMap(HttpServletRequest request) {
|
||||
Map<String, String[]> properties = request.getParameterMap();//把请求参数封装到Map<String, String[]>中
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Iterator<Map.Entry<String, String[]>> iter = properties.entrySet().iterator();
|
||||
String name = "";
|
||||
String value = "";
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, String[]> entry = iter.next();
|
||||
name = entry.getKey();
|
||||
Object valueObj = entry.getValue();
|
||||
if (null == valueObj) {
|
||||
value = "";
|
||||
} else if (valueObj instanceof String[]) {
|
||||
String[] values = (String[]) valueObj;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
value = values[i] + ",";
|
||||
}
|
||||
value = value.substring(0, value.length() - 1);
|
||||
} else {
|
||||
value = valueObj.toString();
|
||||
}
|
||||
returnMap.put(name, value);
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,366 @@
|
|||
package com.weaver.seconddev.chapanda.prop.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.ebuilder.datasource.api.entity.ExecuteSqlEntity;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SourceType;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SqlParamType;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.DynamicParamDto;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.FieldQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.GroupQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.TableQuery;
|
||||
import com.weaver.ebuilder.datasource.api.service.DataSetService;
|
||||
import com.weaver.ebuilder.datasource.api.service.impl.EbFormDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* DatabaseUtil 是一个数据库工具类,提供了一些执行 SQL 查询和操作的方法。
|
||||
*/
|
||||
|
||||
|
||||
@Component
|
||||
public class DatabaseUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(DatabaseUtils.class);
|
||||
|
||||
@Autowired
|
||||
private DataSetService dataSetService;
|
||||
|
||||
@Autowired
|
||||
private EbFormDataService dataService;
|
||||
|
||||
|
||||
/**
|
||||
* 执行 SQL 并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 的相关信息的对象
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity) {
|
||||
Map<String, Object> map = dataSetService.executeSql(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行分页 SQL 查询并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 和分页信息的对象
|
||||
* @param pageNo 当前页码
|
||||
* @param pageSize 每页的数据条数
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity, int pageNo, int pageSize) {
|
||||
entity.setPageNo(pageNo);
|
||||
entity.setPageSize(pageSize);
|
||||
Map<String, Object> map = dataSetService.executeForQuery(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个包含执行 SQL 的对象。
|
||||
*
|
||||
* @param sql 需要执行的 SQL
|
||||
* @param groupId 数据源分组的 ID
|
||||
* @paramDesc 数据源分组的 ID 获取方式 【select APPLICATION_MARK,APPLICATION_name from eteams.ds_mark_service_relation】
|
||||
* @return 包含执行 SQL 的对象
|
||||
*/
|
||||
public ExecuteSqlEntity getExecuteSqlEntity(String sql, String groupId) {
|
||||
log.error("sql=>{}", sql);
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.LOGIC);
|
||||
executeSqlEntity.setGroupKey("0");
|
||||
return executeSqlEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 SQL 进行 Base64 编码。
|
||||
*
|
||||
* @param sql 需要进行编码的 SQL
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public String base64(String sql) {
|
||||
return Base64.encode(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源列表。
|
||||
*
|
||||
* @param map 包含数据源列表信息的 Map 对象
|
||||
* @return 数据源列表的 Map 对象
|
||||
*/
|
||||
public List<Map<String, Object>> getDataSourceList(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = new ArrayList();
|
||||
if ("OK".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT)) && map.get("count") != null && CommonUtils.getIntValue(map.get("count")) > 0) {
|
||||
entity = (List) map.get("records");
|
||||
}
|
||||
|
||||
return keyToLowerCase((List) entity);
|
||||
}
|
||||
|
||||
public Map<String, Object> getOneDataSource(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = getDataSourceList(map);
|
||||
return (Map)(CollectionUtil.isNotEmpty(entity) ? (Map)entity.get(0) : new HashMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMapList 需要转换键的 Map 对象列表
|
||||
* @return 转换后的 Map 对象列表
|
||||
*/
|
||||
public List<Map<String, Object>> keyToLowerCase(List<Map<String, Object>> orgMapList) {
|
||||
List<Map<String, Object>> resultList = new ArrayList();
|
||||
Iterator var2 = orgMapList.iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Map<String, Object> stringObjectMap = (Map) var2.next();
|
||||
resultList.add(keyToLowerCase(stringObjectMap));
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMap 需要转换键的 Map 对象
|
||||
* @return 转换后的 Map 对象
|
||||
*/
|
||||
public Map<String, Object> keyToLowerCase(Map<String, Object> orgMap) {
|
||||
Map<String, Object> resultMap = new HashMap();
|
||||
if (orgMap != null && !orgMap.isEmpty()) {
|
||||
Set<Map.Entry<String, Object>> entrySet = orgMap.entrySet();
|
||||
Iterator var3 = entrySet.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
Map.Entry<String, Object> entry = (Map.Entry) var3.next();
|
||||
String key = (String) entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
resultMap.put(key.toLowerCase(), value);
|
||||
}
|
||||
return resultMap;
|
||||
} else {
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据数据库类型 找到对应数据库
|
||||
*
|
||||
* @param sourceType sourceType 枚举类
|
||||
* ETEAMS :数据仓库
|
||||
* FORM: ebuilder表单
|
||||
* LOGIC: 各模块提供业务数据(逻辑表)
|
||||
* EXTERNAL: 外部数据源
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getDataGroups(String sourceType, Boolean flag) {
|
||||
GroupQuery query = new GroupQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setShowSqlDataset(flag);
|
||||
|
||||
|
||||
DynamicParamDto dynamicParamDto = new DynamicParamDto();
|
||||
dynamicParamDto.setUserId(10000L);
|
||||
dynamicParamDto.setTenantKey("tk");
|
||||
|
||||
query.setDynamicParamDto(dynamicParamDto);
|
||||
|
||||
return dataSetService.getDataGroups(query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据表
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getDataSets(String sourceType, String groupId, Integer pageNum, Integer pageSize) {
|
||||
|
||||
TableQuery tableQuery = new TableQuery();
|
||||
tableQuery.setSourceType(SourceType.valueOf(sourceType));
|
||||
tableQuery.setGroupId(groupId);
|
||||
//非必传
|
||||
//tableQuery.setName(name);
|
||||
tableQuery.setPageNo(pageNum);
|
||||
tableQuery.setPageSize(pageSize);
|
||||
return dataSetService.getDataSetsByPage(tableQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段
|
||||
* sourceType :LOGIC
|
||||
* sourceId : 8494845523559165780
|
||||
* groupId : weaver-crm-service
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getFields(String sourceType, String sourceId, String groupId) {
|
||||
FieldQuery query = new FieldQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setSourceId(sourceId);
|
||||
query.setGroupId(groupId);
|
||||
return dataSetService.getFields(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
* sourceType :LOGIC
|
||||
* groupId : weaver-ebuilder-app-service
|
||||
* sql : select * from ebda_app limit 10
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> execute(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeUpdate(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeForQuery(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param sql
|
||||
* @param sqlparam
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> executeForUpdate(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sql
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public String getMysqlPagedSql(String sql,int pageNo, int pageSize) {
|
||||
if(pageNo<=0){
|
||||
pageNo = 1;
|
||||
}
|
||||
|
||||
if(pageSize<=0){
|
||||
pageSize = 20;
|
||||
}
|
||||
|
||||
int start = (pageNo-1)*pageSize;
|
||||
int end = pageNo*pageSize;
|
||||
|
||||
return new StringBuffer().append(sql).append(
|
||||
" LIMIT "+start+","+(end-start)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取sql入参
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<SqlParamEntity> querySqlParamEntity(List<String> list){
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
for (String str : list){
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(str);
|
||||
sqlparam.add(sqlParamEntity);
|
||||
}
|
||||
return sqlparam;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getSqlList(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
return recordList;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getSqlMap(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
Map<String, Object> recordMap = new HashMap<String, Object>();
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
if(recordList.size() > 0){
|
||||
recordMap = recordList.get(0);
|
||||
}
|
||||
return recordMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.weaver.seconddev.chapanda.prop.util;
|
||||
|
||||
import com.weaver.seconddev.chapanda.prop.dao.ParamConfigDao;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ParamConfigUtil {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ParamConfigUtil.class);
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
ParamConfigDao paramConfigDao;
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String queryEnvironmentValue(String pkey){
|
||||
String value = "";
|
||||
if(StringUtils.isNotBlank(pkey)){
|
||||
SecDevProperty secDevProperty = new SecDevProperty();
|
||||
String envType = secDevProperty.getEvntype();
|
||||
log.error("envType:" + envType);
|
||||
if(StringUtils.isNotBlank(envType)){
|
||||
paramConfigDao.queryEnvironmentValue(pkey,envType);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.weaver.seconddev.chapanda.prop.util;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
|
||||
/**
|
||||
* packageName com.weaver.seconddev.chapanda.prop.util
|
||||
*
|
||||
* @ClassName SecDevProperty
|
||||
* @Author shil
|
||||
* @Date 2025/8/13 18:44
|
||||
* @Description TODO
|
||||
*/
|
||||
|
||||
|
||||
@Configuration
|
||||
// 自动刷新配置,不需要重启服务
|
||||
@RefreshScope
|
||||
public class SecDevProperty {
|
||||
|
||||
@Value("${weaver.secondev.chapanda.evntype:prod}")
|
||||
private String evntype;
|
||||
|
||||
public String getEvntype() {
|
||||
return evntype;
|
||||
}
|
||||
|
||||
public void setEvntype(String evntype) {
|
||||
this.evntype = evntype;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue