package com.zcloud.modules.sys.controller;

import com.zcloud.common.annotation.SysLog;
import com.zcloud.common.utils.*;
import com.zcloud.modules.sys.entity.BusNoticeEntity;
import com.zcloud.modules.sys.service.BusNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;

/**
 * @Author chenxinying
 * @Desc (BusNotice)表控制层
 * @Date 2024-03-28 16:29:56
 */
@Api(tags = "")
@RestController
@RequestMapping("busNotice")
public class BusNoticeController extends AbstractController {

    @Autowired
    private BusNoticeService busNoticeService;

    @ApiOperation("-新增数据")
    @SysLog("-新增数据")
    @PostMapping("/save")
    public R insert(@RequestPart(value = "param") BusNoticeEntity param) throws Exception {
        param.setCreator(getUserId());
        param.setNoticeId(Tools.get32UUID());	//主键
        param.setCreateTime(DateUtil.date2Str(new Date()));	//添加时间
        param.setIsDelete(0);	//是否删除(0:有效 1：删除)
        param.setIsTop(0);
        param.setUserName(getUsername());
        param.setStatus(0);
        busNoticeService.saveNotice(param);

        return R.ok();
    }

    @ApiOperation("-编辑数据")
    @SysLog("-编辑数据")
    @PostMapping("/update")
    public R update(@RequestBody BusNoticeEntity param) {
        busNoticeService.updateById(param);
        return R.ok();
    }

    @ApiOperation("-置顶")
    @SysLog("-置顶")
    @PostMapping("/changeIsTop")
    public R changeIsTop(@RequestBody BusNoticeEntity param) {
        param.getNoticeId();
        busNoticeService.updateById(param);
        return R.ok();
    }


    @ApiOperation("-删除数据")
    @SysLog("-删除数据")
    @PostMapping("/delete")
    public R delete(@RequestBody BusNoticeEntity param) {
        busNoticeService.delete(param.getNoticeId(),getUserId());
        return R.ok();
    }

    @ApiOperation("-分页查询")
    @SysLog("-分页查询")
    @PostMapping("/listPage")
    public R listPage(@RequestBody Map<String, Object> params) {
        PageUtils page = busNoticeService.listPage(params);

		return R.ok().put("page", page);
    }


    @ApiOperation("-根据ID查详情")
    @SysLog("-根据ID查详情")
    @PostMapping("/info")
    public R info(@RequestBody BusNoticeEntity param) {
        BusNoticeEntity busNotice = busNoticeService.getById(param.getNoticeId());
        return R.ok().put("busNotice", busNotice);
    }

}
