Compare commits

..

1 Commits

Author SHA1 Message Date
Chengliang 46f1c9fde1 master分支初始化 9 months ago

2
.gitignore vendored

@ -5,7 +5,7 @@
HELP.md
target/
.idea/
.idea
/test
/src/rebel.xml

@ -1,6 +1,6 @@
<component name="ArtifactManager">
<artifact type="jar" name="weaver-develop:jar">
<output-path>$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib</output-path>
<output-path>$PROJECT_DIR$/out/artifacts/weaver_develop_jar</output-path>
<root id="archive" name="weaver-develop.jar">
<element id="module-output" name="weaver-develop" />
</root>

@ -1,3 +0,0 @@
roleId=67
rolelevel=2
fieldid=field19

@ -1,10 +0,0 @@
package com.api.sship.web;
import javax.ws.rs.Path;
/**
* @author liang.cheng
*/
@Path("/sship/organization/chart")
public class OrgChartController extends com.engine.sship.web.OrgChartController {
}

@ -1,26 +0,0 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author liang.cheng
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChartChildrensVO {
private String id;
private String pid;
private String label;
private List<ChartChildrensVO> childrens;
}

@ -1,32 +0,0 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/1/4 3:22 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PersonTablePO {
private Integer id;
private String lastname;
private String workcode;
private Integer sex;
private Integer managerid;
private String loginid;
}

@ -1,23 +0,0 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/1/4 3:26 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PersonTableParam {
//todo 分页参数
private String id;
}

@ -1,34 +0,0 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/1/4 3:17 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PersonTableVO {
private Integer id;
private String lastname;
private String workcode;
private String sex;
private String manager;
private String loginid;
}

@ -1,27 +0,0 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author apple
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TreeDataVO {
private String id;
private String label;
private List<ChartChildrensVO> childrens;
}

@ -1,22 +0,0 @@
package com.engine.sship.exception;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class CustomizeRunTimeException extends RuntimeException{
public CustomizeRunTimeException(String message) {
super(message);
}
public CustomizeRunTimeException(Throwable cause) {
super(cause);
}
public CustomizeRunTimeException(String message, Throwable cause) {
super(message, cause);
}
}

@ -1,53 +0,0 @@
package com.engine.sship.service;
import com.engine.sship.entity.PersonTableParam;
import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.TreeDataVO;
import java.util.List;
/**
* @author apple
*/
public interface OrgChartService {
/**
* @Description: Id
* @Author: liang.cheng
* @Date: 2024/1/3 3:16 PM
* @param: [roleId, rolelevel]
* @return: int
*/
boolean selectIdsByRole(String roleId,String rolelevel);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/3 10:07 AM
* @param: []
* @return: com.engine.sship.entity.ChartChildrensVO
*/
TreeDataVO selectResourceChart();
/**
* @Description: SiteHead
* @Author: liang.cheng
* @Date: 2024/1/3 4:23 PM
* @param: []
* @return: java.util.List<java.lang.Integer>
*/
List<Integer> selectCusSiteHead();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/4 3:29 PM
* @param: [personTableParam]
* @return: com.engine.sship.entity.PersonTableVO
*/
List<PersonTableVO> selectPerson(PersonTableParam personTableParam);
}

@ -1,238 +0,0 @@
package com.engine.sship.service.impl;
import com.engine.common.service.HrmCommonService;
import com.engine.common.service.impl.HrmCommonServiceImpl;
import com.engine.core.impl.Service;
import com.engine.sship.entity.*;
import com.engine.sship.service.OrgChartService;
import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import lombok.SneakyThrows;
import weaver.conn.RecordSet;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:52 PM
* @Description:
* @Version 1.0
*/
public class OrgChartServiceImpl extends Service implements OrgChartService {
private HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
@Override
public boolean selectIdsByRole(String roleId,String rolelevel) {
String roleMemberIds = hrmCommonService.getRoleMemberIds(roleId, rolelevel);
List<String> roleMemberList = Arrays.stream(roleMemberIds.split(","))
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
return roleMemberList.stream()
.anyMatch(s -> Integer.parseInt(s) == user.getUID());
}
@Override
public TreeDataVO selectResourceChart() {
BaseBean bb = new BaseBean();
String roleId = bb.getPropValue("sship", "roleId");
String rolelevel = bb.getPropValue("sship", "rolelevel");
boolean isExsit = selectIdsByRole(roleId, rolelevel);
if (isExsit || (user.getUID() == 1)) {
return getAllTreeData();
}
return getBaseTreeData();
}
@Override
public List<Integer> selectCusSiteHead() {
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
String fieldid = bb.getPropValue("sship", "fieldid");
String sitehead = bb.getPropValue("sship", "sitehead");
List<Integer> ids = new ArrayList<>();
rs.executeQuery("select id from cus_fielddata where "+fieldid+" = ? and scopeid = 3 and scope = 'HrmCustomFieldByInfoType'",sitehead);
while (rs.next()) {
ids.add(Util.getIntValue(rs.getString("id")));
}
return ids;
}
@SneakyThrows
@Override
public List<PersonTableVO> selectPerson(PersonTableParam personTableParam) {
List<PersonTablePO> poList;
ResourceComInfo rInfo = new ResourceComInfo();
BaseBean bb = new BaseBean();
String shareholder = bb.getPropValue("sship", "shareholder");
String committee = bb.getPropValue("sship", "committee");
switch(personTableParam.getId()){
case "S-1":
poList = selectByLevel(Integer.valueOf(shareholder));
break;
case "C-1":
poList = selectByLevel(Integer.valueOf(committee));
break;
default:
poList = selectByDeptId(personTableParam.getId());
}
return poList.stream()
.map(po -> new PersonTableVO(po.getId(), po.getLastname(), po.getWorkcode(),
po.getSex() == 0 ? "男" : "女",
po.getManagerid() != null ? rInfo.getLastname(String.valueOf(po.getManagerid())) : "",
po.getLoginid()))
.collect(Collectors.toList());
}
private List<PersonTablePO> selectByLevel(Integer level) {
RecordSet rs = new RecordSet();
List<PersonTablePO> poList = new ArrayList<>();
BaseBean bb = new BaseBean();
String fieldid = bb.getPropValue("sship", "fieldid");
rs.executeQuery("select h.id,h.lastname,h.workcode,h.sex,h.managerid,h.loginid from hrmresource h\n" +
" left join cus_fielddata c on h.id = c.id\n" +
" where c.scopeid = 3 and c.scope = 'HrmCustomFieldByInfoType' and c."+fieldid+" = ?",level);
while (rs.next()) {
poList.add(
PersonTablePO.builder()
.id(Util.getIntValue(rs.getString("id")))
.lastname(Util.null2String(rs.getString("lastname")))
.workcode(Util.null2String(rs.getString("workcode")))
.sex(Util.getIntValue(rs.getString("sex")))
.managerid(Util.getIntValue(rs.getString("managerid")))
.loginid(Util.null2String(rs.getString("loginid")))
.build()
);
}
return poList;
}
private List<PersonTablePO> selectByDeptId(String id) {
RecordSet rs = new RecordSet();
List<PersonTablePO> poList = new ArrayList<>();
rs.executeQuery("select id,lastname,workcode,sex,managerid,loginid from hrmresource where status < 4 and departmentid = ?",id);
while (rs.next()) {
poList.add(
PersonTablePO.builder()
.id(Util.getIntValue(rs.getString("id")))
.lastname(Util.null2String(rs.getString("lastname")))
.workcode(Util.null2String(rs.getString("workcode")))
.sex(Util.getIntValue(rs.getString("sex")))
.managerid(Util.getIntValue(rs.getString("managerid")))
.loginid(Util.null2String(rs.getString("loginid")))
.build()
);
}
return poList;
}
/**
*
* @return
*/
@SneakyThrows
private TreeDataVO getBaseTreeData() {
int uid = user.getUID();
List<Integer> idList = selectCusSiteHead();
boolean contains = idList.contains(uid);
DepartmentComInfo dInfo = new DepartmentComInfo();
ResourceComInfo rInfo = new ResourceComInfo();
String departmentId = rInfo.getDepartmentID(String.valueOf(uid));
TreeDataVO build = TreeDataVO.builder()
.id(departmentId)
.label(contains ? dInfo.getDepartmentName(departmentId) : rInfo.getLastname(String.valueOf(uid)))
.build();
boolean manager = hrmCommonService.isManager(uid);
if (manager) {
build.setChildrens(recursionDepartment(uid));
}
return build;
}
/**
*
* @return
*/
private TreeDataVO getAllTreeData() {
//1.股东及委员会层级指定
ChartChildrensVO committee = ChartChildrensVO.builder().id("C-1")
.pid("S-1")
.label("Committee")
.childrens(getSiteHead())
.build();
List<ChartChildrensVO> committeeList = Collections.singletonList(committee);
return TreeDataVO.builder().id("S-1")
.label("Shareholder")
.childrens(committeeList)
.build();
}
@SneakyThrows
private List<ChartChildrensVO> getSiteHead() {
List<Integer> idList = selectCusSiteHead();
List<ChartChildrensVO> siteHeadList = new ArrayList<>();
DepartmentComInfo dInfo = new DepartmentComInfo();
ResourceComInfo rInfo = new ResourceComInfo();
idList.forEach(item -> {
String departmentId = rInfo.getDepartmentID(String.valueOf(item));
ChartChildrensVO build = ChartChildrensVO.builder()
.id(departmentId)
.pid("C-1")
//.label(dInfo.getDepartmentmark(departmentId))
.label(rInfo.getLastname(String.valueOf(item)))
.build();
boolean manager = hrmCommonService.isManager(item);
if (manager) {
build.setChildrens(recursionDepartment(item));
}
siteHeadList.add(build);
});
return siteHeadList;
}
/**
*
* @param id
* @return
*/
@SneakyThrows
private List<ChartChildrensVO> recursionDepartment(Integer id) {
List<ChartChildrensVO> vos = new ArrayList<>();
DepartmentComInfo dInfo = new DepartmentComInfo();
ResourceComInfo rInfo = new ResourceComInfo();
String underling = hrmCommonService.getUnderling(id);
//获取直接下属
List<String> underList = Arrays.stream(underling.split(","))
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
underList.forEach(item -> {
String departmentId = rInfo.getDepartmentID(String.valueOf(item));
ChartChildrensVO build = ChartChildrensVO.builder()
.id(departmentId)
.pid(item)
//.label(dInfo.getDepartmentmark(departmentId))
.label(rInfo.getLastname(String.valueOf(item)))
.build();
boolean manager = hrmCommonService.isManager(Integer.valueOf(item));
if (manager) {
build.setChildrens(recursionDepartment(Integer.valueOf(item)));
}
vos.add(build);
});
return vos;
}
}

@ -1,175 +0,0 @@
package com.engine.sship.util;
import com.engine.sship.exception.CustomizeRunTimeException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.Collection;
import java.util.Map;
/**
* @Author weaver_cl
* @description:
* @Date 2022/4/26
* @Version V1.0
**/
public abstract class CommonAssert {
/**
* null
*
* @param object
* @param message
*/
public static void notNull(Object object, String message) {
if (object == null) {
throw new CustomizeRunTimeException(message);
}
}
/**
* null
*
* @param string
* @param message
*/
public static void notNull(String string, String message) {
if (StringUtils.isBlank(string)) {
throw new CustomizeRunTimeException(message);
}
}
/**
* null
*
* @param message
* @param objects
*/
public static void notNull(String message, Object... objects) {
for (Object obj : objects) {
if (obj == null) {
throw new CustomizeRunTimeException(message);
}
}
}
/**
* null
*
* @param object
* @param message
*/
public static void isNull(Object object, String message) {
if (object != null) {
throw new CustomizeRunTimeException(message);
}
}
/**
*
*
* @param collection
* @param message
*/
public static void isEmpty(Collection<?> collection, String message) {
if (!CollectionUtils.isEmpty(collection)) {
throw new CustomizeRunTimeException(message);
}
}
/**
*
*
* @param collection
* @param message
*/
public static void notEmpty(Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new CustomizeRunTimeException(message);
}
}
/**
*
*
* @param arr
* @param message
*/
public static void notEmpty(Object[] arr, String message) {
if (ObjectUtils.isEmpty(arr)) {
throw new CustomizeRunTimeException(message);
}
}
/**
* map
*
* @param map
* @param message
*/
public static void notEmpty(Map<?, ?> map, String message) {
if (CollectionUtils.isEmpty(map)) {
throw new CustomizeRunTimeException(message);
}
}
/**
*
*
* @param arr
* @param message
*/
public static void notNullElement(Object[] arr, String message) {
if (arr != null) {
for (Object obj : arr) {
if (obj == null) {
throw new CustomizeRunTimeException(message);
}
}
}
}
/**
* boolean
*
* @param expression
* @param message
*/
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new CustomizeRunTimeException(message);
}
}
public static void isFalse(boolean expression, String message) {
if (expression) {
throw new CustomizeRunTimeException(message);
}
}
public static void isBlank(CharSequence cs, String message) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for (int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(cs.charAt(i))) {
throw new CustomizeRunTimeException(message);
}
}
}
}
public static void notBlank(CharSequence cs, String message) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for (int i = 0; i < strLen; ++i) {
if (Character.isWhitespace(cs.charAt(i))) {
throw new CustomizeRunTimeException(message);
}
}
}
if (cs == null || cs.length() == 0) {
throw new CustomizeRunTimeException(message);
}
}
}

@ -1,18 +0,0 @@
package com.engine.sship.util;
/**
* @author apple
*/
public class ExceptionUtil {
public static String getRealMessage(Throwable e) {
while (e != null) {
Throwable cause = e.getCause();
if (cause == null) {
return e.getMessage();
}
e = cause;
}
return "";
}
}

@ -1,185 +0,0 @@
package com.engine.sship.util;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException;
import com.engine.sship.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import weaver.general.BaseBean;
import weaver.hrm.User;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@Slf4j
public class ResponseResult<T, R> {
private static final long serialVersionUID = 1L;
private final User user;
private final BaseBean baseBean = new BaseBean();
private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log"));
public ResponseResult(User user) {
this.user = user;
}
/**
* ()
*/
public String customRun(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return getJsonString(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
*
*/
public String run(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return Ok(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
*
*/
public String run(Consumer<T> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
f.accept(t);
return Ok();
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
return Error(ExceptionUtil.getRealMessage(e));
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
/**
*
*/
public String run(Supplier<R> f) {
try {
if (isLog) {
log.info("run api");
}
return Ok(f.get());
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
private static String getJsonString(Object apidatas) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(apidatas);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return "";
}
/**
*
*/
private String Ok() {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
*
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
apidatas.put("data", r);
String success = getJsonString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
/**
*
*/
private static String Error(String message) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("msg", message);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
*
*/
private static String Error(String message, Exception e) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("msg", message);
apidatas.put("error", e.getMessage());
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
}

@ -1,56 +0,0 @@
package com.engine.sship.web;
import com.engine.common.util.ServiceUtil;
import com.engine.sship.entity.PersonTableParam;
import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.TreeDataVO;
import com.engine.sship.service.OrgChartService;
import com.engine.sship.service.impl.OrgChartServiceImpl;
import com.engine.sship.util.ResponseResult;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:51 PM
* @Description:
* @Version 1.0
*/
public class OrgChartController {
private OrgChartService getOrgChartService(User user) {
return ServiceUtil.getService(OrgChartServiceImpl.class,user);
}
@GET
@Path("/resource-tree")
@Produces(MediaType.APPLICATION_JSON)
public String selectResourceChart(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, TreeDataVO>(user).run(getOrgChartService(user) :: selectResourceChart);
}
@GET
@Path("/person")
@Produces(MediaType.APPLICATION_JSON)
public String selectPerson(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("id") String id) {
User user = HrmUserVarify.getUser(request, response);
PersonTableParam build = PersonTableParam.builder().id(id).build();
return new ResponseResult<PersonTableParam, List<PersonTableVO>>(user).run(getOrgChartService(user) :: selectPerson,build);
}
}

@ -1,7 +1,5 @@
package test;
import java.util.*;
/**
* @Author weaver_cl
* @Description:
@ -12,13 +10,5 @@ public class MainTest {
public static void main(String[] args) {
TreeSet<String> a = new TreeSet<>();
a.add("和平");
a.add("阿姨");
a.add("测试");
for (String string : a) {
System.out.println(string);
}
}
}

Loading…
Cancel
Save