package com.huigou.topsun.sap.clientMaterials.controller;

import com.huigou.context.Operator;
import com.huigou.context.OrgUnit;
import com.huigou.topsun.sap.clientMaterials.application.ClientMaterialsApplication;
import com.huigou.topsun.sap.clientMaterials.domain.ClientMaterials;
import com.huigou.topsun.sap.clientMaterials.domain.query.ClientMaterialsQueryRequest;
import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.bmp.common.BizBillStatus;
import com.huigou.uasp.client.CommonController;
import com.huigou.util.CommonUtil;
import com.huigou.util.SDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**客户供料通知
 * @Auther: LXH
 * @Date: 2024/06/05 10:15
 * @Description:
 */
@Controller
@ControllerMapping("/clientMaterials")
public class ClientMaterialsController extends CommonController {
    @Override
    protected String getPagePath() {
        return "/biz/topsun/sap/clientMaterials/";
    }

    @Resource
    private ClientMaterialsApplication clientMaterialsApplication;


    public String forwardClientMaterialsList(){
        return forward("clientMaterialsList");
    }

    public String slicedClientMaterialsList(){
        SDO sdo = this.getSDO();
        ClientMaterialsQueryRequest queryRequest = sdo.toQueryRequest(ClientMaterialsQueryRequest.class);
        Map<String, Object> map = clientMaterialsApplication.getClientMaterialsList(queryRequest);
        return toResult(map);
    }

    public String forwardClientMaterialsDetail(){
        // 新增的时候procUnitId一定要设置成Apply，不然jsp页面的所有表单元素是readonly状态
        this.putAttribute("processDefinitionKey", ClientMaterialsApplication.PROCESS_DEFINITION_KEY);
        this.putAttribute("procUnitId", "Apply");
        ClientMaterials clientMaterials = new ClientMaterials();
        clientMaterials.setStatusId(BizBillStatus.APPLYING.getId());
        /**c
         * 设置jsp页面初始化填充数据，如果不设置， 那么在jsp页面上填写完表单之后立即提交申请TaskDescription获取不到时间和相关人员信息
         */
        Operator operator = getOperator();
        clientMaterials.setDefaultValues(new OrgUnit(operator.getFullId(), operator.getFullName()));
        clientMaterials.setAttbizId(CommonUtil.createGUID()); // 自动生成附件id
       // ExcelImportTemplate excelImportTemplate=excelImportApplication.loadExcelImportTemplateByCode("ClientMaterialsData");
        return forward("clientMaterialsDetail",clientMaterials);
    }

    public String showClientMaterials(){
        SDO sdo = this.getSDO();
        String id = sdo.getBizId();
       // this.putAttribute("attbizId", id); // 设置附件id
        ClientMaterials clientMaterials = clientMaterialsApplication.getClientMaterialsById(id);
       // sapRetirement.setAttbizId(id);
        return forward("clientMaterialsDetail",clientMaterials);
    }

    /**
     * 删除组件补充发料
     */
    public String deleteClientMaterials() {
        List<String> ids = this.getSDO().getIds();
        clientMaterialsApplication.deleteByIds(ids);
        return success();
    }


}
