package com.nantian.cloud.jljc.controller;


import com.nantian.cloud.jljc.entity.TFaCheckAccept;
import com.nantian.cloud.jljc.entity.TFaFixedAssets;
import com.nantian.cloud.jljc.entity.TFaInvestment;
import com.nantian.cloud.jljc.service.TFaCheckAcceptService;
import com.nantian.cloud.jljc.service.TFaFixedAssetsService;
import com.nantian.cloud.jljc.service.TFaInvestmentService;
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.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 固定资产投资项目节能审查资环处表 前端控制器
 * </p>
 *
 * @author fyf
 * @since 2022-02-25
 */
@CrossOrigin
@AllArgsConstructor
@RestController
@RequestMapping("/tFaInvestment")
public class TFaInvestmentController {

    @Autowired
    TFaInvestmentService tFaInvestmentService;

    @Autowired
    TFaFixedAssetsService tFaFixedAssetsService;

    @Autowired
    TFaCheckAcceptService tFaCheckAcceptService;

    /**
     * 报送资环处
     * @param
     * @return
     */
    @GetMapping("/save")
    @SysLog("新增固定资产投资项目节能审查资环处")
    public R save(@Param("id") Integer id){
        ScUser u = SecurityUtils.getUser();
        TFaInvestment tFaInvestment = new TFaInvestment();
        tFaInvestment.setProjectId(id);
        tFaInvestment.setDelFlag(1);
        tFaInvestment.setDeptId(u.getDeptId());
        tFaInvestment.setUserId(u.getId());
        tFaInvestment.setUpdateTime(new Date());
        tFaInvestmentService.save(tFaInvestment);

        TFaFixedAssets tFaFixedAssets = tFaFixedAssetsService.getById(id);
        tFaFixedAssets.setStatusData(6);
        tFaFixedAssets.setProjectStatus(3);
        tFaFixedAssets.setUserId(u.getId());
        tFaFixedAssets.setDeptId(u.getDeptId());
        tFaFixedAssets.setUpdateTime(new Date());
        tFaFixedAssetsService.updateById(tFaFixedAssets);

        return R.ok();
    }

    /**
     * 项目评审完毕
     * @param id
     * @return
     */
    @GetMapping("/report")
    @SysLog("项目评审完毕")
    public R report(Integer id){
        ScUser u = SecurityUtils.getUser();
        TFaFixedAssets tFaFixedAssets = tFaFixedAssetsService.getById(id);
        tFaFixedAssets.setStatusData(8);
        tFaFixedAssets.setProjectStatus(4);
        tFaFixedAssets.setUserId(u.getId());
        tFaFixedAssets.setDeptId(u.getDeptId());
        tFaFixedAssets.setUpdateTime(new Date());
        tFaFixedAssetsService.updateById(tFaFixedAssets);

        TFaCheckAccept tFaCheckAccept = new TFaCheckAccept();
        tFaCheckAccept.setDelFlag(1);
        tFaCheckAccept.setDeptId(u.getDeptId());
        tFaCheckAccept.setUpdateTime(new Date());
        tFaCheckAccept.setUserId(u.getId());
        tFaCheckAccept.setProjectId(id);
        tFaCheckAcceptService.save(tFaCheckAccept);
        return R.ok();
    }
}
