package com.storlead.sales.controller.customer;


import com.storlead.framework.common.result.Result;
import com.storlead.sales.pojo.dto.customer.BusinessDeleteDTO;
import com.storlead.sales.pojo.entity.customer.LiaisonResourceEntity;
import com.storlead.sales.service.customer.LiaisonResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
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;

/**
 * <p>
 * 联系人资源关联表 前端控制器
 * </p>
 *
 * @author YPZ
 * @since 2024-09-23
 */
@RestController
@RequestMapping("/liaison-resource")
@Api(tags = "销售: 客户联系人管理相关接口")
public class LiaisonResourceController {
    @Resource
    private LiaisonResourceService liaisonResourceService;

    @PostMapping(value = "/add")
    @ApiOperation(value = "联系人业务管理-新增业务联系人关联关系", notes = "客户联系人管理-新增业务联系人关联关系")
    @Transactional(rollbackFor = Throwable.class)
    public Result<?> add(@RequestBody LiaisonResourceEntity liaisonResource) {

        return liaisonResourceService.addLiasonResource(liaisonResource);

    }

    @PostMapping(value = "/edit")
    @ApiOperation(value = "联系人业务管理-编辑业务联系人关联关系", notes = "客户联系人管理-编辑业务联系人关联关系")
    @Transactional(rollbackFor = Throwable.class)
    public Result<?> edit(@RequestBody LiaisonResourceEntity liaisonResource) {

        return liaisonResourceService.editLiasonResource(liaisonResource);

    }

    @ApiOperation(value = "联系人业务管理-删除", notes = "联系人业务管理-删除")
    @PostMapping("/delete")
    public Result delete(@RequestBody BusinessDeleteDTO businessDeleteDTO) {
        boolean deleteOk = false;
        if(!ObjectUtils.isEmpty(businessDeleteDTO.getId())) {
            deleteOk = liaisonResourceService.lgDelete(businessDeleteDTO.getId());
        }
        if(!deleteOk) {
            return Result.error("删除失败");
        }
        return Result.ok();
    }
}
