package com.malk.diwei.controller;

import com.malk.diwei.service.*;
import com.malk.server.common.McR;
import com.malk.utils.UtilServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping()
public class DiweiController {
    @Autowired
    private ClientService clientService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private ProcStepService procStepService;

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private ProcessService processService;

    @Autowired
    private SalesOrderService salesOrderService;

    @Autowired
    private DiweiService diweiService;

    @Autowired
    private ColorService colorService;

    @Autowired
    private SizeService sizeService;

    //同步客户
    @GetMapping("/syncClient")
    public McR syncClient() {
        return clientService.syncClient();
    }

    //同步物料
    @GetMapping("/syncGoods")
    private McR syncGoods(){
        return goodsService.syncGoods();
    }

    //同步工序
    @GetMapping("/syncProcStep")
    public McR syncProcStep(){
        return procStepService.syncProcStep();
    }

    //同步员工
    @GetMapping("/syncEmployee")
    public McR syncEmployee(){
        return employeeService.syncEmplyee();
    }

    //查询物料库存信息
    @GetMapping("/queryGoodsStock")
    public McR queryGoodsStock(Integer goodsId,Integer colorId,Integer sizeId){
        return goodsService.queryGoodsStock(goodsId, colorId, sizeId);
    }

    //同步毛衫加工单
    @GetMapping("/syncProcess")
    public McR syncProcess(){
        return processService.syncProcess();
    }

    //同步横机外发单
    @GetMapping("/syncProcessOut")
    public McR syncProcessOut(){
        return processService.syncProcessOut();
    }

    //同步工艺外发单
    @GetMapping("/syncProcessOut2")
    public McR syncProcessOut2(){
        return processService.syncProcessOut2();
    }

    //同步织片回收单
    @GetMapping("/syncProcessOn")
    public McR syncProcessOn(){
        return processService.syncProcessOn();
    }

    //同步工艺回收单
    @GetMapping("/syncProcessOn2")
    public McR syncProcessOn2(){
        return processService.syncProcessOn2();
    }

    //同步颜色
    @GetMapping("/syncColor")
    public McR syncColor(){
        return colorService.syncColor();
    }

    //同步尺码
    @GetMapping("/syncSize")
    public McR syncSize(){
        return sizeService.syncSize();
    }

    //同步所有基础数据
    @Scheduled(cron = "0 0 0 * * ?")
    @GetMapping("/syncBaseAll")
    public McR syncBaseAll(){
        return diweiService.syncBaseAll();
    }

    //同步所有生产流程数据
    @Scheduled(cron = "0 0 1 * * ?")
    @GetMapping("/syncProcessAll")
    public McR syncProcessAll(){
        return diweiService.syncProcessAll();
    }

    //新增销售订单
    @PostMapping("/addSaleOrder")
    public McR addSaleOrder(@RequestBody Map map){
        return salesOrderService.addSaleOrder(map);
    }

    //新增BOM
    @PostMapping("/addBom")
    public McR addBom(@RequestBody Map map){
        return goodsService.addBom(map);
    }

    //查询成品最新Bom
    @GetMapping("/queryGoodsNewBom")
    public McR queryGoodsNewBom(int goodsId){
        return goodsService.queryGoodsNewBom(goodsId);
    }

    //查询Bom是否存在
    @PostMapping("/queryBomIsExist")
    public McR queryBomIsExist(HttpServletRequest request){
        Map data = UtilServlet.getParamMap(request);
        String bomCode = data.get("bomCode").toString();
        return goodsService.queryBomIsExist(bomCode);
    }


}
