|
@@ -17,14 +17,19 @@ import com.gis.common.util.EncryptUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.db.entity.dto.ProjectDto;
|
|
|
import com.gis.db.entity.po.ProjectEntity;
|
|
|
+import com.gis.db.entity.po.TableEntity;
|
|
|
import com.gis.db.mapper.ProjectMapper;
|
|
|
+import com.gis.db.service.FieldService;
|
|
|
import com.gis.db.service.ProjectService;
|
|
|
+import com.gis.db.service.TableService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -43,6 +48,12 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectEntity
|
|
|
@Autowired
|
|
|
SysUserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ TableService tableService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FieldService fieldService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result pageList(PageDto param) {
|
|
@@ -50,11 +61,16 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectEntity
|
|
|
IPage<ProjectEntity> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
LambdaQueryWrapper<ProjectEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
// 授权才能看到响应的项目
|
|
|
+
|
|
|
+ Long userId = baseService.getUserId();
|
|
|
if (baseService.getIsAdmin()==0){
|
|
|
- SysUserEntity entity = userService.cacheById(baseService.getUserId());
|
|
|
+ SysUserEntity entity = userService.cacheById(userId);
|
|
|
// inSql以字符串形式传入
|
|
|
- wrapper.inSql(ProjectEntity::getId, entity.getProjectIds());
|
|
|
+ wrapper.eq(ProjectEntity::getCreatorId, userId).or();
|
|
|
+ String projectIds = entity.getProjectIds();
|
|
|
+ wrapper.inSql(StrUtil.isNotBlank(projectIds), ProjectEntity::getId, projectIds);
|
|
|
}
|
|
|
+
|
|
|
String searchKey = param.getSearchKey();
|
|
|
wrapper.like(StrUtil.isNotBlank(searchKey), ProjectEntity::getName, searchKey);
|
|
|
wrapper.orderByDesc(ProjectEntity::getCreateTime);
|
|
@@ -84,20 +100,48 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectEntity
|
|
|
if (flag){
|
|
|
Long projectId = entity.getId();
|
|
|
createAppId(projectId);
|
|
|
- // 授权项目
|
|
|
- SysUserEntity userEntity = userService.getById(userId);
|
|
|
- String projectIds = userEntity.getProjectIds();
|
|
|
- if (StrUtil.isNotBlank(projectIds)){
|
|
|
- projectIds = projectIds + "," + projectId;
|
|
|
- } else {
|
|
|
- projectIds = projectId.toString();
|
|
|
- }
|
|
|
- userService.authProject(projectIds, userId.toString());
|
|
|
+// // 授权项目
|
|
|
+// SysUserEntity userEntity = userService.getById(userId);
|
|
|
+// String projectIds = userEntity.getProjectIds();
|
|
|
+// if (StrUtil.isNotBlank(projectIds)){
|
|
|
+// projectIds = projectIds + "," + projectId;
|
|
|
+// } else {
|
|
|
+// projectIds = projectId.toString();
|
|
|
+// }
|
|
|
+// userService.authProject(projectIds, userId.toString());
|
|
|
|
|
|
}
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result del(Long id) {
|
|
|
+ ProjectEntity entity = this.getById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除逻辑
|
|
|
+ List<TableEntity> tables = tableService.findByProjectId(id);
|
|
|
+ ArrayList<String> tableNames = new ArrayList<>();
|
|
|
+ ArrayList<Long> tableIds = new ArrayList<>();
|
|
|
+ for (TableEntity table : tables) {
|
|
|
+ tableNames.add(table.getNameTable());
|
|
|
+ tableIds.add(table.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 物理删除对用的表
|
|
|
+ tableService.delTables(tableNames);
|
|
|
+ // 删除表记录
|
|
|
+ tableService.delByProjectId(id);
|
|
|
+ // 删除字段记录
|
|
|
+ fieldService.removeBatchByTableId(tableIds);
|
|
|
+
|
|
|
+ // 删除项目记录
|
|
|
+ this.removeById(entity);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
private String createAppId(Long id) {
|
|
|
try {
|
|
|
String appId = EncryptUtils.desEncrypt(APP_SALT + id);
|