package com.huigou.topsun.proofing.controller;


import com.huigou.topsun.product.application.ProductLookedApplication;
import com.huigou.topsun.product.domain.ProductLooked;
import com.huigou.topsun.proofing.application.ProofingApplyApplication;
import com.huigou.topsun.proofing.domain.model.ProofingApply;
import com.huigou.topsun.proofing.domain.model.ProofingMake;
import com.huigou.topsun.proofing.domain.vo.ProofingApplyAndLookedVo;
import com.huigou.topsun.proofing.domain.vo.ProofingMakeVo;

import com.huigou.topsun.proofing.service.ProofingMakeService;

import com.huigou.uasp.annotation.ControllerMapping;

import com.huigou.uasp.client.CommonController;
import com.huigou.uasp.log.annotation.LogInfo;
import com.huigou.uasp.log.domain.model.LogType;
import com.huigou.uasp.log.domain.model.OperationType;
import com.huigou.util.SDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
@ControllerMapping("/proofingMake")
public class ProofingMakeController extends CommonController {
    protected String getPagePath() {
        return "/biz/topsun/proofing/";
    }

    @Autowired
    ProofingMakeService proofingMakeService;
    @Autowired
    ProofingApplyApplication proofingApplyApplication;
    @Autowired
    ProductLookedApplication productLookedApplication;


    /**
     * 打样制作表单页
     * @return
     */
    public String forwardProofingMake(){
        String proofingMakeNo = UUID.randomUUID().toString().replace("-", "");
        this.putAttribute("proofingMakeNo", proofingMakeNo);
        this.putAttribute("bizId", "proofingMake");
        return forward("proofingMake");
    }

    /**
     * 打样制作查询页
     * @return
     */
    public String forwardProofingMakeList(){
        return forward("proofingMakeList");
    }


    @LogInfo(logType = LogType.BIZ, subType = "", operaionType = OperationType.QUERY, description = "分页查询打样制造表")
    public String slicedQueryProofingMake() {
        List<ProofingMakeVo> proofingMakeList = proofingMakeService.getProofingMakeVoList();
        Map<String,Object> map =new HashMap();
        map.put("Rows",proofingMakeList);
        return toResult(map);
    }

    /**
     *  跳转打样制造详情页
     */
    public String forwardDetailsProofingMake(){

        SDO sdo = this.getSDO();
        String id = sdo.getId();
        ProofingMakeVo proofingMakeVo =
                (id==null||"".equals(id))?null:proofingMakeService.getProofingMakeVoById(id);
        return forward("proofingMake",proofingMakeVo);
    }

    /**
     * 编辑打样制造信息
     * @return
     */
    public String saveProofingMake(){
        SDO sdo = this.getSDO();
        ProofingMake proofingMake = sdo.toObject(ProofingMake.class);
        proofingMakeService.saveProofingMakeVo(proofingMake);
       return success(proofingMake);
    }


    public String deleteProofingMakeByProofingMakeId(){
        SDO sdo = this.getSDO();
        String proofingMakeId = sdo.getString("ids");
        proofingMakeService.deleteProofingMakeVo(proofingMakeId);
        return success();
    }

    /**
     * 根据测试单号回显相关数据
     * @return
     */
    public String queryProofingApply(){
        SDO sdo = this.getSDO();
        String proofingApplyNo = sdo.getString("proofingApplyNo");
        ProofingApplyAndLookedVo proofingApplyAndLookedVo = proofingApplyApplication.getProofingApplyByProofingApplyNo(proofingApplyNo);
        return toResult(proofingApplyAndLookedVo);
    }


}
