• 人力项目框架解析新增修改方法


    在迁移项目但是遇到了一些问题,迁移项目的时候发现项目的整体框架很有趣,但是苦于项目框架太大了,竟然只能完整迁移,做不到部分迁移,于是我也只能从一半的角度来进行解释整个项目。

    雇员

    我们雇员这个为对象讲解一下整个项目

    @Api(value = "人员基本信息模块", tags = "人员基本信息模块")
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RestController
    @RequestMapping("/api/person/person_base_info")
    @Slf4j
    public class PersonBaseInfoController extends BaseHistoryController<PersonBaseInfo, PersonInfoDTO> {
    
        @Autowired
        private PersonBaseInfoService personBaseInfoService;
    
        @Autowired
        private PersonWordExport personWordExport;
    
        @Autowired
        private PersonAllocationInfoService personAllocationInfoService;
    
        @Autowired
        private PersonLifecycleInfoService personLifecycleInfoService;
    
        @Autowired
        private AddressInfoService addressInfoService;
    
        @Autowired
        private RedisTemplate redisTemplate;
    
        @ApiOperation(value = "人员信息验证", notes = "人员信息验证", response = PersonBaseInfoResponseVerifyDTO.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "long", required = true),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "from", value = "人员信息验证请求", dataType = "PersonBaseInfoRequestVerifyDTO", required = true)
        })
        @ApiResponses({
                @ApiResponse(code = 200, message = "已更正")
        })
        @PostMapping("/verify")
        public ResponseEntity<Object> verify(
                @RequestHeader("X-Person-Id") Long xPersonId,
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @RequestBody PersonBaseInfoRequestVerifyDTO from) {
            try {
                PersonBaseInfoResponseVerifyDTO responseVerifyDTO = personBaseInfoService.verify(xBusinessGroupId, from);
                return new ResponseEntity<>(responseVerifyDTO, HttpStatus.OK);
            } catch (ServiceException e) {
                return new ResponseEntity<>(e.getMessageResponse(), HttpStatus.NOT_FOUND);
            }
        }
    
        @ApiOperation(value = "根据ID查询单个人员基本信息", notes = "根据ID查询单个人员基本信息", response = PersonInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "人员基本信息ID", dataType = "long", required = true),
                @ApiImplicitParam(name = "assignmentId", value = "人员分配信息ID,默认:取主分配第一条", dataType = "long"),
                @ApiImplicitParam(name = "date", value = "查询日期,默认:取当前日期", dataType = "date", format = "date"),
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/{id}")
        public ResponseEntity<Object> select(@PathVariable(value = "id") Long id,
                                             @RequestParam(value = "assignmentId", required = false) Long assignmentId,
                                             @RequestParam(value = "date", required = false)
                                             @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
            PersonInfoDTO result = personBaseInfoService.selectPersonDtoById(id, assignmentId,
                    Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new PersonInfoDTO(), HttpStatus.OK);
            }
        }
    
        @ApiOperation(value = "通过职务id查询范围内的岗位级别", notes = "通过职务id查询范围内的岗位级别", response = GlobalLookupCodeInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "jobId", value = "职务id", dataType = "long"),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001")
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping(value = {"/personGrade/{jobId}", "/personGrade"})
        public ResponseEntity<Object> selectByJobId(@PathVariable(value = "jobId", required = false) Long jobId,
                                                    @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId) {
            return new ResponseEntity<>(personBaseInfoService.selectByJobId(jobId, xBusinessGroupId), HttpStatus.OK);
        }
    
        @ApiOperation(value = "根据证件查询单个人员基本信息", notes = "根据证件查询单个人员基本信息", response = PersonInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "idCardType", value = "证件类型ID", dataType = "long", required = true),
                @ApiImplicitParam(name = "idCardNumber", value = "证件编号", dataType = "string", required = true),
                @ApiImplicitParam(name = "date", value = "查询日期,默认:取当前日期", dataType = "date", format = "date"),
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/card/{idCardType}/{idCardNumber}")
        public ResponseEntity<Object> card(@RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                                           @PathVariable(value = "idCardType") Long idCardType,
                                           @PathVariable(value = "idCardNumber") String idCardNumber,
                                           @RequestParam(value = "date", required = false)
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
            PersonInfoDTO result = personBaseInfoService.selectPersonDtoByCard(xBusinessGroupId, idCardType, idCardNumber,
                    Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new PersonInfoDTO(), HttpStatus.OK);
            }
        }
    
        @Override
        protected ResponseEntity<Object> modify(PersonInfoDTO from, PersonBaseInfo personBaseInfo, LocalDate localDate) {
            return ResponseEntityUtils.buildModifyResponseEntity(personBaseInfoService.modify(from, personBaseInfo, localDate));
        }
    
        @Override
        protected ResponseEntity<Object> renew(PersonInfoDTO from, PersonBaseInfo personBaseInfo, LocalDate localDate) {
            return ResponseEntityUtils.buildRenewResponseEntity(personBaseInfoService.renew(from, personBaseInfo, localDate));
        }
    
        @Override
        protected ResponseEntity<Object> create(PersonInfoDTO from, PersonBaseInfo personBaseInfo) {
            return ResponseEntityUtils.buildCreateResponseEntity(personBaseInfoService.create(from, personBaseInfo));
    
        }
    
        @ApiOperation(value = "更正人员基本和任职信息", notes = "更正人员基本和任职信息", response = PersonInfoDTO.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "long", required = true),
                @ApiImplicitParam(name = "X-Person-Name", value = "登录人姓名", paramType = "header", dataType = "string", required = true),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "date", value = "查询日期", dataType = "date-time", format = "date"),
                @ApiImplicitParam(name = "from", value = "人员基本和任职信息信息", dataType = "PersonInfoDTO", required = true)
        })
        @ApiResponses({
                @ApiResponse(code = 200, message = "已更正")
        })
        @PostMapping
        public ResponseEntity<Object> modify(
                @RequestHeader("X-Person-Id") Long xPersonId,
                @RequestHeader("X-Person-Name") String xPersonName,
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @RequestParam(value = "date", required = false)
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                @RequestBody PersonInfoDTO from) {
            PersonBaseInfo personBaseInfo = newT();
            this.copyProperties(from, xPersonId, xPersonName, personBaseInfo);
            personBaseInfo.setBusinessGroupId(xBusinessGroupId);
            return this.createOrModify(from, xPersonId, xPersonName, date, personBaseInfo);
        }
    
        @Override
        protected void copyProperties(PersonInfoDTO from, Long xPersonId, String xPersonName, PersonBaseInfo t) {
            BeanCopyUtils.copyProperties(from.getPersonBaseInfo(), t, PropertiesCopyable.ignoreCopyable("id"));
            t.setUpdateBy(xPersonId);
            t.setUpdateByName(xPersonName);
        }
    
        @ApiOperation(value = "更新人员基本和任职信息", notes = "更新人员基本和任职信息", response = PersonInfoDTO.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "long", required = true),
                @ApiImplicitParam(name = "X-Person-Name", value = "登录人姓名", paramType = "header", dataType = "string", required = true),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "date", value = "查询日期", dataType = "date-time", format = "date"),
                @ApiImplicitParam(name = "from", value = "人员基本和任职信息", dataType = "PersonInfoDTO", required = true)
        })
        @ApiResponses({
                @ApiResponse(code = 200, message = "已更新")
        })
        @PostMapping("/renew")
        public ResponseEntity<Object> renew(
                @RequestHeader("X-Person-Id") Long xPersonId,
                @RequestHeader("X-Person-Name") String xPersonName,
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @RequestParam(value = "date", required = false)
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                @RequestBody PersonInfoDTO from) {
            PersonBaseInfo personBaseInfo = newT();
            this.copyProperties(from, xPersonId, xPersonName, personBaseInfo);
            personBaseInfo.setBusinessGroupId(xBusinessGroupId);
            return this.createOrRenew(from, xPersonId, xPersonName, date, personBaseInfo);
        }
    
        @ApiOperation(value = "更新人员离职信息", notes = "更新人员离职信息", response = PersonInfoDTO.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "long", required = true),
                @ApiImplicitParam(name = "X-Person-Name", value = "登录人姓名", paramType = "header", dataType = "string", required = true),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "date", value = "查询日期", dataType = "date-time", format = "date"),
                @ApiImplicitParam(name = "from", value = "人员服务期间信息", dataType = "PersonInfoDTO", required = true)
        })
        @ApiResponses({
                @ApiResponse(code = 200, message = "已更新")
        })
        @PostMapping("/leaving")
        public ResponseEntity<Object> leaving(
                @RequestHeader("X-Person-Id") Long xPersonId,
                @RequestHeader("X-Person-Name") String xPersonName,
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @RequestParam(value = "date", required = false)
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                @RequestBody PersonInfoDTO from) {
            try {
                return ResponseEntityUtils.buildRenewResponseEntity(
                        personBaseInfoService.leaving(from, xBusinessGroupId, xPersonId, xPersonName,
                                Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null));
            } catch (ServiceException e) {
                return new ResponseEntity<>(e.getMessageResponse(), HttpStatus.NOT_FOUND);
            }
        }
    
        /**
         * 拼装
         *
         * @param xBusinessGroupId
         * @param personName
         * @param employeeNumber
         * @param orgId
         * @param idCardNumber
         * @param onDutyCategory
         * @param date
         * @param searchText
         * @param dataPermission
         * @return
         */
        public static void fillPersonBaseInfoSearchDTO(PersonBaseInfoSearchDTO searchDTO, Long xBusinessGroupId, String personName,
                                                       String employeeNumber, Long orgId, String idCardNumber, Long onDutyCategory, Date date, String searchText, String dataPermission) {
            searchDTO.setBusinessGroupId(xBusinessGroupId);
            searchDTO.setPersonName(personName);
            searchDTO.setEmployeeNumber(employeeNumber);
            searchDTO.setOrgId(orgId);
            searchDTO.setIdCardNumber(idCardNumber);
            searchDTO.setOnDutyCategory(onDutyCategory);
            searchDTO.setDate(Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            searchDTO.setSearchText(searchText);
            searchDTO.setDataPermission(dataPermission);
        }
    
        @ApiOperation(value = "分页查询人员基本信息", notes = "分页查询人员基本信息", response = Page.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "string", required = true),
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "string", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "X-Data-Permission", value = "数据安全性", paramType = "header", dataType = "String", required = true),
                @ApiImplicitParam(name = "personName", value = "姓名", dataType = "string"),
                @ApiImplicitParam(name = "employeeNumber", value = "员工编号", dataType = "string"),
                @ApiImplicitParam(name = "orgId", value = "部门", dataType = "long"),
                @ApiImplicitParam(name = "idCardNumber", value = "身份证号", dataType = "string"),
                @ApiImplicitParam(name = "onDutyCategory", value = "在岗类别", dataType = "long"),
                @ApiImplicitParam(name = "date", value = "查询日期", dataType = "date", format = "date"),
                @ApiImplicitParam(name = "primary", value = "分配类型 1 只查主分配(默认) 0 只查不是主分配 -1 全查", dataType = "int"),
                @ApiImplicitParam(name = "ignorePersonId", value = "忽略不查询的人员Id", dataType = "long"),
                @ApiImplicitParam(name = "topOrgId", value = "二级单位ID", dataType = "long"),
                @ApiImplicitParam(name = "onDutyCategoryList", value = "只查哪些 在岗类别 \",\"号拼接Id", dataType = "string"),
                @ApiImplicitParam(name = "ignoreOnDutyCategoryList", value = "忽略哪些 在岗类别 \",\"号拼接Id", dataType = "string"),
                @ApiImplicitParam(name = "searchText", value = "人员基本编码 or 人员基本名称", dataType = "string"),
                @ApiImplicitParam(name = "whetherDataPermission", value = "是否适用数据安全性: 1 适用(默认) 0 不适用", dataType = "int"),
                @ApiImplicitParam(name = "pageNumber", value = "当前页", dataType = "int", defaultValue = "1"),
                @ApiImplicitParam(name = "pageSize", value = "页数", dataType = "int", defaultValue = "10")
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/search")
        public ResponseEntity<Object> search(@RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                                             @RequestHeader("X-Data-Permission") String dataPermission,
                                             @RequestParam(value = "personName", required = false) String personName,
                                             @RequestParam(value = "employeeNumber", required = false) String employeeNumber,
                                             @RequestParam(value = "orgId", required = false) Long orgId,
                                             @RequestParam(value = "idCardNumber", required = false) String idCardNumber,
                                             @RequestParam(value = "onDutyCategory", required = false) Long onDutyCategory,
                                             @RequestParam(value = "date", required = false)
                                             @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                             @RequestParam(value = "primary", defaultValue = "1", required = false) Integer primary,
                                             @RequestParam(value = "ignorePersonId", required = false) Long ignorePersonId,
                                             @RequestParam(value = "topOrgId", required = false) Long topOrgId,
                                             @RequestParam(value = "onDutyCategoryList", required = false) String onDutyCategoryList,
                                             @RequestParam(value = "ignoreOnDutyCategoryList", required = false) String ignoreOnDutyCategoryList,
                                             @RequestParam(value = "searchText", required = false) String searchText,
                                             @RequestParam(value = "whetherDataPermission", required = false) Integer whetherDataPermission,
                                             @RequestParam(value = "pageNumber", defaultValue = "1", required = false) Integer pageNumber,
                                             @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
    
            PersonBaseInfoSearchDTO searchDTO = new PersonBaseInfoSearchDTO(pageNumber, pageSize);
            fillPersonBaseInfoSearchDTO(searchDTO, xBusinessGroupId, personName,
                    employeeNumber, orgId, idCardNumber, onDutyCategory, date, searchText, dataPermission);
            // 如果是其他值只查主分配
            if (Objects.isNull(primary)
                    || (primary != 1 && primary != 0 && primary != -1)) {
                primary = 1;
            }
    
            searchDTO.setPrimary(primary);
            searchDTO.setIgnorePersonId(ignorePersonId);
            searchDTO.setTopOrgId(topOrgId);
            searchDTO.setWhetherDataPermission(whetherDataPermission);
            try {
                if (StringUtils.isNotEmpty(onDutyCategoryList)) {
                    searchDTO.setOnDutyCategoryList(
                            Arrays.stream(onDutyCategoryList.split(","))
                                    .filter(StringUtils::isNotEmpty)
                                    .map(Long::valueOf)
                                    .collect(Collectors.toList())
                    );
                }
                if (StringUtils.isNotEmpty(ignoreOnDutyCategoryList)) {
                    searchDTO.setIgnoreOnDutyCategoryList(
                            Arrays.stream(ignoreOnDutyCategoryList.split(","))
                                    .filter(StringUtils::isNotEmpty)
                                    .map(Long::valueOf)
                                    .collect(Collectors.toList())
                    );
                }
            } catch (NumberFormatException e) {
                return new ResponseEntity<>(new MessageResponse("在岗类别\",\"号拼接 Id 只能为数字"), HttpStatus.NOT_FOUND);
            }
            // 不传默认需要分页
            searchDTO.setWhetherPage(ObjectUtil.isEmpty(searchDTO.getWhetherPage()) ? 0 : searchDTO.getWhetherPage());
            Page<PersonBaseInfoVO> page = personBaseInfoService.search(searchDTO);
    
            if (Objects.nonNull(page)) {
                if (ObjectUtil.equal(searchDTO.getWhetherPage(), 1)) {
                    return new ResponseEntity<>(page.getRecords(), HttpStatus.OK);
                }
                return new ResponseEntity<>(page, HttpStatus.OK);
            }
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    
        @ApiOperation(value = "分页查询人员基本信息", notes = "分页查询人员基本信息", response = Page.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "string", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "X-Data-Permission", value = "数据安全性", paramType = "header", dataType = "String"),
                @ApiImplicitParam(name = "searchDTO", value = "人员服务期间信息", dataType = "PersonBaseInfoSearchDTO", required = true)
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @PostMapping("/search")
        public ResponseEntity<Page<PersonBaseInfoVO>> postSearch(@RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                                                                 @RequestHeader(value = "X-Data-Permission", required = false) String dataPermission,
                                                                 @RequestBody PersonBaseInfoSearchDTO searchDTO) {
            searchDTO.setBusinessGroupId(xBusinessGroupId);
            searchDTO.setDataPermission(dataPermission);
            // 不传默认需要分页
            searchDTO.setWhetherPage(ObjectUtil.isEmpty(searchDTO.getWhetherPage()) ? 0 : searchDTO.getWhetherPage());
            if (ObjectUtil.equal(searchDTO.getWhetherPage(), 0)) {
                int offSet = PageHelper.offsetCurrent(searchDTO.getPageNumber(), searchDTO.getPageSize());
                searchDTO.setOffset(offSet);
            }
            Integer primary = searchDTO.getPrimary();
            // 如果是其他值只查主分配
            if (Objects.isNull(primary)
                    || (primary != 1 && primary != 0 && primary != -1)) {
                searchDTO.setPrimary(1);
            }
            Page<PersonBaseInfoVO> page = personBaseInfoService.search(searchDTO);
            if (Objects.nonNull(page)) {
                return new ResponseEntity<>(page, HttpStatus.OK);
            }
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    
        /**
         * 并发数据测试支持千人以上秒级并发峰值访问
         *
         * @param xBusinessGroupId
         * @param dataPermission
         * @param searchDTO
         * @return
         */
        @ApiOperation(value = "分页查询人员基本信息", notes = "分页查询人员基本信息", response = Page.class, httpMethod = "POST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "string", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "X-Data-Permission", value = "数据安全性", paramType = "header", dataType = "String"),
                @ApiImplicitParam(name = "searchDTO", value = "人员服务期间信息", dataType = "PersonBaseInfoSearchDTO", required = true)
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @PostMapping("/searchfortoomuch")
        public ResponseEntity<List<PersonBaseInfoVO>> postSearchForTooMych(@RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                                                                           @RequestHeader(value = "X-Data-Permission", required = false) String dataPermission,
                                                                           @RequestBody PersonBaseInfoSearchDTO searchDTO) throws Exception {
    
            if (searchDTO.getEmployeeNumber() == null || searchDTO.getEmployeeNumber() == "") {
                return new ResponseEntity<>(HttpStatus.NOT_FOUND);
            }
    
            ValueOperations valueOperations = redisTemplate.opsForValue();
    
            if (valueOperations.get(searchDTO.getEmployeeNumber()) != null) {
                return new ResponseEntity<>((List<PersonBaseInfoVO>) valueOperations.get(searchDTO.getEmployeeNumber()), HttpStatus.OK);
            }
    
            List<PersonBaseInfoVO> personBaseInfoVOS = personBaseInfoService.searchFor(searchDTO);
    
            if (Objects.nonNull(personBaseInfoVOS)) {
    
                valueOperations.set(searchDTO.getEmployeeNumber(), personBaseInfoVOS, 5, TimeUnit.HOURS);
    
                return new ResponseEntity<>(personBaseInfoVOS, HttpStatus.OK);
            }
    
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    
        @ApiOperation(value = "分页查询人员基本信息", notes = "分页查询人员基本信息", response = Page.class, httpMethod = "POST")
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @PostMapping("/searchforhello")
        public ResponseEntity<Object> searchforhello() {
            int min = 300;
            int max = 600;
            int time = min + (int) (Math.random() * ((max - min) + 1));
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            String result = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            for (int i = 0; i < time; i++) {
                result += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            }
            return new ResponseEntity<>(result, HttpStatus.OK);
        }
    
        @ApiOperation(value = "查询人员基本历史信息", notes = "查询人员基本历史信息", response = HistoryDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "人员基本ID", dataType = "long", required = true)
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/history/{id}")
        public ResponseEntity<Object> history(@PathVariable(value = "id") Long id) {
            return new ResponseEntity<>(personBaseInfoService.selectHistoryList(id), HttpStatus.OK);
        }
    
        @ApiOperation(value = "查询员工生命周期变更记录", notes = "查询员工生命周期变更记录", response = PersonLifecycleDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "人员基本ID", dataType = "long", required = true)
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/lifecycle/{id}")
        public ResponseEntity<Object> lifecycle(@PathVariable(value = "id") Long id) {
            Map<LocalDate, PersonLifecycleDTO> lifecycleBaseInfoMap = personBaseInfoService.selectLifecycleList(id);
    
            for (Map.Entry<LocalDate, PersonLifecycleDTO> entry : personAllocationInfoService.selectLifecycleList(id).entrySet()) {
                LocalDate key = entry.getKey();
                PersonLifecycleDTO value = entry.getValue();
    
                PersonLifecycleDTO lifecycleBaseInfo = lifecycleBaseInfoMap.get(key);
                // 如果存在 有2种情况
                // 1、信息维护 直接覆盖
                // 2、入/离职 取出来排序
                if (Objects.isNull(lifecycleBaseInfo) || "信息维护".equals(lifecycleBaseInfo.getOperateTypeName())) {
                    lifecycleBaseInfoMap.put(key, value);
                } else {
                    List<PersonLifecycleDTO> temp = new ArrayList<>();
                    // 添加
                    temp.add(lifecycleBaseInfo);
                    temp.addAll(lifecycleBaseInfo.getPersonLifecycleList());
                    temp.add(value);
                    temp.addAll(value.getPersonLifecycleList());
                    // 清空
                    lifecycleBaseInfo.setPersonLifecycleList(new ArrayList<>());
                    value.setPersonLifecycleList(new ArrayList<>());
    
                    // 排序
                    temp.sort(Comparator.comparing(PersonLifecycleDTO::getDate));
    
                    // 将剩余的放入第一个
                    PersonLifecycleDTO firstLifecycle = temp.get(0);
                    temp.remove(0);
                    firstLifecycle.setPersonLifecycleList(temp);
    
                    // 存入
                    lifecycleBaseInfoMap.put(firstLifecycle.getDate(), firstLifecycle);
                }
            }
            return new ResponseEntity<>(lifecycleBaseInfoMap.values(), HttpStatus.OK);
        }
    
        @ApiOperation(value = "查询人员分配信息", notes = "查询人员分配信息", response = PersonAssignmentInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "string", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "id", value = "人员", dataType = "long"),
                @ApiImplicitParam(name = "orgId", value = "部门", dataType = "long"),
                @ApiImplicitParam(name = "jobId", value = "职务", dataType = "long"),
                @ApiImplicitParam(name = "positionId", value = "职位", dataType = "long"),
                @ApiImplicitParam(name = "date", value = "查询日期", dataType = "date", format = "date")
        })
        @GetMapping("/person/{id}/assignment")
        public ResponseEntity<PersonAssignmentInfoDTO> selectAssignmentInfoDtoBy(
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @PathVariable("id") Long id,
                @RequestParam(value = "orgId") Long orgId,
                @RequestParam(value = "jobId") Long jobId,
                @RequestParam(value = "positionId") Long positionId,
                @RequestParam(value = "date", required = false)
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
            PersonAssignmentInfoDTO dto = personBaseInfoService.selectAssignmentInfoDtoBy(
                    xBusinessGroupId, id, orgId, jobId, positionId,
                    Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            if (Objects.nonNull(dto)) {
                return new ResponseEntity<>(dto, HttpStatus.OK);
            }
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    
        @ApiOperation(value = "查询员工异动详细信息", notes = "查询员工异动详细信息", response = PersonAllocationDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "人员基本ID", dataType = "long", required = true),
                @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "date", format = "date", required = true),
                @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "date", format = "date", required = true)
        })
        @GetMapping("/allocation/{id}")
        public ResponseEntity<List<PersonAllocationDTO>> allocation(
                @PathVariable(value = "id") Long id,
                @RequestParam(value = "startDate")
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                @RequestParam(value = "endDate")
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
            List<PersonAllocationDTO> allocationDtoList = personLifecycleInfoService.searchAllocationInfoBy(id, null,
                    Objects.nonNull(startDate) ? startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null,
                    Objects.nonNull(endDate) ? endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            if (Objects.nonNull(allocationDtoList)) {
                return new ResponseEntity<>(allocationDtoList, HttpStatus.OK);
            }
            return new ResponseEntity<>(new ArrayList<>(), HttpStatus.NOT_FOUND);
        }
    
        @ApiOperation(value = "查询员工异动详细信息", notes = "查询员工异动详细信息", response = PersonAllocationDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "from", value = "人员薪酬薪资期间信息", dataType = "PersonAllDTO", required = true)
        })
        @PostMapping("/allocation/list")
        public ResponseEntity<List<PersonAllocationDTO>> allocation(@RequestBody PersonAllFromDTO from) {
            log.info("查询参数:" + from.toString());
            List<PersonAllocationDTO> allocationDtoList = new ArrayList<>();
            HashSet<PersonAllDTO> personAllList = from.getPersonAllList();
            log.info("PersonAllList" + personAllList.toString());
            for (PersonAllDTO dto : personAllList) {
                LocalDate periodStartDate = dto.getPeriodStartDate();
                LocalDate periodEndDate = dto.getPeriodEndDate();
                List<PersonAllocationDTO> list = personLifecycleInfoService.searchAllocationInfoBy(dto.getPersonId(), dto.getPeriodId(),
                        Objects.nonNull(periodStartDate) ? periodStartDate : null,
                        Objects.nonNull(periodEndDate) ? periodEndDate : null);
                allocationDtoList.addAll(list);
            }
            return new ResponseEntity<>(allocationDtoList, HttpStatus.OK);
        }
    
        @ApiOperation(value = "根据员工编号查询单个人员基本信息", notes = "根据员工编号查询单个人员基本信息", response = PersonInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "employeeNumber", value = "员工编号", dataType = "string", required = true),
                @ApiImplicitParam(name = "date", value = "查询日期,默认:取当前日期", dataType = "date", format = "date"),
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/employeeNumber")
        public ResponseEntity<Object> employeeNumber(
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @RequestParam(value = "employeeNumber") String employeeNumber,
                @RequestParam(value = "date", required = false)
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
            PersonInfoDTO result = personBaseInfoService.selectPersonDtoByEmployeeNumber(xBusinessGroupId, employeeNumber,
                    Objects.nonNull(date) ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null);
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new PersonInfoDTO(), HttpStatus.OK);
            }
        }
    
        @ApiOperation(value = "根据cutId查询人员ID信息", notes = "根据cutId查询人员ID信息", response = Long.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "cutId", value = "人员", dataType = "long", required = true)
        })
        @GetMapping("/selectByCutId/{cutId}")
        public ResponseEntity<Long> selectByCutId(@PathVariable(value = "cutId") Long cutId) {
            Long personId = personBaseInfoService.selectByCutId(cutId);
            if (Objects.nonNull(personId)) {
                return new ResponseEntity<>(personId, HttpStatus.OK);
            }
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    
        @ApiOperation(value = "根据参加工作日期及社会工龄调整值(月)计算工龄", notes = "根据参加工作日期及社会工龄调整值(月)计算工龄", response = Integer.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "dateOfWork", value = "参加工作日期", dataType = "date", format = "date"),
                @ApiImplicitParam(name = "dateOfWorkAdj", value = "社会工龄调整值(月)", dataType = "int"),
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/workYear")
        public ResponseEntity<Object> getWorkYear(
                @RequestParam(value = "dateOfWork")
                @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateOfWork,
                @RequestParam(value = "dateOfWorkAdj", defaultValue = "0", required = false) Integer dateOfWorkAdj) {
    
            LocalDate date = Objects.nonNull(dateOfWork) ? dateOfWork.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null;
            Integer workYear = personBaseInfoService.getWorkYear(date, dateOfWorkAdj);
            return new ResponseEntity<>(workYear, HttpStatus.OK);
        }
    
        @ApiOperation(value = "根据X-Person-Id查询personId", notes = "Id查询personId", response = Integer.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Person-Id", value = "登录人ID", paramType = "header", dataType = "long", required = true)
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/getPersonId")
        public ResponseEntity<Long> getPersonId(@RequestHeader("X-Person-Id") Long xPersonId) {
    
            return new ResponseEntity<>(personBaseInfoService.getPersonId(xPersonId), HttpStatus.OK);
        }
    
        @ApiOperation(value = " 根据personId获取人员基本信息", notes = " 根据personId获取人员基本信息", response = PersonBaseInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "ids", value = "人员基本信息ID", dataType = "string", required = true),
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/selectByIds")
        public ResponseEntity<Object> selectByIds(@RequestParam(value = "ids") String ids) {
            List<PersonBaseInfoDTO> result = personBaseInfoService.selectByIds(ids);
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new PersonInfoDTO(), HttpStatus.OK);
            }
        }
    
        @ApiOperation(value = " 根据employeeNumber获取人员基本信息", notes = " 根据personId获取人员基本信息", response = PersonBaseInfoDTO.class, httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "employeeNumbers", value = "员工编号信息ID", dataType = "string", required = true),
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/selectByEmployeeNumbers")
        public ResponseEntity<Object> selectByEmployeeNumbers(@RequestParam(value = "employeeNumbers") String employeeNumbers) {
            List<PersonBaseInfoDTO> result = personBaseInfoService.selectByEmployeeNumbers(employeeNumbers);
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new PersonInfoDTO(), HttpStatus.OK);
            }
        }
    
        @ApiOperation(value = "查询人员基本附加信息", notes = "查询人员基本附加信息", response = HistoryDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "string", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "flexStructureCode", value = "结构COde", dataType = "string", required = true),
                @ApiImplicitParam(name = "id", value = "人员ID,新增-1", dataType = "long")
        })
        @ApiResponse(code = 200, message = "返回数据成功", response = Page.class)
        @GetMapping("/attributesInfo/{id}")
        public ResponseEntity<Object> getAttributesInfo(@PathVariable(value = "id") Long id,
                                                        @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                                                        @RequestParam(value = "flexStructureCode", required = false) String flexStructureCode) {
            return new ResponseEntity<>(personBaseInfoService.getAttributesInfo(xBusinessGroupId, flexStructureCode, id), HttpStatus.OK);
        }
    
        @ApiOperation(value = "导出word", notes = "导出word", response = PersonAnalysesInfoDTO.class, httpMethod = "GET", responseContainer = "LIST")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "X-Business-Group-Id", value = "用户所属业务组编号", paramType = "header", dataType = "long", required = true, defaultValue = "1001"),
                @ApiImplicitParam(name = "personId", value = "员工信息主键", dataType = "long")
        })
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/word/export/{personId}")
        public ResponseEntity<Object> getAnalysesInfo(
                @RequestHeader("X-Business-Group-Id") Long xBusinessGroupId,
                @PathVariable(value = "personId") Long personId) {
            return new ResponseEntity<>(personWordExport.export(xBusinessGroupId, personId), HttpStatus.OK);
        }
    
        @ApiOperation(value = " 查询省市信息集合", notes = " 查询省市信息集合", response = AddressInfoDTO.class, responseContainer = "List", httpMethod = "GET")
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/addressInfo/search")
        public ResponseEntity<Object> searchAddressInfo() {
            List<AddressInfoDTO> result = addressInfoService.searchAddressInfo();
            if (Objects.nonNull(result)) {
                return new ResponseEntity<>(result, HttpStatus.OK);
            } else {
                return new ResponseEntity<>(new AddressInfoDTO(), HttpStatus.OK);
            }
        }
    
        @ApiOperation(value = " 根据市id查询地址信息", notes = " 查询省市信息集合", response = AddressInfo.class, httpMethod = "GET")
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/addressInfo/{id}")
        public ResponseEntity<Object> searchAddressById(@PathVariable String id) {
            AddressInfo result = addressInfoService.searchProvinceName(id);
            return new ResponseEntity<>(result, HttpStatus.OK);
    
        }
    
        @ApiOperation(value = " 获取一个每个字的首字母大写的拼音", notes = " 获取一个每个字的首字母大写的拼音", response = String.class, responseContainer = "String", httpMethod = "GET")
        @ApiResponse(code = 200, message = "返回数据成功")
        @GetMapping("/pinyinName")
        public ResponseEntity<String> pinyinName(@RequestParam(value = "chineseName") String chineseName) {
            return new ResponseEntity<>(PinyinUtils.pinyinName(chineseName), HttpStatus.OK);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687

    好久没有接触过这种写法的项目了,其实刚接触的时候还是不是很适应的,但是这个controller写的还是挺漂亮的
    在这里插入图片描述
    这是所有的方法,

    查询

    在这里插入图片描述
    很标准的一个查询,构建一个查询实体,然后去进行放置参数,进行查询,返回带分页的查询,可以通过参数配置是否需要分页。

    新增、修改

    一般来说会将新增和修改放在同一个接口中
    在这里插入图片描述
    这个时候开始体现框架了。
    this.createOrRenew(from, xPersonId, xPersonName, date, personBaseInfo);方法
    PersonBaseInfoController 继承了BaseHistoryController,BaseHistoryController继承BaseController

        /**
         * 创建 or 更新(插入新的)逻辑
         *
         * @param from
         * @param xPersonId
         * @param xPersonName
         * @param date
         * @param t
         * @return
         */
        protected ResponseEntity<Object> createOrRenew(D from, Long xPersonId, String xPersonName, Date date, T t) {
            try {
                if (Objects.isNull(from.getId())) {
                    return new ResponseEntity<>(new MessageResponse("Id 不能为空!"), HttpStatus.NOT_FOUND);
                } else if (Objects.equals(from.getId(), NEED_CREATE_ID)) {
                    t.setCreateBy(xPersonId);
                    t.setCreateByName(xPersonName);
                    return this.create(from, t);
                } else if (from.getId() > 0) {
                    t.setId(from.getId());
                    if (Objects.isNull(date)) {
                        return this.renew(from, t);
                    } else {
                        LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        return this.renew(from, t, localDate);
                    }
                }
            } catch (ServiceException e) {
                return new ResponseEntity<>(e.getMessageResponse(), HttpStatus.NOT_FOUND);
            }
            return new ResponseEntity<>(new MessageResponse("保存失败!"), HttpStatus.NOT_FOUND);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
        public static final Long NEED_CREATE_ID = -1L;
    
    • 1

    D from就是传进来的参数,然后判断id,是否是存在不存在就提示报错,如果是新增的话id穿-1,如果是修改的话id就传原本的id,因为如果是修改的话也不会是修改id。
    return this.create(from, t);新增,在这里如果是单纯的点击去你就会去点进去
    在这里插入图片描述
    至少在我第一次看的时候确实是没有看到。
    正确的是返回具体的实现类PersonBaseInfoController ,去PersonBaseInfoController 类的方法

        @Override
        protected ResponseEntity<Object> create(PersonInfoDTO from, PersonBaseInfo personBaseInfo) {
            return ResponseEntityUtils.buildCreateResponseEntity(personBaseInfoService.create(from, personBaseInfo));
    
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    然后就去了personBaseInfoService.create方法了,具体去实现了新建的方法
    return this.renew(from, t);修改,

        @Override
        protected ResponseEntity<Object> renew(PersonInfoDTO from, PersonBaseInfo personBaseInfo, LocalDate localDate) {
            return ResponseEntityUtils.buildRenewResponseEntity(personBaseInfoService.renew(from, personBaseInfo, localDate));
        }
    
    • 1
    • 2
    • 3
    • 4

    看到这里其实感觉还是挺简单,但是这些搞了好久,感觉还是挺新奇。
    然后是修改的时候框架又出现了挺有趣的地方

    public class PersonBaseInfoService extends HistoryServiceImpl
    
    • 1

    在PersonBaseInfoService 调用修改的方法renew()的时候,

        @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
        public int renew(T t, LocalDate date) {
            dataFill(t);
            dataCheck(t);
            // 局部date变量
            LocalDate renewDate = this.getOperatingDate(date);
    
            T dbRecord = getDbRecord(t, renewDate);
            Wrapper<T> wrapper = getDbRecordWrapper(dbRecord);
            T update = newT(t.getClass());
            update.setUpdateTime(LocalDateTime.now());
            int result = 0;
            // 更新
            if (renewDate.isAfter(dbRecord.getStartDate())) {
                update.setEndDate(renewDate.minusDays(1));
                this.renewUpdateEndDatePostProcessBefore(t, dbRecord, update, renewDate);
                baseMapper.update(update, wrapper);
                T insert = newT(t.getClass());
                BeanCopyUtils.copyProperties(dbRecord, insert);
                BeanCopyUtils.copyProperties(t, insert, PropertiesCopyable.updateIgnoreCopyable());
                insert.setStartDate(renewDate);
                insert.setUpdateTime(LocalDateTime.now());
                // 这里传入的是更新要insert的对象
                this.updatePostProcessBefore(t, dbRecord, insert, renewDate);
    
    
                String tableName = this.reflectTableName(t);
                if(Objects.nonNull(tableName)) {
                    // SET IDENTITY_INSERT = ON
                    dmMapper.setIdentityInsertON(tableName);
                    System.out.println(t.toString());
                    result = baseMapper.insert(insert);
                    // SET IDENTITY_INSERT = OFF
                    dmMapper.setIdentityInsertOFF(tableName);
                } else {
                    result = baseMapper.insert(insert);
                }
            }
            // 更正
            if (renewDate.isEqual(dbRecord.getStartDate())) {
                BeanCopyUtils.copyProperties(t, update, PropertiesCopyable.updateIgnoreCopyable());
                this.updatePostProcessBefore(t, dbRecord, update, renewDate);
                result = baseMapper.update(update, wrapper);
            }
            this.updatePostProcessAfter(t, dbRecord, update, renewDate, result);
            return result;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    这个有啥用呢
    在这里插入图片描述
    这里只要想要实现具体的方法,就在这里重写即可,我觉得这个写法就很优秀,需要什么业务限制,就重写什么。

  • 相关阅读:
    和数区块链技术可以解决安全信任问题
    scratch绘制红蓝线条 电子学会图形化编程scratch等级考试四级真题和答案解析2022年9月
    Spring IOC工作流程
    configure: error: cannot compute suffix of object files: cannot compile
    前后端分离项目,vue+uni-app+php+mysql订座预约系统(H5移动项目) 开题报告
    【jQuery Demo】图片瀑布流实现
    P1113 杂务
    C++ 内联和嵌套命名空间
    LeetCode(力扣)47.全排列 IIPython
    STM32串口重定向/实现不定长数据接收
  • 原文地址:https://blog.csdn.net/weixin_44077141/article/details/134422417