package com.sw.mes.press;

import com.sw.mes.base.system.entity.InventoryManageInfo;
import com.sw.mes.base.system.service.InventoryManageInfoService;
import com.sw.mes.core.dto.mes.pc.yb.YbInspectDataDto;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.inspect.dto.YbInspectDataCUDto;
import com.sw.mes.inspect.entity.YbInspectData;
import com.sw.mes.inspect.service.YbInspectDataService;
import com.sw.mes.yb.pad.entity.ProductionPaintingLineDetail;
import com.sw.mes.yb.pad.service.ProductionPaintingLineDetailService;
import com.sw.mes.yb.production.entity.AgainTaskDetail;
import com.sw.mes.yb.production.entity.LongCrystal;
import com.sw.mes.yb.production.service.AgainTaskDetailService;
import com.sw.mes.yb.production.service.LongCrystalService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 查询类压力测试接口
 *
 * @Author：wanjia
 * @Date：2024/2/2 14:56
 */
@RestController("/press")
public class QueryPressTestController {


    //------------------------------ 长晶棒产出表 ------------------------------//
    @Autowired
    private LongCrystalService longCrystalService;

    /**
     * 长晶棒业务，根据晶编查询对应的数据
     *
     * @param crystalNo
     * @return
     */
    @RequestMapping("/long_crystal/findById/{crystalNo}")
    public Result<LongCrystal> findByCrystalNo(@PathVariable("crystalNo") String crystalNo) {
        LongCrystal longCrystal = longCrystalService.findByCrystalNo(crystalNo);
        if (null == longCrystal) {
            return ResultGenerator.success("cannot find by crystalNo", null);
        }
        return ResultGenerator.success(longCrystal);
    }

    /**
     * 长晶棒业务，根据晶编查询对应的数据,每次最多传入20个
     *
     * @param crystalNos
     * @return
     */
    @RequestMapping("/long_crystal/findByIds/{crystalNos}")
    public Result<List<LongCrystal>> findByCrystalNos(@PathVariable("crystalNos") List<String> crystalNos) {
        if (CollectionUtils.isEmpty(crystalNos) || crystalNos.size() > 20) {
            return ResultGenerator.fail("param error");
        }
        List<LongCrystal> longCrystal = longCrystalService.findAllByCrystalNo(crystalNos);
        if (null == longCrystal) {
            return ResultGenerator.success("cannot find by crystalNo", null);
        }
        return ResultGenerator.success(longCrystal);
    }

    //------------------------------灌料任务------------------------------//
    @Autowired
    private AgainTaskDetailService againTaskDetailService;

    /**
     * 根据灌料任务id获取灌料任务明细
     *
     * @param againTaskId
     * @return
     */
    @RequestMapping("/again_task/findById/{id}")
    public Result<List<AgainTaskDetail>> findByAgainTaskId(@PathVariable("id") Long againTaskId) {
        List<AgainTaskDetail> list = againTaskDetailService.findByAgainTaskId(againTaskId);
        return ResultGenerator.success(list);
    }


    /**
     * 根据id列表进行查询,每次最多传入20个
     *
     * @param againTaskIds
     * @return
     */
    @RequestMapping("/again_task/findByIds/{id}")
    public Result<List<AgainTaskDetail>> findByAgainTaskIds(@PathVariable("id") List<Long> againTaskIds) {
        if (CollectionUtils.isEmpty(againTaskIds) || againTaskIds.size() > 20) {
            return ResultGenerator.fail("param error");
        }
        List<AgainTaskDetail> list = againTaskDetailService.findByAgainTaskIdList(againTaskIds);
        return ResultGenerator.success(list);
    }

    //------------------------------圆棒检验数据查询------------------------------//
    @Autowired
    private ProductionPaintingLineDetailService productionPaintingLineDetailService;

    /**
     * 根据晶段编号查询对应的数据
     *
     * @param segmentNo
     * @return
     */
    @RequestMapping("/product_paint/findBySegmentNo/{segmentNo}")
    public Result<ProductionPaintingLineDetail> findBySegmentNo(@PathVariable("segmentNo") String segmentNo) {
        ProductionPaintingLineDetail detail = productionPaintingLineDetailService.findBySegmentNo(segmentNo);
        return ResultGenerator.success(detail);
    }

    /**
     * 查询长棒划线明细
     *
     * @param id
     * @return
     */
    @RequestMapping("/product_paint/findByOperateDrawId/{id}")
    public Result<List<ProductionPaintingLineDetail>> findByOperateDrawId(@PathVariable("id") Long id) {
        List<ProductionPaintingLineDetail> list = productionPaintingLineDetailService.findByOperateDrawId(id);
        return ResultGenerator.success(list);
    }


    @Autowired
    private YbInspectDataService ybInspectDataService;


    /**
     * 根据晶段编号查询检验信息
     *
     * @param sectionNo
     * @return
     */
    @RequestMapping("/yb_inspect/findBySectionNo/{sectionNo}")
    public Result<YbInspectData> findBySectionNo(@PathVariable("sectionNo") String sectionNo) {
        YbInspectData data = ybInspectDataService.findBySectionNo(sectionNo);
        return ResultGenerator.success(data);
    }


    /**
     * 根据晶段编号查询检验信息
     *
     * @param sectionNos 最多不超过20个
     * @return
     */
    @RequestMapping("/yb_inspect/findBySectionNos/{sectionNos}")
    public Result<List<YbInspectData>> findBySectionNo(@PathVariable("sectionNos") List<String> sectionNos) {
        if (CollectionUtils.isEmpty(sectionNos) || sectionNos.size() > 20) {
            return ResultGenerator.fail("param error..");
        }
        List<YbInspectData> list = ybInspectDataService.findBySections(sectionNos);
        return ResultGenerator.success(list);
    }


    //------------------------------圆棒检验数据录入------------------------------//

    /**
     * 圆棒检验数据录入
     *
     * @param ybInspectDataCUDto
     * @return
     */
    @PostMapping("/yb_inspect/save")
    public Result saveYbInspectData(YbInspectDataCUDto ybInspectDataCUDto) {
        return ybInspectDataService.saveYbInspectData(ybInspectDataCUDto);
    }

    //------------------------------出入库数据录入------------------------------//
    @Autowired
    private InventoryManageInfoService inventoryManageInfoService;

    /**
     * 写入库存信息
     *
     * @param info
     * @return
     */
    @PostMapping("/inventory/insert")
    public Result<Boolean> insert(InventoryManageInfo info) {
        inventoryManageInfoService.saveOrUpdate(info);
        return ResultGenerator.success();
    }


    @RequestMapping("/inventory/query/{id}")
    public Result<InventoryManageInfo> inventoryQuery(@PathVariable("id") Long id) {
        InventoryManageInfo info = inventoryManageInfoService.get(id);
        return ResultGenerator.success(info);
    }

}
