package com.ics.controller.mobile;

import com.ics.admin.service.IIcsCustomerStaffService;
import com.ics.common.constant.Constants;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.IcsCustomerStaff;
import com.ics.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 访客信息接口
 */
@RestController
@RequestMapping("/user/visitor")
public class VisitorApiController extends BaseController {
    @Autowired
    private IIcsCustomerStaffService icsCustomerStaffService;

    /**
     * 查询列表
     * @param icsCustomerStaff
     * @return
     */
    @GetMapping("list")
    public R list(IcsCustomerStaff icsCustomerStaff) {
        startPage();
        icsCustomerStaff.setDataType(Constants.CUSTOMER_VISIT);
        return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff));
    }

    /**
     * 新增保存访客信息
     */
    @PostMapping("save")
    public R addSave(@RequestBody IcsCustomerStaff icsCustomerStaff) {
        icsCustomerStaff.setCreateTime(new Date());
        icsCustomerStaff.setCreateBy(getLoginName());
        icsCustomerStaff.setDataType(Constants.CUSTOMER_VISIT);
        return toAjax(icsCustomerStaffService.insertIcsCustomerStaff(icsCustomerStaff));
    }

    /***
     * 更新
     * @param icsCustomerStaff
     * @return
     */
    @PostMapping("update")
    public R editSave(@RequestBody IcsCustomerStaff icsCustomerStaff) {
        icsCustomerStaff.setUpdateTime(new Date());
        icsCustomerStaff.setUpdateBy(getLoginName());
        return toAjax(icsCustomerStaffService.updateIcsCustomerStaff(icsCustomerStaff));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @PostMapping("remove")
    public R remove(String ids) {
        return toAjax(icsCustomerStaffService.deleteIcsCustomerStaffByIds(ids));
    }

    /***
     * 查看访客信息
     * @param id
     * @return
     */
    @GetMapping("get/{id}")
    public IcsCustomerStaff get(@PathVariable("id") Long id) {
        return icsCustomerStaffService.selectIcsCustomerStaffById(id);
    }

}
