package com.xmomen.module.wx.controller;

import com.xmomen.framework.exception.BusinessException;
import com.xmomen.framework.mybatis.page.Page;
import com.xmomen.module.base.constant.AppConstants;
import com.xmomen.module.logger.Log;
import com.xmomen.module.member.model.MemberAddressQuery;
import com.xmomen.module.member.model.MemberAddressModel;
import com.xmomen.module.member.service.MemberAddressService;

import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.result.ExcelImportResult;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
import org.jeecgframework.poi.exception.excel.ExcelImportException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import java.io.Serializable;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author tanxinzheng
 * @version 1.0.0
 * @date 2017-3-29 0:27:52
 */
@RestController
@RequestMapping(value = "/wx/memberAddress")
public class WxMemberAddressController {

    @Autowired
    MemberAddressService memberAddressService;

    /**
     * 客户地址列表
     *
     * @param limit      每页结果数
     * @param offset     页码
     * @param id         主键
     * @param ids        主键数组
     * @param excludeIds 不包含主键数组
     * @return Page<MemberAddressModel> 客户地址领域分页对象
     */
    // 使用@RequestMapping注解，指定请求方法为GET
    @RequestMapping(method = RequestMethod.GET)
    // 返回MemberAddressModel类型的List
    public List<MemberAddressModel> getMemberAddressList(@RequestParam(value = "id", required = false) String id,
                                                         // 使用@RequestParam注解，指定参数名为id，非必需
                                                         @RequestParam(value = "ids", required = false) String[] ids,
                                                         // 使用@RequestParam注解，指定参数名为ids，非必需
                                                         @RequestParam(value = "memberId", required = true) String memberId,
                                                         // 使用@RequestParam注解，指定参数名为memberId，必需
                                                         @RequestParam(value = "excludeIds", required = false) String[] excludeIds) {
        // 创建MemberAddressQuery对象
        MemberAddressQuery memberAddressQuery = new MemberAddressQuery();
        // 设置MemberAddressQuery对象的id属性
        memberAddressQuery.setId(id);
        // 设置MemberAddressQuery对象的excludeIds属性
        memberAddressQuery.setExcludeIds(excludeIds);
        // 设置MemberAddressQuery对象的ids属性
        memberAddressQuery.setIds(ids);
        // 设置MemberAddressQuery对象的cdMemberId属性
        memberAddressQuery.setCdMemberId(memberId);
        // 调用memberAddressService的getMemberAddressModels方法，返回MemberAddressModel类型的List
        return memberAddressService.getMemberAddressModels(memberAddressQuery);
    }

    /**
     * 查询单个客户地址
    // 根据id获取会员地址信息
        // 调用memberAddressService的getOneMemberAddressModel方法，根据id获取会员地址信息
     *
     * @param id 主键
     * @return MemberAddressModel   客户地址领域对象
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public MemberAddressModel getMemberAddressById(@PathVariable(value = "id") String id) {
        return memberAddressService.getOneMemberAddressModel(id);
    }

    /**
     * 新增客户地址
     *
     * @param memberAddressModel 新增对象参数
     * @return MemberAddressModel   客户地址领域对象
    // 使用@RequestMapping注解，指定请求方法为POST
     */
    // 使用@RequestBody注解，将请求体中的数据转换为MemberAddressModel对象
    @RequestMapping(method = RequestMethod.POST)
        // 调用memberAddressService的createMemberAddress方法，将MemberAddressModel对象作为参数传入
    public MemberAddressModel createMemberAddress(@RequestBody @Valid MemberAddressModel memberAddressModel) {
        return memberAddressService.createMemberAddress(memberAddressModel);
    }

    /**
     * 更新客户地址
     *
     * @param id                 主键
     * @param memberAddressModel 更新对象参数
     */
    // 使用@RequestMapping注解，指定请求的URL路径和请求方法
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    // 使用@PathVariable注解，将URL中的id参数绑定到方法参数id上
    public void updateMemberAddress(@PathVariable(value = "id") String id,
                                    // 使用@RequestBody注解，将请求体中的JSON数据转换为MemberAddressModel对象
                                    @RequestBody @Valid MemberAddressModel memberAddressModel) {
        // 调用memberAddressService的updateMemberAddress方法，更新会员地址
        memberAddressService.updateMemberAddress(memberAddressModel);
    }

    /**
     * 删除客户地址
     *
     * @param id 主键
     */
    // 根据id删除会员地址
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public void deleteMemberAddress(@PathVariable(value = "id") String id) {
        // 调用memberAddressService的deleteMemberAddress方法，根据id删除会员地址
        memberAddressService.deleteMemberAddress(id);
    }

    /**
     * 删除客户地址
     *
     * @param ids 主键
     */
    // 使用@RequestMapping注解，指定请求方法为DELETE
    @RequestMapping(method = RequestMethod.DELETE)
    // 定义一个方法，用于删除会员地址
    public void deleteMemberAddresss(@RequestParam(value = "ids") String[] ids) {
        // 调用memberAddressService的deleteMemberAddress方法，传入要删除的会员地址id数组
        memberAddressService.deleteMemberAddress(ids);
    }


}
