洲际酒店任务元素开发、delwithbug修复

jingwei
youhong.ai 2023-05-12 11:15:29 +08:00
parent daaefd64c2
commit 0cc0b9889a
12 changed files with 386 additions and 209 deletions

View File

@ -115,6 +115,19 @@ class CusUtils {
return Utils.convertNameObjToId(fieldName) return Utils.convertNameObjToId(fieldName)
} }
getQueryString(name) {
let reg = new RegExp("(^|&|\/?)" + name + "=([^&]*)(&|$)", "i");
let searchStr = window.location.href
if (searchStr.startsWith('&')) {
searchStr = searchStr.substr(1)
}
let search = searchStr.match(reg)
if (search != null) {
return unescape(search[2]);
}
return null;
}
/** /**
* 将字段名称转为字段id * 将字段名称转为字段id
* @param fieldObj 字段名称对象 {string|object} * @param fieldObj 字段名称对象 {string|object}

View File

@ -32,6 +32,7 @@ import weaver.file.ImageFileManager;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.*; import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
@ -127,7 +128,11 @@ public class HttpUtils {
builder.append("&"); builder.append("&");
builder.append(entry.getKey()); builder.append(entry.getKey());
builder.append("="); builder.append("=");
builder.append(entry.getValue()); try {
builder.append(URLEncoder.encode(Util.null2String(entry.getValue()), "UTF-8"));
} catch (UnsupportedEncodingException e) {
builder.append(entry.getKey());
}
} }
return removeSeparator(builder); return removeSeparator(builder);
} }

View File

@ -460,7 +460,7 @@ public class ResultMapper {
} }
if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) { if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) {
if (enable) { if (enable) {
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); ((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(columnName[i]));
continue; continue;
} }
if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) {
@ -473,11 +473,11 @@ public class ResultMapper {
} }
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) { if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
if (enable) { if (enable) {
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i]));
continue; continue;
} }
if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) {
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i]));
} }
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getString(i + 1));
((Map<? super Object, ? super Object>) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(columnName[i].toUpperCase(), rs.getString(i + 1));
@ -507,7 +507,7 @@ public class ResultMapper {
} }
} }
if (enable) { if (enable) {
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i]));
continue; continue;
} }
if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) {
@ -569,7 +569,7 @@ public class ResultMapper {
cassociationValue = paramType.get(declaredField.getType()).apply(String.valueOf(cassociationValue)); cassociationValue = paramType.get(declaredField.getType()).apply(String.valueOf(cassociationValue));
} }
try { try {
if (Objects.nonNull(value)) { if (Objects.nonNull(cassociationValue)) {
propertyDescriptor.getWriteMethod().invoke(o, cassociationValue); propertyDescriptor.getWriteMethod().invoke(o, cassociationValue);
} }
} catch (Exception e) { } catch (Exception e) {
@ -651,7 +651,6 @@ public class ResultMapper {
Association[] mappings = annotation.value(); Association[] mappings = annotation.value();
Association mapping = null; Association mapping = null;
for (Association item : mappings) { for (Association item : mappings) {
Util.getLogger().info("column: " + item.column() + " ===property: " + item.property() + " ====fieldName: " + filedName);
String property = isMap ? item.column() : item.property(); String property = isMap ? item.column() : item.property();
if (isMap ? filedName.equalsIgnoreCase(property) : filedName.equals(property)) { if (isMap ? filedName.equalsIgnoreCase(property) : filedName.equals(property)) {
mapping = item; mapping = item;
@ -664,7 +663,6 @@ public class ResultMapper {
Id id = annotation.id(); Id id = annotation.id();
String column = annotation.column(); String column = annotation.column();
String columnValue = rs.getString(column); String columnValue = rs.getString(column);
Util.getLogger().info(Arrays.toString(rs.getColumnName()));
if (Objects.isNull(columnValue) || "".equals(columnValue)) { if (Objects.isNull(columnValue) || "".equals(columnValue)) {
columnValue = rs.getString(column.toUpperCase()); columnValue = rs.getString(column.toUpperCase());
} }

View File

@ -52,10 +52,40 @@ public class TaskElementController {
@QueryParam("id") String configId) { @QueryParam("id") String configId) {
User user = HrmUserVarify.getUser(request, response); User user = HrmUserVarify.getUser(request, response);
try { try {
return ApiResult.success(service.getList(user, params,configId)); return ApiResult.success(service.getList(user, params, configId));
} catch (Exception e) { } catch (Exception e) {
log.error("get task list error!\n" + Util.getErrString(e)); log.error("get task list error!\n" + Util.getErrString(e));
return ApiResult.error("system error!"); return ApiResult.error("system error!");
} }
} }
@Path("/get-btn")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String buttonInfo(@Context HttpServletRequest request,
@Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
try {
return ApiResult.success(service.buttonInfo(user));
} catch (Exception e) {
log.error("get button info error!\n" + Util.getErrString(e));
return ApiResult.error("system error!");
}
}
@Path("/clear-config")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String clearConfig() {
try {
service.clearConfig();
return ApiResult.successNoData();
} catch (Exception e) {
log.error("clear config error!\n" + Util.getErrString(e));
return ApiResult.error("system error!");
}
}
} }

View File

@ -29,6 +29,11 @@ public class IhgTaskElementConfigItem {
private String unitEn; private String unitEn;
/** icon */ /** icon */
private String icon; private String icon;
/** 移动端图标 */
private String iconMobile;
/** 移动端激活图标 */
private String iconMobileActive;
/** 激活icon */ /** 激活icon */
private String iconActive; private String iconActive;
/** 查看权限 */ /** 查看权限 */
@ -36,6 +41,9 @@ public class IhgTaskElementConfigItem {
/** 数据来源 */ /** 数据来源 */
private String dataSource; private String dataSource;
/** 序号 */
private String sortNum;
/** 跳转链接 */ /** 跳转链接 */
private String link; private String link;
/** 数据来源值 */ /** 数据来源值 */

View File

@ -23,7 +23,7 @@ public interface TaskElementMapper {
* *
* @return * @return
*/ */
@Select("select * from uf_ihg_el_config ") @Select("select * from uf_ihg_el_config where enable_status = 1")
@Associations({ @Associations({
@Association( @Association(
property = "icon", property = "icon",
@ -32,6 +32,14 @@ public interface TaskElementMapper {
@Association( @Association(
property = "iconActive", property = "iconActive",
column = "icon_active", column = "icon_active",
id = @Id(methodId = 1, value = String.class)),
@Association(
property = "iconMobile",
column = "icon_mobile",
id = @Id(methodId = 1, value = String.class)),
@Association(
property = "iconMobileActive",
column = "icon_mobile_active",
id = @Id(methodId = 1, value = String.class)) id = @Id(methodId = 1, value = String.class))
}) })
List<IhgTaskElementConfigItem> selectConfig(); List<IhgTaskElementConfigItem> selectConfig();
@ -42,7 +50,7 @@ public interface TaskElementMapper {
* @param configId id * @param configId id
* @return * @return
*/ */
@Select("select * from uf_ihg_el_config where id = #{configId}") @Select("select * from uf_ihg_el_config where id = #{configId} and enable_status = 1")
@Associations({ @Associations({
@Association( @Association(
property = "icon", property = "icon",
@ -51,6 +59,14 @@ public interface TaskElementMapper {
@Association( @Association(
property = "iconActive", property = "iconActive",
column = "icon_active", column = "icon_active",
id = @Id(methodId = 1, value = String.class)),
@Association(
property = "iconMobile",
column = "icon_mobile",
id = @Id(methodId = 1, value = String.class)),
@Association(
property = "iconMobileActive",
column = "icon_mobile_active",
id = @Id(methodId = 1, value = String.class)) id = @Id(methodId = 1, value = String.class))
}) })
IhgTaskElementConfigItem selectConfig(@ParamMapper("configId") String configId); IhgTaskElementConfigItem selectConfig(@ParamMapper("configId") String configId);
@ -72,7 +88,6 @@ public interface TaskElementMapper {
* @param viewAuthoritySql sql * @param viewAuthoritySql sql
* @param user * @param user
* @param map * @param map
* @param where
* @return * @return
*/ */
@Select(custom = true) @Select(custom = true)
@ -86,6 +101,7 @@ public interface TaskElementMapper {
* @param customerValue sql * @param customerValue sql
* @param item * @param item
* @param user * @param user
* @param map
* @param where * @param where
* @return * @return
*/ */
@ -93,5 +109,16 @@ public interface TaskElementMapper {
List<Map<String, Object>> selectWorkList(@SqlString String customerValue, List<Map<String, Object>> selectWorkList(@SqlString String customerValue,
@ParamMapper("param") Map<String, Object> item, @ParamMapper("param") Map<String, Object> item,
@ParamMapper("user") User user, @ParamMapper("user") User user,
@ParamMapper("where") Map<String, Object> where); @ParamMapper("where") Map<String, Object> where,
@ParamMapper("current") Map<String, Object> map);
/**
* <h2></h2>
*
* @param sql
* @param o
* @return
*/
@Select(custom = true)
String selectConvert(@SqlString String sql, @ParamMapper("value") String o);
} }

View File

@ -9,13 +9,11 @@ import com.api.youhong.ai.ihgzhouji.taskele.entity.IhgTaskElementConfigItem;
import com.api.youhong.ai.ihgzhouji.taskele.mapper.TaskElementMapper; import com.api.youhong.ai.ihgzhouji.taskele.mapper.TaskElementMapper;
import com.api.youhong.ai.ihgzhouji.taskele.mapstruct.TaskElementMapstruct; import com.api.youhong.ai.ihgzhouji.taskele.mapstruct.TaskElementMapstruct;
import com.api.youhong.ai.ihgzhouji.taskele.vo.IhgTaskElementVo; import com.api.youhong.ai.ihgzhouji.taskele.vo.IhgTaskElementVo;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.hrm.User; import weaver.hrm.User;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/** /**
* <h1>service</h1> * <h1>service</h1>
@ -26,6 +24,29 @@ import java.util.stream.Collectors;
*/ */
public class TaskElementService { public class TaskElementService {
private final TaskElementMapper mapper = Util.getMapper(TaskElementMapper.class); private final TaskElementMapper mapper = Util.getMapper(TaskElementMapper.class);
private final Logger log = Util.getLogger();
private final RecordSet rs = new RecordSet();
private volatile Map<String, Object> config = null;
public void clearConfig() {
this.config = null;
}
private Map<String, Object> getConfig() {
if (this.config == null) {
synchronized (TaskElementService.class) {
if (this.config == null) {
this.config = Util.readProperties2Map("IHGWorkListInfoConvert", "cus");
if (config == null) {
this.config = Collections.emptyMap();
}
}
}
}
return config;
}
public List<IhgTaskElementVo> getList(User user) { public List<IhgTaskElementVo> getList(User user) {
List<IhgTaskElementConfigItem> ihgTaskElementConfItemList = mapper.selectConfig(); List<IhgTaskElementConfigItem> ihgTaskElementConfItemList = mapper.selectConfig();
@ -50,7 +71,7 @@ public class TaskElementService {
for (Map.Entry<IhgTaskElementConfigItem, List<Map<String, Object>>> entry : taskConfigMap.entrySet()) { for (Map.Entry<IhgTaskElementConfigItem, List<Map<String, Object>>> entry : taskConfigMap.entrySet()) {
IhgTaskElementConfigItem taskElementConfigItem = entry.getKey(); IhgTaskElementConfigItem taskElementConfigItem = entry.getKey();
List<Map<String, Object>> authorityList = entry.getValue(); List<Map<String, Object>> authorityList = entry.getValue();
List<Map<String, Object>> workList = queryWorkList(taskElementConfigItem, authorityList, user, "", Collections.emptyMap()); List<Map<String, Object>> workList = queryWorkList(taskElementConfigItem, authorityList, user, "", Collections.emptyMap(), map);
IhgTaskElementVo ihgTaskElementVo = TaskElementMapstruct.INSTANCE.entity2Vo(taskElementConfigItem); IhgTaskElementVo ihgTaskElementVo = TaskElementMapstruct.INSTANCE.entity2Vo(taskElementConfigItem);
ihgTaskElementVo.setList(workList); ihgTaskElementVo.setList(workList);
ihgTaskElementVo.setSize(workList.size()); ihgTaskElementVo.setSize(workList.size());
@ -60,26 +81,44 @@ public class TaskElementService {
} }
result.add(ihgTaskElementVo); result.add(ihgTaskElementVo);
} }
result.sort(Comparator.comparing(item -> StrUtil.isBlank(item.getSortNum()) ? -1 : Integer.parseInt(item.getSortNum())));
return result; return result;
} }
private List<Map<String, Object>> queryWorkList(IhgTaskElementConfigItem taskElementConfigItem, private List<Map<String, Object>> queryWorkList(IhgTaskElementConfigItem taskElementConfigItem,
List<Map<String, Object>> authorityList, List<Map<String, Object>> authorityList,
User user, String whereStr, User user, String whereStr,
Map<String, Object> whereMap) { Map<String, Object> whereMap,
Map<String, Object> currentMap) {
String dataSource = taskElementConfigItem.getDataSource(); String dataSource = taskElementConfigItem.getDataSource();
String customerValue = taskElementConfigItem.getCustomerValue(); String customerValue = taskElementConfigItem.getCustomerValue();
if (StrUtil.isBlank(customerValue)) { if (StrUtil.isBlank(customerValue)) {
throw new CustomerException("自定义sql或自定义接口不能为空"); throw new CustomerException("自定义sql或自定义接口不能为空");
} }
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
Map<String, Object> convertConfig = getConfig();
for (Map<String, Object> item : authorityList) { for (Map<String, Object> item : authorityList) {
if ("0".equals(dataSource)) { if ("0".equals(dataSource)) {
// 自定义sql // 自定义sql
customerValue += " " + whereStr; customerValue += " " + whereStr;
List<Map<String, Object>> list = mapper.selectWorkList(customerValue, item, user, whereMap); List<Map<String, Object>> list = mapper.selectWorkList(customerValue, item, user, whereMap, currentMap);
if (CollectionUtil.isNotEmpty(list)) { if (CollectionUtil.isNotEmpty(list)) {
result.addAll(list); result.addAll(list);
Map<String, Object> convert = (Map<String, Object>) convertConfig.get("convert");
if (Objects.nonNull(convert)) {
// 自定义转换设置
for (Map<String, Object> listItem : list) {
for (Map.Entry<String, Object> entry : convert.entrySet()) {
String sql = Util.null2String(entry.getValue());
String replace = sql.replace("$?$", "#{value}");
if (StrUtil.isNotBlank(replace)) {
String value = mapper.selectConvert(replace, Util.null2String(listItem.get(Util.null2String(entry.getKey()))));
listItem.put(entry.getKey(), value);
}
}
}
}
} }
} else { } else {
// 自定义接口 // 自定义接口
@ -99,19 +138,24 @@ public class TaskElementService {
} }
} }
} }
// 去重 return removeDuplicates(result);
result = result.stream()
.filter(distinctByKey(item -> item.get("id")))
.collect(Collectors.toList());
return result;
} }
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { public List<Map<String, Object>> removeDuplicates(List<Map<String, Object>> list) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>(8); Set<String> idSet = new HashSet<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; List<Map<String, Object>> resultList = new ArrayList<>();
for (Map<String, Object> map : list) {
String id = Util.null2String(map.get("id"));
if (!idSet.contains(id)) {
idSet.add(id);
resultList.add(map);
}
}
return resultList;
} }
/** /**
* <h2></h2> * <h2></h2>
* *
@ -134,8 +178,14 @@ public class TaskElementService {
Map<String, Object> valueMap = (Map<String, Object>) entry.getValue(); Map<String, Object> valueMap = (Map<String, Object>) entry.getValue();
String key = Util.null2String(valueMap.get("key")); String key = Util.null2String(valueMap.get("key"));
String value = Util.null2String(valueMap.get("value")); String value = Util.null2String(valueMap.get("value"));
String type = Util.null2String(valueMap.get("type"));
if (StrUtil.isNotBlank(value)) { if (StrUtil.isNotBlank(value)) {
builder.append(" and ").append(key).append(" = ").append("#{where.").append(key).append("}"); if ("like".equalsIgnoreCase(type)) {
value = "%" + value + "%";
builder.append(" and ").append(key).append(" like ").append("#{where.").append(key).append("}");
} else {
builder.append(" and ").append(key).append(" = ").append("#{where.").append(key).append("}");
}
map.put(key, value); map.put(key, value);
} }
} }
@ -147,7 +197,7 @@ public class TaskElementService {
return null; return null;
} }
// 查询数据 // 查询数据
List<Map<String, Object>> workList = this.queryWorkList(ihgTaskElementConfItem, authorityList, user, whereStr, map); List<Map<String, Object>> workList = this.queryWorkList(ihgTaskElementConfItem, authorityList, user, whereStr, map, map);
IhgTaskElementVo ihgTaskElementVo = TaskElementMapstruct.INSTANCE.entity2Vo(ihgTaskElementConfItem); IhgTaskElementVo ihgTaskElementVo = TaskElementMapstruct.INSTANCE.entity2Vo(ihgTaskElementConfItem);
ihgTaskElementVo.setList(workList); ihgTaskElementVo.setList(workList);
ihgTaskElementVo.setSize(workList.size()); ihgTaskElementVo.setSize(workList.size());
@ -157,4 +207,35 @@ public class TaskElementService {
} }
return ihgTaskElementVo; return ihgTaskElementVo;
} }
/**
* <h2></h2>
*
* @param user
* @return
*/
public Map<String, Object> buttonInfo(User user) {
String sendWorkButtonAuthority = Util.getCusConfigValue("SEND_WORK_BUTTON_AUTHORITY");
String sendWorkButtonLink = Util.getCusConfigValue("SEND_WORK_BUTTON_LINK");
String workListButtonAuthority = Util.getCusConfigValue("WORK_LIST_BUTTON_AUTHORITY");
String workListButtonLink = Util.getCusConfigValue("WORK_LIST_BUTTON_LINK");
Map<String, Object> result = new HashMap<>(8);
// 设置查询基础参数
Map<String, Object> map = new HashMap<>(8);
map.put("currentDate", Util.getTime("yyyy-MM-dd"));
map.put("currentTime", Util.getTime("HH:mm:ss"));
if (StrUtil.isNotBlank(sendWorkButtonAuthority)) {
List<Map<String, Object>> maps = mapper.selectAuthority(sendWorkButtonAuthority, user, map);
if (CollectionUtil.isNotEmpty(maps)) {
result.put("sendWork", sendWorkButtonLink);
}
}
if (StrUtil.isNotBlank(sendWorkButtonAuthority)) {
List<Map<String, Object>> maps = mapper.selectAuthority(workListButtonAuthority, user, map);
if (CollectionUtil.isNotEmpty(maps)) {
result.put("workList", workListButtonLink);
}
}
return result;
}
} }

View File

@ -25,15 +25,18 @@ public class IhgTaskElementVo {
private String title; private String title;
/** 单位 */ /** 单位 */
private String unit; private String unit;
/** icon */ /** icon */
private String icon; private String icon;
/** 激活icon */ /** 激活icon */
private String iconActive; private String iconActive;
/** 移动端图标 */
private String iconMobile;
/** 移动端激活图标 */
private String iconMobileActive;
/** 跳转链接 */ /** 跳转链接 */
private String link; private String link;
/** 序号 */
private String sortNum;
/** 数据长度 */ /** 数据长度 */
private Integer size; private Integer size;
/** 数据 */ /** 数据 */

View File

@ -1297,8 +1297,11 @@ public class DealWithMapping extends ToolUtil {
if (null == resultList || resultList.isEmpty()) { if (null == resultList || resultList.isEmpty()) {
return; return;
} }
if (Objects.isNull(childList) || childList.isEmpty()) {
list.addAll(resultList);
return;
}
if ("0".equals(childType)) { if ("0".equals(childType)) {
// 对象类型 // 对象类型
for (Object o : resultList) { for (Object o : resultList) {
Map<String, Object> item = new HashMap<>(); Map<String, Object> item = new HashMap<>();
@ -1376,6 +1379,10 @@ public class DealWithMapping extends ToolUtil {
if (null == resultList || resultList.isEmpty()) { if (null == resultList || resultList.isEmpty()) {
return; return;
} }
if (Objects.isNull(childList) || childList.isEmpty()) {
list.addAll(resultList);
return;
}
if ("0".equals(childType)) { if ("0".equals(childType)) {
// 对象类型 // 对象类型

View File

@ -0,0 +1,2 @@
# 任务接受人转换规则
cus.convert.rwjsr=select lastname from hrmresource where id = $?$

View File

@ -31,189 +31,182 @@ import java.util.stream.Collectors;
@ActionDesc(value = "部门属于酒店的部门分级分权控制定时任务,只能查看到同层的酒店部门信息", author = "aiyh") @ActionDesc(value = "部门属于酒店的部门分级分权控制定时任务,只能查看到同层的酒店部门信息", author = "aiyh")
public class DecentralizationOfPowersCronJob extends BaseCronJob { public class DecentralizationOfPowersCronJob extends BaseCronJob {
@RequiredMark("支持中心部门ID") @RequiredMark("支持中心部门ID")
@PrintParamMark @PrintParamMark
private String supportCenterDeptId; private String supportCenterDeptId;
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private final Logger log = Util.getLogger(); private final Logger log = Util.getLogger();
private final RecordSet recordSet = new RecordSet(); private final RecordSet recordSet = new RecordSet();
private final DecentralizationMapper mapper = Util.getMapper(DecentralizationMapper.class); private final DecentralizationMapper mapper = Util.getMapper(DecentralizationMapper.class);
@Override @Override
public void execute() { public void execute() {
try { try {
Util.verifyRequiredField(this); Util.verifyRequiredField(this);
doExecute(); doExecute();
} catch (Exception e) { } catch (Exception e) {
log.error(Util.logStr("execute cronJob fail! error msg is [{}]stack trace is [\n{}\n]", log.error(Util.logStr("execute cronJob fail! error msg is [{}]stack trace is [\n{}\n]",
e.getMessage(), Util.getErrString(e))); e.getMessage(), Util.getErrString(e)));
throw new CustomerException("execute cronJob fail," + e.getMessage()); throw new CustomerException("execute cronJob fail," + e.getMessage());
} }
} }
public void doExecute() { public void doExecute() {
List<OrgInfoHotelEntity> hotelInfoList = mapper.selectCnTileFromOrginfo(); List<OrgInfoHotelEntity> hotelInfoList = mapper.selectCnTileFromOrginfo();
for (OrgInfoHotelEntity orgInfoHotelEntity : hotelInfoList) { for (OrgInfoHotelEntity orgInfoHotelEntity : hotelInfoList) {
insertSysdetachinfo(orgInfoHotelEntity); insertSysdetachinfo(orgInfoHotelEntity);
} }
log.info("查询酒店后信息数据: " + hotelInfoList.size());
// 将没有infoID的数据过滤 // 将没有infoID的数据过滤
List<OrgInfoHotelEntity> hasInfoIdHotelInfo = hotelInfoList.stream() List<OrgInfoHotelEntity> hasInfoIdHotelInfo = hotelInfoList.stream()
.filter(item -> item.getInfoId() != null && item.getInfoId() > 0) .filter(item -> item.getInfoId() != null && item.getInfoId() > 0)
.collect(Collectors.toList()); .collect(Collectors.toList());
log.info("过滤后数据信息:" + hasInfoIdHotelInfo.size()); Map<String, List<OrgInfoHotelEntity>> groupByUpdate = hasInfoIdHotelInfo
Map<String, List<OrgInfoHotelEntity>> groupByUpdate = hasInfoIdHotelInfo .stream().collect(Collectors.groupingBy(OrgInfoHotelEntity::getUpdate));
.stream().collect(Collectors.groupingBy(OrgInfoHotelEntity::getUpdate));
log.info("分组后数据信息:" + groupByUpdate.size()); List<OrgInfoHotelEntity> updateInfo = groupByUpdate.get("true");
List<OrgInfoHotelEntity> updateInfo = groupByUpdate.get("true"); List<OrgInfoHotelEntity> insertInfo = groupByUpdate.get("false");
List<OrgInfoHotelEntity> insertInfo = groupByUpdate.get("false"); if (updateInfo == null) {
if (updateInfo == null) { updateInfo = new ArrayList<>();
updateInfo = new ArrayList<>(); }
} if (insertInfo == null) {
if (insertInfo == null) { insertInfo = new ArrayList<>();
insertInfo = new ArrayList<>(); }
} List<List> insertSqlArgs = new ArrayList<>();
List<List> insertSqlArgs = new ArrayList<>(); insertInfo.forEach(item -> {
insertInfo.forEach(item -> { List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(item, "");
List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(item, ""); insertSqlArgs.addAll(lists);
insertSqlArgs.addAll(lists); });
}); if (!insertSqlArgs.isEmpty()) {
log.info("将待插入数据插入数据表中: " + insertSqlArgs.size()); boolean insertSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), insertSqlArgs);
if (!insertSqlArgs.isEmpty()) { if (!insertSuccess) {
boolean insertSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), insertSqlArgs); log.error("批量插入权限数据失败!" + OrgInfoHotelEntity.getInsertSql() + " " +
if (!insertSuccess) { JSON.toJSONString(insertSqlArgs.get(0)));
log.error("批量插入权限数据失败!" + OrgInfoHotelEntity.getInsertSql() + " " + }
JSON.toJSONString(insertSqlArgs.get(0))); }
} List<OrgInfoHotelEntity> updateDetachDetailList = new ArrayList<>();
} List<OrgInfoHotelEntity> insertDetachDetailList = new ArrayList<>();
List<OrgInfoHotelEntity> updateDetachDetailList = new ArrayList<>(); for (OrgInfoHotelEntity orgInfoHotelEntity : updateInfo) {
List<OrgInfoHotelEntity> insertDetachDetailList = new ArrayList<>(); Integer detachdetailId1 = mapper.selectSysdetachdetailByInfoIdAndYh(orgInfoHotelEntity.getInfoId(), 1);
for (OrgInfoHotelEntity orgInfoHotelEntity : updateInfo) { if (null != detachdetailId1 && detachdetailId1 > 0) {
log.info("循环查询权限ID " + orgInfoHotelEntity);
Integer detachdetailId1 = mapper.selectSysdetachdetailByInfoIdAndYh(orgInfoHotelEntity.getInfoId(), 1);
if (null != detachdetailId1 && detachdetailId1 > 0) {
// 需要更新 // 需要更新
OrgInfoHotelEntity copy = OrgInfoHotelEntity.copy(orgInfoHotelEntity); OrgInfoHotelEntity copy = OrgInfoHotelEntity.copy(orgInfoHotelEntity);
copy.setId(String.valueOf(detachdetailId1)); copy.setId(String.valueOf(detachdetailId1));
copy.setSourceType(1); copy.setSourceType(1);
updateDetachDetailList.add(copy); updateDetachDetailList.add(copy);
} }
Integer detachdetailId2 = mapper.selectSysdetachdetailByInfoIdAndYh(orgInfoHotelEntity.getInfoId(), 2); Integer detachdetailId2 = mapper.selectSysdetachdetailByInfoIdAndYh(orgInfoHotelEntity.getInfoId(), 2);
if (null != detachdetailId2 && detachdetailId2 > 0) { if (null != detachdetailId2 && detachdetailId2 > 0) {
// 需要更新 // 需要更新
OrgInfoHotelEntity copy = OrgInfoHotelEntity.copy(orgInfoHotelEntity); OrgInfoHotelEntity copy = OrgInfoHotelEntity.copy(orgInfoHotelEntity);
copy.setId(String.valueOf(detachdetailId2)); copy.setId(String.valueOf(detachdetailId2));
copy.setSourceType(2); copy.setSourceType(2);
updateDetachDetailList.add(copy); updateDetachDetailList.add(copy);
} }
boolean hasSourceType1 = null == detachdetailId1 || detachdetailId1 < 0; boolean hasSourceType1 = null == detachdetailId1 || detachdetailId1 < 0;
boolean hasSourceType2 = null == detachdetailId2 || detachdetailId2 < 0; boolean hasSourceType2 = null == detachdetailId2 || detachdetailId2 < 0;
if (hasSourceType1 && hasSourceType2) { if (hasSourceType1 && hasSourceType2) {
// 需要插入 // 需要插入
insertDetachDetailList.add(orgInfoHotelEntity); insertDetachDetailList.add(orgInfoHotelEntity);
} }
} }
log.info("需要插入的数据: " + insertDetachDetailList.size()); insertSqlArgs.clear();
log.info("需要更新的数据: " + updateDetachDetailList.size()); insertDetachDetailList.forEach(item -> {
insertSqlArgs.clear(); List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(item, "");
insertDetachDetailList.forEach(item -> { insertSqlArgs.addAll(lists);
List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(item, ""); });
insertSqlArgs.addAll(lists); if (!insertSqlArgs.isEmpty()) {
}); boolean insertSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), insertSqlArgs);
if (!insertSqlArgs.isEmpty()) { if (!insertSuccess) {
boolean insertSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), insertSqlArgs); log.error("批量插入权限数据失败!" + OrgInfoHotelEntity.getInsertSql() + " " +
if (!insertSuccess) { JSON.toJSONString(insertSqlArgs.get(0)));
log.error("批量插入权限数据失败!" + OrgInfoHotelEntity.getInsertSql() + " " + }
JSON.toJSONString(insertSqlArgs.get(0))); }
}
}
List<List> updateSqlArgs = new ArrayList<>(); List<List> updateSqlArgs = new ArrayList<>();
updateDetachDetailList.forEach(item -> { updateDetachDetailList.forEach(item -> {
List lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlUpdateList(item); List lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlUpdateList(item);
updateSqlArgs.add(lists); updateSqlArgs.add(lists);
}); });
if (!updateSqlArgs.isEmpty()) { if (!updateSqlArgs.isEmpty()) {
boolean updateSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getUpdateSql(), updateSqlArgs); boolean updateSuccess = recordSet.executeBatchSql(OrgInfoHotelEntity.getUpdateSql(), updateSqlArgs);
if (!updateSuccess) { if (!updateSuccess) {
log.error("批量跟新权限数据失败!" + OrgInfoHotelEntity.getUpdateSql() + " " + log.error("批量跟新权限数据失败!" + OrgInfoHotelEntity.getUpdateSql() + " " +
JSON.toJSONString(insertSqlArgs.get(0))); JSON.toJSONString(insertSqlArgs.get(0)));
} }
} }
// 特殊权限设置 // 特殊权限设置
List<String> idList = mapper.selectBrotherDeptIds(supportCenterDeptId); List<String> idList = mapper.selectBrotherDeptIds(supportCenterDeptId);
Integer infoId = mapper.selectInfoIdByCnTitle("支持中心分权查看"); Integer infoId = mapper.selectInfoIdByCnTitle("支持中心分权查看");
if (null == infoId || infoId < 0) { if (null == infoId || infoId < 0) {
// 插入 // 插入
OrgInfoHotelEntity orgInfoHotelEntity = new OrgInfoHotelEntity(); OrgInfoHotelEntity orgInfoHotelEntity = new OrgInfoHotelEntity();
orgInfoHotelEntity.setDeptId(Util.join(idList, ",")); orgInfoHotelEntity.setDeptId(Util.join(idList, ","));
boolean insertSuccess = mapper.insertSysdetachinfo("支持中心分权查看"); boolean insertSuccess = mapper.insertSysdetachinfo("支持中心分权查看");
if (insertSuccess) { if (insertSuccess) {
// 查询最大ID // 查询最大ID
infoId = mapper.selectIdByCntitle("支持中心分权查看"); infoId = mapper.selectIdByCntitle("支持中心分权查看");
orgInfoHotelEntity.setInfoId(infoId); orgInfoHotelEntity.setInfoId(infoId);
List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(orgInfoHotelEntity, supportCenterDeptId); List<List> lists = OrgInfoHotelEntity.orgInfoHotelEntityToSqlList(orgInfoHotelEntity, supportCenterDeptId);
if (!lists.isEmpty()) { if (!lists.isEmpty()) {
boolean b = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), lists); boolean b = recordSet.executeBatchSql(OrgInfoHotelEntity.getInsertSql(), lists);
if (!b) { if (!b) {
log.error("插入特殊权限失败!" + OrgInfoHotelEntity.getInsertSql() + " : " + JSON.toJSONString(lists)); log.error("插入特殊权限失败!" + OrgInfoHotelEntity.getInsertSql() + " : " + JSON.toJSONString(lists));
} }
} }
} }
} else { } else {
// 更新 // 更新
Integer sysdetachId1 = mapper.selectSysdetachdetailByInfoIdAndYh(infoId, 1); Integer sysdetachId1 = mapper.selectSysdetachdetailByInfoIdAndYh(infoId, 1);
Integer sysdetachId2 = mapper.selectSysdetachdetailByInfoIdAndYh(infoId, 2); Integer sysdetachId2 = mapper.selectSysdetachdetailByInfoIdAndYh(infoId, 2);
OrgInfoHotelEntity orgInfoHotelEntity = new OrgInfoHotelEntity(); OrgInfoHotelEntity orgInfoHotelEntity = new OrgInfoHotelEntity();
orgInfoHotelEntity.setDeptId(Util.join(idList, ",")); orgInfoHotelEntity.setDeptId(Util.join(idList, ","));
orgInfoHotelEntity.setInfoId(infoId); orgInfoHotelEntity.setInfoId(infoId);
orgInfoHotelEntity.setId(String.valueOf(sysdetachId1)); orgInfoHotelEntity.setId(String.valueOf(sysdetachId1));
orgInfoHotelEntity.setSourceType(1); orgInfoHotelEntity.setSourceType(1);
List list = OrgInfoHotelEntity.orgInfoHotelEntityToSqlUpdateList(orgInfoHotelEntity); List list = OrgInfoHotelEntity.orgInfoHotelEntityToSqlUpdateList(orgInfoHotelEntity);
if (!list.isEmpty()) { if (!list.isEmpty()) {
recordSet.executeUpdate(OrgInfoHotelEntity.getUpdateSql(), list); recordSet.executeUpdate(OrgInfoHotelEntity.getUpdateSql(), list);
} }
orgInfoHotelEntity.setId(String.valueOf(sysdetachId2)); orgInfoHotelEntity.setId(String.valueOf(sysdetachId2));
orgInfoHotelEntity.setSourceType(2); orgInfoHotelEntity.setSourceType(2);
if (!list.isEmpty()) { if (!list.isEmpty()) {
recordSet.executeUpdate(OrgInfoHotelEntity.getUpdateSql(), list); recordSet.executeUpdate(OrgInfoHotelEntity.getUpdateSql(), list);
} }
} }
AppDetachComInfo appDetachComInfo = new AppDetachComInfo(); AppDetachComInfo appDetachComInfo = new AppDetachComInfo();
appDetachComInfo.resetAppDetachInfo(); appDetachComInfo.resetAppDetachInfo();
} }
/** /**
* *
* *
* @param orgInfoHotelEntity * @param orgInfoHotelEntity
*/ */
private void insertSysdetachinfo(OrgInfoHotelEntity orgInfoHotelEntity) { private void insertSysdetachinfo(OrgInfoHotelEntity orgInfoHotelEntity) {
Integer integer = mapper.selectIdByCntitle(orgInfoHotelEntity.getCnTitle()); Integer integer = mapper.selectIdByCntitle(orgInfoHotelEntity.getCnTitle());
if (null != integer && integer > 0) { if (null != integer && integer > 0) {
orgInfoHotelEntity.setInfoId(integer); orgInfoHotelEntity.setInfoId(integer);
orgInfoHotelEntity.setUpdate("true"); orgInfoHotelEntity.setUpdate("true");
return; return;
} }
boolean insertSuccess = mapper.insertSysdetachinfo(orgInfoHotelEntity.getCnTitle()); boolean insertSuccess = mapper.insertSysdetachinfo(orgInfoHotelEntity.getCnTitle());
if (insertSuccess) { if (insertSuccess) {
// 查询最大ID // 查询最大ID
Integer infoId = mapper.selectIdByCntitle(orgInfoHotelEntity.getCnTitle()); Integer infoId = mapper.selectIdByCntitle(orgInfoHotelEntity.getCnTitle());
orgInfoHotelEntity.setInfoId(infoId); orgInfoHotelEntity.setInfoId(infoId);
orgInfoHotelEntity.setUpdate("false"); orgInfoHotelEntity.setUpdate("false");
} }
} }
} }

View File

@ -3,6 +3,8 @@ package youhong.ai.yihong;
import aiyh.utils.Util; import aiyh.utils.Util;
import basetest.BaseTest; import basetest.BaseTest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.api.youhong.ai.ihgzhouji.taskele.entity.IhgTaskElementConfigItem;
import com.api.youhong.ai.ihgzhouji.taskele.mapper.TaskElementMapper;
import org.junit.Test; import org.junit.Test;
import weaver.youhong.ai.yihong.formmode.stagediagram.mapper.ModeExpandSaveActionMapper; import weaver.youhong.ai.yihong.formmode.stagediagram.mapper.ModeExpandSaveActionMapper;
import weaver.youhong.ai.yihong.formmode.stagediagram.pojo.StageUpdateFieldConfig; import weaver.youhong.ai.yihong.formmode.stagediagram.pojo.StageUpdateFieldConfig;
@ -35,4 +37,12 @@ public class YiHongTest extends BaseTest {
System.out.println(strings.stream().filter(item -> !item.equals("2")).collect(Collectors.toList())); System.out.println(strings.stream().filter(item -> !item.equals("2")).collect(Collectors.toList()));
} }
@Test
public void tesetst() {
TaskElementMapper mapper = Util.getMapper(TaskElementMapper.class);
List<IhgTaskElementConfigItem> ihgTaskElementConfigItems = mapper.selectConfig();
System.out.println(JSON.toJSONString(ihgTaskElementConfigItems));
}
} }