|
@@ -5,11 +5,20 @@ import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.org.OrgUnitServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.org.OrgViewType;
|
|
|
|
+import kd.bos.util.StringUtils;
|
|
|
|
+import kd.tmc.fbp.common.helper.SystemStatusCtrolHelper;
|
|
|
|
+import kd.tmc.fbp.common.util.EmptyUtil;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.BigInteger;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -61,4 +70,145 @@ public class CommonHelperUtils {
|
|
|
|
|
|
return longformat.parse(dateStr + suffix);
|
|
return longformat.parse(dateStr + suffix);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 格式化BigDecimal对象
|
|
|
|
+ * @param objValue
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static BigDecimal getBigDecimal(Object objValue) {
|
|
|
|
+ BigDecimal ret = null;
|
|
|
|
+
|
|
|
|
+ if (objValue == null || objValue.equals("")) {
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
+ }
|
|
|
|
+ if (objValue instanceof BigDecimal) {
|
|
|
|
+ ret = (BigDecimal) objValue;
|
|
|
|
+ } else if (objValue instanceof String) {
|
|
|
|
+ ret = new BigDecimal((String) objValue);
|
|
|
|
+ } else if (objValue instanceof BigInteger) {
|
|
|
|
+ ret = new BigDecimal((BigInteger) objValue);
|
|
|
|
+ } else if (objValue instanceof Number) {
|
|
|
|
+ ret = new BigDecimal(((Number) objValue).doubleValue());
|
|
|
|
+ } else {
|
|
|
|
+ throw new ClassCastException("Not possible to coerce [" + objValue + "] from class " + objValue.getClass() + " into a BigDecimal.");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询实体对象
|
|
|
|
+ * @param entityName
|
|
|
|
+ * @param filterName
|
|
|
|
+ * @param value
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static DynamicObject queryBaseDynamicObject(String entityName, String filterName, String value){
|
|
|
|
+ QFilter qFilter = new QFilter("status", QCP.equals, "C");
|
|
|
|
+ qFilter.and(new QFilter("enable", QCP.equals, "1"));
|
|
|
|
+ qFilter.and(new QFilter(filterName, QCP.equals, value));
|
|
|
|
+
|
|
|
|
+ DynamicObject objectInfo = BusinessDataServiceHelper.loadSingle(entityName, qFilter.toArray());
|
|
|
|
+
|
|
|
|
+ return objectInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询实体对象
|
|
|
|
+ * @param entityName
|
|
|
|
+ * @param filterName
|
|
|
|
+ * @param value
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static DynamicObject queryBillDynamicObject(String entityName, String filterName, String value){
|
|
|
|
+ QFilter qFilter = new QFilter("status", QCP.equals, "C");
|
|
|
|
+ qFilter.and(new QFilter(filterName, QCP.equals, value));
|
|
|
|
+
|
|
|
|
+ DynamicObject objectInfo = BusinessDataServiceHelper.loadSingle(entityName, qFilter.toArray());
|
|
|
|
+
|
|
|
|
+ return objectInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取部门所在的公司
|
|
|
|
+ * @param dept
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static DynamicObject getAdminCompany(DynamicObject dept){
|
|
|
|
+ if(dept == null){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QFilter qFilter = new QFilter("view.id", QCP.equals, 1L);
|
|
|
|
+ qFilter.and(new QFilter("org.id", QCP.equals, dept.getLong("id")));
|
|
|
|
+ DynamicObject openOrg = BusinessDataServiceHelper.loadSingle("bos_org_structure", qFilter.toArray());
|
|
|
|
+ if(openOrg == null){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Long> parentIds = OrgUnitServiceHelper.getAllSuperiorOrgs(OrgViewType.Bankroll, openOrg.getLong("org.id"));
|
|
|
|
+ if(!parentIds.contains(openOrg.getLong("org.id"))){
|
|
|
|
+ parentIds.add(openOrg.getLong("org.id"));
|
|
|
|
+ }
|
|
|
|
+ QFilter filterView = new QFilter("view.id", QCP.equals, 1L);
|
|
|
|
+ QFilter filteraOrg = new QFilter("org.id", QCP.in, parentIds);
|
|
|
|
+ QFilter[] filters = new QFilter[]{filterView, filteraOrg};
|
|
|
|
+ String selectProperties = "org, number";
|
|
|
|
+ String orderBy = "longnumber desc";
|
|
|
|
+ DynamicObject[] orgList = BusinessDataServiceHelper.load("bos_org_structure", selectProperties, filters, orderBy);
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < orgList.length; i++){
|
|
|
|
+ DynamicObject adminCompany = BusinessDataServiceHelper.loadSingle(orgList[i].getLong("org.id"), "bos_org");
|
|
|
|
+
|
|
|
|
+ if(adminCompany.getDynamicObject("orgpattern") != null){
|
|
|
|
+ String pattern = adminCompany.getDynamicObject("orgpattern").getString("name");
|
|
|
|
+ if(StringUtils.isNotEmpty(pattern) && pattern.contains("公司")){
|
|
|
|
+ return adminCompany;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取最新的汇率
|
|
|
|
+ * @param exchangeTableId
|
|
|
|
+ * @param currencyId
|
|
|
|
+ * @param tarCurrencyId
|
|
|
|
+ * @param date
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static BigDecimal getExchangeRate(Long exchangeTableId, Long currencyId, Long tarCurrencyId, Date date){
|
|
|
|
+ if(currencyId.compareTo(tarCurrencyId) == 0){
|
|
|
|
+ return BigDecimal.ONE;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal exchangeRate = BaseDataServiceHelper.getExchangeRate(exchangeTableId, currencyId, tarCurrencyId, date);
|
|
|
|
+
|
|
|
|
+ return exchangeRate;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取汇率表
|
|
|
|
+ * @param orgId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static Long getExchageTableId(Long orgId) {
|
|
|
|
+ Map<String, Long> baseAccountingInfo = BaseDataServiceHelper.getBaseAccountingInfo(orgId);
|
|
|
|
+ Long exchangeTableId = null;
|
|
|
|
+ if (EmptyUtil.isNoEmpty(baseAccountingInfo)) {
|
|
|
|
+ exchangeTableId = (Long)baseAccountingInfo.get("exchangeRateTableID");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (EmptyUtil.isEmpty(exchangeTableId)) {
|
|
|
|
+ DynamicObject standardExRateTable = SystemStatusCtrolHelper.getStandardExRateTable(orgId);
|
|
|
|
+ if (EmptyUtil.isNoEmpty(standardExRateTable)) {
|
|
|
|
+ exchangeTableId = standardExRateTable.getLong("id");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return exchangeTableId;
|
|
|
|
+ }
|
|
}
|
|
}
|