浏览代码

标签管理

master
父节点
当前提交
bc1c55aa6d
共有 16 个文件被更改,包括 568 次插入4 次删除
  1. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java
  2. +56
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/controller/TagController.java
  3. +174
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/manage/TagManage.java
  4. +15
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/mapper/ProjectTagMapper.java
  5. +15
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/mapper/TagMapper.java
  6. +36
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/dto/TagDTO.java
  7. +31
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/dto/TagToProjectDTO.java
  8. +40
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/entity/ProjectTag.java
  9. +45
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/entity/Tag.java
  10. +25
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/req/TagPageReq.java
  11. +40
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/vo/TagVO.java
  12. +14
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/IProjectTagService.java
  13. +14
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/ITagService.java
  14. +21
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/impl/ProjectTagServiceImpl.java
  15. +21
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/impl/TagServiceImpl.java
  16. +19
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/safety/manage/SafetyRiskManage.java

+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java 查看文件

@@ -31,7 +31,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
"com.ningdatech.pmapi.filemanage.controller",
"com.ningdatech.pmapi.performance.controller",
"com.ningdatech.pmapi.irs.controller",
"com.ningdatech.pmapi.safety.controller"
"com.ningdatech.pmapi.safety.controller",
"com.ningdatech.pmapi.portrait.controller"
})
public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {



+ 56
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/controller/TagController.java 查看文件

@@ -0,0 +1,56 @@
package com.ningdatech.pmapi.portrait.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.portrait.manage.TagManage;
import com.ningdatech.pmapi.portrait.model.dto.TagDTO;
import com.ningdatech.pmapi.portrait.model.dto.TagToProjectDTO;
import com.ningdatech.pmapi.portrait.model.req.TagPageReq;
import com.ningdatech.pmapi.portrait.model.vo.TagVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
* @Classname TagController
* @Description
* @Date 2023/8/2 14:11
* @Author PoffyZhang
*/
@RestController
@RequiredArgsConstructor
@Api(tags = "项目画像-标签")
@RequestMapping("/api/v1/portrait/tag")
public class TagController {
private final TagManage tagManage;

@GetMapping("/list/{areaCode}")
@ApiOperation("按区域查询标签列表")
public PageVo<TagVO> list(@PathVariable String areaCode, TagPageReq req) {
return tagManage.list(areaCode,req);
}

@PostMapping("/save")
@ApiOperation("保存标签")
@WebLog("保存标签")
public String save(@Valid @RequestBody TagDTO dto) {
return tagManage.save(dto);
}

@PostMapping("/save-to-project")
@ApiOperation("设置标签到项目")
@WebLog("设置标签到项目")
public String saveToProject(@Valid @RequestBody TagToProjectDTO dto) {
return tagManage.saveToProject(dto);
}

@PostMapping("/remove-tag-to-project")
@ApiOperation("项目删除标签")
@WebLog("项目删除标签")
public String removeTagToProject(@Valid @RequestBody TagToProjectDTO dto) {
return tagManage.removeTagToProject(dto);
}
}

+ 174
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/manage/TagManage.java 查看文件

@@ -0,0 +1,174 @@
package com.ningdatech.pmapi.portrait.manage;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.pmapi.portrait.model.dto.TagDTO;
import com.ningdatech.pmapi.portrait.model.dto.TagToProjectDTO;
import com.ningdatech.pmapi.portrait.model.entity.ProjectTag;
import com.ningdatech.pmapi.portrait.model.entity.Tag;
import com.ningdatech.pmapi.portrait.model.req.TagPageReq;
import com.ningdatech.pmapi.portrait.model.vo.TagVO;
import com.ningdatech.pmapi.portrait.service.IProjectTagService;
import com.ningdatech.pmapi.portrait.service.ITagService;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails;
import com.ningdatech.pmapi.user.util.LoginUserUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
* @Classname TagManage
* @Description
* @Date 2023/8/2 14:10
* @Author PoffyZhang
*/
@Component
@Slf4j
@AllArgsConstructor
public class TagManage {

private final ITagService tagService;

private final IProjectService projectService;

private final IProjectTagService projectTagService;

/**
* 标签分页
* @param areaCode
* @param req
* @return
*/
public PageVo<TagVO> list(String areaCode, TagPageReq req) {
LambdaQueryWrapper<Tag> query = Wrappers.lambdaQuery(Tag.class)
.eq(Tag::getAreaCode, areaCode)
.like(StringUtils.isNotBlank(req.getName()),Tag::getName,req.getName())
.orderByDesc(Tag::getUpdateOn);
checkAuth(query,LoginUserUtil.loginUserDetail());
Page<Tag> page = tagService.page(req.page(), query);
long total;
if ((total = page.getTotal()) == 0) {
return PageVo.empty();
}
List<TagVO> records = CollUtils.convert(page.getRecords(),
t -> BeanUtil.copyProperties(t,TagVO.class));
return PageVo.of(records, total);
}

/**
* 权限控制
* @param query
* @param user
*/
private void checkAuth(LambdaQueryWrapper<Tag> query, UserInfoDetails user) {
//如果是超管
if(user.getSuperAdmin()){
log.info(user.getUsername() + " 是超管,可以看所有标签");
}else if(user.getRegionAdmin()){
//如果是区域管理员
log.info(user.getUsername() + " 是区管,可以看本区域" + user.getRegionCode() + "标签");
query.eq(Tag::getAreaCode,user.getRegionCode());
}else{
//其它角色全都看不见
query.eq(Tag::getId,0L);
}
}

/**
* 保存标签
* @param dto
* @return
*/
public String save(TagDTO dto) {
deduplicationName(dto);
UserInfoDetails user = LoginUserUtil.loginUserDetail();
Tag entity = BeanUtil.copyProperties(dto,Tag.class);
if(Objects.nonNull(dto.getId())){
Tag old = tagService.getById(dto.getId());
VUtils.isTrue(Objects.isNull(old)).throwMessage("此id标签不存在!");
entity.setId(old.getId());
}else{
entity.setId(null);
entity.setCreateOn(LocalDateTime.now());
entity.setCreateBy(user.getUsername());
}
entity.setUpdateOn(LocalDateTime.now());
entity.setUpdateBy(user.getUsername());
tagService.saveOrUpdate(entity);

return "保存成功";
}

/**
* 标签名 去重
* @param dto
*/
private void deduplicationName(TagDTO dto) {
if(StringUtils.isNotBlank(dto.getName())){
long count = tagService.count(Wrappers.lambdaQuery(Tag.class)
.eq(Tag::getAreaCode, dto.getAreaCode())
.eq(Tag::getName, dto.getName())
.ne(Objects.nonNull(dto.getId()), Tag::getId, dto.getId()));
VUtils.isTrue(count > 0).throwMessage("保存失败!此区域标签名重复!");
}
}

public String saveToProject(TagToProjectDTO dto) {
UserInfoDetails user = LoginUserUtil.loginUserDetail();

String projectCode = dto.getProjectCode();
Project project = projectService.getProjectByCode(projectCode);
VUtils.isTrue(Objects.isNull(project)).throwMessage("项目不存在!");
Long tagId = dto.getTagId();
Tag tag = tagService.getById(tagId);
VUtils.isTrue(Objects.isNull(tag)).throwMessage("标签不存在!");

VUtils.isTrue(!tag.getAreaCode().equals(project.getAreaCode()))
.throwMessage("项目和标签不是一个区域的!");

ProjectTag projectTag = new ProjectTag();
projectTag.setProjectCode(projectCode);
projectTag.setTagId(tagId);
projectTag.setCreateOn(LocalDateTime.now());
projectTag.setCreateBy(user.getUsername());
projectTagService.save(projectTag);

return "保存成功";
}

public String removeTagToProject(TagToProjectDTO dto) {
UserInfoDetails user = LoginUserUtil.loginUserDetail();

String projectCode = dto.getProjectCode();
Project project = projectService.getProjectByCode(projectCode);
VUtils.isTrue(Objects.isNull(project)).throwMessage("项目不存在!");
Long tagId = dto.getTagId();
Tag tag = tagService.getById(tagId);
VUtils.isTrue(Objects.isNull(tag)).throwMessage("标签不存在!");

VUtils.isTrue(!tag.getAreaCode().equals(project.getAreaCode()))
.throwMessage("项目和标签不是一个区域的!");

ProjectTag pt = projectTagService.getOne(Wrappers.lambdaQuery(ProjectTag.class)
.eq(ProjectTag::getProjectCode, projectCode)
.eq(ProjectTag::getTagId, tagId));

VUtils.isTrue(Objects.isNull(pt))
.throwMessage("该项目没有绑定此标签!");
projectTagService.removeById(pt.getId());

return "删除成功";
}
}

+ 15
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/mapper/ProjectTagMapper.java 查看文件

@@ -0,0 +1,15 @@
package com.ningdatech.pmapi.portrait.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ningdatech.pmapi.portrait.model.entity.ProjectTag;

/**
* <p>
* </p>
*
* @author ZPF
* @since 2023-08-2
*/
public interface ProjectTagMapper extends BaseMapper<ProjectTag> {

}

+ 15
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/mapper/TagMapper.java 查看文件

@@ -0,0 +1,15 @@
package com.ningdatech.pmapi.portrait.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ningdatech.pmapi.portrait.model.entity.Tag;

/**
* <p>
* </p>
*
* @author ZPF
* @since 2023-08-2
*/
public interface TagMapper extends BaseMapper<Tag> {

}

+ 36
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/dto/TagDTO.java 查看文件

@@ -0,0 +1,36 @@
package com.ningdatech.pmapi.portrait.model.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
* <p>
* 标签
* </p>
*
* @author ZPF
* @since 2023-08-02
*/
@Data
@ApiModel(value = "Tag对象", description = "标签")
public class TagDTO implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty("主键")
private Long id;

@ApiModelProperty("标签名")
private String name;

@ApiModelProperty("备注")
private String remark;

@ApiModelProperty("区域CODE")
@NotNull(message = "区域CODE必填")
private String areaCode;
}

+ 31
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/dto/TagToProjectDTO.java 查看文件

@@ -0,0 +1,31 @@
package com.ningdatech.pmapi.portrait.model.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
* <p>
* 标签
* </p>
*
* @author ZPF
* @since 2023-08-02
*/
@Data
@ApiModel(value = "Tag对象", description = "标签")
public class TagToProjectDTO implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty("主键")
@NotNull(message = "标签ID必填")
private Long tagId;

@ApiModelProperty("当前项目编号")
@NotNull(message = "项目编号必填")
private String projectCode;
}

+ 40
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/entity/ProjectTag.java 查看文件

@@ -0,0 +1,40 @@
package com.ningdatech.pmapi.portrait.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* <p>
* 标签项目关联
* </p>
*
* @author ZPF
* @since 2023-08-02
*/
@Data
@TableName("nd_project_tag")
@ApiModel(value = "ProjectTag对象", description = "标签项目关联")
public class ProjectTag implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty("主键")
@TableId(type = IdType.AUTO)
private Long id;

@ApiModelProperty("项目编号")
private String projectCode;

@ApiModelProperty("标签ID")
private Long tagId;

private LocalDateTime createOn;
private String createBy;
}

+ 45
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/entity/Tag.java 查看文件

@@ -0,0 +1,45 @@
package com.ningdatech.pmapi.portrait.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* <p>
* 标签
* </p>
*
* @author ZPF
* @since 2023-08-02
*/
@Data
@TableName("nd_tag")
@ApiModel(value = "Tag对象", description = "标签")
public class Tag implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty("主键")
@TableId(type = IdType.AUTO)
private Long id;

@ApiModelProperty("标签名")
private String name;

@ApiModelProperty("备注")
private String remark;

@ApiModelProperty("区域CODE")
private String areaCode;

private LocalDateTime createOn;
private LocalDateTime updateOn;
private String createBy;
private String updateBy;
}

+ 25
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/req/TagPageReq.java 查看文件

@@ -0,0 +1,25 @@
package com.ningdatech.pmapi.portrait.model.req;

import com.ningdatech.basic.model.PagePo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

/**
* @Classname TagPageReq
* @Description
* @Date 2023/8/2 14:16
* @Author PoffyZhang
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("标签列表查询")
@EqualsAndHashCode(callSuper = true)
public class TagPageReq extends PagePo {

@ApiModelProperty("标签名")
private String name;

}

+ 40
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/model/vo/TagVO.java 查看文件

@@ -0,0 +1,40 @@
package com.ningdatech.pmapi.portrait.model.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* <p>
* 标签
* </p>
*
* @author ZPF
* @since 2023-08-02
*/
@Data
@ApiModel(value = "Tag对象", description = "标签")
public class TagVO implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty("主键")
private Long id;

@ApiModelProperty("标签名")
private String name;

@ApiModelProperty("备注")
private String remark;

@ApiModelProperty("区域CODE")
private String areaCode;

private LocalDateTime createOn;
private LocalDateTime updateOn;
private String createBy;
private String updateBy;
}

+ 14
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/IProjectTagService.java 查看文件

@@ -0,0 +1,14 @@
package com.ningdatech.pmapi.portrait.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.pmapi.portrait.model.entity.ProjectTag;

/**
* @Classname ITagService
* @Description
* @Date 2023/8/2 10:47
* @Author PoffyZhang
*/
public interface IProjectTagService extends IService<ProjectTag> {

}

+ 14
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/ITagService.java 查看文件

@@ -0,0 +1,14 @@
package com.ningdatech.pmapi.portrait.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.pmapi.portrait.model.entity.Tag;

/**
* @Classname ITagService
* @Description
* @Date 2023/8/2 10:47
* @Author PoffyZhang
*/
public interface ITagService extends IService<Tag> {

}

+ 21
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/impl/ProjectTagServiceImpl.java 查看文件

@@ -0,0 +1,21 @@
package com.ningdatech.pmapi.portrait.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.portrait.mapper.ProjectTagMapper;
import com.ningdatech.pmapi.portrait.model.entity.ProjectTag;
import com.ningdatech.pmapi.portrait.service.IProjectTagService;
import org.springframework.stereotype.Service;

/**
* <p>
* </p>
*
* @author ZPF
* @since 2023-08-2
*/
@Service
public class ProjectTagServiceImpl extends ServiceImpl<ProjectTagMapper,
ProjectTag> implements IProjectTagService {


}

+ 21
- 0
pmapi/src/main/java/com/ningdatech/pmapi/portrait/service/impl/TagServiceImpl.java 查看文件

@@ -0,0 +1,21 @@
package com.ningdatech.pmapi.portrait.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.portrait.mapper.TagMapper;
import com.ningdatech.pmapi.portrait.model.entity.Tag;
import com.ningdatech.pmapi.portrait.service.ITagService;
import org.springframework.stereotype.Service;

/**
* <p>
* </p>
*
* @author ZPF
* @since 2023-08-2
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper,
Tag> implements ITagService {


}

+ 19
- 3
pmapi/src/main/java/com/ningdatech/pmapi/safety/manage/SafetyRiskManage.java 查看文件

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.CollUtils;
@@ -64,7 +65,8 @@ public class SafetyRiskManage {
.ge(Project::getStatus, ProjectStatusEnum.UNDER_CONSTRUCTION.getCode())
.ne(Project::getStatus, ProjectStatusEnum.OPERATION.getCode())
.like(StringUtils.isNotBlank(req.getProjectName()),Project::getProjectName,req.getProjectName())
.like(StringUtils.isNotBlank(req.getBuildOrgName()),Project::getBuildOrgName,req.getBuildOrgName());
.like(StringUtils.isNotBlank(req.getBuildOrgName()),Project::getBuildOrgName,req.getBuildOrgName())
.orderByDesc(Project::getUpdateOn);
checkAuth(query,LoginUserUtil.loginUserDetail());
Page<Project> page = projectService.page(req.page(), query);
long total;
@@ -145,9 +147,16 @@ public class SafetyRiskManage {

UserInfoDetails user = LoginUserUtil.loginUserDetail();

String projectCode = dtos.get(0).getProjectCode();
if(StringUtils.isBlank(projectCode)){
throw new BizException("参数有误!");
}
supplierSafetyQualificationService.remove(Wrappers.lambdaQuery(SupplierSafetyQualification.class)
.eq(SupplierSafetyQualification::getProjectCode, projectCode));

Integer sucessNum = 0;
for(SupplierSafetyQualificationDTO dto : dtos){
String projectCode = dto.getProjectCode();
projectCode = dto.getProjectCode();
Project project = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getNewest, Boolean.TRUE)
.eq(Project::getProjectCode, projectCode)
@@ -176,9 +185,16 @@ public class SafetyRiskManage {

UserInfoDetails user = LoginUserUtil.loginUserDetail();

String projectCode = dtos.get(0).getProjectCode();
if(StringUtils.isBlank(projectCode)){
throw new BizException("参数有误!");
}
personSafetyInfoService.remove(Wrappers.lambdaQuery(PersonSafetyInfo.class)
.eq(PersonSafetyInfo::getProjectCode, projectCode));

Integer sucessNum = 0;
for(PersonSafetyInfoDTO dto : dtos){
String projectCode = dto.getProjectCode();
projectCode = dto.getProjectCode();
Project project = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getNewest, Boolean.TRUE)
.eq(Project::getProjectCode, projectCode)


正在加载...
取消
保存