package com.dk.mdm.controller.core;

import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.pojo.core.Job;
import com.dk.mdm.model.query.core.JobQuery;
import com.dk.mdm.model.response.core.JobResponse;
import com.dk.mdm.model.vo.core.JobVO;
import com.dk.mdm.service.core.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @desc   : 工种API接口
 * @author : 姜宁
 * @date   : 2023/1/4 11:34
 */
@Api(tags = "工种API接口")
@RestController
@RequestMapping("/core/job")
public class JobController{

    public BaseService<Job> getService() {
        return jobService;
    }

    @Autowired
    private JobService jobService;

    /**
     * @desc   : 条件查询
     * @author : 姜宁
     * @date   : 2023/1/4 13:28
     */
    @ApiOperation( value = "分页、关联、条件查询", notes = "分页、关联、条件查询" )
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<JobResponse>> selectByCond(@RequestBody JobQuery jobQuery) {
        return jobService.selectByCond(jobQuery);
    }


   /**
    * @desc   : 通过ID查询
    * @author : 姜宁
    * @date   : 2023/1/4 13:50
    */
    @PostMapping({"{id}"})
    public ResponseResultVO selectById(@PathVariable String id) {
        return jobService.selectById(id);
    }


   /**
    * @desc   : 新建工种
    * @author : 姜宁
    * @date   : 2023/1/4 13:59
    */
    @ApiOperation( value = "新建工种", notes = "新建工种" )
    @PostMapping({"insert"})
    @Transactional(rollbackFor = Exception.class)
    public ResponseResultVO<?> insert(@RequestBody JobVO jobVO) {
        return jobService.insert(jobVO);
    }
//    public ResponseResultVO<?> insert(@RequestBody Map<String, Object> param) {
//        String str = AESUtil.desEncrypt(param.get("param").toString());
//        JSONObject jsonObject = (JSONObject) JSON.parse(str);
//        JobVO jobVO = JSONObject.toJavaObject(jsonObject, JobVO.class);
//        return jobService.insert(jobVO);
//    }

    /**
     * @desc   : 编辑工种
     * @author : 姜宁
     * @date   : 2023/1/4 14:30
     */
    @ApiOperation( value = "编辑工种", notes = "编辑工种" )
    @PostMapping({"update"})
    @Transactional(rollbackFor = Exception.class)
    public ResponseResultVO<Boolean> update(@RequestBody JobVO jobVO) {
        return jobService.update(jobVO);
    }

    /**
     * @desc   : 停用
     * @author : 姜宁
     * @date   : 2023/1/4 14:28
     */
    @ApiOperation(value = "停用", notes = "停用")
    @PostMapping("disable/{id}")
    public ResponseResultVO<Boolean> disable(@PathVariable String id) {
        return this.getService().disable(id);
    }

   /**
    * @desc   : 启用
    * @author : 姜宁
    * @date   : 2023/1/4 14:28
    */
    @ApiOperation(value = "启用", notes = "启用")
    @PostMapping("enable/{id}")
    public ResponseResultVO<Boolean> enable(@PathVariable String id) {
        return this.getService().enable(id);
    }
}
