package com.goafanti.user.controller;

import com.goafanti.common.bo.Result;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.BaseApiController;
import com.goafanti.common.utils.excel.NewExcelUtil;
import com.goafanti.user.bo.InputListOrderUserService;
import com.goafanti.user.bo.InputUserServiceFollow;
import com.goafanti.user.bo.OutOrderUserService;
import com.goafanti.user.service.UserServiceService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/api/admin")
public class UserServiceApiController extends BaseApiController {
	@Resource
	private UserServiceService						userServiceService;
	@Value(value = "${upload.path}")
	private String			uploadPath	= null;

	@RequestMapping(value = "/addUseService",method = RequestMethod.POST)
	public Result addUseService(InputUserServiceFollow us) {
		Result res =new Result();
		if(us.getUid()==null) {
			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "用户编号"));
		}
		if (us.getRenewal()==null||us.getWechat()==null) {
			res.getError().add(buildError("","续签和微信必须选择"));
			return res;
		}
		res.data(userServiceService.addUseService(us));
		return res;
	}




	@RequestMapping(value = "/listUseServiceFollow",method = RequestMethod.GET)
	public Result listUseServiceFollow(String uid) {
		Result res =new Result();
		if(uid==null) {
			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "用户编号"));
		}

		res.data(userServiceService.listUseServiceFollow(uid));
		return res;
	}


	@RequestMapping(value = "/listOrderUseService",method = RequestMethod.GET)
	public Result listOrderUseService(InputListOrderUserService i) {
		Result res =new Result();
		res.data(userServiceService.listOrderUseService(i));
		return res;
	}

	/**导出客服跟进列表
	 *
	 * @param i
	 * @return
	 */
	@RequestMapping(value = "/userServiceExport",method = RequestMethod.GET)
	public Result userServiceExport(InputListOrderUserService i) {
		List<OutOrderUserService> list=userServiceService.listOrderUseServiceGetList(i);
		NewExcelUtil<OutOrderUserService>excel=new NewExcelUtil<>(OutOrderUserService.class);
 		 return  excel.exportExcel(list,"客服订单跟进列表",uploadPath);
	}


}
