|
|
@@ -10,9 +10,10 @@ import com.github.microservice.auth.client.service.OrganizationUserService;
|
|
|
import com.github.microservice.auth.client.service.RoleService;
|
|
|
import com.github.microservice.auth.client.service.UserService;
|
|
|
import com.github.microservice.auth.client.type.LoginType;
|
|
|
+import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
-import com.zhongshu.card.client.model.org.OrganizationAddParam;
|
|
|
-import com.zhongshu.card.client.model.org.OrganizationModel;
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.zhongshu.card.client.model.org.*;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
@@ -28,12 +29,17 @@ import com.zhongshu.card.server.core.domain.org.Role;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import com.zhongshu.card.server.core.util.DateUtils;
|
|
|
import com.zhongshu.card.server.core.util.NextNoUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
@@ -78,6 +84,8 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
|
|
|
@Autowired
|
|
|
DepartmentServiceImpl departmentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AuthHelper authHelper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -88,6 +96,7 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultContent addOrganization(OrganizationAddParam param) {
|
|
|
+ param.setId(null);
|
|
|
// 验证数据
|
|
|
Organization temp = organizationDao.findTopByName(param.getName());
|
|
|
if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
@@ -97,6 +106,12 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
|
|
|
if (authType == AuthType.Platform) {
|
|
|
return ResultContent.buildFail("机构类型错误");
|
|
|
}
|
|
|
+ String contactPhone = param.getContactPhone();
|
|
|
+ List<AuthType> authTypes = List.of(AuthType.School, AuthType.Shop, AuthType.Enterprise);
|
|
|
+ if (authTypes.contains(authType)) {
|
|
|
+ Assert.hasText(contactPhone, "contactPhone 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
String code = param.getCode();
|
|
|
if (StringUtils.isEmpty(code)) {
|
|
|
code = NextNoUtil.getNextNo(authType.getCode().toUpperCase());
|
|
|
@@ -130,29 +145,119 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
|
|
|
Organization organization = new Organization();
|
|
|
BeanUtils.copyProperties(param, organization);
|
|
|
organization.setOid(oid);
|
|
|
+ organization.setCreateUserId(getCurrentUserId());
|
|
|
organizationDao.save(organization);
|
|
|
|
|
|
- // 初始机构数据
|
|
|
- initOrganization(organization);
|
|
|
+ // 不为项目的时候,要初始数据
|
|
|
+ if (authType != AuthType.Project) {
|
|
|
+ // 初始机构数据
|
|
|
+ initOrganization(organization);
|
|
|
+ }
|
|
|
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 编辑机构
|
|
|
+ * 编辑机构 (编辑基本信息)
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResultContent update(OrganizationAddParam param) {
|
|
|
- Organization organization = new Organization();
|
|
|
-
|
|
|
+ public ResultContent update(OrganizationUpdateParam param) {
|
|
|
+ Organization organization = organizationDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ Organization temp = organizationDao.findTopByName(param.getName());
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ if (!temp.getId().equals(param.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIST, param.getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ BeanUtils.copyProperties(param, organization);
|
|
|
organizationDao.save(organization);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除机构
|
|
|
+ * @param oid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public ResultContent deleteOrganization(String oid) {
|
|
|
+ Assert.hasText(oid, "oid不能为空");
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
|
|
|
+ }
|
|
|
+ if(organization.getAuthType() == AuthType.Platform) {
|
|
|
+ return ResultContent.buildFail(String.format("该类型数据不能删除: %s", organization.getAuthType().getRemark()));
|
|
|
+ }
|
|
|
+ String currentOid = getCurrentOid();
|
|
|
+ if (StringUtils.isNotEmpty(currentOid) && currentOid.equals(oid)) {
|
|
|
+ return ResultContent.buildFail(String.format("不能删除当前结构"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除
|
|
|
+ organizationDao.delete(organization);
|
|
|
+
|
|
|
+ // 删除用户关系
|
|
|
+ organizationUserDao.deleteByOrganization(organization);
|
|
|
+
|
|
|
+ // 删除角色?
|
|
|
+
|
|
|
+ // 删除部门
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页数据
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<Page<OrganizationModel>> page(OrganizationSearchParam param, Pageable pageable) {
|
|
|
+ List<Long> times = param.getTimes();
|
|
|
+ if (ObjectUtils.isNotEmpty(times) && times.size() == 2) {
|
|
|
+ Long startTime = times.get(0);
|
|
|
+ startTime = DateUtils.getDayStartTime(startTime);
|
|
|
+ Long endTime = times.get(1);
|
|
|
+ endTime = DateUtils.getDayEndTime(endTime);
|
|
|
+ param.setStartTime(startTime);
|
|
|
+ param.setEndTime(endTime);
|
|
|
+ }
|
|
|
+ Page<Organization> page = organizationDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页数据
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<Page<OrganizationModel>> pageProject(OrganizationSearchParam param, Pageable pageable) {
|
|
|
+ List<Long> times = param.getTimes();
|
|
|
+ if (ObjectUtils.isNotEmpty(times) && times.size() == 2) {
|
|
|
+ Long startTime = times.get(0);
|
|
|
+ startTime = DateUtils.getDayStartTime(startTime);
|
|
|
+ Long endTime = times.get(1);
|
|
|
+ endTime = DateUtils.getDayEndTime(endTime);
|
|
|
+ param.setStartTime(startTime);
|
|
|
+ param.setEndTime(endTime);
|
|
|
+ }
|
|
|
+ Page<Organization> page = organizationDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toProjectModel));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始平台信息
|
|
|
*
|
|
|
@@ -337,4 +442,18 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
|
|
|
}
|
|
|
return model;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目的信息模型
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ProjectOrgModel toProjectModel(Organization entity) {
|
|
|
+ ProjectOrgModel model = new ProjectOrgModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
}
|