package com.xintong.visualinspection.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xintong.visualinspection.bean.CheckOther;
import com.xintong.visualinspection.service.CheckOtherService;
import com.xintong.visualinspection.util.CodeUtil;

/**
 * 文件名：CheckItemController 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation
 * 2017 版权所有.
 */
@RestController
@RequestMapping("/checkOther")
public class CheckOtherController extends BaseController {

	@Autowired
	private CheckOtherService checkOtherService;

	/**添加其他稽查查记录
	 * @param request
	 * @param checkOther
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add(HttpServletRequest request, @Valid @RequestBody CheckOther checkOther) {
		checkOtherService.insert(checkOther);
		return super.returnSuccessResult("添加成功");
	}
	/**根据id删除稽查记录
	 * @param checkOther
	 * @return
	 */
	@RequestMapping(value = "/delete")
    public String delete(@RequestBody CheckOther checkOther){
    	checkOtherService.delete(checkOther.getId());
    	return super.returnSuccessResult("删除成功");
    }
	@RequestMapping(value = "/update")
    public String update(@RequestBody CheckOther checkOther){
    	checkOtherService.update(checkOther);
    	return super.returnSuccessResult("修改成功");
    }

    @RequestMapping(value = "/getOtherCheckStatistics")
    public String getOtherCheckStatistics(@RequestBody CheckOther checkOther){
        Map<String,Object> checkStatistics = checkOtherService.getOtherCheckStatistics(checkOther.getCheck_period(),checkOther.getCheck_type(),checkOther.getSpecial_check_type());
        return super.returnSuccessResult(checkStatistics);
    }




	/**根据id获取稽查记录
	 * @param checkOther
	 * @return
	 */
	@RequestMapping(value = "/getCheckById")
    public String getCheckById(@RequestBody CheckOther checkOther){
    	CheckOther check =checkOtherService.getCheckById(checkOther.getId());
    	return super.returnSuccessResult(check);
    }

	/**根据dept_id 获取稽查记录
	 * @param checkOther
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value = "/getCheckByDeptId/{page}/{size}")
    public String getCheckByDeptId(@RequestBody CheckOther checkOther,@PathVariable Integer page,@PathVariable Integer size){
    	PageHelper.startPage(page, size);
    	List<CheckOther> checkOtherList = checkOtherService.getCheckByDeptId(checkOther);
    	for(CheckOther co : checkOtherList){
    		if(co.getWrecker_check_type()!=null){
    			co.setWrecker_check_type_name(CodeUtil.getCodeNameByFlagAndValue("wrecker_group_check_type", co.getWrecker_check_type()+""));
    		}
    		if(co.getSpecial_check_type()!=null){
    			co.setSpecial_check_type_name(CodeUtil.getCodeNameByFlagAndValue("special_check_type", co.getSpecial_check_type()+""));
    		}
    	}
    	return super.returnSuccessResult(new PageInfo(checkOtherList));
    }
}
