字典类型加上组织字段
This commit is contained in:
@@ -34,6 +34,45 @@ public class SysDictType extends BaseEntity
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 组织表ID */
|
||||
private Long organizationId;
|
||||
|
||||
/** 组织名称 */
|
||||
private String organizationName;
|
||||
|
||||
/** 一级组织表ID */
|
||||
private Long topOrganizationId;
|
||||
|
||||
public Long getOrganizationId()
|
||||
{
|
||||
return organizationId;
|
||||
}
|
||||
|
||||
public void setOrganizationId(Long organizationId)
|
||||
{
|
||||
this.organizationId = organizationId;
|
||||
}
|
||||
|
||||
public String getOrganizationName()
|
||||
{
|
||||
return organizationName;
|
||||
}
|
||||
|
||||
public void setOrganizationName(String organizationName)
|
||||
{
|
||||
this.organizationName = organizationName;
|
||||
}
|
||||
|
||||
public Long getTopOrganizationId()
|
||||
{
|
||||
return topOrganizationId;
|
||||
}
|
||||
|
||||
public void setTopOrganizationId(Long topOrganizationId)
|
||||
{
|
||||
this.topOrganizationId = topOrganizationId;
|
||||
}
|
||||
|
||||
public Long getDictId()
|
||||
{
|
||||
return dictId;
|
||||
@@ -86,6 +125,9 @@ public class SysDictType extends BaseEntity
|
||||
.append("dictName", getDictName())
|
||||
.append("dictType", getDictType())
|
||||
.append("status", getStatus())
|
||||
.append("organizationId", getOrganizationId())
|
||||
.append("organizationName", getOrganizationName())
|
||||
.append("topOrganizationId", getTopOrganizationId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
|
||||
@@ -65,27 +65,67 @@ public class IpUtil {
|
||||
public static IpLocation getLocation(String ip) {
|
||||
IpLocation location = new IpLocation();
|
||||
location.setIp(ip);
|
||||
try (InputStream inputStream = IpUtils.class.getResourceAsStream("/ip2region.xdb");) {
|
||||
if (StrUtil.isBlank(ip) || "unknown".equalsIgnoreCase(ip.trim()))
|
||||
{
|
||||
return location;
|
||||
}
|
||||
String ipv4 = ip.trim();
|
||||
if (ipv4.contains(","))
|
||||
{
|
||||
ipv4 = ipv4.substring(0, ipv4.indexOf(',')).trim();
|
||||
}
|
||||
// ip2region xdb 对 IPv6 / 非法串可能抛 ArrayIndexOutOfBoundsException,仅对 IPv4 做库查询
|
||||
if (!isLikelyIpv4(ipv4))
|
||||
{
|
||||
return location;
|
||||
}
|
||||
try (InputStream inputStream = IpUtils.class.getResourceAsStream("/ip2region.xdb"))
|
||||
{
|
||||
if (inputStream == null)
|
||||
{
|
||||
log.warn("ip2region.xdb 未找到,跳过 IP 归属解析");
|
||||
return location;
|
||||
}
|
||||
byte[] bytes = IoUtil.readBytes(inputStream);
|
||||
Searcher searcher = Searcher.newWithBuffer(bytes);
|
||||
String region = searcher.search(ip);
|
||||
if (StrUtil.isAllNotBlank(region)) {
|
||||
// xdb返回格式 国家|区域|省份|城市|ISP,
|
||||
// 只有中国的数据绝大部分精确到了城市,其他国家部分数据只能定位到国家,后前的选项全部是0
|
||||
String[] result = region.split("\\|");
|
||||
location.setCountry(ZERO.equals(result[0]) ? StrUtil.EMPTY : result[0]);
|
||||
location.setProvince(ZERO.equals(result[2]) ? StrUtil.EMPTY : result[2]);
|
||||
location.setCity(ZERO.equals(result[3]) ? StrUtil.EMPTY : result[3]);
|
||||
location.setIsp(ZERO.equals(result[4]) ? StrUtil.EMPTY : result[4]);
|
||||
try
|
||||
{
|
||||
String region = searcher.search(ipv4);
|
||||
if (StrUtil.isNotBlank(region))
|
||||
{
|
||||
// xdb返回格式 国家|区域|省份|城市|ISP,
|
||||
String[] result = region.split("\\|");
|
||||
if (result.length >= 5)
|
||||
{
|
||||
location.setCountry(ZERO.equals(result[0]) ? StrUtil.EMPTY : result[0]);
|
||||
location.setProvince(ZERO.equals(result[2]) ? StrUtil.EMPTY : result[2]);
|
||||
location.setCity(ZERO.equals(result[3]) ? StrUtil.EMPTY : result[3]);
|
||||
location.setIsp(ZERO.equals(result[4]) ? StrUtil.EMPTY : result[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
searcher.close();
|
||||
} catch (Exception e) {
|
||||
log.error("ip地址解析异常,error:", e);
|
||||
finally
|
||||
{
|
||||
searcher.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warn("ip地址解析失败,ip={}, msg={}", ipv4, e.getMessage());
|
||||
return location;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
private static boolean isLikelyIpv4(String ip)
|
||||
{
|
||||
if (ip == null || ip.contains(":"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ip.chars().filter(ch -> ch == '.').count() == 3L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据iP获取归属地信息 - 拼接
|
||||
*
|
||||
@@ -93,7 +133,7 @@ public class IpUtil {
|
||||
*/
|
||||
public static String getLocationSplicing(String ip) {
|
||||
IpLocation location = getLocation(ip);
|
||||
return location.getProvince()+location.getCity();
|
||||
return StrUtil.nullToEmpty(location.getProvince()) + StrUtil.nullToEmpty(location.getCity());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -80,7 +80,15 @@ public class LogAspect
|
||||
// 请求的地址
|
||||
String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
||||
operLog.setOperIp(ip);
|
||||
operLog.setOperLocation(StrUtil.isNotEmpty(operLog.getOperIp()) ? IpUtil.getLocationSplicing(operLog.getOperIp()) : "");
|
||||
try
|
||||
{
|
||||
operLog.setOperLocation(StrUtil.isNotEmpty(operLog.getOperIp()) ? IpUtil.getLocationSplicing(operLog.getOperIp()) : "");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
log.warn("操作日志 IP 归属解析跳过: {}", t.getMessage());
|
||||
operLog.setOperLocation("");
|
||||
}
|
||||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null){
|
||||
|
||||
+9
@@ -72,4 +72,13 @@ public class DictUtils
|
||||
{
|
||||
return Constants.SYS_DICT_KEY + configKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典缓存键:同一 dict_type 在不同组织下可并存,需带上组织维度(null 视为 0 平台)
|
||||
*/
|
||||
public static String dictTypeOrgCacheKey(String dictType, Long organizationId)
|
||||
{
|
||||
long oid = organizationId == null ? 0L : organizationId.longValue();
|
||||
return dictType + "@" + oid;
|
||||
}
|
||||
}
|
||||
|
||||
+46
@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.mhd.common.core.constant.UserConstants;
|
||||
import com.mhd.common.core.domain.po.UserPo;
|
||||
import com.mhd.common.core.utils.StringUtils;
|
||||
import com.mhd.common.core.utils.poi.ExcelUtil;
|
||||
import com.mhd.common.core.web.controller.BaseController;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
@@ -23,6 +25,7 @@ import com.mhd.common.log.annotation.Log;
|
||||
import com.mhd.common.log.enums.BusinessType;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.system.api.domain.SysDictType;
|
||||
import com.mhd.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* 数据字典信息
|
||||
@@ -73,6 +76,7 @@ public class SysDictTypeController extends BaseController
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody SysDictType dict)
|
||||
{
|
||||
fillDictTypeOrganization(dict);
|
||||
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
|
||||
{
|
||||
return AjaxResult.error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||
@@ -81,6 +85,47 @@ public class SysDictTypeController extends BaseController
|
||||
return toAjax(dictTypeService.insertDictType(dict));
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入组织维度:优先使用请求体中选择的组织;未传时使用当前登录用户所属组织;无登录上下文时按平台(0)处理。
|
||||
*/
|
||||
private void fillDictTypeOrganization(SysDictType dict)
|
||||
{
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser == null || loginUser.getUserPo() == null)
|
||||
{
|
||||
if (dict.getOrganizationId() == null)
|
||||
{
|
||||
dict.setOrganizationId(0L);
|
||||
}
|
||||
return;
|
||||
}
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
if (dict.getOrganizationId() == null)
|
||||
{
|
||||
dict.setOrganizationId(userPo.getOrganizationId());
|
||||
if (StringUtils.isEmpty(dict.getOrganizationName()))
|
||||
{
|
||||
dict.setOrganizationName(userPo.getOrganizationName());
|
||||
}
|
||||
if (dict.getTopOrganizationId() == null)
|
||||
{
|
||||
dict.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dict.getTopOrganizationId() == null)
|
||||
{
|
||||
dict.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
}
|
||||
if (StringUtils.isEmpty(dict.getOrganizationName())
|
||||
&& dict.getOrganizationId().equals(userPo.getOrganizationId()))
|
||||
{
|
||||
dict.setOrganizationName(userPo.getOrganizationName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
@@ -89,6 +134,7 @@ public class SysDictTypeController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysDictType dict)
|
||||
{
|
||||
fillDictTypeOrganization(dict);
|
||||
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
|
||||
{
|
||||
return AjaxResult.error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||
|
||||
@@ -56,7 +56,7 @@ public interface SysDictDataMapper extends BaseMapper<SysDictData>
|
||||
* @param dictType 字典类型
|
||||
* @return 字典数据
|
||||
*/
|
||||
public int countDictDataByType(String dictType);
|
||||
int countDictDataByType(@Param("dictType") String dictType, @Param("organizationId") Long organizationId);
|
||||
|
||||
/**
|
||||
* 通过字典ID删除字典数据信息
|
||||
@@ -97,5 +97,15 @@ public interface SysDictDataMapper extends BaseMapper<SysDictData>
|
||||
* @param newDictType 新旧字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
|
||||
int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType,
|
||||
@Param("organizationId") Long organizationId);
|
||||
|
||||
/**
|
||||
* 按字典类型批量同步字典数据的组织信息(与字典类型归属一致)
|
||||
*/
|
||||
int updateDictDataOrganizationByDictType(@Param("dictType") String dictType,
|
||||
@Param("organizationId") Long organizationId,
|
||||
@Param("organizationName") String organizationName,
|
||||
@Param("topOrganizationId") Long topOrganizationId,
|
||||
@Param("scopeOrganizationId") Long scopeOrganizationId);
|
||||
}
|
||||
|
||||
@@ -79,5 +79,5 @@ public interface SysDictTypeMapper
|
||||
* @param dictType 字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
public SysDictType checkDictTypeUnique(String dictType);
|
||||
public SysDictType checkDictTypeUnique(SysDictType dictType);
|
||||
}
|
||||
|
||||
+16
-3
@@ -107,8 +107,11 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
dictDataMapper.deleteDictDataById(dictCode);
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(data.getDictType());
|
||||
Long oid = data.getOrganizationId() != null ? data.getOrganizationId() : 0L;
|
||||
dictData.setOrganizationId(oid);
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictData);
|
||||
DictUtils.setDictCache(data.getDictType(), dictDatas);
|
||||
DictUtils.setDictCache(DictUtils.dictTypeOrgCacheKey(data.getDictType(), oid), dictDatas);
|
||||
DictUtils.removeDictCache(data.getDictType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,8 +138,11 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
{
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(data.getDictType());
|
||||
Long oid = data.getOrganizationId() != null ? data.getOrganizationId() : 0L;
|
||||
dictData.setOrganizationId(oid);
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictData);
|
||||
DictUtils.setDictCache(data.getDictType(), dictDatas);
|
||||
DictUtils.setDictCache(DictUtils.dictTypeOrgCacheKey(data.getDictType(), oid), dictDatas);
|
||||
DictUtils.removeDictCache(data.getDictType());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
@@ -180,13 +186,20 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
}
|
||||
}
|
||||
data.setUpdateBy(loginUser.getUserPo().getUserName());
|
||||
Long oldOid = sysDictData.getOrganizationId() != null ? sysDictData.getOrganizationId() : 0L;
|
||||
int row = dictDataMapper.updateDictData(data);
|
||||
if (row > 0)
|
||||
{
|
||||
DictUtils.removeDictCache(DictUtils.dictTypeOrgCacheKey(sysDictData.getDictType(), oldOid));
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(data.getDictType());
|
||||
Long oid = data.getOrganizationId() != null ? data.getOrganizationId()
|
||||
: (sysDictData.getOrganizationId() != null ? sysDictData.getOrganizationId() : 0L);
|
||||
dictData.setOrganizationId(oid);
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictData);
|
||||
DictUtils.setDictCache(data.getDictType(), dictDatas);
|
||||
DictUtils.setDictCache(DictUtils.dictTypeOrgCacheKey(data.getDictType(), oid), dictDatas);
|
||||
DictUtils.removeDictCache(data.getDictType());
|
||||
DictUtils.removeDictCache(sysDictData.getDictType());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
+53
-8
@@ -16,8 +16,10 @@ import com.mhd.common.core.constant.UserConstants;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.common.core.utils.StringUtils;
|
||||
import com.mhd.common.security.utils.DictUtils;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.system.api.domain.SysDictData;
|
||||
import com.mhd.system.api.domain.SysDictType;
|
||||
import com.mhd.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* 字典 业务层处理
|
||||
@@ -74,22 +76,47 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
@Override
|
||||
public List<SysDictData> selectDictDataByType(String dictType)
|
||||
{
|
||||
List<SysDictData> dictDatas = DictUtils.getDictCache(dictType);
|
||||
Long orgId = resolveLoginOrganizationIdForDict();
|
||||
String cacheKey = DictUtils.dictTypeOrgCacheKey(dictType, orgId);
|
||||
List<SysDictData> dictDatas = DictUtils.getDictCache(cacheKey);
|
||||
if (StringUtils.isEmpty(dictDatas))
|
||||
{
|
||||
dictDatas = DictUtils.getDictCache(dictType);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dictDatas))
|
||||
{
|
||||
return dictDatas;
|
||||
}
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(dictType);
|
||||
dictData.setOrganizationId(orgId);
|
||||
dictDatas = dictDataMapper.selectDictDataByType(dictData);
|
||||
if (StringUtils.isNotEmpty(dictDatas))
|
||||
{
|
||||
DictUtils.setDictCache(dictType, dictDatas);
|
||||
DictUtils.setDictCache(cacheKey, dictDatas);
|
||||
return dictDatas;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 字典数据按组织隔离;未登录按平台 0 */
|
||||
private Long resolveLoginOrganizationIdForDict()
|
||||
{
|
||||
try
|
||||
{
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null && loginUser.getUserPo() != null
|
||||
&& loginUser.getUserPo().getOrganizationId() != null)
|
||||
{
|
||||
return loginUser.getUserPo().getOrganizationId();
|
||||
}
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型ID查询信息
|
||||
*
|
||||
@@ -125,11 +152,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
for (Long dictId : dictIds)
|
||||
{
|
||||
SysDictType dictType = selectDictTypeById(dictId);
|
||||
if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0)
|
||||
Long typeOrgId = dictType.getOrganizationId() != null ? dictType.getOrganizationId() : 0L;
|
||||
if (dictDataMapper.countDictDataByType(dictType.getDictType(), typeOrgId) > 0)
|
||||
{
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
|
||||
}
|
||||
dictTypeMapper.deleteDictTypeById(dictId);
|
||||
DictUtils.removeDictCache(DictUtils.dictTypeOrgCacheKey(dictType.getDictType(), typeOrgId));
|
||||
DictUtils.removeDictCache(dictType.getDictType());
|
||||
}
|
||||
}
|
||||
@@ -142,7 +171,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
{
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setStatus("0");
|
||||
Map<String, List<SysDictData>> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType));
|
||||
Map<String, List<SysDictData>> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream()
|
||||
.collect(Collectors.groupingBy(d -> DictUtils.dictTypeOrgCacheKey(d.getDictType(), d.getOrganizationId())));
|
||||
for (Map.Entry<String, List<SysDictData>> entry : dictDataMap.entrySet())
|
||||
{
|
||||
DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList()));
|
||||
@@ -180,7 +210,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
int row = dictTypeMapper.insertDictType(dict);
|
||||
if (row > 0)
|
||||
{
|
||||
DictUtils.setDictCache(dict.getDictType(), null);
|
||||
Long oid = dict.getOrganizationId() != null ? dict.getOrganizationId() : 0L;
|
||||
DictUtils.removeDictCache(DictUtils.dictTypeOrgCacheKey(dict.getDictType(), oid));
|
||||
DictUtils.removeDictCache(dict.getDictType());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
@@ -196,14 +228,27 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
public int updateDictType(SysDictType dict)
|
||||
{
|
||||
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId());
|
||||
dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType());
|
||||
Long oldTypeOrgId = oldDict.getOrganizationId() != null ? oldDict.getOrganizationId() : 0L;
|
||||
dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType(), oldTypeOrgId);
|
||||
int row = dictTypeMapper.updateDictType(dict);
|
||||
if (row > 0)
|
||||
{
|
||||
if (dictDataMapper.countDictDataByType(dict.getDictType(), oldTypeOrgId) > 0)
|
||||
{
|
||||
dictDataMapper.updateDictDataOrganizationByDictType(dict.getDictType(),
|
||||
dict.getOrganizationId(), dict.getOrganizationName(), dict.getTopOrganizationId(),
|
||||
oldTypeOrgId);
|
||||
}
|
||||
DictUtils.removeDictCache(DictUtils.dictTypeOrgCacheKey(oldDict.getDictType(), oldTypeOrgId));
|
||||
DictUtils.removeDictCache(DictUtils.dictTypeOrgCacheKey(dict.getDictType(), dict.getOrganizationId()));
|
||||
DictUtils.removeDictCache(oldDict.getDictType());
|
||||
DictUtils.removeDictCache(dict.getDictType());
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(dict.getDictType());
|
||||
Long newOrgId = dict.getOrganizationId() != null ? dict.getOrganizationId() : 0L;
|
||||
dictData.setOrganizationId(newOrgId);
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictData);
|
||||
DictUtils.setDictCache(dict.getDictType(), dictDatas);
|
||||
DictUtils.setDictCache(DictUtils.dictTypeOrgCacheKey(dict.getDictType(), newOrgId), dictDatas);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
@@ -218,7 +263,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
public String checkDictTypeUnique(SysDictType dict)
|
||||
{
|
||||
Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId();
|
||||
SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType());
|
||||
SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict);
|
||||
if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue())
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
|
||||
@@ -58,6 +58,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="topOrganizationId != null">
|
||||
and (top_organization_id = #{topOrganizationId} OR is_default = 'Y')
|
||||
</if>
|
||||
<if test="organizationId != null">
|
||||
and (IFNULL(organization_id, 0) = #{organizationId} OR is_default = 'Y')
|
||||
</if>
|
||||
</where>
|
||||
order by dict_sort asc
|
||||
</select>
|
||||
@@ -73,7 +76,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</select>
|
||||
|
||||
<select id="countDictDataByType" resultType="Integer">
|
||||
select count(1) from sys_dict_data where dict_type=#{dictType}
|
||||
select count(1) from sys_dict_data
|
||||
where dict_type = #{dictType}
|
||||
and IFNULL(organization_id, 0) = IFNULL(#{organizationId}, 0)
|
||||
</select>
|
||||
|
||||
<delete id="deleteDictDataById" parameterType="Long">
|
||||
@@ -108,8 +113,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where dict_code = #{dictCode}
|
||||
</update>
|
||||
|
||||
<update id="updateDictDataType" parameterType="String">
|
||||
update sys_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType}
|
||||
<update id="updateDictDataType">
|
||||
update sys_dict_data set dict_type = #{newDictType}
|
||||
where dict_type = #{oldDictType}
|
||||
and IFNULL(organization_id, 0) = IFNULL(#{organizationId}, 0)
|
||||
</update>
|
||||
|
||||
<update id="updateDictDataOrganizationByDictType">
|
||||
update sys_dict_data
|
||||
set organization_id = #{organizationId},
|
||||
organization_name = #{organizationName},
|
||||
top_organization_id = #{topOrganizationId},
|
||||
update_time = sysdate()
|
||||
where dict_type = #{dictType}
|
||||
and IFNULL(organization_id, 0) = IFNULL(#{scopeOrganizationId}, 0)
|
||||
</update>
|
||||
|
||||
<insert id="insertDictData" parameterType="SysDictData">
|
||||
|
||||
@@ -13,10 +13,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="organizationId" column="organization_id" />
|
||||
<result property="organizationName" column="organization_name" />
|
||||
<result property="topOrganizationId" column="top_organization_id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDictTypeVo">
|
||||
select dict_id, dict_name, dict_type, status, create_by, create_time, remark
|
||||
select dict_id, dict_name, dict_type, status, create_by, create_time, remark,
|
||||
organization_id, organization_name, top_organization_id
|
||||
from sys_dict_type
|
||||
</sql>
|
||||
|
||||
@@ -32,6 +37,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="dictType != null and dictType != ''">
|
||||
AND dict_type like concat('%', #{dictType}, '%')
|
||||
</if>
|
||||
<if test="organizationId != null">
|
||||
AND organization_id = #{organizationId}
|
||||
</if>
|
||||
<if test="topOrganizationId != null">
|
||||
AND (top_organization_id = #{topOrganizationId} OR IFNULL(organization_id, 0) = 0)
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
@@ -53,11 +64,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="selectDictTypeByType" parameterType="String" resultMap="SysDictTypeResult">
|
||||
<include refid="selectDictTypeVo"/>
|
||||
where dict_type = #{dictType}
|
||||
order by (IFNULL(organization_id, 0) = 0) desc, dict_id asc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult">
|
||||
<select id="checkDictTypeUnique" parameterType="SysDictType" resultMap="SysDictTypeResult">
|
||||
<include refid="selectDictTypeVo"/>
|
||||
where dict_type = #{dictType} limit 1
|
||||
where dict_type = #{dictType}
|
||||
and IFNULL(organization_id, 0) = IFNULL(#{organizationId}, 0)
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<delete id="deleteDictTypeById" parameterType="Long">
|
||||
@@ -78,6 +93,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="organizationId != null">organization_id = #{organizationId},</if>
|
||||
<if test="organizationName != null">organization_name = #{organizationName},</if>
|
||||
<if test="topOrganizationId != null">top_organization_id = #{topOrganizationId},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
@@ -90,6 +108,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="dictType != null and dictType != ''">dict_type,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="organizationId != null">organization_id,</if>
|
||||
<if test="organizationName != null and organizationName != ''">organization_name,</if>
|
||||
<if test="topOrganizationId != null">top_organization_id,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
@@ -97,6 +118,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="dictType != null and dictType != ''">#{dictType},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="organizationId != null">#{organizationId},</if>
|
||||
<if test="organizationName != null and organizationName != ''">#{organizationName},</if>
|
||||
<if test="topOrganizationId != null">#{topOrganizationId},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user