|
@@ -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
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ 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();
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|