use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.
the class SysSiteAdminController method save.
/**
* @param entity
* @param domainName
* @param roleName
* @param deptName
* @param userName
* @param password
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(SysSite entity, String domainName, String roleName, String deptName, String userName, String password, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
return TEMPLATE_ERROR;
}
if (!entity.isUseStatic()) {
entity.setUseSsi(false);
}
if (null != entity.getId()) {
entity = service.update(entity.getId(), entity, ignoreProperties);
if (null != entity) {
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
} else {
if (ControllerUtils.verifyCustom("needAuthorizationEdition", !CmsVersion.isAuthorizationEdition(), model) || ControllerUtils.verifyCustom("unauthorizedDomain", !CmsVersion.verifyDomain(domainName), model) || ControllerUtils.verifyNotEmpty("userName", userName, model) || ControllerUtils.verifyNotEmpty("password", password, model) || ControllerUtils.verifyHasExist("domain", service.getEntity(domainName), model)) {
return TEMPLATE_ERROR;
}
service.save(entity);
SysDomain domain = new SysDomain(domainName, entity.getId(), false);
domainService.save(domain);
SysDept dept = new SysDept(entity.getId(), deptName, 0, true, true);
// 初始化部门
deptService.save(dept);
SysRole role = new SysRole(entity.getId(), roleName, true, true);
// 初始化角色
roleService.save(role);
SysUser user = new SysUser(entity.getId(), userName, VerificationUtils.md5Encode(password), userName, dept.getId(), role.getId().toString(), null, false, true, false, null, null, 0, CommonUtils.getDate());
// 初始化用户
userService.save(user);
// 初始化角色用户映射
roleUserService.save(new SysRoleUser(new SysRoleUserId(role.getId(), user.getId())));
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
siteComponent.clear();
return TEMPLATE_DONEANDREFRESH;
}
use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.
the class SysDeptCategoryDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
Integer deptId = handler.getInteger("deptId");
Integer categoryId = handler.getInteger("categoryId");
if (CommonUtils.notEmpty(deptId)) {
if (CommonUtils.notEmpty(categoryId)) {
SysDept entity = sysDeptService.getEntity(deptId);
if (null != entity) {
if (entity.isOwnsAllCategory()) {
handler.put("object", true).render();
} else {
handler.put("object", null != service.getEntity(new SysDeptCategoryId(deptId, categoryId))).render();
}
}
} else {
Integer[] categoryIds = handler.getIntegerArray("categoryIds");
if (CommonUtils.notEmpty(categoryIds)) {
Map<String, Boolean> map = new LinkedHashMap<>();
SysDept entity = sysDeptService.getEntity(deptId);
if (null != entity) {
if (entity.isOwnsAllCategory()) {
for (Integer id : categoryIds) {
map.put(String.valueOf(id), true);
}
} else {
SysDeptCategoryId[] ids = new SysDeptCategoryId[categoryIds.length];
for (int i = 0; i < categoryIds.length; i++) {
map.put(String.valueOf(categoryIds[i]), false);
ids[i] = new SysDeptCategoryId(deptId, categoryIds[i]);
}
for (SysDeptCategory e : service.getEntitys(ids)) {
map.put(String.valueOf(e.getId().getCategoryId()), true);
}
}
}
handler.put("map", map).render();
}
}
}
}
use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.
the class SysDeptAdminController method enable.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping(value = "enableUser", method = RequestMethod.POST)
public String enable(Long id, HttpServletRequest request, HttpSession session, ModelMap model) {
if (ControllerUtils.verifyEquals("admin.operate", getAdminFromSession(session).getId(), id, model)) {
return TEMPLATE_ERROR;
}
SysUser entity = userService.getEntity(id);
if (null != entity) {
SysSite site = getSite(request);
SysDept dept = service.getEntity(entity.getDeptId());
SysUser admin = getAdminFromSession(session);
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model)) {
return TEMPLATE_ERROR;
}
userService.updateStatus(id, false);
logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "enable.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.
the class SysDeptAdminController method saveUser.
/**
* @param entity
* @param repassword
* @param roleIds
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("saveUser")
public String saveUser(SysUser entity, String repassword, Integer[] roleIds, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
entity.setName(StringUtils.trim(entity.getName()));
entity.setNickName(StringUtils.trim(entity.getNickName()));
entity.setPassword(StringUtils.trim(entity.getPassword()));
repassword = StringUtils.trim(repassword);
SysDept dept = service.getEntity(entity.getDeptId());
SysUser admin = getAdminFromSession(session);
if (ControllerUtils.verifyNotEmpty("username", entity.getName(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), dept.getSiteId(), model) || ControllerUtils.verifyNotEmpty("nickname", entity.getNickName(), model) || verifyNotUserName("username", entity.getName(), model) || verifyNotNickName("nickname", entity.getNickName(), model)) {
return TEMPLATE_ERROR;
}
entity.setSuperuserAccess(true);
entity.setRoles(arrayToCommaDelimitedString(roleIds));
if (null != entity.getId()) {
SysUser oldEntity = userService.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
SysUser user = userService.getEntity(entity.getId());
if ((!user.getName().equals(entity.getName()) && ControllerUtils.verifyHasExist("username", userService.findByName(site.getId(), entity.getName()), model)) || (!user.getNickName().equals(entity.getNickName()) && ControllerUtils.verifyHasExist("nickname", userService.findByNickName(site.getId(), entity.getNickName()), model))) {
return TEMPLATE_ERROR;
}
if (CommonUtils.notEmpty(entity.getPassword())) {
if (ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model)) {
return TEMPLATE_ERROR;
}
entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
} else {
entity.setPassword(user.getPassword());
if (CommonUtils.empty(entity.getEmail()) || !entity.getEmail().equals(user.getEmail())) {
entity.setEmailChecked(false);
}
}
entity = userService.update(entity.getId(), entity, userIgnoreProperties);
if (null != entity) {
roleUserService.dealRoleUsers(entity.getId(), roleIds);
logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
} else {
if (ControllerUtils.verifyNotEmpty("password", entity.getPassword(), model) || ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model) || ControllerUtils.verifyHasExist("username", userService.findByName(site.getId(), entity.getName()), model)) {
return TEMPLATE_ERROR;
}
entity.setDeptId(dept.getId());
entity.setSiteId(site.getId());
entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
userService.save(entity);
if (CommonUtils.notEmpty(roleIds)) {
for (Integer roleId : roleIds) {
roleUserService.save(new SysRoleUser(new SysRoleUserId(roleId, entity.getId())));
}
}
logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysDept in project PublicCMS-preview by sanluan.
the class SysDeptAdminController method save.
/**
* @param entity
* @param categoryIds
* @param pages
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(SysDept entity, Integer[] categoryIds, String[] pages, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (null != entity.getId()) {
SysDept oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
entity = service.update(entity.getId(), entity, ignoreProperties);
if (null != entity) {
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.dept", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
sysDeptCategoryService.updateDeptCategorys(entity.getId(), categoryIds);
sysDeptPageService.updateDeptPages(entity.getId(), pages);
} else {
entity.setSiteId(site.getId());
service.save(entity);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.dept", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
if (CommonUtils.notEmpty(categoryIds)) {
List<SysDeptCategory> list = new ArrayList<>();
for (int categoryId : categoryIds) {
list.add(new SysDeptCategory(new SysDeptCategoryId(entity.getId(), categoryId)));
}
sysDeptCategoryService.save(list);
}
if (CommonUtils.notEmpty(pages)) {
List<SysDeptPage> list = new ArrayList<>();
for (String page : pages) {
list.add(new SysDeptPage(new SysDeptPageId(entity.getId(), page)));
}
sysDeptPageService.save(list);
}
}
return TEMPLATE_DONE;
}
Aggregations