package com.changhong.epc.tenant.service.system.budget.impl;
|
|
import com.changhong.epc.bean.admin.CorresElField;
|
import com.changhong.epc.bean.tenant.master.MasterValue;
|
import com.changhong.epc.bean.tenant.org.TenantOrg;
|
import com.changhong.epc.bean.tenant.system.budget.BudgetOrg;
|
import com.changhong.epc.bean.tenant.system.budget.extend.BudgetOrgExtend;
|
import com.changhong.epc.constter.admin.CorresElFieldConst;
|
import com.changhong.epc.constter.base.BaseConst;
|
import com.changhong.epc.constter.base.Context;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.UserInfo;
|
import com.changhong.epc.rely.api.bean.*;
|
import com.changhong.epc.rely.api.epc.admin.CorresElFieldApi;
|
import com.changhong.epc.rely.api.service.CscApiService;
|
import com.changhong.epc.rely.api.tool.OrgUtil;
|
import com.changhong.epc.rely.api.tool.VersionFilterApi;
|
import com.changhong.epc.tenant.mapper.tenant.norm.TenantOrgMapper;
|
import com.changhong.epc.tenant.mapper.tenant.system.budget.BudgetConfigMapper;
|
import com.changhong.epc.tenant.service.norm.impl.MasterValueServiceImpl;
|
import com.changhong.epc.tenant.service.system.budget.BudgetConfigService;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import com.iemsoft.framework.cloud.core.tools.StringUtil;
|
import com.iemsoft.framework.cloud.redis.service.CacheUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLDecoder;
|
import java.util.*;
|
|
/**
|
* 预算占用实现类
|
*
|
* @author liush
|
*/
|
@Slf4j
|
@Service
|
public class BudgetConfigServiceImpl implements BudgetConfigService, BaseConst, CorresElFieldConst, SystemClients {
|
|
@Autowired
|
private MasterValueServiceImpl masterValueService;
|
|
@Resource
|
private BudgetConfigMapper budgetConfigMapper;
|
|
@Resource(name = "cscApiServiceImpl")
|
private CscApiService cscApiService;
|
|
@Resource
|
private TenantOrgMapper tenantOrgMapper;
|
|
@Resource
|
private CorresElFieldApi corresElFieldApi;
|
|
@Value("${orgName:F319}")
|
private String orgName;
|
|
|
@Override
|
public List<Organization> getAll() {
|
Organizations orgs = cscApiService.findRelationDetail();
|
// System.out.println("组织机构:" + JSONTool.toJson(orgs));
|
OrgUtil.organizationFormat(orgs.getOrgs());
|
// System.out.println("组织机构:" + JSONTool.toJson(orgs.getOrgs()));
|
return orgs.getOrgs();
|
}
|
|
|
@Transactional
|
@Override
|
public Integer insertBudgetList(List<BudgetOrg> budgetList) {
|
|
// System.err.println(budgetList);
|
int i = 0;
|
if(ObjectUtil.empty(budgetList)){
|
return i;
|
}
|
String groupId = StringUtil.getUUID();
|
// System.err.println(groupId);
|
if (budgetList.size() > 0) {
|
BudgetOrg budget = budgetList.get(0);
|
//修改预算,处在一个事物中
|
if (budget.getFlag()!=null && budget.getFlag()) {
|
//Integer cid = budget.getCId();
|
String groupIdOld = budget.getGroupId();
|
BudgetOrg bug=new BudgetOrg();
|
bug.setGroupId(groupIdOld);
|
budgetConfigMapper.delete(bug);
|
// i += budgetConfigMapper.updateByCidAndGroupId(cid, groupIdOld);
|
}
|
}
|
for (BudgetOrg bug : budgetList) {
|
bug.initParam();
|
if (bug.getGroupId() == null) {
|
bug.setGroupId(groupId);
|
}
|
// System.err.println(bug);
|
i += budgetConfigMapper.insert(bug);
|
}
|
return i;
|
}
|
|
@Override
|
public List<BudgetOrgExtend> getBudgetOrgList(BudgetOrg budgetOrg) {
|
Organizations orgs = cscApiService.findRelationDetail();
|
List<BudgetOrgExtend> budgetOrgExtendList = budgetConfigMapper.selectLinkPage(budgetOrg);
|
|
for (BudgetOrgExtend budgetOrgExtend : budgetOrgExtendList) {
|
//转换字符为数组
|
String[] orgCodes = budgetOrgExtend.getOrgCode().split(",");
|
String[] parentOrgCodes = budgetOrgExtend.getParentOrgCode().split(",");
|
|
List<String> strCodeList = new ArrayList<String>();
|
//数组转换为List后合并
|
strCodeList.addAll(OrgUtil.getCodeList(orgCodes));
|
strCodeList.addAll(OrgUtil.getCodeList(parentOrgCodes));
|
|
Map<String, String> map = new HashMap<String, String>();
|
//依据List中的组织机构code查询组织机构name生成对应Map
|
map = OrgUtil.getMap(strCodeList, orgs.getOrgs());
|
|
//拼接组织机构name并格式化为,分隔的字符串
|
String getOrgFormat = OrgUtil.stringFormat(map, orgCodes);
|
String getPartenOrgFormat = OrgUtil.stringFormat(map, parentOrgCodes);
|
budgetOrgExtend.setOrgName(getOrgFormat);
|
budgetOrgExtend.setParentOrgName(getPartenOrgFormat);
|
}
|
|
|
return budgetOrgExtendList;
|
|
}
|
|
@Transactional
|
@Override
|
public Integer deleteBudgetList(Map<String, Object> map) {
|
List<String> groupIdList = JSONTool.toList(JSONTool.toJson(map.get("groupId")), String.class);
|
BudgetOrg budgetOrg = new BudgetOrg();
|
int count = 0;
|
if(ObjectUtil.empty(groupIdList)){
|
return count;
|
}
|
for (String groupId : groupIdList) {
|
budgetOrg.setGroupId(groupId);
|
count += budgetConfigMapper.delete(budgetOrg);
|
}
|
return count;
|
}
|
|
@Transactional
|
@Override
|
public Integer deleteBudgetListByDataStart(Map<String, Object> map) {
|
List<String> groupIdList = JSONTool.toList(JSONTool.toJson(map.get("groupId")), String.class);
|
// System.err.println(groupIdList);
|
BudgetOrg budgetOrg = new BudgetOrg();
|
int count = 0;
|
if(ObjectUtil.empty(groupIdList)){
|
return count;
|
}
|
for (String groupId : groupIdList) {
|
budgetOrg.setGroupId(groupId);
|
// System.err.println(budgetOrg);
|
List<BudgetOrg> budgetOrgList = budgetConfigMapper.select(budgetOrg);
|
for (BudgetOrg budget : budgetOrgList) {
|
budgetOrg.setId(budget.getId());
|
budgetOrg.setDataStart(99);
|
// System.err.println(budgetOrg.getId());
|
count += budgetConfigMapper.updateByPrimaryKeySelective(budgetOrg);
|
budgetOrg.setId(null);
|
budgetOrg.setDataStart(null);
|
}
|
}
|
return count;
|
}
|
|
@Override
|
public List<Integer> getCidList(BudgetOrg budgetOrg) {
|
return budgetConfigMapper.getCidList(budgetOrg);
|
}
|
|
@Override
|
public List<String> getOrgCodeList(BudgetOrg budgetOrg) {
|
return budgetConfigMapper.getOrgCodeList(budgetOrg);
|
}
|
|
@Override
|
public List<String> getParentOrgCodeList(BudgetOrg budgetOrg) {
|
return budgetConfigMapper.getParentOrgCodeList(budgetOrg);
|
}
|
|
@Override
|
public List<String> getParentBudgetOrg(BudgetOrg budgetOrg) {
|
budgetOrg.setDataStart(0);
|
Organizations orgs = cscApiService.findRelationDetail();
|
List<Organization> orgLists = new ArrayList<Organization>();
|
List<BudgetOrg> budgetOrgList = budgetConfigMapper.select(budgetOrg);
|
if (budgetOrgList != null && budgetOrgList.size() > 0) {
|
for (BudgetOrg budget : budgetOrgList) {
|
Organization org = new Organization();
|
org.setCode(budget.getParentOrgCode());
|
OrgUtil.getOrg(org.getCode(), orgs.getOrgs(), org);
|
orgLists.add(org);
|
// System.err.println(org);
|
}
|
} else {
|
Organization org = new Organization();
|
OrgUtil.getParentId(budgetOrg.getOrgCode(), orgs.getOrgs(), org);
|
OrgUtil.getParentOrg(org.getId(), orgs.getOrgs(), org);
|
org.setId(null);
|
orgLists.add(org);
|
// System.err.println(org);
|
}
|
Set<String> set = new HashSet<String>();
|
for (Organization o : orgLists) {
|
set.add(o.getCode());
|
}
|
//if(set.size() == 0){
|
//赵臻
|
// List<Organization> allOrganization = this.getAll();
|
// this.getOrgMap(allOrganization, null);
|
//递归成map
|
//set.add(orgMap.get(budgetOrg.getOrgCode()).getCode());
|
set.add(budgetOrg.getOrgCode());
|
//}
|
List<String> list = new ArrayList<String>(set);
|
return list;
|
|
}
|
|
|
public Organizations getOrgsOfTree(String code) {
|
return cscApiService.getOrgsOfTree(code);
|
}
|
|
|
@Override
|
public UserInfo findOrganizationByTenantId() {
|
String tenantId = Objects.toString(Context.getTenantId(), "");
|
Integer companyId = Context.getCompanyId();
|
// if(!ObjectUtil.empty(ThreadData.get(COMPANY_ID)) && !ObjectUtil.empty(ThreadData.get(TENANT_ID))){
|
// tenantId = ThreadData.get(TENANT_ID);
|
// companyId = ThreadData.get(COMPANY_ID);
|
// }
|
|
UserInfo user = new UserInfo();
|
//取出当前用户所在公司ID
|
TenantsAndCompanys o = cscApiService.findTenantsAndCompanys();
|
//判断多租户列表如果为空,添加人员、
|
if (ObjectUtil.empty(o) || ObjectUtil.empty(o.getTenants()) || 0 >= o.getTenants().size()) {
|
String a = null;
|
try {
|
a = URLDecoder.decode(Context.getUserInfo().getUserName(), "utf-8");
|
} catch (UnsupportedEncodingException e) {
|
// System.err.println(e.getMessage());
|
}
|
Map<String, Object> map = new HashMap<>();
|
map.put("userName", a);
|
map.put("openId", ThreadData.get(OPEN_ID));
|
cscApiService.addUserInfo(map);
|
}
|
// System.out.println("组织机构:" + JSONTool.toJson(o));
|
for (Tenant tenant : o.getTenants()) {
|
if (tenantId.equals(Objects.toString(tenant.getId(), ""))) {
|
user.setTenantId(tenant.getId());
|
for (Company com : tenant.getCompanys()) {
|
if (Objects.equals(companyId, com.getId())) {
|
user.setCompanyId(com.getId());
|
user.setHotInfoCompanyId(com.getHotInfoCompanyId());
|
for (SystemManager sys : com.getData()) {
|
user.setServiceId(sys.getId());
|
}
|
}
|
}
|
}
|
}
|
//当前业务系统Id暂时写死
|
// Organization org = cscApiService.findOrganization(user.getTenantId());
|
// // System.out.println("dfds:"+JSONTool.toJson(org));
|
// user.setUid(org.getCode());
|
//取出人员code
|
//user.setUserCode(getUserCode());
|
return user;
|
|
}
|
|
|
@Override
|
public TenantsAndCompanys findTenantsAndCompanys() {
|
TenantsAndCompanys tenant = cscApiService.findTenantsAndCompanys();
|
if (ObjectUtil.empty(tenant) || ObjectUtil.empty(tenant.getTenants()) || 0 >= tenant.getTenants().size()) {
|
String a = Context.getUserInfo().getUserName();
|
Map<String, Object> map = new HashMap<>();
|
map.put("userName", a);
|
map.put("openId", ThreadData.get(OPEN_ID));
|
cscApiService.addUserInfo(map);
|
}
|
return tenant;
|
}
|
|
|
@Override
|
public List<Organization> getOne() {
|
Organizations orgs = cscApiService.findRelationDetail();
|
// System.out.println("zuzhi11:" + JSONTool.toJson(orgs));
|
// System.out.println("组织机构:" + JSONTool.toJson(orgs.getOrgs()));
|
for (Organization org : orgs.getOrgs()) {
|
return org.getChildren();
|
}
|
return null;
|
}
|
|
|
@Override
|
public Organizations getUser() {
|
return cscApiService.findRelationDetail();
|
}
|
|
|
//取出当前登录人员的 code
|
public UserInfo getUserCode(UserInfo userInfo) {
|
//获取当前对象
|
UserInfo use = Context.getUserInfo();
|
String userName = use.getPhone();
|
MasterValue master = new MasterValue();
|
master.setDefineCode(corresElFieldApi.getVal(PERSONNEL, CorresElField::getMdCode));
|
master.setEleValue(userName);
|
String code = masterValueService.getMasterCode(master);
|
UserInfo a = new UserInfo();
|
a.setUserCode(code);
|
a.setUserName(use.getUserName());
|
return a;
|
}
|
|
|
@Override
|
public int addUserInfo(Map<String, Object> map) {
|
cscApiService.addUserInfo(map);
|
return 1;
|
}
|
|
@Override
|
public int updateUserName(Map<String, Object> user) {
|
return cscApiService.updateUserName(user);
|
}
|
|
@Override
|
@Transactional
|
public Integer synOrg() {
|
//判断版本号
|
String version = CacheUtils.get(String.format("version_org_%s",ThreadData.get(COMPANY_ID)),String.class);
|
log.debug("缓存中组织版本:"+version);
|
String orgVersion = cscApiService.getOrgVersion();
|
log.debug("组织机构当前版本:"+orgVersion);
|
if(Objects.equals(version,orgVersion)){
|
return 0;
|
}else{
|
String num = String.format("version_org_%s",ThreadData.get(COMPANY_ID));
|
CacheUtils.set(num,orgVersion,0);
|
Organizations orgs = cscApiService.findRelationDetail();
|
if(orgs == null){
|
return 0;
|
}
|
tenantOrgMapper.deleteAll();
|
this.addTenantOrg(orgs.getOrgs(),null);
|
VersionFilterApi.filter(orgName, Context.getTenantIdStr(), Context.getCompanyIdStr());
|
}
|
return 1;
|
}
|
|
@Override
|
public Integer checkOccupation(BudgetOrg budgetOrg) {
|
return tenantOrgMapper.selectOccCount(budgetOrg);
|
}
|
|
/**
|
* 递归添加
|
*/
|
public int addTenantOrg(List<Organization> dataList,Organization parent){
|
if(parent != null){
|
dataList.stream().forEach(o->{
|
TenantOrg t = new TenantOrg(o.getCode(),o.getName(),parent.getCode(),parent.getName());
|
t.setId(Integer.parseInt(o.getId()));
|
t.initParam();
|
tenantOrgMapper.insert(t);
|
if(o.getChildren() !=null && o.getChildren().size()>0){
|
this.addTenantOrg(o.getChildren(),o);
|
}
|
});
|
return 0;
|
}
|
//parent为null是顶级元素的时候执行
|
dataList.stream().forEach(o->{
|
TenantOrg t = new TenantOrg(o.getCode(),o.getName(),null,null);
|
t.setId(Integer.parseInt(o.getId()));
|
t.initParam();
|
tenantOrgMapper.insert(t);
|
if(o.getChildren() !=null && o.getChildren().size()>0){
|
this.addTenantOrg(o.getChildren(),o);
|
}
|
});
|
return 0;
|
}
|
}
|