package com.zzsmart.qomo.kn.cost.manage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostCount;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: app_scene_cost_count
 * @Author: jeecg-boot
 * @Date: 2024-07-29
 * @Version: V1.0
 */
@Api(tags = "cost-标准成本计算")
@RestController
@RequestMapping("//costCount")
@Slf4j
public class AppSceneCostCountController extends JeecgController<AppSceneCostCount, IAppSceneCostCountService> {
    @Autowired
    private IAppSceneCostCountService appSceneCostCountService;

    /**
     * 分页列表查询
     *
     * @param appSceneCostCount
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "app_scene_cost_count-分页列表查询")
    @ApiOperation(value = "标准成本计算-分页列表查询", notes = "标准成本计算-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<AppSceneCostCount>> queryPageList(AppSceneCostCount appSceneCostCount,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          HttpServletRequest req) {
        QueryWrapper<AppSceneCostCount> queryWrapper = QueryGenerator.initQueryWrapper(appSceneCostCount, req.getParameterMap());
        Page<AppSceneCostCount> page = new Page<AppSceneCostCount>(pageNo, pageSize);
        IPage<AppSceneCostCount> pageList = appSceneCostCountService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加标准成本计算任务
     *
     * @param appSceneCostCount
     * @return
     */
    @AutoLog(value = "app_scene_cost_count-添加")
    @ApiOperation(value = "添加标准成本计算任务", notes = "添加标准成本计算任务")
    @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:addCostCountTask")
    @PostMapping(value = "/addCostCountTask")
    public Result<String> addCostCountTask(@RequestBody AppSceneCostCount appSceneCostCount) {
        appSceneCostCountService.addCostCountTask(appSceneCostCount);
        return Result.OK("添加成功！");
    }


    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "app_scene_cost_count-通过id删除")
    @ApiOperation(value = "标准成本计算-通过id删除", notes = "标准成本计算-通过id删除")
    @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        appSceneCostCountService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "app_scene_cost_count-批量删除")
    @ApiOperation(value = "app_scene_cost_count-批量删除", notes = "app_scene_cost_count-批量删除")
    @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.appSceneCostCountService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 重新计算
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "app_scene_cost_count-通过id查询")
    @ApiOperation(value = "标准成本计算-重新计算", notes = "标准成本计算-重新计算")
    @GetMapping(value = "/recountById")
    public Result<AppSceneCostCount> recountById(@RequestParam(name = "id", required = true) Integer id) {
        AppSceneCostCount appSceneCostCount = appSceneCostCountService.recountById(id);
        if (appSceneCostCount == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(appSceneCostCount);
    }

    /**
     * 查看关键缺失部件
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "app_scene_cost_count-通过id查询")
    @ApiOperation(value = "标准成本计算-查看关键缺失部件", notes = "标准成本计算-查看关键缺失部件")
    @GetMapping(value = "/queryMissingComponentById")
    public Result<AppSceneCostCount> queryMissingComponentById(@RequestParam(name = "id", required = true) String id) {
        AppSceneCostCount appSceneCostCount = appSceneCostCountService.queryMissingComponentById(id);
        if (appSceneCostCount == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(appSceneCostCount);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param appSceneCostCount
     */
    @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AppSceneCostCount appSceneCostCount) {
        return super.exportXls(request, appSceneCostCount, AppSceneCostCount.class, "app_scene_cost_count");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AppSceneCostCount.class);
    }

}
