@ -8,13 +8,16 @@ import java.util.stream.Collectors;
import javax.annotation.PostConstruct ;
import javax.annotation.PostConstruct ;
import com.hxhq.business.domain.SystemLog ;
import com.hxhq.business.domain.SystemLog ;
import com.hxhq.business.form.common.SignForm ;
import com.hxhq.business.service.ISystemLogService ;
import com.hxhq.business.service.ISystemLogService ;
import com.hxhq.business.utils.ObjectCompareUtil ;
import com.hxhq.business.utils.ObjectCompareUtil ;
import com.hxhq.common.security.utils.SecurityUtils ;
import com.hxhq.common.security.utils.SecurityUtils ;
import com.hxhq.system.api.domain.SysRole ;
import com.hxhq.system.api.domain.SysRole ;
import com.hxhq.system.domain.SysMenu ;
import com.hxhq.system.domain.SysMenu ;
import com.hxhq.system.form.DictSaveForm ;
import com.hxhq.system.mapper.SysDictDataMapper ;
import com.hxhq.system.mapper.SysDictDataMapper ;
import com.hxhq.system.mapper.SysDictTypeMapper ;
import com.hxhq.system.mapper.SysDictTypeMapper ;
import com.hxhq.system.service.ISysUserService ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
@ -42,6 +45,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
@Autowired
@Autowired
private ISystemLogService systemLogService ;
private ISystemLogService systemLogService ;
@Autowired
private ISysUserService userService ;
/ * *
/ * *
* 项目启动时 , 初始化字典到缓存
* 项目启动时 , 初始化字典到缓存
@ -125,24 +130,21 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
/ * *
/ * *
* 批量删除字典类型信息
* 批量删除字典类型信息
*
*
* @param dictIds 需要删除的字典ID
* @param form 需要删除的字典ID
* /
* /
@Override
@Override
public void deleteDictTypeByIds ( Long [ ] dictIds )
public void deleteDictTypeByIds ( DictSaveForm form )
{
{
for ( Long dictId : dictIds )
userService . checkPassword ( SecurityUtils . getLoginUser ( ) . getSysUser ( ) , form . getSign ( ) . getQmrmm ( ) , false ) ;
Long dictId = form . getDict ( ) . getDictId ( ) ;
SysDictType dictType = selectDictTypeById ( dictId ) ;
if ( dictDataMapper . countDictDataByType ( dictType . getDictType ( ) ) > 0 )
{
{
SysDictType dictType = selectDictTypeById ( dictId ) ;
if ( dictDataMapper . countDictDataByType ( dictType . getDictType ( ) ) > 0 )
{
throw new ServiceException ( String . format ( "%1$s已分配,不能删除" , dictType . getDictName ( ) ) ) ;
}
dictTypeMapper . deleteDictTypeById ( dictId ) ;
DictUtils . removeDictCache ( dictType . getDictType ( ) ) ;
systemLogService . saveInfo ( dictType . getDictName ( ) , null , "删除字典" , "Remove Term Book" , null , null , SecurityUtils . getUserId ( ) , SecurityUtils . getNickName ( ) , SecurityUtils . getUsername ( ) , null ) ;
throw new ServiceException ( String . format ( "%1$s已分配,不能删除" , dictType . getDictName ( ) ) ) ;
}
}
dictTypeMapper . deleteDictTypeById ( dictId ) ;
DictUtils . removeDictCache ( dictType . getDictType ( ) ) ;
systemLogService . saveInfo ( dictType . getDictName ( ) , null , "删除字典" , "Remove Term Book" , null , null , SecurityUtils . getUserId ( ) , SecurityUtils . getNickName ( ) , SecurityUtils . getUsername ( ) , form . getSign ( ) . getRemark ( ) ) ;
}
}
/ * *
/ * *
@ -182,31 +184,35 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
/ * *
/ * *
* 新增保存字典类型信息
* 新增保存字典类型信息
*
*
* @param dict 字典类型信息
* @param form 字典类型信息
* @return 结果
* @return 结果
* /
* /
@Override
@Override
public int insertDictType ( SysDictType dict )
public int insertDictType ( DictSaveForm form )
{
{
userService . checkPassword ( SecurityUtils . getLoginUser ( ) . getSysUser ( ) , form . getSign ( ) . getQmrmm ( ) , false ) ;
SysDictType dict = form . getDict ( ) ;
int row = dictTypeMapper . insertDictType ( dict ) ;
int row = dictTypeMapper . insertDictType ( dict ) ;
if ( row > 0 )
if ( row > 0 )
{
{
DictUtils . setDictCache ( dict . getDictType ( ) , null ) ;
DictUtils . setDictCache ( dict . getDictType ( ) , null ) ;
}
}
systemLogService . saveInfo ( dict . getDictName ( ) , null , "新增字典" , "Create Term Book" , null , null , SecurityUtils . getUserId ( ) , SecurityUtils . getNickName ( ) , SecurityUtils . getUsername ( ) , null ) ;
systemLogService . saveInfo ( dict . getDictName ( ) , null , "新增字典" , "Create Term Book" , null , null , SecurityUtils . getUserId ( ) , SecurityUtils . getNickName ( ) , SecurityUtils . getUsername ( ) , form . getSign ( ) . getRemark ( ) ) ;
return row ;
return row ;
}
}
/ * *
/ * *
* 修改保存字典类型信息
* 修改保存字典类型信息
*
*
* @param dict 字典类型信息
* @param form 字典类型信息
* @return 结果
* @return 结果
* /
* /
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public int updateDictType ( SysDictType dict )
public int updateDictType ( DictSaveForm form )
{
{
userService . checkPassword ( SecurityUtils . getLoginUser ( ) . getSysUser ( ) , form . getSign ( ) . getQmrmm ( ) , false ) ;
SysDictType dict = form . getDict ( ) ;
SysDictType oldDict = dictTypeMapper . selectDictTypeById ( dict . getDictId ( ) ) ;
SysDictType oldDict = dictTypeMapper . selectDictTypeById ( dict . getDictId ( ) ) ;
dictDataMapper . updateDictDataType ( oldDict . getDictType ( ) , dict . getDictType ( ) ) ;
dictDataMapper . updateDictDataType ( oldDict . getDictType ( ) , dict . getDictType ( ) ) ;
int row = dictTypeMapper . updateDictType ( dict ) ;
int row = dictTypeMapper . updateDictType ( dict ) ;
@ -216,7 +222,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
DictUtils . setDictCache ( dict . getDictType ( ) , dictDatas ) ;
DictUtils . setDictCache ( dict . getDictType ( ) , dictDatas ) ;
}
}
List < SystemLog > logList = getModifyLogList ( dict , oldDict ) ;
List < SystemLog > logList = getModifyLogList ( dict , oldDict , form . getSign ( ) ) ;
if ( logList . size ( ) > 0 ) {
if ( logList . size ( ) > 0 ) {
systemLogService . saveBatch ( logList ) ;
systemLogService . saveBatch ( logList ) ;
}
}
@ -247,12 +253,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* @param old
* @param old
* @return
* @return
* /
* /
private List < SystemLog > getModifyLogList ( SysDictType info , SysDictType old ) {
private List < SystemLog > getModifyLogList ( SysDictType info , SysDictType old , SignForm sign ) {
List < SystemLog > list = new ArrayList < > ( ) ;
List < SystemLog > list = new ArrayList < > ( ) ;
List < ObjectCompareUtil . FieldChange > fieldChanges = ObjectCompareUtil . compareObjects ( old , info ) ;
List < ObjectCompareUtil . FieldChange > fieldChanges = ObjectCompareUtil . compareObjects ( old , info ) ;
for ( ObjectCompareUtil . FieldChange fieldChange : fieldChanges ) {
for ( ObjectCompareUtil . FieldChange fieldChange : fieldChanges ) {
SystemLog log = getLogInfo ( old ) ;
SystemLog log = getLogInfo ( old , sign ) ;
log . setJcnr ( fieldChange . toString ( ) ) ;
log . setJcnr ( fieldChange . toString ( ) ) ;
log . setJcnrEn ( fieldChange . toEnString ( ) ) ;
log . setJcnrEn ( fieldChange . toEnString ( ) ) ;
list . add ( log ) ;
list . add ( log ) ;
@ -264,7 +270,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* 获取日志基础信息
* 获取日志基础信息
* @return
* @return
* /
* /
private SystemLog getLogInfo ( SysDictType sysDictType ) {
private SystemLog getLogInfo ( SysDictType sysDictType , SignForm sign ) {
SystemLog log = new SystemLog ( ) ;
SystemLog log = new SystemLog ( ) ;
log . setName ( sysDictType . getDictName ( ) ) ;
log . setName ( sysDictType . getDictName ( ) ) ;
log . setNameEn ( sysDictType . getDictName ( ) ) ;
log . setNameEn ( sysDictType . getDictName ( ) ) ;
@ -273,6 +279,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
log . setQmrId ( SecurityUtils . getUserId ( ) ) ;
log . setQmrId ( SecurityUtils . getUserId ( ) ) ;
log . setQmrMc ( SecurityUtils . getNickName ( ) ) ;
log . setQmrMc ( SecurityUtils . getNickName ( ) ) ;
log . setQmrMcEn ( SecurityUtils . getUsername ( ) ) ;
log . setQmrMcEn ( SecurityUtils . getUsername ( ) ) ;
log . setRemark ( sign . getRemark ( ) ) ;
return log ;
return log ;
}
}
}
}