package com.ruoyi.web.controller.zdsz;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zdsz.domain.vo.ZEngiineeringPhotoVo;
import com.ruoyi.zdsz.domain.bo.ZEngiineeringPhotoBo;
import com.ruoyi.zdsz.service.IZEngiineeringPhotoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 照片
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engiineeringPhoto")
public class ZEngiineeringPhotoController extends BaseController {

    private final IZEngiineeringPhotoService iZEngiineeringPhotoService;

    /**
     * 查询照片列表
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngiineeringPhotoVo> list(ZEngiineeringPhotoBo bo, PageQuery pageQuery) {
        return iZEngiineeringPhotoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出照片列表
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:export")/
    @Log(title = "照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngiineeringPhotoBo bo, HttpServletResponse response) {
        List<ZEngiineeringPhotoVo> list = iZEngiineeringPhotoService.queryList(bo);
        ExcelUtil.exportExcel(list, "照片", ZEngiineeringPhotoVo.class, response);
    }

    /**
     * 获取照片详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:query")
    @GetMapping("/{id}")
    public R<ZEngiineeringPhotoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZEngiineeringPhotoService.queryById(id));
    }

    /**
     * 新增照片
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:add")
    @Log(title = "照片", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngiineeringPhotoBo bo) {
        return toAjax(iZEngiineeringPhotoService.insertByBo(bo));
    }

    /**
     * 修改照片
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:edit")
    @Log(title = "照片", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngiineeringPhotoBo bo) {
        return toAjax(iZEngiineeringPhotoService.updateByBo(bo));
    }

    /**
     * 删除照片
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:remove")
    @Log(title = "照片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iZEngiineeringPhotoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 删除照片也删除obs
     *
     */
//    @SaCheckPermission("zdsz:engiineeringPhoto:remove")
    @Log(title = "照片", businessType = BusinessType.DELETE)
    @DeleteMapping("/url")
    public R remove1(ZEngiineeringPhotoBo bo) {
        return toAjax(iZEngiineeringPhotoService.deleteWithValidByurls(bo.getPicUrl()));
    }
}
