package com.ssm.controller;


import javax.persistence.Column;
import javax.persistence.Id;

import com.github.pagehelper.PageInfo;
import com.ssm.filter.LoginInterceptor;
import com.ssm.manage.entity.JobContentList;
import com.ssm.manage.dto.JobContentListDto;
import com.ssm.manage.response.*;
import com.ssm.manage.service.JobContentListService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import java.io.Serializable;

import lombok.extern.slf4j.Slf4j;
import com.ssm.core.utils.SnowflakeUtil;

import java.util.Random;

/**
 * 工作内容
 * (JobContentList)表控制层
 *
 * @author makejava
 * @since 2023-12-19 13:56:50
 */
@RestController
@RequestMapping("jobContentList")
@Slf4j
@Api(tags = "工作内容")
public class JobContentListController {
    /**
     * 服务对象
     */
    @Autowired
    private JobContentListService jobContentListService;

/**
 * 通过主键查询单条数据
 *
 * @param id 主键
 * @return
 @GetMapping("{id}")
 @ApiOperation("通过主键查询单条数据")
 //@RequiresPermissions("system:jobContentList:query")
 public ResultVo get(@PathVariable Serializable id) {
 return this.jobContentListService.queryById(id);
 }
 */


    /**
     * 分页查询工作内容
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询工作内容 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:jobContentList:query")
    public PageResponse<JobContentListVo> listPage(JobContentListDto dto) {
        PageResponse<JobContentListVo> pageResponse = new PageResponse<>();
        PageInfo<JobContentListVo> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.jobContentListService.selectPage(dto);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    /**
     * 新增工作内容
     *
     * @param jobContentList
     * @return
     */
    @PostMapping
    @ApiOperation("新增工作内容 ")
//@RequiresPermissions("system:jobContentList:add")
    public GenericResponse add(@RequestBody JobContentList jobContentList) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            jobContentList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
            i = this.jobContentListService.save(jobContentList);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 编辑工作内容
     *
     * @param jobContentList
     * @return
     */
    @PutMapping
    @ApiOperation("编辑工作内容 ")
//@RequiresPermissions("system:jobContentList:edit")
    public GenericResponse edit(@RequestBody JobContentList jobContentList) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.jobContentListService.updateNotNull(jobContentList);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 根据主键删除工作内容
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除工作内容 ")
//@RequiresPermissions("system:jobContentList:delete")
    public GenericResponse delete(@PathVariable Long id) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            JobContentList jobContentList = new JobContentList();
            jobContentList.setId(id);
            i = this.jobContentListService.delete(jobContentList);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

}
