use of com.netsteadfast.greenstep.po.hbm.TbSysMenuRole in project bamboobsc by billchen198318.
the class RoleLogicServiceImpl method updateMenuRole.
/**
* 更新存在選單中程式的選單所屬 role
*
* @param progOid
* @param roles
* @return
* @throws ServiceException
* @throws Exception
*/
@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> updateMenuRole(String progOid, List<String> roles) throws ServiceException, Exception {
if (super.isBlank(progOid)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
SysProgVO sysProg = new SysProgVO();
sysProg.setOid(progOid);
DefaultResult<SysProgVO> spResult = this.sysProgService.findObjectByOid(sysProg);
if (spResult.getValue() == null) {
throw new ServiceException(spResult.getSystemMessage().getValue());
}
sysProg = spResult.getValue();
DefaultResult<Boolean> result = new DefaultResult<Boolean>();
result.setValue(false);
result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
Map<String, Object> params = new HashMap<String, Object>();
params.put("progId", sysProg.getProgId());
List<TbSysMenuRole> sysMenuRoleList = this.sysMenuRoleService.findListByParams(params);
for (int i = 0; sysMenuRoleList != null && i < sysMenuRoleList.size(); i++) {
TbSysMenuRole sysMenuRole = sysMenuRoleList.get(i);
this.sysMenuRoleService.delete(sysMenuRole);
}
for (int i = 0; roles != null && i < roles.size(); i++) {
String roleOid = roles.get(i).trim();
if (super.isBlank(roleOid)) {
continue;
}
RoleVO role = new RoleVO();
role.setOid(roleOid);
DefaultResult<RoleVO> rResult = this.roleService.findObjectByOid(role);
if (rResult.getValue() == null) {
throw new ServiceException(rResult.getSystemMessage().getValue());
}
role = rResult.getValue();
SysMenuRoleVO sysMenuRole = new SysMenuRoleVO();
sysMenuRole.setProgId(sysProg.getProgId());
sysMenuRole.setRole(role.getRole());
DefaultResult<SysMenuRoleVO> smrResult = this.sysMenuRoleService.saveObject(sysMenuRole);
if (smrResult.getValue() == null) {
throw new ServiceException(smrResult.getSystemMessage().getValue());
}
}
result.setValue(true);
result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
return result;
}
use of com.netsteadfast.greenstep.po.hbm.TbSysMenuRole in project bamboobsc by billchen198318.
the class RoleLogicServiceImpl method copyAsNew.
/**
* 拷備一份role
*
* @param fromRoleOid
* @param role
* @return
* @throws ServiceException
* @throws Exception
*/
@ServiceMethodAuthority(type = { ServiceMethodType.INSERT })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<RoleVO> copyAsNew(String fromRoleOid, RoleVO role) throws ServiceException, Exception {
if (role == null || super.isBlank(role.getRole()) || super.isBlank(fromRoleOid)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
super.setStringValueMaxLength(role, "description", MAX_DESCRIPTION_LENGTH);
DefaultResult<RoleVO> result = this.roleService.saveObject(role);
RoleVO oldRole = new RoleVO();
oldRole.setOid(fromRoleOid);
DefaultResult<RoleVO> fromResult = this.roleService.findObjectByOid(oldRole);
if (fromResult.getValue() == null) {
throw new ServiceException(fromResult.getSystemMessage().getValue());
}
oldRole = fromResult.getValue();
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("role", oldRole.getRole());
List<TbRolePermission> permissions = this.rolePermissionService.findListByParams(paramMap);
for (int i = 0; permissions != null && i < permissions.size(); i++) {
RolePermissionVO permission = new RolePermissionVO();
this.rolePermissionService.fillToValueObject(permission, permissions.get(i));
permission.setOid(null);
permission.setRole(result.getValue().getRole());
this.rolePermissionService.saveObject(permission);
}
// 選單menu role 也copy一份
List<TbSysMenuRole> menuRoles = this.sysMenuRoleService.findListByParams(paramMap);
for (int i = 0; menuRoles != null && i < menuRoles.size(); i++) {
SysMenuRoleVO menuRole = new SysMenuRoleVO();
this.sysMenuRoleService.fillToValueObject(menuRole, menuRoles.get(i));
menuRole.setOid(null);
menuRole.setRole(result.getValue().getRole());
this.sysMenuRoleService.saveObject(menuRole);
}
return result;
}
use of com.netsteadfast.greenstep.po.hbm.TbSysMenuRole in project bamboobsc by billchen198318.
the class SystemProgramLogicServiceImpl method delete.
/**
* 刪除 TB_SYS_PROG 資料
*
* @param sysProg
* @return
* @throws ServiceException
* @throws Exception
*/
@ServiceMethodAuthority(type = { ServiceMethodType.DELETE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> delete(SysProgVO sysProg) throws ServiceException, Exception {
if (sysProg == null || StringUtils.isBlank(sysProg.getOid())) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
DefaultResult<SysProgVO> sysProgResult = this.sysProgService.findObjectByOid(sysProg);
if (sysProgResult.getValue() == null) {
throw new ServiceException(sysProgResult.getSystemMessage().getValue());
}
sysProg = sysProgResult.getValue();
Map<String, Object> params = new HashMap<String, Object>();
params.put("progId", sysProg.getProgId());
if (this.sysMenuService.countByParams(params) > 0) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_CANNOT_DELETE));
}
// 刪除 TB_SYS_MENU_ROLE 資料
List<TbSysMenuRole> sysMenuRoleList = this.sysMenuRoleService.findListByParams(params);
for (int i = 0; sysMenuRoleList != null && i < sysMenuRoleList.size(); i++) {
TbSysMenuRole sysMenuRole = sysMenuRoleList.get(i);
this.sysMenuRoleService.delete(sysMenuRole);
}
// 刪除名稱語言資料 tb_sys_prog_multi_name
List<TbSysProgMultiName> progMultiNames = this.sysProgMultiNameService.findListByParams(params);
for (int i = 0; progMultiNames != null && i < progMultiNames.size(); i++) {
this.sysProgMultiNameService.delete(progMultiNames.get(i));
}
return this.sysProgService.deleteObject(sysProg);
}
Aggregations