package com.mortals.xhx.module.attendance.web;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.AppealResultEnum;
import com.mortals.xhx.common.code.ProcessStatusEnum;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.workman.model.WorkmanQuery;
import com.mortals.xhx.module.workman.service.WorkmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toMap;

/**
*
* 请假记录信息
*
* @author zxfei
* @date 2023-04-07
*/
@RestController
@RequestMapping("attendance/leave/record")
public class AttendanceLeaveRecordController extends BaseCRUDJsonBodyMappingController<AttendanceLeaveRecordService,AttendanceLeaveRecordEntity,Long> {

    @Autowired
    private ParamService paramService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private WorkmanService workmanService;
    @Autowired
    private UserService userService;
//    @Autowired
//    private IUserFeign iUserFeign;

    public AttendanceLeaveRecordController(){
        super.setModuleDesc( "请假记录信息");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "deptId", deptService.find(new DeptQuery()).stream().collect(toMap(x->x.getId().toString(), y->y.getDeptName(),(o, n)->n)));
        this.addDict(model, "approverId", workmanService.find(new WorkmanQuery()).stream().collect(toMap(x->x.getId().toString(), y->y.getName(),(o, n)->n)));
        this.addDict(model, "leaveType", paramService.getParamBySecondOrganize("AttendanceLeaveRecord","leaveType"));
        this.addDict(model, "auditResult", AppealResultEnum.getEnumMap());
        this.addDict(model, "processStatus", ProcessStatusEnum.getEnumMap());
        this.addDict(model, "createUserId", userService.find(new UserQuery()).stream().collect(toMap(x -> x.getId().toString(), y -> y.getRealName(), (o, n) -> n)));

//        //从门户获取登录用户信息
//        UserPdu userPdu = new UserPdu();
//        userPdu.setSize(-1);
//        List <UserPdu> userPduList = iUserFeign.list(userPdu).getData().getData();
//        Map<String, String> ans = new HashMap<>();
//        for(UserPdu str: userPduList) {
//            if(str != null) {  //增加非空判断
//                ans.put(str.getId().toString(), str.getRealName());
//            }
//        }
//
//        this.addDict(model, "createUserId", ans);


        super.init(model, context);
    }


}