You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.9 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.chenxuan.controller;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenxuan.base.controller.BaseController;
import com.chenxuan.base.entity.AjaxResult;
import com.chenxuan.base.entity.Query;
import com.chenxuan.bean.annotation.LogAnnotation;
import com.chenxuan.entity.model.SysPost;
import com.chenxuan.enums.OperateType;
import com.chenxuan.service.SysPostService;
import com.chenxuan.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
/**
* @ClassNameSysPostController
* @Description 岗位信息操作处理
* @Author Arno_Fu
* @CreatTime11/29/2019 - 1:51 PM
* @Version V1.0
*/
@Slf4j
@RestController
@RequestMapping("/system/post")
public class SysPostController extends BaseController {
@Autowired
private SysPostService postService;
/**
* 获取岗位列表
*/
@GetMapping(value = "/list")
public AjaxResult list( ) {
List<SysPost> list = postService.lists( );
return AjaxResult.success( list );
}
/**
* 获取岗位分页
*/
@GetMapping(value = "/page")
public AjaxResult page( Query query) {
log.debug( "--- 分页请求参数 -->>[{}]", query );
Page<SysPost> page = postService.page( query );
log.debug( "--- 分页请求返回数据 -->>[{}]", page );
return AjaxResult.success( page );
}
/**
* 新增岗位
*/
@LogAnnotation(module = "岗位管理", operateType = OperateType.INSERT)
@PostMapping(value = "/add")
public AjaxResult add(@RequestBody SysPost post) {
if (!postService.checkPostNameUnique( post )) {
return AjaxResult.error( "新增岗位'" + post.getPostName() + "'失败,岗位名称已存在" );
}
if (!postService.checkPostCodeUnique( post )) {
return AjaxResult.error( "新增岗位'" + post.getPostName() + "'失败,岗位编码已存在" );
}
post.setCreateBy( SecurityUtils.getUsername() );
post.setCreateTime( new Date() );
postService.insertPost( post );
return AjaxResult.success();
}
/**
* 修改岗位
*/
@LogAnnotation(module = "岗位管理", operateType = OperateType.UPDATE)
@PutMapping(value = "/update")
public AjaxResult update(@RequestBody SysPost post) {
if (!postService.checkPostNameUnique( post )) {
return AjaxResult.error( "修改岗位'" + post.getPostName() + "'失败,岗位名称已存在" );
}
if (!postService.checkPostCodeUnique( post )) {
return AjaxResult.error( "修改岗位'" + post.getPostName() + "'失败,岗位编码已存在" );
}
post.setUpdateBy( SecurityUtils.getUsername() );
post.setUpdateTime( new Date() );
postService.updatePost( post );
return AjaxResult.success();
}
/**
* 删除岗位
*/
@LogAnnotation(module = "岗位管理", operateType = OperateType.DELETE)
@DeleteMapping(value = "/delete")
public AjaxResult remove(@RequestParam("ids") Long[] ids) {
postService.deleteByIds( ids ) ;
return AjaxResult.success();
}
/**
* 根据岗位编号获取详细信息
*/
@GetMapping(value = "/info")
public AjaxResult info(@RequestParam("id") Long id) {
SysPost find = postService.getByPK(id );
return AjaxResult.success(find);
}
}