package com.pj.project.tb_favorite_contacts;

import com.pj.project.tb_favorite_contacts.param.FavoriteContactsParam;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: tb_favorite_contacts -- 常用联系人
 * @author lbl
 */
@RestController
@RequestMapping("/app/TbFavoriteContacts/")
public class AppFavoriteContactsController {

	/** 底层 Service 对象 */
	@Autowired
	TbFavoriteContactsService tbFavoriteContactsService;

	/** 增 */
	@RequestMapping("appAdd")
	public AjaxJson appAdd(@RequestBody FavoriteContactsParam  t){
		tbFavoriteContactsService.appAdd(t);
		return AjaxJson.getSuccess();
	}

	/** 删 */
	@RequestMapping("delete")
	public AjaxJson delete(Long id){
		 tbFavoriteContactsService.delete(id);
		return AjaxJson.getSuccess();
	}

	/** 删 - 根据id列表 */
	@RequestMapping("deleteByIds")
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
		int line = SP.publicMapper.deleteByIds(TbFavoriteContacts.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}

	/** 改 */
	@RequestMapping("update")
	public AjaxJson update(TbFavoriteContacts t){
		tbFavoriteContactsService.update(t);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbFavoriteContacts t = tbFavoriteContactsService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 查集合 - 查询当前登录人的收货地址 */
	@RequestMapping("getAppList")
	public AjaxJson getAppList() {
		SoMap so = SoMap.getRequestSoMap();
		List<TbFavoriteContacts> list = tbFavoriteContactsService.getAppList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}









}
