package com.nantian.cloud.dbcapp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.dbcapp.service.TExceptionHandlingLogService;
import com.nantian.cloud.dbcapp.vo.TExceptionHandlingLogVo;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("exceptionHandlingLog")
public class TExceptionHandlingLogController {

    @Autowired
    private TExceptionHandlingLogService tExceptionHandlingLogService;


    @PostMapping("save")
    @SysLog("保存企业异常处理记录")
    public R save(@RequestBody List<TExceptionHandlingLogVo> tExceptionHandlingLogVo) {
        ScUser u = SecurityUtils.getUser();
        tExceptionHandlingLogVo.forEach(r->{
            if (u.getId() != null) {
                r.setUserid(u.getId());
            }
            r.setUpdateTime(new Date());
            r.setDelFlag("1");
            r.setDeptId(u.getDeptId());
            r.setCreatTime(new Date());
            r.setName(u.getUsername());
        });
        return R.ok(tExceptionHandlingLogService.saveBatch(tExceptionHandlingLogVo));
    }

    @GetMapping("page")
    @SysLog("获取企业异常处理记录")
    public R page(Page page,TExceptionHandlingLogVo obj) {
        return R.ok(tExceptionHandlingLogService.getPage(page,obj));
    }

}
