Newer
Older
PgInterface / src / main / java / com / casic / PgInterface / rs / PgInPgPersonRs.java
xiaowei on 23 Mar 2018 7 KB 完成入廊人员管理接口
package com.casic.PgInterface.rs;

import com.casic.PgInterface.patroler.domain.PgInPgPerson;
import com.casic.PgInterface.patroler.dto.PgInPgPersonDto;
import com.casic.PgInterface.patroler.manager.PgInPgPersonManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by yxw on 2018/3/23.
 */
@Component
@Path("pgInPerson")
public class PgInPgPersonRs {

    private static Logger logger = LoggerFactory.getLogger(PgDeviceRs.class);

    private PgInPgPersonManager pgInPgPersonManager;

    @Resource
    public void setPgInPgPersonManager(PgInPgPersonManager pgInPgPersonManager) {
        this.pgInPgPersonManager = pgInPgPersonManager;
    }

    /**
     * 派发工作证(新增入廊记录)
     */
    @POST
    @Path("addInPgPerson")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> addInPgPerson(@FormParam("userName") String userName,
                                             @FormParam("phoneNumber") String phoneNumber,
                                             @FormParam("inTime") String inTime,
                                             @FormParam("outTime") String outTime,
                                             @FormParam("type") String type) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String result = "";
        String msg = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            PgInPgPerson pgInPgPerson = new PgInPgPerson();
            pgInPgPerson.setUserName(userName);
            pgInPgPerson.setPhoneNumber(phoneNumber);
            pgInPgPerson.setInTime(sdf.parse(inTime));
            pgInPgPerson.setOutTime(sdf.parse(outTime));
            pgInPgPerson.setType(type);

            pgInPgPersonManager.save(pgInPgPerson);

            result = "true";
            msg = "保存成功";
        } catch (Exception e) {
            result = "false";
            msg = "保存失败";
            e.printStackTrace();
        }
        resultMap.put("success", result);
        resultMap.put("msg", msg);
        return resultMap;
    }

    /**
     * 获取人员信息列表
     */
    @POST
    @Path("getInPgPerson")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getInPgPerson() throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg = "";

        List<PgInPgPersonDto> pgInPgPersonDtoList = new ArrayList<PgInPgPersonDto>();
        try {
            pgInPgPersonDtoList = pgInPgPersonManager.getPgInPersonList();
            if (pgInPgPersonDtoList == null || pgInPgPersonDtoList.size() == 0)
                msg = "没有找到入廊人员信息";
            else
                msg = "入廊人员信息获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "入廊人员信息获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgInPgPersonDtoList);
        return resultMap;
    }

    /**
     * 获取在线人员信息列表
     */
    @POST
    @Path("getInPgPersonInPg")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getInPgPersonInPg() throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg = "";

        List<PgInPgPersonDto> pgInPgPersonDtoList = new ArrayList<PgInPgPersonDto>();
        try {
            pgInPgPersonDtoList = pgInPgPersonManager.getPgInPersonListInPg();
            if (pgInPgPersonDtoList == null || pgInPgPersonDtoList.size() == 0)
                msg = "没有找到入廊人员信息";
            else
                msg = "入廊人员信息获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "入廊人员信息获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgInPgPersonDtoList);
        return resultMap;
    }

    /**
     * 根据人员名称获取人员信息
     */
    @POST
    @Path("getInPgPersonByName")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getInPgPersonByName(@FormParam("userName") String userName,
                                                   @FormParam("inTime") String inTime,
                                                   @FormParam("outTime") String outTime) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg = "";

        PgInPgPerson pgInPgPerson=null;
        try {
            pgInPgPerson = pgInPgPersonManager.getPersonByUserName(userName);
            if (pgInPgPerson == null)
                msg = "不存在人员信息";
            else
                msg = "人员信息获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "人员信息获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgInPgPerson);
        return resultMap;
    }

    /**
     * 人员出廊确认
     */
    @POST
    @Path("outPgPerson")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> outPgPerson(@FormParam("userName") String userName) throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        String result = "";
        String msg = "";

        try {
            PgInPgPerson pgInPgPerson=pgInPgPersonManager.getPersonByUserName(userName);
            pgInPgPerson.setOutTime(new Date());
            pgInPgPerson.setIsInPg("0");

            pgInPgPersonManager.save(pgInPgPerson);
            result = "true";
            msg = "编辑成功";
            //}
        } catch (Exception e) {
            result = "false";
            msg = "编辑失败";
            e.printStackTrace();
        }

        resultMap.put("result",result);
        resultMap.put("msg",msg);
        return resultMap;
    }

    /**
     * 根据时间统计入廊人员次数
     */
    @POST
    @Path("getInPgPersonByTime")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getInPgPersonByTime(@FormParam("year") String year,
                                                   @FormParam("statisticType") String statisticType) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg = "";

        List<PgInPgPersonDto> pgInPgPersonDtoList = new ArrayList<PgInPgPersonDto>();
        try {
            pgInPgPersonDtoList = pgInPgPersonManager.getPgInPersonList();
            if (pgInPgPersonDtoList == null || pgInPgPersonDtoList.size() == 0)
                msg = "没有找到入廊人员信息";
            else
                msg = "入廊人员统计信息获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "入廊人员统计信息获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgInPgPersonDtoList);
        return resultMap;
    }




}