package cn.com.countrygarden.bi.main.controller.dup;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.dup.CaseField;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.dup.ApprovalInfoService;

@RestController("ApprovalInfoController")
@RequestMapping("/api/biapp/approvalInfo")
public class ApprovalInfoController extends BaseController {
	@Autowired
	private ApprovalInfoService approvalInfoService;
	@Autowired
    private AccessTokenService accessTokenService;
	
	@GetMapping(value="/one",produces = "application/json;charset=utf-8")
	public Result queryApprovalById(@RequestParam(value = "id", required = true)Integer id,
				HttpServletRequest request) {
		return approvalInfoService.queryApprovalById(id);
	}
	
	@PutMapping(value="/editApproval")
	public Result saveApprovalInfo(CaseField caseField,HttpServletRequest request) {
		String accessToken = request.getParameter("AccessToken");
        AccessToken token = accessTokenService.findByToken(accessToken);
        String userCode = token.getUserCode();
		caseField.setApprover(userCode);
		
		caseField.setApprovalDate(new Date());
		
		return approvalInfoService.eidtApproval(caseField, getAccessToken(request));
	}
}
