package com.zd.system.controller;

import com.zd.common.core.domain.R;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.system.api.domain.SysDept;
import com.zd.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 部门电子签章信息
 *
 * @author liubo
 */
@RestController
@RequestMapping("/dept/sign")
@Api(tags = "部门电子签章")
public class SysDeptSignController {

    @Autowired
    private ISysDeptService deptService;

    @ApiOperation(value = "查询列表", notes = "权限字符" + PerPrefix.SYSTEM_DEPT_SIGN+ PerFun.LIST)
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_DEPT_SIGN+ PerFun.LIST)
    @GetMapping("/list")
    public List<SysDept> list(SysDept dept) {
        List<SysDept> depts = deptService.selectDeptList(dept);
        return depts;
    }

    @ApiOperation(value = "修改签章", notes = "权限字符" + PerPrefix.SYSTEM_DEPT_SIGN + PerFun.EDIT)
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_DEPT_SIGN + PerFun.EDIT)
    @PutMapping
    public SysDept edit(@RequestBody SysDept dept) {
        return deptService.updateDeptSign(dept);
    }

    @ApiOperation(value = "用户查询是否有电子签章")
    @GetMapping("/queryDeptSignByUserId")
    public R<Map<String, Object>> queryDeptSignByUserId() {
        Map<String, Object> map = deptService.queryDeptSignByUserId(SecurityUtils.getUserId());
        map.put("deptSignUrl", null);
        return R.ok(map);
    }
}
