package com.ozs.web.controller.pm;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ozs.common.core.controller.BaseController;
import com.ozs.common.core.domain.AjaxResult;
import com.ozs.common.core.domain.entity.SysDept;
import com.ozs.pm.doman.PmAuditDeptRef;
import com.ozs.pm.service.PmAuditDeptRefService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
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;

import java.util.List;

@Api(tags = "审核关联")
@RestController
@RequestMapping("/pm/audit")
public class PmAuditDeptRefController extends BaseController {

    @Autowired
    private PmAuditDeptRefService pmAuditDeptRefService;
    @Autowired
    private com.ozs.system.service.ISysDeptService deptService;

    @PostMapping("/list")
    public AjaxResult list(@RequestBody PmAuditDeptRef vo) {
        LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
        lw.eq(PmAuditDeptRef::getRefId, vo.getRefId());
        lw.eq(PmAuditDeptRef::getRefType, vo.getRefType());
        List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
        if (!ObjectUtils.isEmpty(list)) {
            for (PmAuditDeptRef pmAuditDeptRef : list) {
                com.ozs.common.core.domain.entity.SysDept d = deptService.selectById(pmAuditDeptRef.getDeptId());
                if (!ObjectUtils.isEmpty(d)) {
                    pmAuditDeptRef.setDeptName(d.getDeptName());
                }
                pmAuditDeptRef.setStatusStr(pmAuditDeptRef.getStatus().equals(Integer.parseInt("0")) ? "待审核" : "已审核");
            }
        }
        return success(list);
    }
}
