Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【自取】框架增强 - java 增强示例 #7236

Open
huangwei2013 opened this issue Sep 18, 2024 · 0 comments
Open

【自取】框架增强 - java 增强示例 #7236

huangwei2013 opened this issue Sep 18, 2024 · 0 comments

Comments

@huangwei2013
Copy link

因为坑爹的框架,基于 online 表单 的表id只能是 string(uuid),非常不满足业务需要,被迫如此:

@Component("CgformEnhanceInsertSetId")
public class CgformEnhanceInsertSetId implements CgformEnhanceJavaInter {

    // 定义类变量
    private static final Map<String, Integer> predefinedMap;

    // 静态初始化块,用于初始化类变量
    static {
        predefinedMap = new HashMap<>();
        predefinedMap.put("库名.表名", 1); // 对应 online 表单开发中,设置的 "表名"
        // 可以根据需要添加更多元素
    }

    @Autowired
    private JdbcTemplate jdbcTemplate; 

    /**
     * @param tableName
     * @param json
     * @throws BusinessException
     */
    @Override
    public void execute(String tableName, JSONObject json) throws BusinessException {

        if(predefinedMap.containsKey(tableName)) {
            // 查询对应表的 maxId,用于设置 maxId
            String sql = "SELECT COALESCE(MAX(id), 0) FROM " + tableName;
            Long maxId = jdbcTemplate.queryForObject(sql, Long.class);

            if (maxId != null) {
                json.put("id", ++maxId);
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant