package com.ylx.web.controller.massage;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.annotation.Log;
import com.ylx.common.core.controller.BaseController;
import com.ylx.common.core.domain.R;
import com.ylx.common.enums.BusinessType;
import com.ylx.common.utils.StringUtils;
import com.ylx.common.utils.poi.ExcelUtil;
import com.ylx.massage.domain.TJsDay;
import com.ylx.massage.service.TJsDayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;


/**
 * 技师数据统计(TJsDay)表控制层
 *
 * @author makejava
 * @since 2024-08-14 18:00:30
 */
@RestController
@Api(tags = {"技师数据统计"})
@RequestMapping("tJsDay")
public class TJsDayController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TJsDayService tJsDayService;

    /**
     * 分页查询所有数据
     *
     * @param page   分页对象
     * @param tJsDay 查询实体
     * @return R 所有数据
     */
    @GetMapping("selectAll")
    @ApiOperation("分页查询所有数据")
    public R selectAll(Page<TJsDay> page, TJsDay tJsDay) {
        LambdaQueryWrapper<TJsDay> tJsDayLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tJsDayLambdaQueryWrapper.le(StringUtils.isNotBlank(tJsDay.getEndTime()) && StringUtils.isNotBlank(tJsDay.getStartTime()), TJsDay::getCountDate, tJsDay.getEndTime()).
                ge(StringUtils.isNotBlank(tJsDay.getStartTime()) && StringUtils.isNotBlank(tJsDay.getEndTime()),TJsDay::getCountDate, tJsDay.getStartTime()).
            eq(StringUtils.isNotBlank(tJsDay.getName()), TJsDay::getName, tJsDay.getName()).
        orderByDesc(TJsDay::getCountDate);
        if(null != this.getDeptId() && this.getDeptId() != 100){
            tJsDayLambdaQueryWrapper.eq(TJsDay::getDeptId, this.getDeptId());
        }
        return R.ok(this.tJsDayService.page(page, tJsDayLambdaQueryWrapper));
    }

    @GetMapping("selectApp")
    @ApiOperation("技师app数据-本月")
    public R selectAll(TJsDay tJsDay) {
        return R.ok(this.tJsDayService.selectApp(tJsDay));
    }

    @Log(title = "技师统计信息导出", businessType = BusinessType.EXPORT)
    @ApiOperation("导出")
    @RequestMapping(value = "export", method = RequestMethod.POST)
    public void export(HttpServletResponse response, Page<TJsDay> page, TJsDay tJsDay) {
        LambdaQueryWrapper<TJsDay> tJsDayLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tJsDayLambdaQueryWrapper.le(StringUtils.isNotBlank(tJsDay.getEndTime()) && StringUtils.isNotBlank(tJsDay.getStartTime()), TJsDay::getCountDate, tJsDay.getEndTime()).
                ge(StringUtils.isNotBlank(tJsDay.getStartTime()) && StringUtils.isNotBlank(tJsDay.getEndTime()),TJsDay::getCountDate, tJsDay.getStartTime()).
                eq(StringUtils.isNotBlank(tJsDay.getName()), TJsDay::getName, tJsDay.getName()).
                orderByDesc(TJsDay::getCountDate);
        Page<TJsDay> day = this.tJsDayService.page(page, tJsDayLambdaQueryWrapper);
        ExcelUtil<TJsDay> util = new ExcelUtil<TJsDay>(TJsDay.class);
        util.exportExcel(response, day.getRecords(), "技师业绩");
    }

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

    /**
     * 新增数据
     *
     * @param tJsDay 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    @ApiOperation("新增数据")
    public R insert(@RequestBody TJsDay tJsDay) {
        return R.ok(this.tJsDayService.save(tJsDay));
    }

    /**
     * 修改数据
     *
     * @param tJsDay 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    @ApiOperation("修改数据")
    public R update(@RequestBody TJsDay tJsDay) {
        return R.ok(this.tJsDayService.updateById(tJsDay));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("delete")
    @ApiOperation("删除数据")
    public R delete(@RequestBody List<String> idList) {
        return R.ok(this.tJsDayService.removeByIds(idList));
    }
}

