lgy vor 6 Jahren
Ursprung
Commit
9c052a5e68

+ 17 - 2
pom.xml

@@ -291,6 +291,21 @@
       <artifactId>shiro-spring</artifactId>
       <version>1.2.3</version>
     </dependency>
+    <dependency>
+      <groupId>com.alibaba</groupId>
+      <artifactId>fastjson</artifactId>
+      <version>1.2.47</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.5.2</version>
+    </dependency>
+    <dependency>
+      <groupId>com.belerweb</groupId>
+      <artifactId>pinyin4j</artifactId>
+      <version>2.5.1</version>
+    </dependency>
   </dependencies>
   <build>
     <finalName>booking</finalName>
@@ -310,8 +325,8 @@
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <configuration>
-                  <source>1.6</source>
-                  <target>1.6</target>
+                  <source>8</source>
+                  <target>8</target>
               </configuration>
           </plugin>
       </plugins>

+ 255 - 24
src/main/java/com/persagy/controller/OrdinaryController.java

@@ -1,18 +1,30 @@
 package com.persagy.controller;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.persagy.domain.*;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.domain.ReservationCustom;
+import com.persagy.domain.ReservationVo;
+import com.persagy.domain.Room;
 import com.persagy.service.ReservationService;
 import com.persagy.service.RoomService;
-import com.persagy.service.UserService;
+import com.persagy.util.PinyinUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Created by Admiral on 2018/1/20.
@@ -27,13 +39,23 @@ public class OrdinaryController {
 
     @Resource(name = "reservationServiceImpl")
     private ReservationService reservationService;
+    //获取CorpAccessToken URL
+    private String corpAccessTokenURL = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2";
+    //部门列表
+    private String departmentURL = "https://open.fxiaoke.com/cgi/department/list";
+    //部门下人员列表
+    private String userURL = "https://open.fxiaoke.com/cgi/user/list";
+    //消息
+    private String messageURL = "https://open.fxiaoke.com/cgi/message/send";
+    private String corpAccessToken = null;
+    private String corpId = null;
 
     /**
      * 获取会议室列表
      * @return
      * @throws Exception
      */
-    @RequestMapping(value="/roomList", method=RequestMethod.GET)
+    @RequestMapping(value="/roomList", method=RequestMethod.POST)
     @ResponseBody
     public List<Room> roomList() throws Exception {
         List<Room> list = roomService.findByPaging(1);
@@ -47,8 +69,10 @@ public class OrdinaryController {
      * @throws Exception
      */
     @RequestMapping(value = "/queryRoomByName", method = {RequestMethod.POST,RequestMethod.GET})
-    private List<Room> queryRoomByName(String roomName) throws Exception {
-        List<Room> list = roomService.findByName(roomName);
+    private List<Room> queryRoomByName(@RequestBody String roomName) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(roomName);
+        String name = jsonObject.getString("roomName");
+        List<Room> list = roomService.findByName(name);
         return list;
     }
 
@@ -59,8 +83,10 @@ public class OrdinaryController {
      * @throws Exception
      */
     @RequestMapping(value = "/queryRoomById", method = {RequestMethod.POST,RequestMethod.GET})
-    private Room queryRoomById(Integer roomID) throws Exception {
-        Room room = roomService.findById(roomID);
+    private Room queryRoomById(@RequestBody String roomID) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(roomID);
+        Integer id = jsonObject.getInteger("roomID");
+        Room room = roomService.findById(id);
         return room;
     }
 
@@ -83,9 +109,11 @@ public class OrdinaryController {
      * @throws Exception
      */
     @RequestMapping("/showRecordByRoomId")
-    public List<ReservationVo> findAllReservationByRoomId(Integer id) throws Exception {
+    public List<ReservationVo> findAllReservationByRoomId(@RequestBody String id) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(id);
+        Integer roomId = jsonObject.getInteger("id");
         List<ReservationVo> list = null;
-        list = reservationService.findByRoomId(id);
+        list = reservationService.findByRoomId(roomId);
         return list;
     }
 
@@ -97,9 +125,11 @@ public class OrdinaryController {
      * @return
      * @throws Exception
      */
-    @RequestMapping(value = "/queryByUser")
-    private List<ReservationVo> queryUser(String userName) throws Exception {
-        List<ReservationVo> list = reservationService.queryByUser(userName);
+    @RequestMapping(value = "/queryByUser",method = RequestMethod.POST)
+    private List<ReservationVo> queryUser(@RequestBody String userName) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(userName);
+        String name = jsonObject.getString("userName");
+        List<ReservationVo> list = reservationService.queryByUser(name);
         return list;
     }
 
@@ -113,13 +143,39 @@ public class OrdinaryController {
         return "/ordinary/reserveRoom";
     }
 
-    //预约会议室功能实现
+    /**
+     * 预约会议室功能实现
+     * @param reservation
+     * @return
+     * @throws Exception
+     */
     @RequestMapping(value = "/reserveRoom", method = RequestMethod.POST)
-    public String reserveRoom(ReservationCustom reservationCustom) throws Exception {
+    public String reserveRoom(@RequestBody String reservation) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(reservation);
+        String roomName = jsonObject.getString("roomName");
+        int roomId = jsonObject.getIntValue("roomId");
+        int userID = jsonObject.getIntValue("userID");
+        String userName = jsonObject.getString("userName");
+
+        JSONArray dateArray = jsonObject.getJSONArray("dateArray");
+        for (int i = 0; i <dateArray.size() ; i++) {
+            JSONObject json = dateArray.getJSONObject(i);
+            String date = json.getString("date");
+            String beginTime = json.getString("beginTime");
+            String endTime = json.getString("endTime");
+            ReservationCustom reservationCustom = new ReservationCustom();
+            reservationCustom.setDate(date);
+            reservationCustom.setBeginTime(beginTime);
+            reservationCustom.setEndTime(endTime);
+            reservationCustom.setUser(userName);
+            reservationCustom.setRoomId(roomId);
+            reservationCustom.setMark("待审核");
+            reservationCustom.setName(roomName);
+            reservationService.addReservation(reservationCustom);
+        }
 
-        reservationService.addReservation(reservationCustom);
 
-        return "redirect:/ordinary/showRecord";
+        return "success";
     }
 
     //取消预约申请页面跳转
@@ -132,11 +188,186 @@ public class OrdinaryController {
     }
 
     //取消预约申请业务实现
-    @RequestMapping("/cancelApply")
-    public String cancelApplication(Integer id) throws Exception{
-        reservationService.cancelApplication(id);
+    @RequestMapping(value = "/cancelApply", method = RequestMethod.POST)
+    public String cancelApplication(@RequestBody String id) throws Exception{
+        JSONObject jsonObject = JSONObject.parseObject(id);
+        Integer cancelID = jsonObject.getInteger("id");
+        reservationService.cancelApplication(cancelID);
+        return "success";
+    }
+    //获取数字签名
+    public void getSignature() throws Exception{
+        //appId
+        String appId = "FSAID_131860e";
+        //appSecret
+        String appSecret = "e1c53d3c6dff4e96b9ec155a031889af";
+        //永久授权码
+        String permanentCode = "B83ED308137C9653E543303740DB2533";
+        JSONObject corpAccessTokenObj = getCorpAccessToken(appId,appSecret,permanentCode);
+        corpAccessToken = corpAccessTokenObj.getString("corpAccessToken");
+        corpId = corpAccessTokenObj.getString("corpId");
+
+    }
+
+    /**
+     *  获取所有部门
+     */
+    @RequestMapping(value="/departmentList", method=RequestMethod.POST)
+    @ResponseBody
+    public String departmentList() throws Exception {
+        getSignature();
+        Map<String,Object> obj = new HashMap<String, Object>();
+        obj.put("corpAccessToken",corpAccessToken);
+        obj.put("corpId",corpId);
+        String result = httpPostRequest(departmentURL, obj);
+        return result;
+    }
+
+    /**
+     * 获取部门下所有人员
+     */
+    @RequestMapping(value="/usertList", method=RequestMethod.POST)
+    @ResponseBody
+    public String usertList(@RequestBody String jsonStr) throws Exception {
+        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
+        String departmentId = jsonObject.getString("departmentId");
+        Map<String,Object> obj = new HashMap<String, Object>();
+        obj.put("corpAccessToken",corpAccessToken);
+        obj.put("corpId",corpId);
+        obj.put("departmentId",Integer.valueOf(departmentId));
+        String result = httpPostRequest(userURL, obj);
+        return result;
+    }
 
-        return "redirect:/ordinary/showRecord";
+
+
+    private JSONObject getCorpAccessToken(String appId, String appSecret, String permanentCode) throws Exception{
+        Map<String,Object> obj = new HashMap<String, Object>();
+        obj.put("appId",appId);
+        obj.put("appSecret",appSecret);
+        obj.put("permanentCode",permanentCode);
+        String result = httpPostRequest(corpAccessTokenURL, obj);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        return jsonObject;
+    }
+
+    /**
+     * 执行http请求
+     * @param httpClient
+     * @param httpRequest
+     * @return
+     */
+    private String executeHttpRequest(CloseableHttpClient httpClient, HttpUriRequest httpRequest){
+        CloseableHttpResponse response = null;
+        String respContent = null;
+        try {
+            response = httpClient.execute(httpRequest);
+            respContent = EntityUtils.toString(response.getEntity(), "utf-8");
+        } catch (Exception e) {
+        }finally {
+            try {
+                httpClient.close();
+            } catch (IOException e) {
+            }
+            if(response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        return respContent;
+    }
+
+    public String httpPostRequest(String url, Map<String, Object> params) throws Exception {
+        String respContent = null;
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        HttpPost httpPost = new HttpPost(url);
+        httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
+        // 设置请求的的参数
+        JSONObject jsonParam = new JSONObject();
+        Set<String> keySet = params.keySet();
+        for (String key : keySet) {
+            jsonParam.put(key, params.get(key));
+        }
+        httpPost.setEntity(new StringEntity(jsonParam.toString(), "utf-8"));
+        // 执行请求
+        respContent = executeHttpRequest(httpclient, httpPost);
+        return respContent;
     }
+    /**
+     * 所有人员
+     */
+    @RequestMapping(value="/usertListFirst", method=RequestMethod.POST)
+    @ResponseBody
+    public String usertList() throws Exception {
+        Map<String,Object> obj = new HashMap<String, Object>();
+        obj.put("corpAccessToken",corpAccessToken);
+        obj.put("corpId",corpId);
+        String result = httpPostRequest(departmentURL, obj);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        JSONArray departments = jsonObject.getJSONArray("departments");
+        JSONArray jsonArray = new JSONArray();
+        Integer departmentId = 0;
+        for (int i = 0; i < departments.size(); i++) {
+            JSONObject department = (JSONObject)departments.get(i);
+            Boolean isStop = department.getBoolean("isStop");
+            if(isStop){
+               continue;
+            }
+            departmentId = department.getInteger("id");
+            //获取人员
+            Map<String,Object> personobj = new HashMap<String, Object>();
+            personobj.put("corpAccessToken",corpAccessToken);
+            personobj.put("corpId",corpId);
+            personobj.put("departmentId",departmentId);
+            String resultStr = httpPostRequest(userURL, personobj);
+            jsonObject = JSONObject.parseObject(resultStr);
+            JSONArray userList = jsonObject.getJSONArray("userList");
+            for (int j = 0; j < userList.size(); j++) {
+                JSONObject jsonObject1 = new JSONObject();
+                JSONObject user = (JSONObject)userList.get(j);
+                Boolean stop = user.getBoolean("isStop");
+                if(stop){
+                    continue;
+                }
+                String name = user.getString("name");
+                String openUserId = user.getString("openUserId");
+                String first = name;
+                jsonObject1.put("name",name);
+                jsonObject1.put("openUserId",openUserId);
+                System.out.println(PinyinUtils.getPinYinHeadChar(name));
+                jsonObject1.put("first", PinyinUtils.getPinYinHeadChar(name));
+                jsonArray.add(jsonObject1);
+            }
+        }
+        return jsonArray.toJSONString();
+    }
+    /**
+     * 发送消息
+     */
+    @RequestMapping(value="/sendMessage", method=RequestMethod.POST)
+    @ResponseBody
+    public String sendMessage(@RequestBody String jsonStr) throws Exception {
+        getSignature();
+        Map<String,Object> obj = new HashMap<String, Object>();
+        obj.put("corpAccessToken",corpAccessToken);
+        obj.put("corpId",corpId);
+        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
+        //消息内容
+        String text = jsonObject.getString("text");
+        //发送人
+        JSONArray users = jsonObject.getJSONArray("users");
+//        JSONArray users = new JSONArray();
+//        users.add("FSUID_782A9585B3CEB91B9DC0C709FA4D3119");
 
+        obj.put("toUser",users);
+        obj.put("msgType","text");
+        JSONObject content = new JSONObject();
+        content.put("content","luo nb");
+        obj.put("text",content);
+
+        String result = httpPostRequest(messageURL, obj);
+        return result;
+    }
 }

+ 7 - 7
src/main/java/com/persagy/dao/ReservationMapper.xml

@@ -3,37 +3,37 @@
 
 <mapper namespace="com.persagy.dao.ReservationMapper">
     <select id="reservationCount" resultType="int">
-        SELECT count(*) FROM reservation a WHERE date>CURDATE() AND a.mark='待审核'
+        SELECT count(*) FROM reservation a WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND a.mark='待审核'
     </select>
 
     <select id="reserveCount" resultType="int">
-        SELECT count(*) FROM reservation a WHERE date>CURDATE() AND mark!='取消申请'
+        SELECT count(*) FROM reservation a WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND mark!='取消申请'
     </select>
 
     <select id="findByPaging" parameterType="com.persagy.domain.PagingVO" resultType="com.persagy.domain.ReservationVo">
         SELECT a.id,b.`name` ,a.date,a.begintime,a.endtime,a.`user`,a.mobile,a.mark FROM reservation a
         LEFT JOIN room b on a.room_id=b.id
-        WHERE date>CURDATE() AND a.mark='待审核' ORDER BY id
+        WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND a.mark='待审核' ORDER BY id
         limit #{toPageNo}, #{pageSize}
     </select>
 
     <select id="findAllByPaging" parameterType="com.persagy.domain.PagingVO" resultType="com.persagy.domain.ReservationVo">
         SELECT a.id,b.`name` ,a.date,a.begintime,a.endtime,a.`user`,a.mobile,a.mark FROM reservation a
         LEFT JOIN room b on a.room_id=b.id
-        WHERE date>CURDATE() AND mark!='取消申请' ORDER BY date DESC
+        WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND mark!='取消申请' ORDER BY date DESC
         limit #{toPageNo}, #{pageSize}
     </select>
 
     <select id="findByName" parameterType="string" resultType="com.persagy.domain.ReservationVo">
         SELECT a.id,b.`name` ,a.date,a.begintime,a.endtime,a.`user`,a.mobile,a.mark FROM reservation a
         LEFT JOIN room b on a.room_id=b.id
-        WHERE date>CURDATE() AND a.mark='待审核' AND a.user LIKE '%${value}%' ORDER BY id
+        WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND a.mark='待审核' AND a.user LIKE '%${value}%' ORDER BY id
     </select>
 
     <select id="findByRoomId" parameterType="int" resultType="com.persagy.domain.ReservationVo">
         SELECT a.id,b.`name` ,a.date,a.begintime,a.endtime,a.`user`,a.mobile,a.mark FROM reservation a
         LEFT JOIN room b on a.room_id=b.id
-        WHERE date>CURDATE() AND mark!='取消申请' AND a.room_id=#{id} ORDER BY id
+        WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND mark!='取消申请' AND a.room_id=#{id} ORDER BY id
     </select>
 
     <select id="reservationPassCount" resultType="int">
@@ -50,7 +50,7 @@
     <select id="queryByUser" parameterType="string" resultType="com.persagy.domain.ReservationVo">
         SELECT a.id,b.`name` ,a.date,a.begintime,a.endtime,a.`user`,a.mobile,a.mark FROM reservation a
         LEFT JOIN room b on a.room_id=b.id
-        WHERE date>CURDATE() AND a.user LIKE '%${value}%' ORDER BY date DESC
+        WHERE date>DATE_SUB(curdate(),INTERVAL 1 DAY) AND a.user LIKE '%${value}%' ORDER BY date DESC
     </select>
 
     <update id="reviewReservation" parameterType="int">

+ 43 - 9
src/main/java/com/persagy/domain/Reservation.java

@@ -1,5 +1,8 @@
 package com.persagy.domain;
 
+import com.persagy.util.DateUtil;
+
+import java.text.ParseException;
 import java.util.Date;
 
 /**
@@ -22,6 +25,20 @@ public class Reservation {
 
     private String mark;
 
+    private String enterUsers;
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+
+    public String getEnterUsers() {
+        return enterUsers;
+    }
+
+    public void setEnterUsers(String enterUsers) {
+        this.enterUsers = enterUsers;
+    }
+
     public int getId() {
         return id;
     }
@@ -54,28 +71,45 @@ public class Reservation {
         this.mobile = mobile;
     }
 
-    public Date getDate() {
-        return date;
+    public String getDate() {
+        return DateUtil.formatStr(DateUtil.date,date);
     }
 
     public void setDate(Date date) {
         this.date = date;
     }
+    public void setDate(String date) {
+        try {
+            this.date = DateUtil.parseDate(DateUtil.date,date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
 
-    public Date getBeginTime() {
-        return beginTime;
+    public String getBeginTime() {
+        return DateUtil.formatStr(DateUtil.time,beginTime);
     }
 
     public void setBeginTime(Date beginTime) {
         this.beginTime = beginTime;
     }
-
-    public Date getEndTime() {
-        return endTime;
+    public void setBeginTime(String beginTime) {
+        try {
+            this.beginTime = DateUtil.parseDate(DateUtil.time,beginTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
+    public String getEndTime() {
+        return DateUtil.formatStr(DateUtil.time,endTime);
     }
 
-    public void setEndTime(Date endTime) {
-        this.endTime = endTime;
+    public void setEndTime(String endTime) {
+        try {
+            this.endTime = DateUtil.parseDate(DateUtil.time,endTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
     }
 
     public String getMark() {

+ 39 - 8
src/main/java/com/persagy/domain/ReservationVo.java

@@ -1,5 +1,8 @@
 package com.persagy.domain;
 
+import com.persagy.util.DateUtil;
+
+import java.text.ParseException;
 import java.util.Date;
 
 /**
@@ -21,6 +24,15 @@ public class ReservationVo {
     private Date endTime;
 
     private String mark;
+    private String enterUsers;
+
+    public String getEnterUsers() {
+        return enterUsers;
+    }
+
+    public void setEnterUsers(String enterUsers) {
+        this.enterUsers = enterUsers;
+    }
 
     public int getId() {
         return id;
@@ -54,30 +66,49 @@ public class ReservationVo {
         this.mobile = mobile;
     }
 
-    public Date getDate() {
-        return date;
+    public String getDate() {
+        return DateUtil.formatStr(DateUtil.date,date);
     }
 
     public void setDate(Date date) {
         this.date = date;
     }
-
-    public Date getBeginTime() {
-        return beginTime;
+    public void setDate(String date) {
+        try {
+            this.date = DateUtil.parseDate(DateUtil.date,date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
+    public String getBeginTime() {
+        return DateUtil.formatStr(DateUtil.time,beginTime);
     }
 
     public void setBeginTime(Date beginTime) {
         this.beginTime = beginTime;
     }
+    public void setBeginTime(String beginTime) {
+        try {
+            this.beginTime = DateUtil.parseDate(DateUtil.time,beginTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
 
-    public Date getEndTime() {
-        return endTime;
+    public String getEndTime() {
+        return DateUtil.formatStr(DateUtil.time,endTime);
     }
 
     public void setEndTime(Date endTime) {
         this.endTime = endTime;
     }
-
+    public void setEndTime(String endTime) {
+        try {
+            this.endTime = DateUtil.parseDate(DateUtil.time,endTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
     public String getMark() {
         return mark;
     }

+ 291 - 0
src/main/java/com/persagy/util/DateUtil.java

@@ -0,0 +1,291 @@
+/**
+ * @包名称 com.sagacloud.common
+ * @文件名 DateUtil.java
+ * @创建者 wanghailong
+ * @邮箱 wanghailong@persagy.com  
+ * @修改描述 
+ */
+
+package com.persagy.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/** 
+ * 功能描述: 日期工具类
+ * @类型名称 DateUtil
+ * @创建者 wanghailong
+ * @邮箱 wanghailong@persagy.com  
+ * @修改描述 
+ */
+public class DateUtil {
+	public static final String sdfTime = "yyyyMMddHHmmss";
+	public static final String sdftime = "yyyyMMddHHmmss";
+	public static final String sdfTimeMinute = "yyyyMMddHHmm";
+	public static final String sdftimemilli = "yyyyMMddHHmmssSSS";
+	public static final String sdfDay = "yyyyMMdd";
+	public static final String sdf_time = "yyyy-MM-dd HH:mm:ss";
+	public static final String date = "yyyy-MM-dd";
+	public static final String time = "HH:mm:ss";
+	public static final String customStateTimeFormat = "yyyyMMddHHmm";
+
+
+    public static String getNowTimeStr() {
+    	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        return sdf.format(new Date());
+    }
+    public static String getNowTimeStrSSS() {
+    	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
+    	return sdf.format(new Date());
+    }
+
+    public static String getNowDate() {
+    	SimpleDateFormat sdf = new SimpleDateFormat(sdfDay);
+    	return sdf.format(new Date());
+    }
+
+	/**
+	 * 获取当前的UTC时间,精确到毫秒
+	 */
+	public static Long getUtcTimeNow(){
+		Date dateNow = new Date();
+		Long lRes = dateNow.getTime();
+		return lRes;
+	}
+
+	/**
+	 * 转换时间格式
+	 * @param dateStr
+	 * @param fromDateFormat
+	 * @param toDateFormat
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String transferDateFormat(String dateStr, String fromDateFormat, String toDateFormat) throws ParseException {
+		SimpleDateFormat fromSdf = new SimpleDateFormat(fromDateFormat);
+		SimpleDateFormat toSdf = new SimpleDateFormat(toDateFormat);
+		return toSdf.format(fromSdf.parse(dateStr));
+	}
+
+	/**
+	 * 获取时间小时数
+	 * @return
+	 */
+	public static String getNowTimeMinutes(){
+		Date date = new Date();
+		long time = date.getTime();
+		return (time/100) + "";
+	}
+
+	public static String getTimeMinutes(String timeStr, String timeFormat){
+		try {
+		SimpleDateFormat simpleDateFormat  = new SimpleDateFormat(timeFormat);
+		Date date;
+			date = simpleDateFormat.parse(timeStr);
+			long time = date.getTime();
+			return (time/100) + "";
+		} catch (ParseException e) {
+		}
+		return null;
+	}
+
+	/**
+	 * 获取时间 yyyyMMdd 转换成int
+	 * @return
+	 */
+	public static String getDayFromDateString(String dateStr, String timeFormat) throws ParseException{
+		Date date = parseDate(timeFormat, dateStr);
+		return formatStr(sdfDay, date);
+	}
+
+	/**
+	 *
+	 * @param timeStr
+	 * @param timeFormat
+	 * @param aheadHour
+	 * @return
+	 * @throws Exception
+	 */
+	public static Calendar getBeforeTime(String timeStr, String timeFormat, int aheadHour) throws Exception{
+		Calendar calendar = Calendar.getInstance();
+		Date date = parseDate(timeFormat, timeStr);
+		calendar.setTime(date);
+		if(aheadHour != 0){
+			calendar.add(Calendar.HOUR, aheadHour * -1);
+		}
+		return calendar;
+	}
+
+	/**
+	 * 根据日历获取时间yyyyMMdd
+	 * @param calendar
+	 * @return
+	 */
+	public static String getDayFromCalendar(Calendar calendar){
+		Date date = calendar.getTime();
+		return formatStr(sdfDay, date);
+	}
+
+	/**
+	 *
+	 * @param timeStr
+	 * @param timeFormat
+	 * @param aheadHour
+	 * @return
+	 * @throws Exception
+	 */
+	public static String getAfterDateOfDay(String timeStr, String timeFormat, int aheadHour){
+		Calendar calendar = Calendar.getInstance();
+		Date date = new Date();
+		try {
+			date = parseDate(timeFormat, timeStr);
+		} catch (ParseException e) {
+		}
+		calendar.setTime(date);
+		if(aheadHour != 0){
+			calendar.add(Calendar.DATE, aheadHour);
+		}
+		return new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
+	}
+
+	/**
+	 * 获取m个天后的日期
+	 * @param afterDay
+	 * @return yyyyMMdd
+	 */
+	public static String getAfterDateOfDay(int afterDay){
+		Calendar calendar = Calendar.getInstance();
+		if(afterDay !=0){
+			calendar.add(Calendar.DATE, afterDay);
+		}
+		return new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
+	}
+
+	/**
+	 * 获取m个小时后的日期
+	 * @param afterHour
+	 * @return
+	 */
+	public static String getAfterDateOfHour(int afterHour){
+		Calendar calendar = Calendar.getInstance();
+		if(afterHour !=0){
+			calendar.add(Calendar.HOUR, afterHour);
+		}
+		return new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
+	}
+
+	/**
+	 * 获取n天、m个小时后的日期
+	 * @param afterHour
+	 * @return
+	 */
+	public static String getAfterDate(int afterYear, int afterMonth, int afterDay, int afterHour){
+		Calendar calendar = Calendar.getInstance();
+		if(afterYear !=0){
+			calendar.add(Calendar.YEAR, afterYear);
+		}
+		if(afterMonth !=0){
+			calendar.add(Calendar.MONTH, afterMonth);
+		}
+		if(afterDay !=0){
+			calendar.add(Calendar.DATE, afterDay);
+		}
+		if(afterHour !=0){
+			calendar.add(Calendar.HOUR, afterHour);
+		}
+		return new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
+	}
+
+	/**
+	 * 获取n天、m个小时后的日期
+	 * @param afterHour
+	 * @return
+	 */
+	public static String getAfterDate(Date date, String timeFormat, int afterYear, int afterMonth, int afterDay, int afterHour){
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		if(afterYear !=0){
+			calendar.add(Calendar.YEAR, afterYear);
+		}
+		if(afterMonth !=0){
+			calendar.add(Calendar.MONTH, afterMonth);
+		}
+		if(afterDay !=0){
+			calendar.add(Calendar.DATE, afterDay);
+		}
+		if(afterHour !=0){
+			calendar.add(Calendar.HOUR, afterHour);
+		}
+		return new SimpleDateFormat(timeFormat).format(calendar.getTime());
+	}
+
+	/**
+	 * 获取时间差值-格式**天**小时**分钟
+	 * @param fromTime
+	 * @param toTime
+	 * @param timeFormat
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getTimeDiffence(String fromTime, String toTime, String timeFormat) throws ParseException {
+		if(fromTime == null || toTime == null)
+			return null;
+		SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
+		Date startTime = sdf.parse(fromTime);
+		Date endTime = sdf.parse(toTime);
+		long diffenceValue = endTime.getTime() - startTime.getTime();
+		long days = diffenceValue / (24*60*60*1000);
+		long hours = (diffenceValue/(60*60*1000)-days*24);
+		long min=((diffenceValue/(60*1000))-days*24*60-hours*60);
+		String str = "";
+		if(days != 0){
+			str += days + "天";
+		}
+		if(hours != 0 || days != 0){
+			str += hours + "小时";
+		}
+		if(min != 0 || days != 0 || hours != 0 || (days == 0 && hours == 0)){
+			str += min + "分钟";
+		}
+		return str;
+	}
+
+	public static String formatStr(String pattern, Date date) {
+		String str = new SimpleDateFormat(pattern).format(date);
+		return str;
+	}
+	public static Date parseDate(String pattern, String str) throws ParseException {
+		Date date = new SimpleDateFormat(pattern).parse(str);
+		return date;
+	}
+
+	/**
+	* 将毫秒转成时间格式的字符串
+	* @param pattern
+	* @param milis
+	* @return
+	*/
+	public static String parseDate(String pattern, long milis){
+	String date = new SimpleDateFormat(pattern).format(milis);
+	return date;
+	}
+
+	/**
+	 * 当前时间到第二日凌晨的秒数
+	 */
+    public static Long getSecondsNextEarlyMorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DAY_OF_YEAR, 1);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
+    }
+
+	public static void main(String[] args) {
+		System.out.println("AboLuo".substring(0,1));
+	}
+}

+ 86 - 0
src/main/java/com/persagy/util/PinyinUtils.java

@@ -0,0 +1,86 @@
+package com.persagy.util;
+
+import net.sourceforge.pinyin4j.PinyinHelper;
+import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
+import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
+import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
+
+public class PinyinUtils {
+    /**
+     * 将汉字转换为全拼
+     * @param src
+     * @return
+     */
+    public static String getPinYin(String src){
+        char[] hz = null;
+        hz = src.toCharArray();//该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符
+        String[] py = new String[hz.length];//该数组用来存储
+        //设置汉子拼音输出的格式
+        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
+        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
+        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
+        format.setVCharType(HanyuPinyinVCharType.WITH_V);
+
+        String pys = ""; //存放拼音字符串
+        int len = hz.length;
+
+        try {
+            for (int i = 0; i < len ; i++ ){
+                //先判断是否为汉字字符
+                if(Character.toString(hz[i]).matches("[\\u4E00-\\u9FA5]+")){
+                    //将汉字的几种全拼都存到py数组中
+                    py = PinyinHelper.toHanyuPinyinStringArray(hz[i],format);
+                    //取出改汉字全拼的第一种读音,并存放到字符串pys后
+                    pys += py[0];
+                }else{
+                    //如果不是汉字字符,间接取出字符并连接到 pys 后
+                    pys += Character.toString(hz[i]);
+                }
+            }
+        } catch (BadHanyuPinyinOutputFormatCombination e){
+            e.printStackTrace();
+        }
+        return pys;
+    }
+
+    /**
+     * 提取每个汉字的首字母
+     * @param str
+     * @return
+     */
+    public static String getPinYinHeadChar(String str){
+        String convert = "";
+        for (int i = 0; i < str.length(); i++) {
+            char word = str.charAt(i);
+            //提取汉字的首字母
+            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
+            if (pinyinArray != null){
+                convert += pinyinArray[0].charAt(0);
+            }else{
+                convert += word;
+            }
+        }
+        return convert.toUpperCase();
+    }
+
+    /**
+     * 将字符串转换成ASCII码
+     */
+    public static String getCnASCII(String str){
+        StringBuffer buf = new StringBuffer();
+        //将字符串转换成字节序列
+        byte[] bGBK = str.getBytes();
+        for (int i = 0; i < bGBK.length; i++) {
+            //将每个字符转换成ASCII码
+            buf.append(Integer.toHexString(bGBK[i] & 0xff));
+        }
+        return buf.toString();
+    }
+
+    public static void main(String[] args) {
+        System.out.println(getPinYinHeadChar("康"));
+    }
+
+}