package com.ruoyi.system.controller;

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

import com.ruoyi.system.service.IServiceGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QuoteCraft;
import com.ruoyi.system.service.IQuoteCraftService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目报价--服务工艺Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/QuoteCraft")
public class QuoteCraftController extends BaseController
{
    @Autowired
    private IQuoteCraftService quoteCraftService;



    @Autowired
    private IServiceGoodsService serviceGoodsService;
    /**
     * 查询项目报价--服务工艺列表
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuoteCraft quoteCraft)
    {
        startPage();
        if(quoteCraft.getGoodId()!=null){
            quoteCraft.setGoodId("\""+quoteCraft.getGoodId()+"\"");
        }
        List<QuoteCraft> list = quoteCraftService.selectQuoteCraftList(quoteCraft);
        //做字典映射关联到服务名称
        for(QuoteCraft  quoteCraftData:list){
            List<String> idslist = Arrays.asList(
                    quoteCraftData.getGoodId().replaceAll("[\\[\\]\"]", "").split(", "));
            quoteCraftData.setServiceName(serviceGoodsService.selectTitlesByIds(idslist));
        }
        return getDataTable(list);
    }

    /**
     * 导出项目报价--服务工艺列表
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:export')")
    @Log(title = "项目报价--服务工艺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuoteCraft quoteCraft)
    {
        List<QuoteCraft> list = quoteCraftService.selectQuoteCraftList(quoteCraft);
        ExcelUtil<QuoteCraft> util = new ExcelUtil<QuoteCraft>(QuoteCraft.class);
        util.exportExcel(response, list, "项目报价--服务工艺数据");
    }

    /**
     * 获取项目报价--服务工艺详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(quoteCraftService.selectQuoteCraftById(id));
    }

    /**
     * 新增项目报价--服务工艺
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:add')")
    @Log(title = "项目报价--服务工艺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuoteCraft quoteCraft)
    {
        return toAjax(quoteCraftService.insertQuoteCraft(quoteCraft));
    }

    /**
     * 修改项目报价--服务工艺
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:edit')")
    @Log(title = "项目报价--服务工艺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuoteCraft quoteCraft)
    {
        return toAjax(quoteCraftService.updateQuoteCraft(quoteCraft));
    }

    /**
     * 删除项目报价--服务工艺
     */
    @PreAuthorize("@ss.hasPermi('system:QuoteCraft:remove')")
    @Log(title = "项目报价--服务工艺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quoteCraftService.deleteQuoteCraftByIds(ids));
    }
}
