package com.goafanti.ambSystem.controller;

import com.goafanti.ambSystem.bo.InputAmb;
import com.goafanti.ambSystem.bo.InputAmbPayment;
import com.goafanti.ambSystem.service.AmbPaymentService;
import com.goafanti.ambSystem.service.AmbService;
import com.goafanti.common.bo.Result;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.utils.ParamUtils;
import com.goafanti.order.enums.OrderImgEnums;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(value = "/api/admin/amb/payment")
public class AmbPaymentApiController extends CertifyApiController {
	@Autowired
	private AmbPaymentService ambPaymentService;

	/**
	 * 新增巴付款
	 * @param in
	 * @param bindingResult
	 * @return
	 */
	@RequestMapping(value="/add",method = RequestMethod.POST)
	public Result add(@Validated InputAmbPayment in, BindingResult bindingResult){
		Result res =new Result();
		if (bindingResult.hasErrors()) {
			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
					ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
			return res;
		}

		res.data(ambPaymentService.add(in));
		return res;
	}

	/**
	 * 修改巴付款
	 * @param in
	 * @return
	 */
	@RequestMapping(value="/update",method = RequestMethod.POST)
	public Result update( InputAmbPayment in){
		Result res =new Result();

		res.data(ambPaymentService.update(in));
		return res;
	}
//
//	@RequestMapping(value="/delete",method = RequestMethod.POST)
//	public Result deleteAmb( InputAmb in){
//		Result res =new Result();
//		if (in.getId()==null){
//			res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"巴编号"));
//			return res;
//		}
//		int i=ambService.checkAmb(in,2);
//		if (i==-1){
//			res.getError().add(buildError("巴存在子项目，请先删除所有子项"));
//			return res;
//		}
//		res.data(ambService.deleteAmb(in));
//		return res;
//	}
//
//	@RequestMapping(value="/details",method = RequestMethod.GET)
//	public Result detailsAmb( InputAmb in){
//		Result res =new Result();
//		if (in.getId()==null){
//			res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"巴编号"));
//			return res;
//		}
//		res.data(ambService.detailsAmb(in));
//		return res;
//	}
//
//	@RequestMapping(value="/select",method = RequestMethod.GET)
//	public Result selectAmb( InputAmb in){
//		Result res =new Result();
//		res.data(ambService.selectAmb(in));
//		return res;
//	}
//
//	@RequestMapping(value="/selectAll",method = RequestMethod.GET)
//	public Result selectAll( ){
//		Result res =new Result();
//		res.data(ambService.selectAll());
//		return res;
//	}



}
