/**
 *
 */
package org.springblade.finance.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.tool.api.R;
import org.springblade.finance.entity.DealUsersView;
import org.springblade.finance.enums.DealTypeEnum;
import org.springblade.finance.service.IDealUsersViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author wookvn
 *
 */
@RestController
@RequestMapping("finance/channel")
@Api(value = "渠道管理", tags = "渠道管理接口")
public class ChannelController {

	@Autowired
	private IDealUsersViewService dealUsersViewService;


	/**
	 * 渠道列表
	 * @return
	 */
	@GetMapping("/list")
	@ApiOperation("社会渠道->渠道信息下拉列表")
	public R list(){
		QueryWrapper<DealUsersView> queryWrapper = new QueryWrapper<DealUsersView>();
		queryWrapper.select("DEAL_USERID, DEAL_USER_NAME").isNotNull("DEAL_USERID");
		//queryWrapper.in("MODULE", DealTypeEnum.shqd_deal.getValue(),DealTypeEnum.hlw1_deal.getValue());
		queryWrapper.eq("MODULE", DealTypeEnum.shqd_deal.getValue());
		List<DealUsersView> list = dealUsersViewService.list(queryWrapper);
		List<Map<String, Object>> data = list.stream()
			.map(obj -> {
				Map<String, Object> map = new HashMap<>();
				map.put("dealUserid", obj.getDealUserid());
				map.put("dealUserName", obj.getDealUserName());
				return map;
			}).collect(Collectors.toList());
		return R.data(data);
	}

	/**
	 * 渠道列表
	 * @return
	 */
	@GetMapping("/hlwlist")
	@ApiOperation("互联网1->渠道信息下拉列表")
	public R hlwlist(){
		QueryWrapper<DealUsersView> queryWrapper = new QueryWrapper<DealUsersView>();
		queryWrapper.select("DEAL_USERID, DEAL_USER_NAME").isNotNull("DEAL_USERID");
		queryWrapper.eq("MODULE",DealTypeEnum.hlw1_deal.getValue());
		List<DealUsersView> list = dealUsersViewService.list(queryWrapper);
		List<Map<String, Object>> data = list.stream()
			.map(obj -> {
				Map<String, Object> map = new HashMap<>();
				map.put("dealUserid", obj.getDealUserid());
				map.put("dealUserName", obj.getDealUserName());
				return map;
			}).collect(Collectors.toList());
		return R.data(data);
	}

}
