package com.crm.manager.controller;

import com.crm.manager.service.MamListFeignService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.dto.mam.MamListDto;
import com.crm.rely.backend.core.entity.base.BaseDeleteEntities;
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.MamListSearchEntity;
import com.crm.rely.backend.exception.ServiceException;
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")
public class MamListController {

    @Autowired
    private MamListFeignService mamListFeignService;

    /**
     * 查询mam账户列表
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/list")
    public BaseResultWithPagerDto<List<MamListDto>> mamList(@RequestBody MamListSearchEntity entity) throws Exception {
        return mamListFeignService.mamList(entity);
    }

    /**
     * 删除PM账户
     *
     * @param entities
     * @param infoEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/pm/delete")
    public BaseResultDto<Boolean> deletePm(@RequestBody BaseDeleteEntities entities, InfoEntity infoEntity) throws Exception {
        entities.setModifyUser(infoEntity.getIbInfo().getId());
        entities.setModifyTime(new Date());
        return mamListFeignService.deletePm(entities);
    }

    @PostMapping("/lock")
    public BaseResultDto<Object> lock(@RequestBody SingleLongEntity entity) throws ServiceException {
        return mamListFeignService.lock(entity);
    }

}
