Browse Source

更新职务档案

jihs 4 years ago
parent
commit
e1692dfa3c

+ 85 - 0
src/main/java/org/jeecg/common/dto/basedata/ArchivesPostListRespDTO.java

@@ -0,0 +1,85 @@
+package org.jeecg.common.dto.basedata;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.jeecg.modules.basedata.entity.BaseArchivesPost;
+import java.util.List;
+
+/**
+   * @Author jihaosen
+   * @date 2021/2/23
+   * @desc 职务档案参数返回
+   */
+public class ArchivesPostListRespDTO {
+    @ApiModelProperty("key")
+    private String key;
+    @ApiModelProperty("父节点id")
+    private String parentId;
+    @ApiModelProperty("职务编码")
+    private String code;
+    @ApiModelProperty("职务名称")
+    private String title;
+    @ApiModelProperty(" 是否叶子节点: 1:是 0:不是")
+    private boolean isLeaf;
+
+    private List<ArchivesPostListRespDTO> children;
+
+    public ArchivesPostListRespDTO() {
+    }
+
+    public ArchivesPostListRespDTO(BaseArchivesPost baseArchivesPost) {
+        this.key = baseArchivesPost.getId();
+        this.parentId = baseArchivesPost.getParentId();
+        this.code = baseArchivesPost.getCode();
+        this.title = baseArchivesPost.getName();
+        this.isLeaf = false;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(String parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public boolean getIsLeaf() {
+        return isLeaf;
+    }
+
+    public void setIsLeaf(boolean leaf) {
+        isLeaf = leaf;
+    }
+
+    public List<ArchivesPostListRespDTO> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<ArchivesPostListRespDTO> children) {
+        this.children = children;
+    }
+}

+ 206 - 0
src/main/java/org/jeecg/modules/basedata/controller/BaseArchivesPostController.java

@@ -0,0 +1,206 @@
+package org.jeecg.modules.basedata.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.common.collect.Lists;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.authz.annotation.Logical;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.NotDuplicate;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.dto.basedata.ArchivesPostListRespDTO;
+import org.jeecg.modules.basedata.entity.BaseArchivesPost;
+import org.jeecg.modules.basedata.entity.FdContractClass;
+import org.jeecg.modules.basedata.service.BaseArchivesPostService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import javax.validation.Valid;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Author jihaosen
+ * @date 2021/2/23
+ * @desc 职务档案 controller
+ */
+@Api(value = "职务档案")
+@RestController
+@RequestMapping("/base/archivesPost")
+@Slf4j
+public class BaseArchivesPostController {
+    @Autowired
+    private BaseArchivesPostService baseArchivesPostService;
+
+    /**
+     * @desc 职务档案列表查询
+     */
+    @ApiOperation(value = "职务档案列表查询", notes = "职务档案列表查询")
+    @GetMapping(value = "/list")
+    public Result<List<ArchivesPostListRespDTO>> queryList() {
+        Result<List<ArchivesPostListRespDTO>> result = new Result<List<ArchivesPostListRespDTO>>();
+        QueryWrapper<BaseArchivesPost> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("del_flag", CommonConstant.STATUS_NORMAL.toString());
+        queryWrapper.orderByDesc("create_time");
+        List<BaseArchivesPost> list = baseArchivesPostService.list(queryWrapper);
+        List<ArchivesPostListRespDTO> respDTOS = getTreeList(list);
+        result.setSuccess(true);
+        result.setResult(respDTOS);
+        return result;
+    }
+
+    /**
+     * @desc  添加职务档案
+     */
+    @ApiOperation(value = "新增职务档案", notes = "新增职务档案")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="parentId", value="父节点",required=true, dataType="String"),
+            @ApiImplicitParam(name="code", value="职务编码",required=true, dataType="String"),
+            @ApiImplicitParam(name="name", value="职务名称",required=true, dataType="String"),
+            @ApiImplicitParam(name="pkOrg", value="组织",required=false, dataType="String"),
+    })
+    @PostMapping(value = "/add")
+    @NotDuplicate
+//    @RequiresPermissions(value = {"contract-class:add","contract-class-parent:add"},logical = Logical.OR)
+    public Result<BaseArchivesPost> add(@RequestBody @Valid BaseArchivesPost baseArchivesPost, BindingResult bindingResult) {
+        Result<BaseArchivesPost> result = new Result<BaseArchivesPost>();
+        try {
+            StringBuilder sb = new StringBuilder();
+            if (bindingResult.hasErrors()){
+                //记录错误信息
+                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
+                result.error500(sb.toString());
+                return result;
+            }
+            //查询是否有同样编码
+            LambdaQueryWrapper<BaseArchivesPost> contractClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            contractClassLambdaQueryWrapper.eq(BaseArchivesPost::getCode,baseArchivesPost.getCode());
+            contractClassLambdaQueryWrapper.eq(BaseArchivesPost::getDelFlag,"0");
+            List<BaseArchivesPost> contractClassList = baseArchivesPostService.list(contractClassLambdaQueryWrapper);
+            if(contractClassList.size()>0){
+                throw new RuntimeException("编码不能重复");
+            }
+            baseArchivesPost.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
+            baseArchivesPostService.save(baseArchivesPost);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.info(e.getMessage());
+            result.error500("操作失败:"+e.getMessage());
+
+        }
+        return result;
+    }
+
+    /**
+     *  @desc 编辑职务档案
+     */
+    @ApiOperation(value = "编辑职务档案", notes = "编辑职务档案")
+    @PostMapping(value = "/edit")
+    @NotDuplicate
+//    @RequiresPermissions("contract-class:update")
+    public Result<BaseArchivesPost> edit(@RequestBody @Valid BaseArchivesPost baseArchivesPost, BindingResult bindingResult) {
+        Result<BaseArchivesPost> result = new Result<BaseArchivesPost>();
+        BaseArchivesPost baseArchivesPostEntity = baseArchivesPostService.getById(baseArchivesPost.getId());
+        if(baseArchivesPostEntity == null) {
+            result.error500("未找到对应实体");
+        }else {
+            StringBuilder sb = new StringBuilder();
+            if (bindingResult.hasErrors()){
+                //记录错误信息
+                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
+                result.error500(sb.toString());
+                return result;
+            }
+            boolean ok = baseArchivesPostService.updateById(baseArchivesPost);
+            if(ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * @desc 通过id删除
+     */
+    @ApiOperation(value = "通过id删除", notes = "通过id删除")
+    @PostMapping(value = "/delete")
+    @NotDuplicate
+//    @RequiresPermissions("contract-class:delete")
+    public Result<FdContractClass> delete(@RequestBody @Valid BaseArchivesPost baseArchivesPost) {
+        Result<FdContractClass> result = new Result<FdContractClass>();
+        BaseArchivesPost baseArchivesPostEntity = baseArchivesPostService.getById(baseArchivesPost.getId());
+        if(baseArchivesPostEntity == null) {
+            result.error500("未找到对应实体");
+        }else {
+            baseArchivesPostEntity.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
+            boolean ok = baseArchivesPostService.updateById(baseArchivesPostEntity);
+            if(ok) {
+                result.success("删除成功!");
+            }
+        }
+
+        return result;
+    }
+
+
+
+    /**
+     * @desc 获取职务档案的数据
+     */
+    private List<ArchivesPostListRespDTO> getTreeList(List<BaseArchivesPost> list) {
+        List<ArchivesPostListRespDTO> resp = Lists.newArrayList();
+        //根据parentId分组
+        Map<String, List<BaseArchivesPost>> postMap = list.stream().collect(Collectors.groupingBy(BaseArchivesPost :: getParentId));
+        List<BaseArchivesPost>  baseArchivesPosts = postMap.get("0");
+        if(CollectionUtils.isEmpty(baseArchivesPosts)){
+            return null;
+        }
+        for(BaseArchivesPost baseArchivesPost : baseArchivesPosts){
+            ArchivesPostListRespDTO archivesPostListRespDTO = new ArchivesPostListRespDTO(baseArchivesPost);
+            archivesPostListRespDTO.setChildren(getChildes(list, archivesPostListRespDTO.getKey(), postMap));
+            //判断是否为末节点
+            List<BaseArchivesPost> posts = postMap.get(archivesPostListRespDTO.getKey());
+            if(CollectionUtils.isEmpty(posts)){
+                archivesPostListRespDTO.setIsLeaf(true);
+            }
+            resp.add(archivesPostListRespDTO);
+        }
+        return resp;
+    }
+
+    /**
+     * @desc 获取子节点数据
+     */
+    private List<ArchivesPostListRespDTO> getChildes(List<BaseArchivesPost> list, String key, Map<String, List<BaseArchivesPost>> postMap) {
+        List<ArchivesPostListRespDTO> resp = Lists.newArrayList();
+        for(BaseArchivesPost baseArchivesPost : list){
+            if(baseArchivesPost.getParentId().equals(key)){
+                ArchivesPostListRespDTO archivesPostListRespDTO = new ArchivesPostListRespDTO(baseArchivesPost);
+                archivesPostListRespDTO.setChildren(getChildes(list, archivesPostListRespDTO.getKey(), postMap));
+                //判断是否为末节点
+                List<BaseArchivesPost> posts = postMap.get(archivesPostListRespDTO.getKey());
+                if(CollectionUtils.isEmpty(posts)){
+                    archivesPostListRespDTO.setIsLeaf(true);
+                }
+                resp.add(archivesPostListRespDTO);
+            }
+        }
+        return resp;
+    }
+}

+ 0 - 3
src/main/java/org/jeecg/modules/basedata/controller/FdPersonnelController.java

@@ -545,9 +545,6 @@ public class FdPersonnelController {
 
         return result;
     }
-
-//    public Result<>
-
 }
 
 

+ 68 - 0
src/main/java/org/jeecg/modules/basedata/entity/BaseArchivesPost.java

@@ -0,0 +1,68 @@
+package org.jeecg.modules.basedata.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import javax.validation.constraints.NotEmpty;
+
+@Data
+@ApiModel("职务档案")
+public class BaseArchivesPost implements Serializable {
+    @ApiModelProperty("id")
+    @TableId(type = IdType.UUID)
+    private String id;
+    @ApiModelProperty("父节点id")
+    private String parentId;
+    @ApiModelProperty("职务编码")
+    @NotEmpty(message = "职务编码不为空")
+    private String code;
+    @ApiModelProperty("职务名称")
+    @NotEmpty(message = "职务名称不为空")
+    private String name;
+    @ApiModelProperty("创建时间")
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    @ApiModelProperty("创建人")
+    private String createBy;
+    @ApiModelProperty("修改时间")
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+    @ApiModelProperty("修改人")
+    private String updateBy;
+    @ApiModelProperty("删除状态(0,正常,1已删除)")
+    private String delFlag;
+    @ApiModelProperty("组织")
+    private String pkOrg;
+
+    private static final long serialVersionUID = 1L;
+
+    public BaseArchivesPost() {
+    }
+
+    /**
+     * @desc 添加用
+     */
+    public BaseArchivesPost(String id, String parentId, String code, String name,
+        Date createTime, String createBy, Date updateTime, String updateBy, String delFlag,
+        String pkOrg) {
+        this.id = id;
+        this.parentId = parentId;
+        this.code = code;
+        this.name = name;
+        this.createTime = createTime;
+        this.createBy = createBy;
+        this.updateTime = updateTime;
+        this.updateBy = updateBy;
+        this.delFlag = delFlag;
+        this.pkOrg = pkOrg;
+    }
+}

+ 9 - 0
src/main/java/org/jeecg/modules/basedata/mapper/BaseArchivesPostMapper.java

@@ -0,0 +1,9 @@
+package org.jeecg.modules.basedata.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.jeecg.modules.basedata.entity.BaseArchivesPost;
+
+@Mapper
+public interface BaseArchivesPostMapper extends BaseMapper<BaseArchivesPost> {
+}

+ 16 - 0
src/main/java/org/jeecg/modules/basedata/mapper/xml/BaseArchivesPostMapper.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.basedata.mapper.BaseArchivesPostMapper">
+  <resultMap id="BaseResultMap" type="org.jeecg.modules.basedata.entity.BaseArchivesPost">
+    <id column="id" property="id" />
+    <result column="parent_id" property="parentId" />
+    <result column="code" property="code" />
+    <result column="name" property="name" />
+    <result column="create_time" property="createTime" />
+    <result column="create_by" property="createBy" />
+    <result column="update_time" property="updateTime" />
+    <result column="update_by" property="updateBy" />
+    <result column="del_flag" property="delFlag" />
+    <result column="pk_org"  property="pkOrg" />
+  </resultMap>
+</mapper>

+ 12 - 0
src/main/java/org/jeecg/modules/basedata/service/BaseArchivesPostService.java

@@ -0,0 +1,12 @@
+package org.jeecg.modules.basedata.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.basedata.entity.BaseArchivesPost;
+
+/**
+   * @Author jihaosen
+   * @date 2021/2/23
+   * @desc
+   */
+public interface BaseArchivesPostService extends IService<BaseArchivesPost> {
+}

+ 20 - 0
src/main/java/org/jeecg/modules/basedata/service/impl/BaseArchivesPostServiceImpl.java

@@ -0,0 +1,20 @@
+package org.jeecg.modules.basedata.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.basedata.entity.BaseArchivesPost;
+import org.jeecg.modules.basedata.mapper.BaseArchivesPostMapper;
+import org.jeecg.modules.basedata.service.BaseArchivesPostService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+ /**
+   * @Author jihaosen
+   * @date 2021/2/23
+   * @desc 职务档案service服务
+   */
+@Service
+public class BaseArchivesPostServiceImpl extends ServiceImpl<BaseArchivesPostMapper, BaseArchivesPost> implements BaseArchivesPostService {
+    @Autowired
+    private BaseArchivesPostMapper baseArchivesPostMapper;
+
+}