package com.ylx.web.controller.massage;


import com.ylx.common.annotation.Log;
import com.ylx.common.core.domain.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.core.controller.BaseController;
import com.ylx.common.enums.BusinessType;
import com.ylx.massage.domain.Complaint;
import com.ylx.massage.enums.ComplaintEnum;
import com.ylx.massage.enums.Enumproject;
import com.ylx.massage.service.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 投诉(Complaint)表控制层
 *
 * @author makejava
 * @since 2024-07-30 11:06:59
 */
@RestController
@RequestMapping("complaint")
@Api(tags = {"投诉"})
public class ComplaintController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ComplaintService complaintService;

    /**
     * 分页查询所有投诉数据
     *
     * @param page      分页对象
     * @param complaint 查询实体
     * @return R
     */
    @GetMapping("selectAll")
    @ApiOperation("分页查询所有投诉数据")
    @Log(title = "分页查询所有投诉数据", businessType = BusinessType.OTHER)
    public R selectAll(Page<Complaint> page, Complaint complaint) {
        if(null != this.getDeptId() && this.getDeptId() != 100){
            complaint.setDeptId(this.getDeptId().toString());
        }
        Page<Complaint> complaints = complaintService.selectAll(page, complaint);
        return R.ok(complaints);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public R selectOne(@PathVariable Serializable id) {

        Complaint byId = this.complaintService.getById(id);
        if (byId == null) {
            return R.fail("该投诉不存在");
        }
        byId.setComplaintType(ComplaintEnum.getDescByCode(byId.getComplaintType()));
        return R.ok(byId);
    }

    /**
     * 新增数据
     *
     * @param complaint 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    @ApiOperation("新增数据")
    @Log(title = "投诉新新增数据", businessType = BusinessType.INSERT)
    public R insert(@RequestBody Complaint complaint) {
        return R.ok(this.complaintService.save(complaint));
    }

    /**
     * 修改数据
     *
     * @param complaint 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    @ApiOperation("修改数据")
    @Log(title = "投诉修改数据", businessType = BusinessType.UPDATE)
    public R update(@RequestBody Complaint complaint) {
        return R.ok(this.complaintService.updateById(complaint));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("delete")
    @ApiOperation("删除数据")
    @Log(title = "投诉删除数据", businessType = BusinessType.DELETE)
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(this.complaintService.removeByIds(idList));
    }
    @PostMapping("complaintEnum")
    @ApiOperation("投诉类型")
    public R getEnum() {
        List<Enumproject> statusEnum = ComplaintEnum.getStatusEnum();
        return R.ok(statusEnum);
    }
}

