package com.crm.manager.controller;

import com.crm.manager.service.MamApplyFeignService;
import com.crm.rely.backend.core.dto.base.BaseReportResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.mam.MamApplyDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import com.crm.rely.backend.core.entity.mam.MamApplyApproveEntity;
import com.crm.rely.backend.core.entity.mam.MamApplyDeleteEntity;
import com.crm.rely.backend.core.entity.mam.MamApplyListEntity;
import org.apache.activemq.network.jms.InboundQueueBridge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * Created by max on 2020/8/24.
 */
@RestController
@RequestMapping("/mam/apply")
public class MamApplyController {

    @Autowired
    private MamApplyFeignService mamApplyFeignService;

    @PostMapping("/list")
    public BaseResultDto<List<MamApplyDto>> applyList(@RequestBody MamApplyListEntity entity, InfoEntity infoEntity) throws Exception {
        return mamApplyFeignService.applyList(entity);
    }

    @PostMapping("/approve")
    public BaseResultDto<Object> applyApprove(@RequestBody MamApplyApproveEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setApproveTime(new Date());
        entity.setApproveUser(infoEntity.getIbInfo().getId());
        return mamApplyFeignService.approveApply(entity);
    }

    @PostMapping("/delete")
    public BaseResultDto<Object> deleteApply(@RequestBody SingleLongEntity entity, InfoEntity infoEntity) throws Exception {
        MamApplyDeleteEntity deleteEntity = new MamApplyDeleteEntity();
        deleteEntity.setId(entity.getId());
        return mamApplyFeignService.deleteApply(deleteEntity);
    }

}
