|
|
|
|
package com.weaver.seconddev.sxjg.controller;
|
|
|
|
|
/**
|
|
|
|
|
* 工资条获取接口开发
|
|
|
|
|
* 个人信息outkey接口开发
|
|
|
|
|
* nc自定义档案数据源接口开发
|
|
|
|
|
*/
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
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.common.authority.annotation.WeaPermission;
|
|
|
|
|
import com.weaver.common.base.entity.result.WeaResult;
|
|
|
|
|
import com.weaver.seconddev.sxjg.config.EbDbDataSourceConfigResp;
|
|
|
|
|
import com.weaver.seconddev.sxjg.util.NccApiUtil;
|
|
|
|
|
import com.weaver.seconddev.sxjg.util.ProvinceCityNode;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/papi/secondev/sxjg")
|
|
|
|
|
public class PayslipPageController {
|
|
|
|
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(PayslipPageController.class);
|
|
|
|
|
|
|
|
|
|
private JdbcTemplate jdbcTemplateresp = new JdbcTemplate(EbDbDataSourceConfigResp.dbDataSource());
|
|
|
|
|
|
|
|
|
|
//根据人员id获取人员outkey字段
|
|
|
|
|
@WeaPermission(publicPermission = true)
|
|
|
|
|
@GetMapping("/getUserOutKey")
|
|
|
|
|
public String getUserOutKeyById(@RequestParam("id")String id) {
|
|
|
|
|
String sql = "select outkey from eteams.employee where id = "+id;
|
|
|
|
|
String currentOutkey = "";
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Object> map = jdbcTemplateresp.queryForMap(sql);
|
|
|
|
|
currentOutkey = String.valueOf(map.get("outkey"));
|
|
|
|
|
}catch (Exception e){};
|
|
|
|
|
return currentOutkey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@WeaPermission(publicPermission = true)
|
|
|
|
|
@PostMapping("/getPayslipageInfo")
|
|
|
|
|
public WeaResult<JSONObject> getPayslipageInfo(
|
|
|
|
|
@RequestParam("userid") String userid,
|
|
|
|
|
@RequestParam("begindate") String begindate,
|
|
|
|
|
@RequestParam("enddate") String enddate,
|
|
|
|
|
@RequestParam("name") String name
|
|
|
|
|
) throws Exception {
|
|
|
|
|
String sql = "select outkey from eteams.employee where id = "+userid;
|
|
|
|
|
log.error(sql);
|
|
|
|
|
log.error(userid);
|
|
|
|
|
String currentOutkey = "";
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Object> map = jdbcTemplateresp.queryForMap(sql);
|
|
|
|
|
currentOutkey = String.valueOf(map.get("outkey"));
|
|
|
|
|
}catch (Exception e){};
|
|
|
|
|
if(currentOutkey.length()==0) {
|
|
|
|
|
return WeaResult.fail("当前用户没有outkey!");
|
|
|
|
|
}
|
|
|
|
|
Map<String,String> rs = new HashMap<>();
|
|
|
|
|
JSONObject r1 = new JSONObject();
|
|
|
|
|
JSONArray r2 = new JSONArray();
|
|
|
|
|
JSONObject r3 = new JSONObject();
|
|
|
|
|
r3.put("pk_psndoc",currentOutkey);
|
|
|
|
|
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/payslipSync/entry";
|
|
|
|
|
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,begindate,enddate,name);
|
|
|
|
|
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);
|
|
|
|
|
// 将排好序的 List 转换为 JSONArray
|
|
|
|
|
JSONArray r = new JSONArray();
|
|
|
|
|
for(JSONObject js : list) {
|
|
|
|
|
r.add(js);
|
|
|
|
|
}
|
|
|
|
|
rsf.put("data",r);
|
|
|
|
|
return WeaResult.success(rsf);
|
|
|
|
|
}else {
|
|
|
|
|
return WeaResult.fail(rsf.getString("message"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断年月在日期之间
|
|
|
|
|
*/
|
|
|
|
|
private boolean judegNy(JSONObject obj,String beingdate1,String enddate1,String name){
|
|
|
|
|
String ny1 = obj.getString("year");
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
ny1 = ny1+"-05";
|
|
|
|
|
beingdate1 = beingdate1+"-05";
|
|
|
|
|
enddate1 = enddate1+"-05";
|
|
|
|
|
String famc = obj.getString("name");//方案名称
|
|
|
|
|
// 定义要转换的字符串格式
|
|
|
|
|
try {
|
|
|
|
|
boolean flag2 = false;
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date ny = dateFormat.parse(ny1);
|
|
|
|
|
Date beingdate = dateFormat.parse(beingdate1);
|
|
|
|
|
Date enddate = dateFormat.parse(enddate1);
|
|
|
|
|
long ny2 =ny.getTime();
|
|
|
|
|
long beingdate2 =beingdate.getTime();
|
|
|
|
|
long enddate2 =enddate.getTime();
|
|
|
|
|
if(ny2>=beingdate2 && ny2<=enddate2) {
|
|
|
|
|
flag2 = true;
|
|
|
|
|
}
|
|
|
|
|
if((!"null".equals(name)) && flag2) {
|
|
|
|
|
if(famc.equals(name)) {
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
flag = flag2;
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){};
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//跟据doclistpk获取基础数据集合
|
|
|
|
|
@WeaPermission(publicPermission = true)
|
|
|
|
|
@GetMapping("/getDataSourceList")
|
|
|
|
|
public WeaResult<JSONArray> getDataSourceList(@RequestParam("dataSourcePk")String dataSourcePk,
|
|
|
|
|
@RequestParam(value = "type",required = false,defaultValue = "0") Integer type) throws JsonProcessingException {
|
|
|
|
|
if(type == 10) {//籍贯省市区
|
|
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
|
String sql = "select id,pk_defdoc,defdocname,enablestate,pid from ec_ebuilder_designer.uf_ncc_defdoc where doclistpk = '"+dataSourcePk+"' order by defdoccode ASC";
|
|
|
|
|
List<Map<String, Object>> rs = jdbcTemplateresp.queryForList(sql);
|
|
|
|
|
List<ProvinceCityNode> data = new ArrayList<>();
|
|
|
|
|
if(CollectionUtil.isNotEmpty(rs)) {
|
|
|
|
|
for(Map<String, Object> single : rs) {
|
|
|
|
|
String id = String.valueOf(single.get("id"));
|
|
|
|
|
String pk_defdoc = String.valueOf(single.get("pk_defdoc"));
|
|
|
|
|
String defdocname = String.valueOf(single.get("defdocname"));
|
|
|
|
|
//String enablestate = String.valueOf(single.get("enablestate"));
|
|
|
|
|
String pid = String.valueOf(single.get("pid"));
|
|
|
|
|
ProvinceCityNode provinceCityNode = new ProvinceCityNode(id,pid,pk_defdoc,defdocname);
|
|
|
|
|
data.add(provinceCityNode);
|
|
|
|
|
}
|
|
|
|
|
//创建一个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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
// 将 List<Map<String, Object>> 转换为 JSON
|
|
|
|
|
String json = objectMapper.writeValueAsString(menuList);
|
|
|
|
|
result = JSONArray.parseArray(json);
|
|
|
|
|
}
|
|
|
|
|
return WeaResult.success(result);
|
|
|
|
|
}else {
|
|
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
|
String sql = "select pk_defdoc,defdocname,enablestate,pid from ec_ebuilder_designer.uf_ncc_defdoc where doclistpk = '"+dataSourcePk+"'";
|
|
|
|
|
List<Map<String, Object>> rs = jdbcTemplateresp.queryForList(sql);
|
|
|
|
|
Map<String, Object> singlemap = null;
|
|
|
|
|
if(CollectionUtil.isNotEmpty(rs)) {
|
|
|
|
|
for(Map<String, Object> rsmap : rs) {
|
|
|
|
|
JSONObject rsobj = new JSONObject();
|
|
|
|
|
String pk_defdoc = String.valueOf(rsmap.get("pk_defdoc"));
|
|
|
|
|
String defdocname = String.valueOf(rsmap.get("defdocname"));
|
|
|
|
|
String enablestate = String.valueOf(rsmap.get("enablestate"));
|
|
|
|
|
String parentdoc = String.valueOf(rsmap.get("pid"));
|
|
|
|
|
rsobj.put("pkvalue",pk_defdoc);
|
|
|
|
|
rsobj.put("pkname",defdocname);
|
|
|
|
|
rsobj.put("enablestate",enablestate);
|
|
|
|
|
if(!("null".equals(parentdoc))) {
|
|
|
|
|
sql = "select pk_defdoc from ec_ebuilder_designer.uf_ncc_defdoc where id = '"+parentdoc+"'";
|
|
|
|
|
singlemap = jdbcTemplateresp.queryForMap(sql);
|
|
|
|
|
String singlepkdoc = String.valueOf(singlemap.get("pk_defdoc"));
|
|
|
|
|
rsobj.put("parentpkvlaue",singlepkdoc);
|
|
|
|
|
}else {
|
|
|
|
|
rsobj.put("parentpkvlaue",parentdoc);
|
|
|
|
|
}
|
|
|
|
|
result.add(rsobj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return WeaResult.success(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归获取子级节点
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|