package org.springblade.workorder.publicevent.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springblade.flow.core.feign.IFlowClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.workorder.publicevent.entity.PublicEvent;
import org.springblade.workorder.publicevent.vo.PublicEventVO;
import org.springblade.workorder.publicevent.wrapper.PublicEventWrapper;
import org.springblade.workorder.publicevent.service.IPublicEventService;

import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-09
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/publicevent")

public class PublicEventClient implements IPublicEventClient {

    private final IPublicEventService publicEventService;
    private final IFlowClient flowClient;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public PublicEventVO detail(PublicEvent publicEvent) {
        PublicEvent detail = publicEventService.getOne(Condition.getQueryWrapper(publicEvent));
        return PublicEventWrapper.build(publicEventService, flowClient).entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<PublicEventVO> list(PublicEvent publicEvent) {
        return PublicEventWrapper.build(publicEventService, flowClient).listVO(publicEventService.list(Condition.getQueryWrapper(publicEvent)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody PublicEvent publicEvent) {
        return publicEventService.save(publicEvent);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody PublicEvent publicEvent) {
        return publicEventService.updateById(publicEvent);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody PublicEvent publicEvent) {
        return publicEventService.saveOrUpdate(publicEvent);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return publicEventService.deleteLogic(Func.toLongList(ids));
        }


}
