package com.crm.manager.controller;

import com.crm.manager.service.CustomRemarkService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.custom.remark.CustomRemarkSearchListDto;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import com.crm.rely.backend.core.entity.custom.remark.CustomRemarkAddEntity;
import com.crm.rely.backend.core.entity.custom.remark.CustomRemarkSearchListEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

/**
 * @description: 客户备注控制器
 * @author: houn
 * @create: 2020-06-13 17:52
 **/
@RestController
@RequestMapping("/custom/remark")
public class CustomRemarkController {

    @Autowired
    private CustomRemarkService customRemarkService;

    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated CustomRemarkAddEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setUserId(infoEntity.getIbInfo().getId());
        customRemarkService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/search/list")
    public BaseResultDto searcherList(@RequestBody @Validated CustomRemarkSearchListEntity entity, InfoEntity infoEntity) throws Exception {

        if (entity.getOwn() != null && entity.getOwn().equals(1)) {
            entity.setUserId(infoEntity.getIbInfo().getId());
        }
        ResultWithPagerDto<CustomRemarkSearchListDto> remarkSearchListDtoResultWithPagerDto = customRemarkService.searchList(entity);

        return remarkSearchListDtoResultWithPagerDto;
    }
}
