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

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.project.ProjectJointPlan;
import cn.com.countrygarden.bi.main.model.project.ProjectSignInfo;
import cn.com.countrygarden.bi.main.model.project.ProjectTarget;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.project.ProjectJointPlanService;
import cn.com.countrygarden.bi.main.service.project.ProjectSignInfoService;
import cn.com.countrygarden.bi.main.service.project.ProjectTargetService;



@RestController("ProjectBIController")
@RequestMapping("/api/service/datav/bii")
public class ProjectBIController {
	@Autowired
	ProjectTargetService projectTargetService;
	@Autowired
	ProjectSignInfoService projectSignInfoService;
	 @RequestMapping(value = "expandCondition", method = {RequestMethod.GET})
	public Object expandCondition() {
		 Calendar cal = Calendar.getInstance();  
   	  cal.setTime(new Date());  
  		 String y = cal.get(Calendar.YEAR)+"";
		 
		// projectSignInfoService.statistical(y);
		 
		 Map<String,Object> map = new HashMap<>();
		 List<ProjectTarget> list =  projectTargetService.getTargetByYear(y);
		 Double mbbhsr = 0d;
		 //本年目标饱和收入
		 for (ProjectTarget projectTarget : list) {
			 if(projectTarget.getSaturationIncomeAll() == null) {
				 mbbhsr += 0d;
			 }else {
				 mbbhsr += projectTarget.getSaturationIncomeAll();
			 }
		}
		map.put("mbbhsr", mbbhsr);
		//完成率
		BigDecimal bhsrwcl = projectSignInfoService.getAllInfo(y);
		map.put("bhsrwcl", bhsrwcl);
		//实际饱和收入
		BigDecimal sjbhsr = projectSignInfoService.getSingAllByYear(y);
		map.put("sjbhsr", sjbhsr.doubleValue());
		//本月饱和收入
		Integer month = new Date().getMonth();
		BigDecimal bybhsr;
		if(month<10) {
			bybhsr = projectSignInfoService.getSingAllByMonth(y,"0"+month);
		}else {
			bybhsr = projectSignInfoService.getSingAllByMonth(y,""+month);
		}
		map.put("bybhsr", bybhsr.doubleValue());
		//上月饱和收入
		month -= 1;
		BigDecimal sybhsr;
		if(month<10) {
			sybhsr = projectSignInfoService.getSingAllByMonth(y,"0"+month);
		}else if(month <= 0){
			Integer edy = Integer.parseInt(y);
			edy-=1;
			sybhsr = projectSignInfoService.getSingAllByMonth(edy+"","12");
		}else {
			sybhsr = projectSignInfoService.getSingAllByMonth(y,""+month);
		}
		map.put("sybhsr", sybhsr.doubleValue());
		
		
		
		
		
		return null;
	}
}
