package com.willalp.web.controller.app;

import com.willalp.addressbook.service.IHsAddressBookService;
import com.willalp.clockingin.service.IHsPnsClockingInService;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.group.service.IHsGroupConfigService;
import com.willalp.salary.service.IHsSalarySlipService;
import com.willalp.yiqing.domain.vo.UserQueResultVo;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hs
 */
@Api("app考勤系统控制层")
@RestController
@RequestMapping("/api/ci/")
public class AppClockingInController extends BaseController {

    @Resource
    private IHsPnsClockingInService clockingInService;

    @Resource
    private IHsAddressBookService hsAddressBookService;

    @Resource
    private IHsSalarySlipService salarySlipService;

    @Resource
    private IHsGroupConfigService groupConfigService;

    /**
     * 任务打卡
     *
     * @param userQueResultVo
     * @return
     */
    @RequestMapping("clocking/in")
    public AjaxResult clockIn(@RequestBody UserQueResultVo userQueResultVo) {
        return toAjax(clockingInService.addDailyClockIn(userQueResultVo));
    }


    /**
     * 获取今日已打卡信息
     *
     * @param userQueResultVo
     * @return
     */
    @RequestMapping("clocking/info")
    public AjaxResult info(@RequestBody UserQueResultVo userQueResultVo) {
        return AjaxResult.success(clockingInService.todayIsClockingIn(userQueResultVo));
    }

    /**
     * 获取用户通讯录数据
     *
     * @param userName
     * @return
     */
    @RequestMapping("/abDepts")
    public AjaxResult abDepts(@RequestParam("un") String userName, @RequestParam("oc") String oc) {
        return AjaxResult.success(hsAddressBookService.institutionList(userName, oc));
    }

    /**
     * 获取用户通讯录数据
     *
     * @param department
     * @return
     */
    @RequestMapping("/ab")
    public AjaxResult addressBook(@RequestParam("un") String department) {
        return AjaxResult.success(hsAddressBookService.abList(department));
    }

    /**
     * 获取用户通讯录数据
     *
     * @param data 用户编号字符串
     * @return
     */
    @RequestMapping("/gab")
    public AjaxResult groupAbList(@RequestParam("data") String data) {
        return AjaxResult.success(hsAddressBookService.groupAbList(data));
    }

    /**
     * 获取用户工资条
     *
     * @param userName
     * @param orgCode
     * @return
     */
    @RequestMapping("/sl")
    public AjaxResult salarySlip(@RequestParam("un") String userName,
                                 @RequestParam("oc") String orgCode) {
        return AjaxResult.success(salarySlipService.appGetSalarySlipToUser(userName, orgCode));
    }

    /**
     * 获取用户通讯录数据
     *
     * @param userName
     * @return
     */
    @RequestMapping("/gl")
    public AjaxResult groupList(@RequestParam("un") String userName) {
        return AjaxResult.success(groupConfigService.appGroupList(userName));
    }
}
