ProjectTemplate projectTemplate = getProjectTemplate(category.getCode());
//
String projectCode = String.valueOf(10000000 + projectUser.getId());
//
Date now = new Date();
Project project = new Project();
project.setCode(projectCode);
project.setTitle(projectUser.getNickname());
project.setDescription(projectTemplate.getDescription());
project.setCategoryId(category.getId());
project.setCreatedAt(now);
project.setModifiedAt(now);
project.setCreatedById(projectUser.getId());
project.setModifiedById(projectUser.getId());
//
projectDao.insert(project);
// 更新 注册用户的 project id
projectUser.setProjectId(project.getId());
projectUserDao.update(projectUser);
//
for(ProjectFeature projectFeature : projectTemplate.getProjectFeatures()) {
projectFeature.setProjectId(project.getId());
projectFeatureDao.insert(projectFeature);
}
//
for(ProjectRole projectRole : projectTemplate.getProjectRoles()) {
// project role
projectRole.setProjectId(project.getId());
projectRoleDao.insert(projectRole);
for(ProjectAuthority projectAuthority : projectTemplate.getProjectAuthorities(projectRole)) {
// project authority
ProjectAuthority _projectAuthority = projectAuthorityDao.selectByCode(projectAuthority.getCode());
// project permission
ProjectPermission projectPermission = new ProjectPermission();
projectPermission.setProjectId(project.getId());
projectPermission.setProjectRoleId(projectRole.getId());
projectPermission.setProjectAuthorityId(_projectAuthority.getId());
projectPermission.setEnabled(projectAuthority.isEnabled());
//
projectPermissionDao.insert(projectPermission);