package com.sptg.gateway.controller.implement;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.common.security.service.SecurityServiceInterface;
import com.sptg.estate.api.constant.EstateSecurityToken;
import com.sptg.estate.api.entity.ProjectCompletion;
import com.sptg.estate.api.feigns.ProjectCompletionFeign;
import com.sptg.permissions.api.entity.Account;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * title: ProjectCompletionController
 * package: com.sptg.estate.biz.security
 * description: 物业验收-控制器
 *
 *               
 *                      
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/implement/projectCompletion")
public class ProjectCompletionController {

    private final ProjectCompletionFeign projectCompletionFeign;
    private final SecurityServiceInterface<Account> securityServiceInterface;
    /**
     * 功能描述:显示新增iframe
     *               
     *                      
     */
    @GetMapping("/insert/view")
    @Security(token = EstateSecurityToken.IMPLEMENT_PROJECT_COMPLETION_ACCEPTANCE,format = DataFormatEnum.JSON)
    public ModelAndView insertView(Long projectId){
        ModelAndView modelAndView = new ModelAndView("implement/project-completion-insert");
        modelAndView.addObject("projectId",projectId);
        return modelAndView;
    }

    /**
     * 功能描述:新增
     * @param projectCompletion
     * @return ResultBean<Boolean>
     *               
     *                      
     */
    @PostMapping("/insert")
    @Security(token = EstateSecurityToken.IMPLEMENT_PROJECT_COMPLETION_ACCEPTANCE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> insert(ProjectCompletion projectCompletion){
        //获取当前登陆用户
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        projectCompletion.setCreateAccountId(onLineUser.getId());
        projectCompletion.setCreateName(onLineUser.getUserName());
        projectCompletion.setCreateDate(new Date());
        return this.projectCompletionFeign.insert(projectCompletion);
    }
}
