package com.storlead.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.storlead.framework.common.result.Result;
import com.storlead.user.pojo.entity.JobEntity;
import com.storlead.user.service.IJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/lingcun/job")
@Slf4j
@Api(tags="平台中心 - 系统: 公共接口")
public class JobController {

	@Resource
	private IJobService jobService;

	/**
	 * 查询数据 查出所有部门,并以树结构数据格式响应给前端
	 *
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ApiOperation(value = "公共接口-职位-列表", notes = "公共接口-职位-列表")
	@ApiResponses({
			@ApiResponse(code = 200, message = "", response = JobEntity.class)
	})
	public Result<List<JobEntity>> queryTreeList() {
		Result<List<JobEntity>> result = new Result<>();
		try {
			LambdaQueryWrapper<JobEntity> queryWrapper = new LambdaQueryWrapper();
			queryWrapper.select(JobEntity::getDeptId, JobEntity::getName,JobEntity::getSort,JobEntity::getId);
			List<JobEntity> list = jobService.list(queryWrapper);
			result.setResult(list);
			result.setSuccess(true);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
		return result;
	}


}
