package com.bonus.canteen.core.customer.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.common.base.BaseController;
import com.bonus.canteen.core.customer.model.CustJob;
import com.bonus.canteen.core.customer.service.CustJobService;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping({"/custJob"})
@Api(
   tags = {"customer-人员职位职称控制器"}
)
public class CustJobController extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(CustJobController.class);
   private final CustJobService custJobService;
//   @Autowired
//   SyncCustJobAPI syncCustJobAPI;

   @ApiOperation("全量查询")
   @PostMapping({"/queryAllCustJob"})
   public AjaxResult queryAllCustJob(@RequestBody CustJob record) {
      List<CustJob> list = this.custJobService.list(Wrappers.query(record));
      return AjaxResult.success(list);
   }

//   @ApiOperation("分页查询")
//   @PostMapping({"/pageCustJobList"})
//   @RequiresAuthentication
//   public LeResponse pageCustJobList(@RequestBody LeRequest<CustJobDTO> request) {
//      CustJobDTO content = (CustJobDTO)request.getContent();
//      PageDTO page = ((CustJobDTO)request.getContent()).getPage();
//      Page<CustJobVO> mpPage = Page.of(page.getCurrent(), page.getSize());
//      Page<CustJobVO> response = this.custJobService.pageCustJobList(mpPage, content);
//      return LeResponse.succ(response);
//   }
//
//   @RequiresPermissions({"cust:job:query"})
//   @ApiOperation("分页查询")
//   @GetMapping({"/queryPageCustJob"})
//   @RequiresAuthentication
//   public LeResponse queryPageCustJob(LeRequest<String> request) {
//      String content = (String)request.getContent();
//      PageDTO pageDTO = QueryParseHelper.getPageFromContent(content);
//      CustJob record = (CustJob)QueryParseHelper.getParamFromContent(content, CustJob.class);
//      Page<CustJob> resultPage = (Page)this.custJobService.page(Page.of(pageDTO.getCurrent(), pageDTO.getSize()), (Wrapper)Wrappers.query(record).orderByDesc("crtime"));
//      return LeResponse.succ(resultPage);
//   }
//
//   @ApiOperation("根据id查询")
//   @GetMapping({"/queryCustJobById"})
//   @RequiresGuest
//   public LeResponse queryCustJobById(LeRequest<String> request) {
//      String content = (String)request.getContent();
//      Map<String, JSONObject> contentMap = (Map)this.gson.fromJson(content, Map.class);
//      CustJob params = (CustJob)this.gson.fromJson(this.gson.toJson(contentMap.get("object")), CustJob.class);
//      if (params.getId() == null) {
//         log.error("[人员职位职称]根据id查询_上送参数错误,主键id不能为空");
//         return LeResponse.fail();
//      } else {
//         CustJob custJob = (CustJob)this.custJobService.getById(params.getId());
//         return LeResponse.succ(custJob);
//      }
//   }
//
//   @RequiresPermissions({"cust:job:add"})
//   @ApiOperation("新增")
//   @PostMapping({"/addCustJob"})
//   @RequiresAuthentication
//   public LeResponse addCustJob(@RequestBody LeRequest<CustJob> request) {
//      CustJob custJob = (CustJob)request.getContent();
//      if (!StringUtils.isBlank(custJob.getJobCode()) && !StringUtils.isBlank(custJob.getJobName()) && custJob.getJobType() != null) {
//         this.custJobService.addCustJob(custJob);
//         return LeResponse.succ();
//      } else {
//         log.error("[人员职位职称]根据id修改_上送参数错误,编码、名称、类型均不能为空");
//         return LeResponse.fail(I18n.getMessage("customer.job.numAndnameAndType.nonNull", new Object[0]));
//      }
//   }
//
//   @RequiresPermissions({"cust:job:edit"})
//   @ApiOperation("根据id修改")
//   @PutMapping({"/updateCustJobById"})
//   @RequiresAuthentication
//   public LeResponse updateCustJobById(@RequestBody LeRequest<CustJob> request) {
//      CustJob custJob = (CustJob)request.getContent();
//      if (custJob.getId() == null) {
//         log.error("[人员职位职称]根据id修改_上送参数错误,主键id不能为空");
//         return LeResponse.fail();
//      } else {
//         this.custJobService.updateById(custJob);
//         return LeResponse.succ();
//      }
//   }
//
//   @RequiresPermissions({"cust:job:del"})
//   @ApiOperation("根据id删除")
//   @DeleteMapping({"/deleteCustJobById"})
//   @RequiresAuthentication
//   public LeResponse deleteCustJobById(@RequestBody LeRequest<CustJob> request) {
//      CustJob custJob = (CustJob)request.getContent();
//      if (custJob.getId() == null) {
//         log.error("[人员职位职称]根据id删除_上送参数错误,主键id不能为空");
//         return LeResponse.fail();
//      } else {
//         this.custJobService.deleteCustJobById(Collections.singleton(custJob.getId()));
//         return LeResponse.succ();
//      }
//   }
//
//   @ApiOperation("测试同步人员职位职称")
//   @PostMapping({"/testSyncCustJob"})
//   public LeResponse testSyncCustJob(@RequestBody LeRequest<List<SyncCustJobDTO>> request) {
//      List<String> strings = this.syncCustJobAPI.syncCustJobByType((List)request.getContent(), CustJobTypeEnum.POSITION);
//      return LeResponse.succ(strings);
//   }

//   public CustJobController(final CustJobService custJobService, final SyncCustJobAPI syncCustJobAPI) {
//      this.custJobService = custJobService;
//      this.syncCustJobAPI = syncCustJobAPI;
//   }

   public CustJobController(final CustJobService custJobService) {
      this.custJobService = custJobService;
   }
}
