package com.prolog.rdc.tms.controller;

import java.util.List;
import java.util.Map;

import com.prolog.rdc.tms.model.dto.LmsTmsZoneMinDTO;
import com.prolog.rdc.tms.model.dto.ProvinceZoneDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.LmsTmsZoneDTO;
import com.prolog.rdc.tms.model.entity.LmsTmsZoneModel;
import com.prolog.rdc.tms.model.vo.LmsTmsZoneQueryVO;
import com.prolog.rdc.tms.model.vo.LmsTmsZoneVO;
import com.prolog.rdc.tms.service.LmsTmsZoneService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * 行政区域 Controller
 *
 * @className :LmsTmsZoneController
 * @author :fanzw
 * @creationTime :2020/07/03
 * @description :
 * @modifier :fanzw
 * @modifyTime :2020/07/03
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "基础数据-行政区域")
@RestController
@RequestMapping("/zone")
public class LmsTmsZoneController {

	@Autowired
	private LmsTmsZoneService lmstmszoneservice;

	@ApiOperation(value = "根据上级编号(fatherid)获取区域信息", notes = "根据上级编号获取区域信息")
	@ApiImplicitParam(name = "param", value = "{fatherid: \"01\"}")
	@PostMapping("/get-by-pid")
	public RestMessage<List<LmsTmsZoneDTO>> getZoneByFatherid(@RequestBody LmsTmsZoneVO lmstmszonevo) throws Exception {
		List<LmsTmsZoneDTO> list = lmstmszoneservice.getZoneByFatherid(lmstmszonevo);
		return RestMessage.newInstance(true, "查询成功", list);
	}

	@ApiOperation(value = "根据当前编号(zoneid)获取所有区域", notes = "根据当前编号(zoneid)获取所有区域")
	@PostMapping("/get")
	public RestMessage<LmsTmsZoneModel> getZoneById(String zoneid) throws Exception {
		LmsTmsZoneModel lmsTmsZone = lmstmszoneservice.getZoneById(zoneid);
		return RestMessage.newInstance(true, "查询成功", lmsTmsZone);
	}

	@ApiOperation(value = "根据当前编号(zoneid)获取所有区域", notes = "根据当前编号(zoneid)获取所有区域")
	@PostMapping("/get_zones")
	public RestMessage<List<LmsTmsZoneModel>> getZoneByIds(@RequestBody List<String> zoneIds) throws Exception {
		List<LmsTmsZoneModel> lmsTmsZones = lmstmszoneservice.getZoneByIds(zoneIds);
		return RestMessage.newInstance(true, "查询成功", lmsTmsZones);
	}

	@ApiOperation(value = "根据当前编号(zoneid)删除区域及区域下的所有子区域", notes = "根据当前编号(zoneid)删除区域及区域下的所有子区域")
	@PutMapping("/delete-zone")
	@ApiImplicitParam(name = "list", value = "[{\"zoneid\":\"0201\"}]")
	public RestMessage<String> deleteZone(@RequestBody List<LmsTmsZoneModel> list) throws Exception {
		lmstmszoneservice.deleteZone(list);
		return RestMessage.newInstance(true, "删除成功", null);
	}

	@ApiOperation(value = "默认展示所有行政区域", notes = "默认展示所有行政区域")
	@PutMapping("/list-all")
	public RestMessage<List<LmsTmsZoneDTO>> getZone() {
		List<LmsTmsZoneDTO> param = lmstmszoneservice.getZone();
		return RestMessage.newInstance(true, "查询成功", param);
	}

	@ApiOperation(value = "叶子节点第一级(fatherid为空)", notes = "叶子节点第一级(fatherid为空)")
	@PostMapping("/top-list")
	public RestMessage<List<LmsTmsZoneDTO>> getFatheridIsNull() {
		List<LmsTmsZoneDTO> list = lmstmszoneservice.getFatheridIsNull();
		return RestMessage.newInstance(true, "查询成功", list);
	}

	@ApiOperation(value = "获取行政区域列表", notes = "根据上级区域找下级区域")
	@PostMapping("/dd-list")
	@ApiImplicitParam(name = "param")
	public RestMessage<List<Map<String, Object>>> getDropDownList(@RequestBody Map<String, Object> param) {
		List<Map<String, Object>> list = lmstmszoneservice.getDropDownList(param);
		return RestMessage.newInstance(true, "查询成功", list);
	}

	@UserLog("行政区域新增")
	@ApiOperation(value = "行政区域新增", notes = "行政区域新增")
	@PostMapping("/addZone")
	public RestMessage<String> insertZoneExecute(@RequestBody LmsTmsZoneVO lmstmszonevo) {
		try {
			lmstmszoneservice.insertZoneData(lmstmszonevo);
			return RestMessage.newInstance(true, "保存成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("行政区域修改")
	@ApiOperation(value = "行政区域修改", notes = "行政区域修改")
	@PostMapping("/updateZone")
	public RestMessage<String> updateZoneByIdExecute(@RequestBody LmsTmsZoneVO lmstmszonevo) {
		try {
			lmstmszoneservice.updateZoneByIdData(lmstmszonevo);
			return RestMessage.newInstance(true, "修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "默认展示所有行政区域", notes = "默认展示所有行政区域")
	@PutMapping("/list-all-page")
	public RestMessage<Page<LmsTmsZoneDTO>> getZoneByPage(@RequestBody LmsTmsZoneVO lmstmszonevo) {
		Page<LmsTmsZoneDTO> param = lmstmszoneservice.getZoneByPage(lmstmszonevo.getPageNum(), lmstmszonevo.getPageSize());
		return RestMessage.newInstance(true, "查询成功", param);
	}

	@UserLog("根据名称查询行政区域编码")
	@ApiOperation(value = "根据名称查询行政区域编码", notes = "根据名称查询行政区域编码")
	@PostMapping("/get-by-name")
	public RestMessage<List<LmsTmsZoneDTO>> getLmsTmsZoneByNameExecute(@RequestBody LmsTmsZoneQueryVO lmstmszonequeryvo) {
		try {
			List<LmsTmsZoneDTO> tmsshipbilldispatchdtos = lmstmszoneservice.getLmsTmsZoneByNameData(lmstmszonequeryvo);
			return RestMessage.newInstance(true, "查询成功", tmsshipbilldispatchdtos);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("根据名称/编码查询行政区域编码")
	@ApiOperation(value = "根据名称/编码查询行政区域编码", notes = "根据名称/编码查询行政区域编码")
	@PostMapping("/get-by-conditions")
	public RestMessage<Page<LmsTmsZoneModel>> getZoneByConditions(@RequestBody LmsTmsZoneVO lmstmszonevo) {
		try {
			Page<LmsTmsZoneModel> list = lmstmszoneservice.getZoneByConditions(lmstmszonevo);
			return RestMessage.newInstance(true, "查询成功", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "默认展示所有行政区域", notes = "默认展示所有行政区域")
	@PostMapping("/get-all")
	public RestMessage<List<LmsTmsZoneDTO>> getAllZone() {
		List<LmsTmsZoneDTO> param = lmstmszoneservice.getAllZone();
		return RestMessage.newInstance(true, "查询成功", param);
	}

	@ApiOperation(value = "获取所有省市区数据", notes = "获取所有省市区数据")
	@PostMapping("/get-all-ProvinceCityDistrict")
	public RestMessage<List<ProvinceZoneDTO>> getAllProvinceCityDistrictZone() {
		List<ProvinceZoneDTO> param = lmstmszoneservice.getAllProvinceCityDistrict();
		return RestMessage.newInstance(true, "查询成功", param);
	}

	@ApiOperation(value = "所有行政区域", notes = "所有行政区域")
	@GetMapping("/getAllZoneMin")
	public RestMessage<List<LmsTmsZoneMinDTO>> getAllZoneMin() {
		return RestMessage.newInstance(true, "查询成功", lmstmszoneservice.getAllZoneMin());
	}
}
