package com.eitc.patient.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eitc.common.annotation.Log;
import com.eitc.common.core.controller.BaseController;
import com.eitc.common.core.domain.AjaxResult;
import com.eitc.common.core.page.TableDataInfo;
import com.eitc.common.enums.BusinessType;
import com.eitc.patient.domain.CollectCostDetails;
import com.eitc.patient.service.ICollectCostDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * CollectCostDetailsController
 *
 * @author mtx
 * @date: 2024/05/17 15:51
 */
@Api(tags = "收费分类详情")
@RestController
@RequestMapping("/collect-cost-details")
public class CollectCostDetailsController extends BaseController {

    @Resource
    private ICollectCostDetailsService collectCostDetailsService;


    /**
     * 查询收费分类详情列表
     */
    @GetMapping("/page")
    @ApiOperation("查询收费分类详情列表")
    public TableDataInfo page(CollectCostDetails collectCostDetails) {
        startPage();
        LambdaQueryWrapper<CollectCostDetails> wrapper = Wrappers.<CollectCostDetails>lambdaQuery()
                .eq(CollectCostDetails::getCollectCostTypeId, collectCostDetails.getCollectCostTypeId())
                .like(StringUtils.isNotBlank(collectCostDetails.getProjectName()),
                        CollectCostDetails::getProjectName, collectCostDetails.getProjectName());
        wrapper.orderByDesc(CollectCostDetails::getCreateDate);
        List<CollectCostDetails> list = collectCostDetailsService.list(wrapper);
        return getDataTable(list);
    }

    @GetMapping("/list")
    @ApiOperation("查询收费分类详情列表")
    public AjaxResult list(CollectCostDetails collectCostDetails) {
        LambdaQueryWrapper<CollectCostDetails> wrapper = Wrappers.<CollectCostDetails>lambdaQuery()
                .eq(CollectCostDetails::getStatus, 1)
                .eq(StringUtils.isNotBlank(collectCostDetails.getCollectCostTypeId()),
                        CollectCostDetails::getCollectCostTypeId, collectCostDetails.getCollectCostTypeId())
                .like(StringUtils.isNotBlank(collectCostDetails.getProjectName()),
                        CollectCostDetails::getProjectName, collectCostDetails.getProjectName());
        wrapper.orderByAsc(CollectCostDetails::getOrderNum);
        List<CollectCostDetails> list = collectCostDetailsService.list(wrapper);
        return success(list);
    }

    /**
     * 获取收费分类详情详细信息
     */
    @GetMapping(value = "/detail")
    @ApiOperation("获取收费分类详情详细信息")
    public AjaxResult detail(String id) {
        return success(collectCostDetailsService.getById(id));
    }

    /**
     * 新增收费分类详情
     */
    @Log(title = "新增收费分类详情", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增收费分类详情")
    public AjaxResult add(@Valid @RequestBody CollectCostDetails collectCostDetails) {
        return toAjax(collectCostDetailsService.save(collectCostDetails));
    }

    /**
     * 修改收费分类详情
     */
    @Log(title = "修改收费分类详情", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改收费分类详情")
    public AjaxResult edit(@Valid @RequestBody CollectCostDetails collectCostDetails) {
        return toAjax(collectCostDetailsService.updateById(collectCostDetails));
    }

    /**
     * 删除收费分类详情
     */
    @Log(title = "删除收费分类详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    @ApiOperation("删除收费分类详情")
    public AjaxResult remove(String ids) {
        List<String> idList = Arrays.asList(ids.split(","));
        return toAjax(collectCostDetailsService.removeBatchByIds(idList));
    }


}
