package com.engine.htsc.zlsbjs.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.zlsbjs.service.UnlockControlService;
import com.engine.htsc.zlsbjs.service.impl.UnlockControlServiceImpl;
import com.engine.workflow.util.CommonUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.general.Util;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;

public class UnlockControlAction {

    private Log log = LogFactory.getLog(this.getClass());
    private UnlockControlService getService(HttpServletRequest req, HttpServletResponse resp){
        User user = CommonUtil.getUserByRequest(req, resp);
        return (UnlockControlService) ServiceUtil.getService(UnlockControlServiceImpl.class,user);
    }

    /**
     * 分公司负责人和分支机构人员默认带出
     * @param req
     * @param response
     * @return
     */
    @GET
    @Path("/formData")
    @Produces({MediaType.APPLICATION_JSON})
    public Map<String,Object> formDefaultData(@Context HttpServletRequest req, @Context HttpServletResponse response){
        int szbm = Util.getIntValue(req.getParameter("szbm"));
        Map<String, Object> formDefaultData = this.getService(req, response).getFormDefaultData(szbm);
        return formDefaultData;
    }

    /**
     * 已锁定查询接口
     * @param req
     * @param response
     * @return
     */
    @GET
    @Path("/isLock")
    @Produces({MediaType.TEXT_PLAIN})
    public String isLock(@Context HttpServletRequest req, @Context HttpServletResponse response){
        String account = Util.null2String(req.getParameter("account"));
        String type = Util.null2String(req.getParameter("type"));
        JSONObject dataObject = this.getService(req, response).isLock(account, type);
        return dataObject.toString();
    }

}
