|
|
|
@ -4,7 +4,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.parser.Feature;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.weaver.seconddev.sxjg.util.NccApiUtil;
|
|
|
|
|
import com.weaver.seconddev.sxjg.util.ProvinceCityNode;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
@ -72,6 +76,67 @@ public class PayslipPageTestController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void test1() throws Exception {
|
|
|
|
|
Map<String,String> rs = new HashMap<>();
|
|
|
|
|
JSONObject r1 = new JSONObject();
|
|
|
|
|
JSONArray r2 = new JSONArray();
|
|
|
|
|
JSONObject r3 = new JSONObject();
|
|
|
|
|
r3.put("pk_psndoc","0001A2100000006CWEBW");
|
|
|
|
|
r2.add(r3);
|
|
|
|
|
r1.put("data",r2);
|
|
|
|
|
NccApiUtil nccApiUtil = new NccApiUtil();
|
|
|
|
|
nccApiUtil.init();
|
|
|
|
|
String token = nccApiUtil.getToken();
|
|
|
|
|
String url = nccApiUtil.getBaseUrl()+"nccloud/api/hrtrn/openAPI/psninfoconf/list";
|
|
|
|
|
String rs11 = nccApiUtil.doJsonPost(url,token,r1.toJSONString());
|
|
|
|
|
JSONObject rsf = JSONObject.parseObject(rs11, Feature.OrderedField);
|
|
|
|
|
if("1000000000".equals(rsf.getString("code"))) {
|
|
|
|
|
JSONArray dataarr = rsf.getJSONArray("data");
|
|
|
|
|
JSONArray dataguolv = new JSONArray();
|
|
|
|
|
if(dataarr.size()>0) {
|
|
|
|
|
for(int i = 0; i <dataarr.size();i++) {
|
|
|
|
|
JSONObject ra = dataarr.getJSONObject(i);
|
|
|
|
|
Boolean flag= judegNy(ra,"2024-02","2024-02","陕西建工集团数字科技有限公司(在册)薪资方案");
|
|
|
|
|
if(flag) {
|
|
|
|
|
dataguolv.add(ra);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//按照日期排序
|
|
|
|
|
List<JSONObject> list = new ArrayList<>();
|
|
|
|
|
for (int i=0; i < dataguolv.size(); i++) {
|
|
|
|
|
list.add(dataguolv.getJSONObject(i));
|
|
|
|
|
}
|
|
|
|
|
// 创建日期比较器
|
|
|
|
|
Comparator<JSONObject> dateComparator = new Comparator<JSONObject>() {
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(JSONObject obj1, JSONObject obj2) {
|
|
|
|
|
try {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
|
|
Date date1 = sdf.parse(obj1.getString("year"));
|
|
|
|
|
Date date2 = sdf.parse(obj2.getString("year"));
|
|
|
|
|
return date2.compareTo(date1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// 根据日期进行排序
|
|
|
|
|
Collections.sort(list, dateComparator);
|
|
|
|
|
String s = JSON.toJSONString(list);
|
|
|
|
|
System.out.println(s);
|
|
|
|
|
// 将排好序的 List 转换为 JSONArray
|
|
|
|
|
JSONArray r = new JSONArray();
|
|
|
|
|
for(JSONObject js : list) {
|
|
|
|
|
r.add(js);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(r.toJSONString());
|
|
|
|
|
rsf.put("data",r);
|
|
|
|
|
}else {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断年月在日期之间
|
|
|
|
|
*/
|
|
|
|
@ -105,4 +170,98 @@ public class PayslipPageTestController {
|
|
|
|
|
}catch (Exception e){};
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void tp() throws JsonProcessingException {
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> rs = getMuneTree();
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
// 将 List<Map<String, Object>> 转换为 JSON
|
|
|
|
|
String json = objectMapper.writeValueAsString(rs);
|
|
|
|
|
|
|
|
|
|
System.out.println(json);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 将有父子关系的数据转换成树形结构数据
|
|
|
|
|
*
|
|
|
|
|
* @return 最终的树状结构的集合数据
|
|
|
|
|
*/
|
|
|
|
|
public List<Map<String, Object>> getMuneTree() {
|
|
|
|
|
// 获取数据库中带有有父子关系的数据
|
|
|
|
|
List<ProvinceCityNode> data = new ArrayList<>();
|
|
|
|
|
ProvinceCityNode provinceCityNode11 = new ProvinceCityNode("1","null","pk11","第一级1");
|
|
|
|
|
ProvinceCityNode provinceCityNode12 = new ProvinceCityNode("2","null","pk12","第一级2");
|
|
|
|
|
ProvinceCityNode provinceCityNode13 = new ProvinceCityNode("3","null","pk13","第一级3");
|
|
|
|
|
ProvinceCityNode provinceCityNode14 = new ProvinceCityNode("4","null","pk14","第一级4");
|
|
|
|
|
ProvinceCityNode provinceCityNode111 = new ProvinceCityNode("11","1","pk111","第一级11");
|
|
|
|
|
ProvinceCityNode provinceCityNode112 = new ProvinceCityNode("12","1","pk112","第一级12");
|
|
|
|
|
ProvinceCityNode provinceCityNode113 = new ProvinceCityNode("13","1","pk113","第一级13");
|
|
|
|
|
ProvinceCityNode provinceCityNode121 = new ProvinceCityNode("15","2","pk211","第一级21");
|
|
|
|
|
ProvinceCityNode provinceCityNode122 = new ProvinceCityNode("16","2","pk212","第一级22");
|
|
|
|
|
ProvinceCityNode provinceCityNode123 = new ProvinceCityNode("17","2","pk213","第一级23");
|
|
|
|
|
ProvinceCityNode provinceCityNode1111 = new ProvinceCityNode("1111","11","pk111","第一级1111");
|
|
|
|
|
ProvinceCityNode provinceCityNode1112 = new ProvinceCityNode("1112","11","pk111","第一级1112");
|
|
|
|
|
ProvinceCityNode provinceCityNode1113 = new ProvinceCityNode("1113","11","pk111","第一级1113");
|
|
|
|
|
data.add(provinceCityNode11);
|
|
|
|
|
data.add(provinceCityNode12);
|
|
|
|
|
data.add(provinceCityNode13);
|
|
|
|
|
data.add(provinceCityNode14);
|
|
|
|
|
data.add(provinceCityNode111);
|
|
|
|
|
data.add(provinceCityNode112);
|
|
|
|
|
data.add(provinceCityNode113);
|
|
|
|
|
data.add(provinceCityNode121);
|
|
|
|
|
data.add(provinceCityNode122);
|
|
|
|
|
data.add(provinceCityNode123);
|
|
|
|
|
data.add(provinceCityNode1111);
|
|
|
|
|
data.add(provinceCityNode1112);
|
|
|
|
|
data.add(provinceCityNode1113);
|
|
|
|
|
//创建一个List集合来存放最终的树状结构数据
|
|
|
|
|
List<Map<String, Object>> menuList = new ArrayList<>();
|
|
|
|
|
// 先存入最顶级的树(0代表没有父级,即最顶级),然后通过最顶级的id递归获取子级
|
|
|
|
|
for (ProvinceCityNode entity : data) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
if (entity.parentid ==null || "null".equals(entity.parentid) || "".equals(entity.parentid) || "0".equals(entity.parentid)) {
|
|
|
|
|
map.put("id", entity.id);
|
|
|
|
|
map.put("value", entity.value);
|
|
|
|
|
map.put("isLeaf", entity.isLeaf);
|
|
|
|
|
map.put("parentid", entity.parentid);
|
|
|
|
|
map.put("loading", entity.loading);
|
|
|
|
|
map.put("label", entity.label);
|
|
|
|
|
map.put("disabled", entity.disabled);
|
|
|
|
|
map.put("children", getChildren(data, entity.id));
|
|
|
|
|
menuList.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return menuList;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 递归处理:通过id获取子级,查询子级下的子级
|
|
|
|
|
* @param data 数据库的原始数据
|
|
|
|
|
* @param id 主id
|
|
|
|
|
* @return 该id下得子级
|
|
|
|
|
*/
|
|
|
|
|
public List<Map<String, Object>> getChildren(List<ProvinceCityNode> data, String id) {
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
if (data == null || data.size() == 0 || id == null) {
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
for (ProvinceCityNode entity : data) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
//如果本级id与数据的父id相同,就说明是子父级关系
|
|
|
|
|
if (id.equals(entity.parentid)) {
|
|
|
|
|
map.put("id", entity.id);
|
|
|
|
|
map.put("value", entity.value);
|
|
|
|
|
map.put("isLeaf", entity.isLeaf);
|
|
|
|
|
map.put("parentid", entity.parentid);
|
|
|
|
|
map.put("loading", entity.loading);
|
|
|
|
|
map.put("label", entity.label);
|
|
|
|
|
map.put("disabled", entity.disabled);
|
|
|
|
|
map.put("children", getChildren(data, entity.id));
|
|
|
|
|
list.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|