package com.goafanti.order.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.goafanti.common.bo.Result;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.order.bo.InputNewOrderDunBo;
import com.goafanti.order.service.NewOrderDunService;

@RestController
@RequestMapping(value = "/api/admin/newOrderDun")
public class AdminNewOrderDunApiController extends CertifyApiController {
	
	@Resource
	private NewOrderDunService	newOrderDunService;
	
	/**
	 * 创建催款信息
	 * @return
	 */
	@RequestMapping(value = "/createDun",method = RequestMethod.POST)
	public Result createDun(InputNewOrderDunBo ib){
		Result res = new Result();
		if(StringUtils.isBlank(ib.getOrderNo())||null==ib.getTid()) {
			res.getError().add(buildError("", "订单编号与项目编号必须指定"));
			return res;
		}
		if(null==ib.getProjectType()||null==ib.getDunType()) {
			res.getError().add(buildError("", "项目分类和催款分类必须指定"));
			return res;
		}
		res.data(newOrderDunService.createDun(ib));
		return res;
	}	
	/**
	 * 修改催款信息
	 * @return
	 */
	@RequestMapping(value = "/updateDun",method = RequestMethod.POST)
	public Result updateDun(InputNewOrderDunBo ib){
		Result res = new Result();
		if(null==ib.getId()) {
			res.getError().add(buildError("", "催款ID必须指定"));
			return res;
		}
		if(StringUtils.isBlank(ib.getOrderNo())||null==ib.getTid()) {
			res.getError().add(buildError("", "订单编号与项目编号必须指定"));
			return res;
		}
		if(null==ib.getProjectType()||null==ib.getDunType()) {
			res.getError().add(buildError("", "项目分类和催款分类必须指定"));
			return res;
		}
		res.data(newOrderDunService.updateDun(ib));
		return res;
	}	
	/**
	 * 删除催款信息
	 * @return
	 */
	@RequestMapping(value = "/deleteDun",method = RequestMethod.POST)
	public Result deleteDun(Integer id){
		Result res = new Result();
		if(null==id) {
			res.getError().add(buildError("", "催款ID必须指定"));
			return res;
		}
		res.data(newOrderDunService.deleteDun( id));
		return res;
	}	
	/**
	 * 	查看催款信息
	 * @return
	 */
	@RequestMapping(value = "/selectDun",method = RequestMethod.GET)
	public Result selectDun(Integer id){
		Result res = new Result();
		if(null==id) {
			res.getError().add(buildError("", "催款ID必须指定"));
			return res;
		}
		res.data(newOrderDunService.selectDun( id));
		return res;
	}	
	/**
	 * 	催款信息列表
	 * @return
	 */
	@RequestMapping(value = "/selectListNewOrderDun",method = RequestMethod.GET)
	public Result selectListNewOrderDun(String orderNo){
		Result res = new Result();
		res.data(newOrderDunService.selectListNewOrderDun(orderNo));
		return res;
	}	
}
