taikai2312/uapbd/src/public/nc/bs/uapbd/util/MyHelper.java

216 lines
8.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package nc.bs.uapbd.util;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.logging.Logger;
import nc.bs.trade.business.HYSuperDMO;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.cmp.util.StringUtils;
import nc.vo.fi.pub.SqlUtils;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 工具类
*
* @author mzr
* @date 2025/7/3
*/
public class MyHelper {
private static final BaseDAO dao = new BaseDAO();
/**
* 单个字段值翻译
*/
public static String transferField(String tableName, String selectField, String pkField, String pk) throws BusinessException {
if (StringUtils.isEmpty(pk)) {
return null;
}
SqlBuilder sqlBuilder = new SqlBuilder();
sqlBuilder.append(" select " + selectField);
sqlBuilder.append(" from " + tableName);
sqlBuilder.append(" where ");
sqlBuilder.append(pkField, pk);
Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
if (o == null) {
Logger.info("未查询到编码信息sql【" + sqlBuilder + "");
// throw new BusinessException("未查询到编码信息sql【" + sqlBuilder + "】");
}
return String.valueOf(o);
}
/**
* 多个字段值翻译
*/
public static Map<String, Object> transferFields(String tableName, String selectFields, String pkField, String pk) throws BusinessException {
if (StringUtils.isEmpty(pk)) {
return null;
}
SqlBuilder sqlBuilder = new SqlBuilder();
sqlBuilder.append(" select " + selectFields);
sqlBuilder.append(" from " + tableName);
sqlBuilder.append(" where ");
sqlBuilder.append(pkField, pk);
Map<String, Object> result = (Map<String, Object>) dao.executeQuery(sqlBuilder.toString(), new MapProcessor());
if (result == null || result.isEmpty()) {
result = new HashMap<>();
}
return result;
}
public static String getStrValByCondition(String tableName, String fieldName, String condition) throws BusinessException {
String result = "";
String sql = " SELECT " + fieldName + " FROM " + tableName + " " +
" WHERE nvl(" + tableName + " .dr,0)= 0 " +
" and " + condition + " ";
result = (String) dao.executeQuery(sql, new ColumnProcessor());
return result;
}
public static Map<String, Object> getMapValByCondition(String tableName, String fieldName, String condition) throws BusinessException {
String sql = " SELECT " + fieldName + " FROM " + tableName + " " +
" WHERE nvl(" + tableName + " .dr,0)= 0 " +
" and " + condition + " ";
Map<String, Object> result = (Map<String, Object>) dao.executeQuery(sql, new MapProcessor());
if (result == null || result.isEmpty()) {
result = new HashMap<>();
}
return result;
}
public static List<Map<String, String>> getListByCondition(String tableName, String fieldName, String condition) throws BusinessException {
String sql = " SELECT " + fieldName + " FROM " + tableName + " " +
" WHERE nvl(" + tableName + " .dr,0)= 0 " +
" and " + condition + " ";
return (List<Map<String, String>>) new BaseDAO().executeQuery(sql, new MapListProcessor());
}
/**
* 检查当前组织是否为电力电子
*/
public static boolean checkIfDldzOrg(String code, Map<String, String> configParams) throws BusinessException {
String targetCode = configParams.get("dldzOrg");
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
throw new BusinessException("未配置组织参数");
}
String[] orgItem = targetCode.split(",");
for (String orgCode : orgItem) {
if (!orgCode.isEmpty() && orgCode.equals(code)) {
Logger.info("当前处理组织校验为电力电子:" + code);
return false;
}
}
return true;
}
/**
* 转换特殊字段 如 1/1 转换为小数 1.0
*/
public static String transferSpecialField(String field) {
if (field == null || field.trim().isEmpty()) {
return null;
}
String[] split = field.split("/");
if (split.length == 2) {
String numStr = split[0].trim();
String denStr = split[1].trim();
if (denStr.equals("0")) {
return "0.00"; // 分母不能为零
}
try {
BigDecimal numerator = new BigDecimal(numStr);
BigDecimal denominator = new BigDecimal(denStr);
return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString();
} catch (NumberFormatException e) {
return field; // 非法数字,返回原字段
}
}
return field;
}
public static Map<String, String> getConfigParams(String code, String pkOrg) {
Map<String, String> map = new HashMap<String, String>();
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='[code]' and dr=0 ) and dr=0";
strWhere = strWhere.replace("[code]", code);
if (!StringUtils.isEmpty(pkOrg)) {
strWhere = strWhere + " and = pk_org '" + pkOrg + "'";
}
try {
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
if (defdocVOs != null) {
for (DefdocVO defdocVO : defdocVOs) {
map.put(defdocVO.getCode().trim(), defdocVO.getName());
}
}
} catch (DAOException e) {
Logger.error("getConfigParams-exp:" + e.getMessage());
}
return map;
}
/**
* 检查当前组织是否为配置的组织
*/
public static Integer checkIfOrg(Map<String, String> configParams, String pkMaterial, String orgFlag) throws BusinessException {
String targetCode = configParams.get(orgFlag);
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
throw new BusinessException("未配置组织参数");
}
String[] orgItem = targetCode.split(",");
String inStr = SqlUtils.getInStr("b.code", orgItem, Boolean.TRUE);
String countSql = "SELECT count(1)" +
" FROM bd_materialstock a" +
" LEFT JOIN org_stockorg b ON a.pk_org = b.pk_stockorg" +
" WHERE " +
" a.pk_material = '[pkMaterial]'" +
" AND " + inStr;
countSql = countSql.replace("[pkMaterial]", pkMaterial);
// NCCForUAPLogger.debug(countSql);
return (Integer) dao.executeQuery(countSql, new ColumnProcessor());
}
/**
* 检查物料仓库的组织是否符合条件
*/
public static Integer checkIfOrg1(Map<String, String> configParams, String pk_materialstock, String orgFlag) throws BusinessException {
String targetCode = configParams.get(orgFlag);
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
throw new BusinessException("未配置组织参数");
}
String[] orgItem = targetCode.split(",");
String inStr = SqlUtils.getInStr("b.code", orgItem, Boolean.TRUE);
String countSql = "SELECT count(1)" +
" FROM bd_materialstock a" +
" LEFT JOIN org_stockorg b ON a.pk_org = b.pk_stockorg" +
" WHERE " +
" a.pk_materialstock = '[pk_materialstock]'" +
" AND " + inStr;
countSql = countSql.replace("[pk_materialstock]", pk_materialstock);
// NCCForUAPLogger.debug(countSql);
return (Integer) dao.executeQuery(countSql, new ColumnProcessor());
}
public static String skipNull(Object value) {
if ((value == null) || (value.toString().trim().length() == 0)) {
return "";
}
return value.toString().trim();
}
}