package com.sifang.modules.smallprogram.ItemManagement.controller;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.utils.EmployeRoleUtils;
import com.sifang.modules.flowable.service.ItemManageService;
import com.sifang.modules.smallprogram.ItemManagement.service.NeedToDealService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.dao.UserDao;
import com.sifang.modules.sys.entity.Operator;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseExceptionController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 事项管理 controller
 */
@Controller
@RequestMapping("${adminPath}/main/itemManagement/needToDeal")
public class NeedToDealController extends BaseExceptionController {

    @Autowired
    private NeedToDealService needToDealService;

    @Autowired
    private UserDao userDao;

    /**
     * 获取待办事项的列表数据
     * 参数：userId   page    limit
     */
    @ResponseBody
    @RequestMapping(value = "getNeedToDealList")
    public Object getNeedToDealList(HttpServletRequest request){
        Map<String, String> map = getParams(request);
        LayuiPage page = new LayuiPage(request);
        Operator operator = getOperatorBy(request);
        map.put("formKeys","91,92,93,94");
        String userId =  request.getParameter("userId");
        String traderId = request.getParameter("traderId");
        map.put("traderId",traderId);
        User user = userDao.getById(userId);
        if(User.USER_TYPE_WXG.equals(user.getUserType())){  //平台员工
            EmployeRoleUtils.getUserDataAuthority(userId,map);
        }
        map.put("employeeUserId", userId);
        List<Record> list= needToDealService.needToDealList(page,map,operator);
        page.setData(list);
        page.setCode("200");
        return page.renderJson();
    }
}
