1、删除无用demo代码

2、添加主数据模块项目
This commit is contained in:
2025-10-15 10:05:49 +08:00
parent b850a3779c
commit fd6e2d8ce6
89 changed files with 1312 additions and 2364 deletions

View File

@ -0,0 +1,166 @@
package com.pictc.jdbc;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.sql.Array;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.CallableStatement;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
import java.sql.Struct;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.format.DateTimeParseException;
import com.pictc.utils.StringUtils;
public class CallUtils {
@SuppressWarnings("unchecked")
public static <T> T getObject(CallableStatement res,int columnIndex,Class<T> type) throws SQLException {
if (type.equals(String.class)) {
return (T) res.getString(columnIndex);
} else if (type.equals(BigDecimal.class)) {
return (T) res.getBigDecimal(columnIndex);
} else if (type.equals(BigInteger.class)) {
return (T) getBigInteger(res, columnIndex);
} else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
return (T) Boolean.valueOf(res.getBoolean(columnIndex));
} else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
return (T) Integer.valueOf(res.getInt(columnIndex));
} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
return (T) Long.valueOf(res.getLong(columnIndex));
} else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
return (T) Float.valueOf(res.getFloat(columnIndex));
} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
return (T) Double.valueOf(res.getDouble(columnIndex));
} else if (type.equals(byte[].class)) {
return (T) res.getBytes(columnIndex);
} else if (type.equals(Date.class)) {
return (T) res.getDate(columnIndex);
} else if (type.equals(Time.class)) {
return (T) res.getTime(columnIndex);
} else if (type.equals(Timestamp.class)) {
return (T) res.getTimestamp(columnIndex);
} else if (type.equals(java.sql.Clob.class)) {
return (T) res.getClob(columnIndex);
} else if (type.equals(java.sql.Blob.class)) {
return (T) res.getBlob(columnIndex);
} else if (type.equals(Array.class)) {
return (T) res.getArray(columnIndex);
} else if (type.equals(Ref.class)) {
return (T) res.getRef(columnIndex);
} else if (type.equals(URL.class)) {
return (T) res.getURL(columnIndex);
} else if (type.equals(Struct.class)) {
throw new SQLFeatureNotSupportedException();
} else if (type.equals(RowId.class)) {
return (T) res.getRowId(columnIndex);
} else if (type.equals(NClob.class)) {
return (T) res.getNClob(columnIndex);
} else if (type.equals(SQLXML.class)) {
return (T) res.getSQLXML(columnIndex);
} else if (type.equals(LocalDate.class)) {
return (T) getLocalDate(res,columnIndex);
} else if (type.equals(LocalDateTime.class)) {
return (T) getLocalDateTime(res,columnIndex);
} else if (type.equals(LocalTime.class)) {
return (T) getLocalTime(res,columnIndex);
} else if (type.equals(OffsetDateTime.class)) {
try {
String odt = res.getString(columnIndex);
return odt == null ? null : (T) OffsetDateTime.parse(odt);
} catch (DateTimeParseException e) {
// Let it continue and try by object deserialization.
}
} else if (type.equals(OffsetTime.class)) {
try {
String ot = res.getString(columnIndex);
return ot == null ? null : (T) OffsetTime.parse(ot);
} catch (DateTimeParseException e) {}
}else if(type.isEnum()) {
try {
String _vl = res.getString(columnIndex);
if(!StringUtils.isEmpty(_vl)) {
Method method=Enum.class.getMethod("valueOf", String.class);
return (T) method.invoke(null,_vl);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return (T) res.getObject(columnIndex);
}
private static LocalDate getLocalDate(CallableStatement res,int columnIndex) throws SQLException {
Date date = res.getDate(columnIndex);
if(date!=null) {
return date.toLocalDate();
}
return null;
}
private static LocalDateTime getLocalDateTime(CallableStatement res,int columnIndex) throws SQLException {
Timestamp date = res.getTimestamp(columnIndex);
if(date!=null) {
return date.toLocalDateTime();
}
return null;
}
private static LocalTime getLocalTime(CallableStatement res,int columnIndex) throws SQLException {
Time date = res.getTime(columnIndex);
if(date!=null) {
return date.toLocalTime();
}
return null;
}
private static BigInteger getBigInteger(CallableStatement res,int columnIndex) throws SQLException {
String stringVal = res.getString(columnIndex);
if (stringVal == null) {
return null;
}
try {
return new BigInteger(stringVal);
} catch (NumberFormatException nfe) {
throw new RuntimeException("CallableStatement.Bad_format_for_BigInteger");
}
}
}

View File

@ -140,18 +140,34 @@ public static final int DEF_STEP = 1000;
}
}
}
private void setOutParams() throws SQLException {
if(params!=null) {
for (int i = 0; i < params.size(); i++) {
JdbcParam parameter = params.get(i);
int index = i+1;
if(parameter.isOut()) {
parameter.setVal(CallUtils.getObject(ctmt, index,parameter.getJavaType()));
continue;
}
}
}
}
public int executeUpdate() throws SQLException {
executeParams();
size = this._executeUpdate();
setOutParams();
return size;
}
public boolean execute() throws SQLException {
executeParams();
return this._execute();
boolean res = this._execute();
setOutParams();
return res;
}
public int executeBatch() throws SQLException {

View File

@ -162,6 +162,23 @@ public class JdbcTools {
}
}
/**
* 执行存储过程返回基础数据类型
* */
public static void call(String sql,List<JdbcParam> params){
JdbcContext context = null;
try {
context = new JdbcContext(true);
context.initCall(sql);
context.setParams(params);
context.execute();
} catch (SQLException e) {
throw context.createException(e);
}finally {
context.end();
}
}
/**
* 执行存储过程返回基础数据类型
* */

View File

@ -33,7 +33,7 @@ public class JdbcParam implements Serializable{
@Override
public String toString() {
return val+"("+JdbcType.valueOf(jdbc).name()+")";
return (out?"OUT ":"IN ")+val+"("+JdbcType.valueOf(jdbc).name()+")";
}
public static JdbcParam ofOut(int jdbc,Class<?> javaType) {
@ -160,6 +160,111 @@ public class JdbcParam implements Serializable{
.setJavaType(LocalDateTime.class)
.setVal(val);
}
/**
* 获取String类型值
*/
public String getStringValue() {
return val == null ? null : String.class.cast(val);
}
/**
* 获取Integer类型值
*/
public Integer getIntValue() {
return val == null ? null : Integer.class.cast(val);
}
/**
* 获取Long类型值
*/
public Long getLongValue() {
return val == null ? null : Long.class.cast(val);
}
/**
* 获取Boolean类型值
*/
public Boolean getBooleanValue() {
return val == null ? null : Boolean.class.cast(val);
}
/**
* 获取Float类型值
*/
public Float getFloatValue() {
return val == null ? null : Float.class.cast(val);
}
/**
* 获取Double类型值
*/
public Double getDoubleValue() {
return val == null ? null : Double.class.cast(val);
}
/**
* 获取Byte类型值
*/
public Byte getByteValue() {
return val == null ? null : Byte.class.cast(val);
}
/**
* 获取Short类型值
*/
public Short getShortValue() {
return val == null ? null : Short.class.cast(val);
}
/**
* 获取Date类型值
*/
public Date getDateValue() {
return val == null ? null : Date.class.cast(val);
}
/**
* 获取Timestamp类型值
*/
public Timestamp getTimestampValue() {
return val == null ? null : Timestamp.class.cast(val);
}
/**
* 获取BigDecimal类型值
*/
public BigDecimal getBigDecimalValue() {
return val == null ? null : BigDecimal.class.cast(val);
}
/**
* 获取BigInteger类型值
*/
public BigInteger getBigIntegerValue() {
return val == null ? null : BigInteger.class.cast(val);
}
/**
* 获取LocalDate类型值
*/
public LocalDate getLocalDateValue() {
return val == null ? null : LocalDate.class.cast(val);
}
/**
* 获取LocalTime类型值
*/
public LocalTime getLocalTimeValue() {
return val == null ? null : LocalTime.class.cast(val);
}
/**
* 获取LocalDateTime类型值
*/
public LocalDateTime getLocalDateTimeValue() {
return val == null ? null : LocalDateTime.class.cast(val);
}
}

View File

@ -0,0 +1,104 @@
package com.xjrsoft.module.common.db.service;
import java.util.List;
import org.springframework.stereotype.Component;
import com.pictc.jdbc.JdbcTools;
import com.pictc.jdbc.model.JdbcParam;
import com.pictc.utils.ListUtils;
import com.pictc.utils.StringUtils;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 通用保存、删除、启用、作废存储过程调用
* 通用 CommonCallService
* 合同 ContractCallService
* 采购 ProcurementCallService
* 销售 SalesCallService
* 运输 TransportCallService
* 储备 ReserveCallService
* 财务 FinanceCallService
*/
@Component
public class CommonCallService {
/**
* @Description:
一、新增、修改记录时,在同一个事务里执行如下过程:
1、更新表
2、调用数据库函数pc_表名.f_save(表主键)
3、函数返回非空、或者数据库异常时rollback函数返回空时commit
* @param table 表名
* @param id 表主键
* @return String 返回类型 函数返回非空、或者数据库异常时rollback函数返回空时commit
*/
public String saveAfter(String table,Long id) {
String sql = StringUtils.format("{? = call pc_{0}.f_save(?)}",table);
List<JdbcParam> params = ListUtils.newArrayList(JdbcParam.ofLong(id));
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofLong(id));
JdbcTools.call(sql,params);
return outParam.getStringValue();
}
/**
* @Description:
二、删除记录时,在同一个事务里执行如下过程:
1、调用数据库函数pc_表名.f_delete(表主键)
2、函数返回非空、或者数据库异常时rollback函数返回空时commit
* @return
* @return String 返回类型
*/
public String deleteBefore(String table,Long id) {
String sql = StringUtils.format("{? = call pc_{0}.f_delete(?)}",table);
List<JdbcParam> params = ListUtils.newArrayList(JdbcParam.ofLong(id));
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofLong(id));
JdbcTools.call(sql,params);
return outParam.getStringValue();
}
/**
* @Description:
二、停用时,在同一个事务里执行如下过程:
1、调用数据库函数pc_表名.f_off(表主键)
2、函数返回非空、或者数据库异常时rollback函数返回空时commit
* @return
* @return String 返回类型
*/
public String disableBefore(String table,Long id) {
String sql = StringUtils.format("{? = call pc_{0}.f_off(?)}",table);
List<JdbcParam> params = ListUtils.newArrayList(JdbcParam.ofLong(id));
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofLong(id));
JdbcTools.call(sql,params);
return outParam.getStringValue();
}
/**
* @Description:
1、调用数据库函数pc_表名.f_on(表主键)
2、函数返回非空、或者数据库异常时rollback函数返回空时commit
* @return
* @return String 返回类型
*/
public String enableBefore(String table,Long id) {
String sql = StringUtils.format("{? = call pc_{0}.f_on(?)}",table);
List<JdbcParam> params = ListUtils.newArrayList(JdbcParam.ofLong(id));
JdbcParam outParam = JdbcParam.ofString(null).setOut(true);
params.add(outParam);
params.add(JdbcParam.ofLong(id));
JdbcTools.call(sql,params);
return outParam.getStringValue();
}
}

View File

@ -0,0 +1,13 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 合同相关的存储过程
*/
@Component
public class ContractCallService {
}

View File

@ -0,0 +1,14 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 财务相关的存储过程
*/
@Component
public class FinanceCallService {
}

View File

@ -0,0 +1,14 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 采购相关的存储过程
*/
@Component
public class ProcurementCallService {
}

View File

@ -0,0 +1,14 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 储备相关的存储过程
*/
@Component
public class ReserveCallService {
}

View File

@ -0,0 +1,14 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 销售相关的存储过程
*/
@Component
public class SalesCallService {
}

View File

@ -0,0 +1,14 @@
package com.xjrsoft.module.common.db.service;
import org.springframework.stereotype.Component;
/**
* @author 张福财
* @date 2025年10月14日 上午11:47:59
* @Description: 运输相关的存储过程
*/
@Component
public class TransportCallService {
}

View File

@ -0,0 +1,4 @@
# src/main/resources/META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pictc.config.PcitcAutoConfig,\
com.pictc.config.JdbcConfig

View File

@ -0,0 +1 @@
component=com.pictc

View File

@ -0,0 +1,9 @@
███████ ██████ ██ ██████████ ██████
░██░░░░██ ██░░░░██░██░░░░░██░░░ ██░░░░██
░██ ░██ ██ ░░ ░██ ░██ ██ ░░ 服务名称:${serverName}
░███████ ░██ ░██ ░██ ░██ 启动环境:${profiles}
░██░░░░ ░██ ░██ ░██ ░██ 启动耗时:${time}s
░██ ░░██ ██░██ ░██ ░░██ ██ 访问地址:${url}
░██ ░░██████ ░██ ░██ ░░██████
░░ ░░░░░░ ░░ ░░ ░░░░░░