com.fhs.pagex.service.PageXDBService Maven / Gradle / Ivy
The newest version!
package com.fhs.pagex.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fhs.pagex.dto.PagexAddDTO;
import com.fhs.redis.service.RedisCacheService;
import com.mybatis.jpa.cache.JpaTools;
import com.fhs.common.utils.*;
import com.fhs.core.base.bean.SuperBean;
import com.fhs.core.exception.BusinessException;
import com.fhs.core.trans.TransService;
import com.fhs.pagex.bean.DefaultPageXBean;
import com.mybatis.jpa.common.ColumnNameUtil;
import org.apache.commons.collections.map.HashedMap;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* pagex dbservice
* 1 根据配置文件拼接sql
* 2 根据namespace 执行sql返回结果
*
* @ProjectName: framework_v2_idea2
* @Package: com.fhs.pagex.service
* @ClassName: PageXDBService
* @Author: JackWang
* @CreateDate: 2018/12/3 0003 20:01
* @UpdateUser: JackWang
* @UpdateDate: 2018/12/3 0003 20:01
* @Version: 1.0
*/
@Service
public class PageXDBService {
private static final Logger LOG = Logger.getLogger(PageXDBService.class);
@Autowired
private SqlSessionTemplate sqlsession;
@Autowired
private TransService transService;
@Autowired
private RedisCacheService redisCacheService;
private static final String DO_CACHE_KEY = "docache:";
/**
* 需要翻译的namespace集合
*/
private Set needTransNamespaceSet = Collections.synchronizedSet(new HashSet<>());
/**
* key namespace value 对应namespace的PO class
*/
private Map namespaceClassMap = new ConcurrentHashMap<>();
/**
* 插入一条数据到db
*
* @param paramMap 参数
* @param namespace namespace
* @return
*/
public int insert(EMap paramMap, String namespace) {
insertAndUpdateX(paramMap, namespace, true);
return sqlsession.insert(getSqlNamespace() + namespace + "_insertPageX", paramMap);
}
/**
* 处理一对多
*
* @param paramMap 参数
* @param namespace namespace
*/
private void insertAndUpdateX(EMap paramMap, String namespace, boolean isAdd) {
PagexAddDTO addDTO = PagexDataService.SIGNEL.getPagexAddDTOFromCache(namespace);
Map modelConfig = addDTO.getModelConfig();
//是否存在一对多
if (ConverterUtils.toBoolean(addDTO.getModelConfig().get("isOne2X"))) {
String createUser = isAdd ? paramMap.getStr("createUser") : paramMap.getStr("updateUser");
String groupCode = paramMap.getStr("groupCode");
String pkey = isAdd ? paramMap.getStr("pkey") : paramMap.getStr(modelConfig.get("pkey"));
List namespaces = new ArrayList<>();
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy