yujian
2019-05-20 fa5a54ef993f05cf353e13652eec4bb15e2a9d66
邀请素材管理
3个文件已删除
10个文件已添加
5128 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/CustomerServiceController.java 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/RecommendController.java 2356 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java 861 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/dynamic/InviteMaterialDao.java 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/dynamic/InviteMaterial.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/InviteMaterialServiceImpl.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/InviteMaterialService.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/test/java/org/fanli/date/Test_LunarUtil.java 301 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/test/java/org/fanli/dynamic/Lunar.java 208 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/test/java/org/fanli/dynamic/Test_DrawInviteMaterial.java 250 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/test/java/org/fanli/dynamic/Test_InviteMaterialService.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/DateLunarUtil.java 539 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/entity/DateInfo.java 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/CustomerServiceController.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/controller/client/RecommendController.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/dao/dynamic/InviteMaterialDao.java
New file
@@ -0,0 +1,130 @@
package com.yeshi.fanli.dao.dynamic;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import com.yeshi.fanli.entity.dynamic.InviteMaterial;
@Repository
public class InviteMaterialDao {
    @Resource
    private MongoTemplate mongoTemplate;
    /**
     * 新增
     *
     * @param record
     */
    public void insert(InviteMaterial record) {
        if (record == null) {
            return;
        }
        mongoTemplate.insert(record);
    }
    /**
     * 更新状态
     *
     * @param record
     */
    public void updateState(int state, String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(id));
        Update update = Update.update("state", state);
        mongoTemplate.updateMulti(query, update, InviteMaterial.class);
    }
    /**
     * 更新信息
     *
     * @param record
     */
    public void update(InviteMaterial record) {
        if (record == null) {
            return;
        }
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(record.getId()));
        Update update = Update.update("picture", record.getPicture()).set("text", record.getText()).set("state",
                record.getState());
        mongoTemplate.updateMulti(query, update, InviteMaterial.class);
    }
    /**
     * 根据id查询数据
     *
     * @param id
     * @return
     */
    public InviteMaterial getById(String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(id));
        return mongoTemplate.findOne(query, InviteMaterial.class);
    }
    /**
     * 删除
     *
     * @param id
     * @return
     */
    public void deleteById(String id) {
        InviteMaterial info = getById(id);
        if (info == null) {
            return;
        }
        mongoTemplate.remove(info);
    }
    /**
     * 查询所有数据
     *
     * @param clazz
     * @return
     */
    public List<InviteMaterial> query(int start, int count) {
        Query query = new Query();
        // 分页
        query.skip(start).limit(count);
        List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class);
        return list;
    }
    public long count() {
        Query query = new Query();
        return mongoTemplate.count(query, InviteMaterial.class);
    }
    /**
     * 根据状态查询
     * @param state
     * @return
     */
    public List<InviteMaterial> queryByState(int state) {
        Query query = new Query();
        query.addCriteria(Criteria.where("state").is(state));
        List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class);
        return list;
    }
    /**
     * 查询所有数据
     *
     * @param clazz
     * @return
     */
    public List<InviteMaterial> queryAll() {
        return (List<InviteMaterial>) mongoTemplate.findAll(InviteMaterial.class);
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/dynamic/InviteMaterial.java
New file
@@ -0,0 +1,63 @@
package com.yeshi.fanli.entity.dynamic;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
/**
 * 邀请问候图片文字信息 -素材
 *
 * @author Administrator
 *
 */
@Document(collection = "invite_material")
public class InviteMaterial {
    @Id
    @Field("id")
    private String id;
    // 图片
    @Field("picture")
    private String picture;
    // 内容
    @Field("text")
    private String text;
    // 状态: 已发布1, 未发布0
    @Field("state")
    private Integer state;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPicture() {
        return picture;
    }
    public void setPicture(String picture) {
        this.picture = picture;
    }
    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/InviteMaterialServiceImpl.java
New file
@@ -0,0 +1,53 @@
package com.yeshi.fanli.service.impl.dynamic;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.dynamic.InviteMaterialDao;
import com.yeshi.fanli.entity.dynamic.InviteMaterial;
import com.yeshi.fanli.service.inter.dynamic.InviteMaterialService;
@Service
public class InviteMaterialServiceImpl implements InviteMaterialService {
    @Resource
    private InviteMaterialDao inviteMaterialDao;
    @Override
    public void insert(InviteMaterial record) {
        inviteMaterialDao.insert(record);
    }
    @Override
    public void update(InviteMaterial record) {
        inviteMaterialDao.update(record);
    }
    @Override
    public void updateState(int state, String id) {
        inviteMaterialDao.updateState(state, id);
    }
    @Override
    public InviteMaterial getById(String id) {
        return inviteMaterialDao.getById(id);
    }
    @Override
    public void deleteById(String id) {
        inviteMaterialDao.deleteById(id);
    }
    @Override
    public InviteMaterial getInviteMaterial() {
        List<InviteMaterial> list = inviteMaterialDao.queryByState(0);
        if (list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/InviteMaterialService.java
New file
@@ -0,0 +1,47 @@
package com.yeshi.fanli.service.inter.dynamic;
import com.yeshi.fanli.entity.dynamic.InviteMaterial;
public interface InviteMaterialService {
    /**
     * 插入
     * @param record
     */
    public void insert(InviteMaterial record);
    /**
     * 更新
     * @param record
     */
    public void update(InviteMaterial record);
    /**
     * 更新分享次数
     * @param record
     */
    public void updateState(int state, String id);
    /**
     * 根据id查询
     * @param id
     * @return
     */
    public InviteMaterial getById(String id);
    /**
     *  删除
     * @return
     */
    public void deleteById(String id);
    /**
     * 获取邀请素材
     * @return
     */
    public InviteMaterial getInviteMaterial();
}
fanli/src/test/java/org/fanli/date/Test_LunarUtil.java
New file
@@ -0,0 +1,301 @@
package org.fanli.date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * Created by hcf on 2017/12/4.
 */
public class Test_LunarUtil {
    private int year;
    private int month;
    private int day;
    private boolean leap;
    final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七",
            "八", "九", "十", "十一", "十二"};
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    final static long[] lunarInfo = new long[]{0x04bd8, 0x04ae0, 0x0a570,
            0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
            0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
            0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
            0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,
            0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
            0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,
            0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,
            0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950,
            0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260,
            0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0,
            0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
            0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40,
            0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,
            0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,
            0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,
            0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,
            0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0,
            0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65,
            0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0,
            0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,
            0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0};
    // ====== 传回农历 y年的总天数
    final private static int yearDays(int y) {
        int i, sum = 348;
        for (i = 0x8000; i > 0x8; i >>= 1) {
            if ((lunarInfo[y - 1900] & i) != 0)
                sum += 1;
        }
        return (sum + leapDays(y));
    }
    // ====== 传回农历 y年闰月的天数
    final private static int leapDays(int y) {
        if (leapMonth(y) != 0) {
            if ((lunarInfo[y - 1900] & 0x10000) != 0)
                return 30;
            else
                return 29;
        } else
            return 0;
    }
    // ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
    final private static int leapMonth(int y) {
        return (int) (lunarInfo[y - 1900] & 0xf);
    }
    // ====== 传回农历 y年m月的总天数
    final private static int monthDays(int y, int m) {
        if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
            return 29;
        else
            return 30;
    }
    // ====== 传回农历 y年的生肖
    final public String animalsYear() {
        final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇",
                "马", "羊", "猴", "鸡", "狗", "猪"};
        return Animals[(year - 4) % 12];
    }
    // ====== 传入 月日的offset 传回干支, 0=甲子
    final private static String cyclicalm(int num) {
        final String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚",
                "辛", "壬", "癸"};
        final String[] Zhi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午",
                "未", "申", "酉", "戌", "亥"};
        return (Gan[num % 10] + Zhi[num % 12]);
    }
    // ====== 传入 offset 传回干支, 0=甲子
    final public String cyclical() {
        int num = year - 1900 + 36;
        return (cyclicalm(num));
    }
    /** */
    /**
     *   * 传出y年m月d日对应的农历.   * yearCyl3:农历年与1864的相差数 ?   *
     * monCyl4:从1900年1月31日以来,闰月数   * dayCyl5:与1900年1月31日相差的天数,再加40 ?   * @param
     * cal   * @return
     */
    public Test_LunarUtil(Calendar cal) {
        @SuppressWarnings("unused")
        int yearCyl, monCyl, dayCyl;
        int leapMonth = 0;
        Date baseDate = null;
        try {
            baseDate = chineseDateFormat.parse("1900-1-31");
        } catch (ParseException e) {
            e.printStackTrace(); // To change body of catch statement use
            // Options | File Templates.
        }
        // 求出和1900年1月31日相差的天数
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
        dayCyl = offset + 40;
        monCyl = 14;
        // 用offset减去每农历年的天数
        // 计算当天是农历第几天
        // i最终结果是农历的年份
        // offset是当年的第几天
        int iYear, daysOfYear = 0;
        for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
            daysOfYear = yearDays(iYear);
            offset -= daysOfYear;
            monCyl += 12;
        }
        if (offset < 0) {
            offset += daysOfYear;
            iYear--;
            monCyl -= 12;
        }
        // 农历年份
        year = iYear;
        yearCyl = iYear - 1864;
        leapMonth = leapMonth(iYear); // 闰哪个月,1-12
        leap = false;
        // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
        int iMonth, daysOfMonth = 0;
        for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
            // 闰月
            if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
                --iMonth;
                leap = true;
                daysOfMonth = leapDays(year);
            } else
                daysOfMonth = monthDays(year, iMonth);
            offset -= daysOfMonth;
            // 解除闰月
            if (leap && iMonth == (leapMonth + 1))
                leap = false;
            if (!leap)
                monCyl++;
        }
        // offset为0时,并且刚才计算的月份是闰月,要校正
        if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
            if (leap) {
                leap = false;
            } else {
                leap = true;
                --iMonth;
                --monCyl;
            }
        }
        // offset小于0时,也要校正
        if (offset < 0) {
            offset += daysOfMonth;
            --iMonth;
            --monCyl;
        }
        month = iMonth;
        day = offset + 1;
    }
    /** */
    /**
     *   * 传出y年m月d日对应的农历.   * yearCyl3:农历年与1864的相差数 ?   *
     * monCyl4:从1900年1月31日以来,闰月数   * dayCyl5:与1900年1月31日相差的天数,再加40 ?   * @param
     * cal   * @return
     */
    public String getLunar(Calendar cal) {
        int yearCyl, monCyl, dayCyl;
        int leapMonth = 0;
        Date baseDate = null;
        try {
            baseDate = chineseDateFormat.parse("1900-1-31");
        } catch (ParseException e) {
            e.printStackTrace(); // To change body of catch statement use
        }
        // 求出和1900年1月31日相差的天数
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
        dayCyl = offset + 40;
        monCyl = 14;
        // 用offset减去每农历年的天数
        // 计算当天是农历第几天
        // i最终结果是农历的年份
        // offset是当年的第几天
        int iYear, daysOfYear = 0;
        for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
            daysOfYear = yearDays(iYear);
            offset -= daysOfYear;
            monCyl += 12;
        }
        if (offset < 0) {
            offset += daysOfYear;
            iYear--;
            monCyl -= 12;
        }
        // 农历年份
        year = iYear;
        yearCyl = iYear - 1864;
        leapMonth = leapMonth(iYear); // 闰哪个月,1-12
        leap = false;
        // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
        int iMonth, daysOfMonth = 0;
        for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
            // 闰月
            if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
                --iMonth;
                leap = true;
                daysOfMonth = leapDays(year);
            } else
                daysOfMonth = monthDays(year, iMonth);
            offset -= daysOfMonth;
            // 解除闰月
            if (leap && iMonth == (leapMonth + 1))
                leap = false;
            if (!leap)
                monCyl++;
        }
        // offset为0时,并且刚才计算的月份是闰月,要校正
        if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
            if (leap) {
                leap = false;
            } else {
                leap = true;
                --iMonth;
                --monCyl;
            }
        }
        // offset小于0时,也要校正
        if (offset < 0) {
            offset += daysOfMonth;
            --iMonth;
            --monCyl;
        }
        String lunar = "";
        if (leap) {
            lunar = "闰";
        }
        lunar += iMonth + "月";
        lunar += offset + 1;
        return lunar;
    }
    public static String getChinaDayString(int day) {
        String chineseTen[] = {"初", "十", "廿", "卅"};
        int n = day % 10 == 0 ? 9 : day % 10 - 1;
        if (day > 30)
            return "";
        if (day == 10)
            return "初十";
        else
            return chineseTen[day / 10] + chineseNumber[n];
    }
    public String toString() {
        return year + "年" + (leap ? "闰" : "") + chineseNumber[month - 1] + "月"
                + getChinaDayString(day);
    }
    public static void main(String[] args) throws ParseException {
//        Date date = new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        String d = dateFormat.format(date);
//        Calendar today = Calendar.getInstance();
//        today.setTime(chineseDateFormat.parse(d));
//        Test_LunarUtil lunar = new Test_LunarUtil(today);
//        System.out.println("北京时间:" + chineseDateFormat.format(today.getTime())
//                + " 农历" + lunar);
        String year = "1952";
        for (int i = 0;i<year.length() ;i ++) {
            System.out.println(year.charAt(i));
        }
    }
}
fanli/src/test/java/org/fanli/dynamic/Lunar.java
New file
@@ -0,0 +1,208 @@
package org.fanli.dynamic;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Lunar {
    private int year;
    private int month;
    private int day;
    private boolean leap;
    final static String chineseNumber[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
    final static String Big_Or_Small[] = { "大", "小", "大", "小", "大", "小", "大", "大", "小", "大", "小", "大" };
    private String[] LunarHolDayName = { "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑",
            "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" };
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat(" yyyy年MM月dd日 ");
    final static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0,
            0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
            0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0,
            0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0,
            0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573,
            0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950,
            0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
            0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970,
            0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954, 0x0d4a0, 0x0da50,
            0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0,
            0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260,
            0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
            0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };
    // ====== 传回农历 y年的总天数
    final private static int yearDays(int y) {
        int i, sum = 348;
        for (i = 0x8000; i > 0x8; i >>= 1) {
            if ((lunarInfo[y - 1900] & i) != 0)
                sum += 1;
        }
        return (sum + leapDays(y));
    }
    // ====== 传回农历 y年闰月的天数
    final private static int leapDays(int y) {
        if (leapMonth(y) != 0) {
            if ((lunarInfo[y - 1900] & 0x10000) != 0)
                return 30;
            else
                return 29;
        } else
            return 0;
    }
    // ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
    final private static int leapMonth(int y) {
        return (int) (lunarInfo[y - 1900] & 0xf);
    }
    // ====== 传回农历 y年m月的总天数
    final private static int monthDays(int y, int m) {
        if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
            return 29;
        else
            return 30;
    }
    // ====== 传回农历 y年的生肖
    final public String animalsYear() {
        final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
        return Animals[(year - 4) % 12];
    }
    // ====== 传入 月日的offset 传回干支, 0=甲子
    final private static String cyclicalm(int num) {
        final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
        final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
        return (Gan[num % 10] + Zhi[num % 12]);
    }
    // ====== 传入 offset 传回干支, 0=甲子
    final public String cyclical() {
        int num = year - 1900 + 36;
        return (cyclicalm(num));
    }
    /** */
    /**
     * 传出y年m月d日对应的农历. yearCyl3:农历年与1864的相差数 ? monCyl4:从1900年1月31日以来,闰月数
     * dayCyl5:与1900年1月31日相差的天数,再加40 ?
     *
     * @param cal
     * @return
     */
    public Lunar(Calendar cal) {
        // cal.add(cal.get(Calendar.DAY_OF_MONTH),1);
        @SuppressWarnings(" unused ")
        int yearCyl, monCyl, dayCyl;
        int leapMonth = 0;
        Date baseDate = null;
        try {
            baseDate = chineseDateFormat.parse(" 1900年1月31日 ");
        } catch (ParseException e) {
            e.printStackTrace(); // To change body of catch statement use
                                    // Options | File Templates.
        }
        // 求出和1900年1月31日相差的天数
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
        dayCyl = offset + 40;
        monCyl = 14;
        // 用offset减去每农历年的天数
        // 计算当天是农历第几天
        // i最终结果是农历的年份
        // offset是当年的第几天
        int iYear, daysOfYear = 0;
        for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
            daysOfYear = yearDays(iYear);
            offset -= daysOfYear;
            monCyl += 12;
        }
        if (offset < 0) {
            offset += daysOfYear;
            iYear--;
            monCyl -= 12;
        }
        // 农历年份
        year = iYear;
        yearCyl = iYear - 1864;
        leapMonth = leapMonth(iYear); // 闰哪个月,1-12
        leap = false;
        // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
        int iMonth, daysOfMonth = 0;
        for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
            // 闰月
            if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
                --iMonth;
                leap = true;
                daysOfMonth = leapDays(year);
            } else
                daysOfMonth = monthDays(year, iMonth);
            offset -= daysOfMonth;
            // 解除闰月
            if (leap && iMonth == (leapMonth + 1))
                leap = false;
            if (!leap)
                monCyl++;
        }
        // offset为0时,并且刚才计算的月份是闰月,要校正
        if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
            if (leap) {
                leap = false;
            } else {
                leap = true;
                --iMonth;
                --monCyl;
            }
        }
        // offset小于0时,也要校正
        if (offset < 0) {
            offset += daysOfMonth;
            --iMonth;
            --monCyl;
        }
        month = iMonth;
        day = offset + 1;
    }
    public static String getChinaDayString(int day) {
        String chineseTen[] = { "初", "十", "廿", "卅" };
        int n = day % 10 == 0 ? 9 : day % 10 - 1;
        if (day > 30)
            return "";
        if (day == 10)
            return "初十";
        else
            return chineseTen[day / 10] + chineseNumber[n];
    }
    public String toString() {
        return /* cyclical() + "年" + */(leap ? "闰" : "") + chineseNumber[month - 1] + "月" + getChinaDayString(day);
    }
    public String numeric_md() {// 返回阿拉伯数字的阴历日期
        String temp_day;
        String temp_mon;
        temp_mon = month < 10 ? "0" + month : "" + month;
        temp_day = day < 10 ? "0" + day : "" + day;
        return temp_mon + temp_day;
    }
    public String get_month() {// 返回阴历的月份
        return chineseNumber[month - 1];
    }
    public String get_date() {// 返回阴历的天
        return getChinaDayString(day);
    }
    public String get_Big_Or_Small() {// 返回的月份的大或小
        return Big_Or_Small[month - 1];
    }
}
fanli/src/test/java/org/fanli/dynamic/Test_DrawInviteMaterial.java
New file
@@ -0,0 +1,250 @@
package org.fanli.dynamic;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashMap;
import javax.imageio.ImageIO;
import org.junit.Test;
import org.yeshi.utils.DateLunarUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.QRCodeUtil;
import org.yeshi.utils.entity.DateInfo;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FileUtil;
import com.yeshi.fanli.util.ImageUtil;
import com.yeshi.fanli.util.StringUtil;
public class Test_DrawInviteMaterial {
    @Test
    public void draw1() {
        try {
            long uid = 911382;
            String targetPath = FileUtil.getCacheDir() + "/share_" + uid +".jpg";
            String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
            String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
                    + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
            // 生成
            try {
                QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
            // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
            inviteFriendImgLower(erCodeInputStream, targetPath, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     *
     * @param urlInputStream
     * @param portraitInputStream
     * @param erCodeInputStream
     * @param targetPath
     * @param pX                  -二维码的横坐标
     * @param pY                  -二维码的纵坐标
     * @param size                -二维码的尺寸
     * @param inviteCode          -邀请码
     * @throws IOException
     */
    // 邀请好友图片 - 底部
    public static void inviteFriendImgLower(InputStream erCodeInputStream, String targetPath, Date date) throws IOException {
        String inviteCode = "LKFK5P";
        BufferedImage bgImage = ImageIO
                .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/bg.jpg"));
        final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        HashMap<Key, Object> mapH = new HashMap<Key, Object>();
        mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关)  
        mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
        // 画 背景图片
        final Graphics2D g2d = targetImg.createGraphics();
        g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
        g2d.setBackground(Color.BLACK);
        // 画 蒙层
        BufferedImage mengCeng = ImageIO
                .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/mc.png"));
        g2d.drawImage(mengCeng, 0, bgImage.getHeight()/2, bgImage.getWidth(), bgImage.getHeight()/2, null);
        int width = bgImage.getWidth();
        int height = bgImage.getHeight();
        int pX = width - 250;
        int pY = height - 290; // 320
        int size = 210; // 230
        // 画 二维码
        BufferedImage qrCodeImage = ImageIO.read(erCodeInputStream);
        qrCodeImage = ImageUtil.qrCodeImage(g2d, qrCodeImage, pX, pY, size, size); // 二维码长宽
        // 230*230
        // 画 头像
        // BufferedImage portraitImg = ImageIO.read(portraitInputStream);
        BufferedImage portraitImg = ImageIO
                .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/hd.jpg"));
        int portraitSize = size * 5 / 23;
        int pPX = pX + size / 2 - portraitSize / 2;
        int pPY = pY + size / 2 - portraitSize / 2;
        portraitImg = ImageUtil.portraitImg(g2d, portraitImg, pPX, pPY, portraitSize, portraitSize);// 头像长宽
        // 文字白色
        Color color = new Color(255, 255, 255);
        String os = System.getProperty("os.name");
        String fontBoldPath = "/usr/share/fonts/yahei.ttf";
        if (os.toLowerCase().startsWith("win")) {
            fontBoldPath = "D:/yahei.ttf";
        }
        Font boldFont = null;
        // 画邀请码(邀请码的大小与字体固定)
        if (!StringUtil.isNullOrEmpty(inviteCode)) {
            String st = "邀请码:" + inviteCode;
            try {
                boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(32.0f);
            } catch (FontFormatException e) {
                e.printStackTrace();
            }
            g2d.setFont(boldFont);
            g2d.setColor(new Color(255, 255, 255));
            FontMetrics fm = g2d.getFontMetrics(boldFont);
            int textLength = fm.stringWidth(st);
            int ax = (width - textLength) - 30;
            int ay = bgImage.getHeight() - 50 + boldFont.getSize() / 2 - 5;
            g2d.setColor(new Color(255, 255, 255));
            g2d.drawString(st, ax, ay);
        }
        int padding_left = 30;
        // 日历
        try {
            if (date == null) {
                date = new Date();
            }
            boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
            g2d.setFont(boldFont);
            g2d.setColor(color);
            DateInfo dateInfo = DateLunarUtil.getDateInfo(date);
            // 农历
            g2d.drawString(dateInfo.getLunar_month() + dateInfo.getLunar_day(), padding_left, height - 80 );
            // 天干地支
            g2d.drawString(dateInfo.getAgenary_month() +" " + dateInfo.getAgenary_day(), padding_left, height - 140 );
            // 当前日期
            Font boldFontMax = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(100.0f);
            g2d.setFont(boldFontMax);
            if (dateInfo.getDay() < 10) {
                g2d.drawString("0" + dateInfo.getDay().toString(), padding_left, height - 200 );
            } else {
                g2d.drawString(dateInfo.getDay().toString(), padding_left, height - 200 );
            }
            String theDate= "";
            if (dateInfo.getMonth() < 10) {
                theDate ="/0";
            } else {
                theDate ="/";
            }
            theDate += dateInfo.getMonth() + "/"+ dateInfo.getYear() + " " + dateInfo.getWeekDay();
            g2d.setFont(boldFont);
            g2d.drawString(theDate, padding_left + boldFontMax.getSize() + 15, height - 200 );
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 文字内容
        try {
            boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
            g2d.setFont(boldFont);
            g2d.setColor(color);
            String content = "对自己严格一点儿,时间长了,努力便成为一种心理习惯,一种生活方式。未必人人都可以做到优秀,但至少可以努力做到比昨天的自己更优秀。";
            System.out.println(content.length());
            int lineHeight = 70;
            int lineTextLength = 19;
            if (content.length() <= lineTextLength) {
                g2d.drawString(content, padding_left, height - 350 );
            } else {
                String text = "";
                int mod = content.length() % lineTextLength;
                if (mod == 0) {
                    text = content.substring(content.length() -lineTextLength,content.length());
                    content = content.substring(0, content.length() -lineTextLength);
                } else {
                    text = content.substring(content.length() -mod ,content.length());
                    content = content.substring(0, content.length() -mod);
                }
                g2d.drawString(text, padding_left, height - 350);
                int i = 1;
                while (true) {
                    if (content.length() <= 17) {
                        g2d.drawString(content, padding_left, height - 350 - lineHeight * i);
                        break;
                    } else {
                        text = content.substring(content.length() -lineTextLength,content.length());
                        content = content.substring(0, content.length() -lineTextLength);
                        g2d.drawString(text, padding_left, height - 350 - lineHeight * i);
                        i ++;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        OutputStream out = new FileOutputStream(new File(targetPath));
        ImageIO.write(targetImg, "JPEG", out);
        out.flush();
        out.close();
    }
}
fanli/src/test/java/org/fanli/dynamic/Test_InviteMaterialService.java
New file
@@ -0,0 +1,40 @@
package org.fanli.dynamic;
import org.junit.Test;
import com.yeshi.fanli.entity.dynamic.InviteMaterial;
import com.yeshi.fanli.service.inter.dynamic.InviteMaterialService;
import com.yeshi.fanli.util.BeanUtil;
public class Test_InviteMaterialService {
    @Test
    public void draw1() {
        try {
            InviteMaterialService service = BeanUtil.getBean(InviteMaterialService.class);
//            String picture = "http://img.flqapp.com/resource/invite/everyday/1.jpg";
//            String text = "有时候,活得累,并非生活过于刻薄,而是太容易被外界的氛围所感染,被他人的情绪所左右。";
//            String picture = "http://img.flqapp.com/resource/invite/everyday/2.jpg";
//            String text = "别把窘境迁怒于别人,唯一可以抱怨的,只是不够努力的自己。";
//            String picture = "http://img.flqapp.com/resource/invite/everyday/3.jpg";
//            String text = "世上的事,只要肯用心去学,没有一件是太晚的。要始终保持敬畏之心,对阳光,对美,对痛楚。";
            String picture = "http://img.flqapp.com/resource/invite/everyday/4.jpg";
            String text = "人生就像是一个马尔可夫链,未来取决于当下正在做的事,而无关于过去做完的事。";
            InviteMaterial material = new InviteMaterial();
            material.setState(0);
            material.setText(text);
            material.setPicture(picture);
            service.insert(material);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
utils/src/main/java/org/yeshi/utils/DateLunarUtil.java
New file
@@ -0,0 +1,539 @@
package org.yeshi.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.yeshi.utils.entity.DateInfo;
/**
 * 〈将日期转换为干支历法的年月日时,并计算生肖、阴历、星期几〉
 *
 */
public class DateLunarUtil {
    static int[] lunarInfo = new int[] { 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0,
            0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
            0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0,
            0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0,
            0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573,
            0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950,
            0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6,
            0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970,
            0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954, 0x0d4a0, 0x0da50,
            0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0,
            0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260,
            0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
            0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, 0x14b63 };
    static String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
    static String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
    static long[] sTermInfo = new long[] { 0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551,
            218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532,
            504758 };
    final static String chineseNumber[] = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊" };
    final static String chineseNumber1[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
    // 当前年
    private static Integer year;
    // 当前月
    private static Integer month;
    // 当前日
    private static Integer day;
    // 当前星期几
    private static String weekDay;
    // 农历-年
    private static String lunar_year;
    // 农历-月
    private static String lunar_month;
    // 农历-日
    private static String lunar_day;
    // 天干地支-年
    private static String agenary_year;
    // 天干地支-月
    private static String agenary_month;
    // 天干地支-日
    private static String agenary_day;
    // 天干地支-时辰
    private static String agenary_hour;
    /**
     * 分裂当前成 年、月、日
     *
     * @param date
     */
    public static void splitDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH) + 1;
        day = cal.get(Calendar.DAY_OF_MONTH);
    }
    /**
     * 转换成阴历
     *
     * @param date
     * @return
     */
    public static String toLunar(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int leapMonth = 0;
        Date baseDate = null;
        try {
            baseDate = chineseDateFormat.parse("1900年1月31日");
        } catch (ParseException e) {
            e.printStackTrace(); // To change body of catch statement use
            // Options | File Templates.
        }
        // 求出和1900年1月31日相差的天数
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
        // 用offset减去每农历年的天数
        // 计算当天是农历第几天
        // i最终结果是农历的年份
        // offset是当年的第几天
        int iYear, daysOfYear = 0;
        for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
            daysOfYear = lYearDays(iYear);
            offset -= daysOfYear;
        }
        if (offset < 0) {
            offset += daysOfYear;
            iYear--;
        }
        // 农历年份
        int year = iYear;
        leapMonth = leapMonth(iYear); // 闰哪个月,1-12
        boolean leap = false;
        // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
        int iMonth, daysOfMonth = 0;
        for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
            // 闰月
            if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
                --iMonth;
                leap = true;
                daysOfMonth = leapDays(year);
            } else
                daysOfMonth = monthDays(year, iMonth);
            offset -= daysOfMonth;
            // 解除闰月
            if (leap && iMonth == (leapMonth + 1))
                leap = false;
        }
        // offset为0时,并且刚才计算的月份是闰月,要校正
        if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
            if (leap) {
                leap = false;
            } else {
                leap = true;
                --iMonth;
            }
        }
        // offset小于0时,也要校正
        if (offset < 0) {
            offset += daysOfMonth;
            --iMonth;
        }
        lunar_year = chineseNumberYear(iYear) + "年";
        if (leap) {
            lunar_month = "闰" + chineseNumber[iMonth - 1] + "月";
        } else {
            lunar_month = chineseNumber[iMonth - 1] + "月";
        }
        lunar_day = getChinaDayString(offset + 1);
        return lunar_year + lunar_month + lunar_day;
    }
    /**
     * 将年份转换为中文
     *
     * @param year
     * @return
     */
    public static String chineseNumberYear(int year) {
        String year_str = year + "";
        String newYear = "";
        for (int i = 0; i < year_str.length(); i++) {
            newYear += formatDigit(year_str.charAt(i));
        }
        return newYear;
    }
    public static char formatDigit(char sign) {
        if (sign == '0')
            sign = '〇';
        if (sign == '1')
            sign = '一';
        if (sign == '2')
            sign = '二';
        if (sign == '3')
            sign = '三';
        if (sign == '4')
            sign = '四';
        if (sign == '5')
            sign = '五';
        if (sign == '6')
            sign = '六';
        if (sign == '7')
            sign = '七';
        if (sign == '8')
            sign = '八';
        if (sign == '9')
            sign = '九';
        return sign;
    }
    public static String getChinaDayString(int day) {
        String chineseTen[] = { "初", "十", "廿", "卅" };
        int n = day % 10 == 0 ? 9 : day % 10 - 1;
        if (day > 30)
            return "";
        if (day == 10)
            return "初十";
        if (day == 20)
            return "二十";
        if (day == 30)
            return "三十";
        return chineseTen[day / 10] + chineseNumber1[n];
    }
    /**
     * 计算输出星期几
     *
     * @param weekday
     * @return
     */
    public static String getChinaWeekdayString(String weekday) {
        if (weekday.equals("Mon"))
            return "一";
        if (weekday.equals("Tue"))
            return "二";
        if (weekday.equals("Wed"))
            return "三";
        if (weekday.equals("Thu"))
            return "四";
        if (weekday.equals("Fri"))
            return "五";
        if (weekday.equals("Sat"))
            return "六";
        if (weekday.equals("Sun"))
            return "日";
        else
            return "";
    }
    /**
     * 获取星期几中文
     *
     * @param date
     * @return
     */
    public static String getWeekd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        weekDay = "星期" + getChinaWeekdayString(calendar.getTime().toString().substring(0, 3));
        return weekDay;
    }
    /**
     * 返回农历 y年的总天数
     *
     * @param y
     */
    public static int lYearDays(int y) {
        int i, sum = 348;
        for (i = 0x8000; i > 0x8; i >>= 1) {
            sum += (lunarInfo[y - 1900] & i) > 0 ? 1 : 0;
        }
        return (sum + leapDays(y));
    }
    /**
     * 返回农历 y年闰月的天数
     *
     * @param y
     * @return
     */
    public static int leapDays(int y) {
        if (leapMonth(y) > 0) {
            long day = lunarInfo[y - 1900] & 0x10000;
            return day > 0 ? 30 : 29;
        } else
            return 0;
    }
    /**
     * 返回农历 y年闰哪个月 1-12 , 没闰返回 0
     *
     * @param y
     * @return
     */
    public static int leapMonth(int y) {
        return (lunarInfo[y - 1900] & 0xf);
    }
    /**
     * 返回农历 y年m月的总天数
     *
     * @param y
     * @param m
     * @return
     */
    public static int monthDays(int y, int m) {
        return ((lunarInfo[y - 1900] & (0x10000 >> m)) > 0 ? 30 : 29);
    }
    final public String animalsYear(int year) {
        final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
        return Animals[(year - 4) % 12];
    }
    // ===== 某年的第n个节气为几日(从0小寒起算) Date.UTC(1900, 0, 6, 2, 5)
    /**
     * 正确的立春时间应该是以小时来进行计算的
     *
     * @param y
     * @param n
     * @return
     */
    public static int sTerm(int y, int n) {
        long times = 31556925974l * (y - 1900) + sTermInfo[n] * 60000l + (long) 0.7 * (y - 1900);
        Date offDate = new Date(times - 2208549300000l);
        // 1、取得本地时间:
        Calendar cal = Calendar.getInstance();
        cal.setTime(offDate);
        // 2、取得时间偏移量:
        int zoneOffset = cal.get(cal.ZONE_OFFSET);
        // 3、取得夏令时差:
        int dstOffset = cal.get(cal.DST_OFFSET);
        // 4、从本地时间里扣除这些差量,即可以取得UTC时间:
        cal.add(cal.MILLISECOND, -(zoneOffset + dstOffset));
        // 之后调用cal.get(int x)或cal.getTimeInMillis()方法所取得的时间即是UTC标准时间。
        return (cal.get(Calendar.DATE));
    }
    /**
     * 传入 offset 返回干支, 0=甲子
     *
     * @param num
     * @return
     */
    public static String cyclical(int num) {
        return (Gan[num % 10] + Zhi[num % 12]);
    }
    /**
     * 计算 并 打印 八字
     *
     * @param date
     * @throws ParseException
     */
    public static String horoscope(Date date) throws ParseException {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int i = cal.get(Calendar.DATE) - 1;
        String cY = null;
        String cM = null;
        String cD = null;
        String cH = null;
        // 年柱 1900年立春后为庚子年(60进制36)
        if (m < 2) {
            cY = cyclical(y - 1900 + 36 - 1);
        } else {
            cY = cyclical(y - 1900 + 36);
        }
        int term2 = sTerm(y, 2); // 立春日期
        // 月柱 1900年1月小寒以前为 丙子月(60进制12)
        int firstNode = sTerm(y, m * 2); // 返回当月「节」为几日开始
        cM = cyclical((y - 1900) * 12 + m + 12);
        int dayCyclical = jlday(y, m);
        // 依节气调整二月分的年柱, 以立春为界
        if (m == 1 && (i + 1) >= term2)
            cY = cyclical(y - 1900 + 36);
        // 依节气月柱, 以「节」为界
        if ((i + 1) >= firstNode)
            cM = cyclical((y - 1900) * 12 + m + 13);
        // 日柱
        cD = cyclical(dayCyclical + i);
        // 时柱
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        cH = Gan[hourG(cD.substring(0, 1), hour)] + Zhi[hourZ(hour)];
        agenary_year = cY + "年";
        agenary_month = cM + "月";
        agenary_day = cD + "日";
        agenary_hour = cH + "时";
        return agenary_year + agenary_month + agenary_day + agenary_hour;
    }
    /**
     * 根据 日干 推算 时柱 根据提供的推算图来计算
     *
     * @param dG
     * @param hour
     * @return
     */
    public static int hourG(String dG, int hour) {
        int ind = 1;
        for (String s : Gan) {
            if (s.equals(dG)) {
                break;
            }
            ind++;
        }
        ind = ind % 5; // 五个为一周期
        int hourind = hourZ(hour);
        if (hourind > 10)
            return hourind - 10 + (ind - 1) * 2;
        else {
            hourind = hourind + (ind - 1) * 2;
            return hourind >= 10 ? hourind - 10 : hourind;
        }
    }
    /**
     * 返回 小时对应的 支的索引
     *
     * @param hour
     * @return
     */
    public static int hourZ(int hour) {
        if (hour >= 23 || hour < 1)
            return 0;
        else if (hour >= 1 && hour < 3)
            return 1;
        else if (hour >= 3 && hour < 5)
            return 2;
        else if (hour >= 5 && hour < 7)
            return 3;
        else if (hour >= 7 && hour < 9)
            return 4;
        else if (hour >= 9 && hour < 11)
            return 5;
        else if (hour >= 11 && hour < 13)
            return 6;
        else if (hour >= 13 && hour < 15)
            return 7;
        else if (hour >= 15 && hour < 17)
            return 8;
        else if (hour >= 17 && hour < 19)
            return 9;
        else if (hour >= 19 && hour < 21)
            return 10;
        else if (hour >= 21 && hour < 23)
            return 11;
        return 0;
    }
    /**
     * 间隔天数
     *
     * @param y
     * @param m
     * @return
     */
    public static int jlday(int y, int m) {
        ScriptEngineManager sem = new ScriptEngineManager(); /* script引擎管理 */
        ScriptEngine se = sem.getEngineByName("javascript"); /* script引擎 */
        try {
            se.eval(" var y =" + y + ",m=" + m + " ;"); /* 执行一段script */
            se.eval("function jlday(   ) { " + "return Date.UTC(y,m,1,0,0,0,0)/86400000+25567+10;" + "}"); /* 添加一个方法 */
            Invocable invocableEngine = (Invocable) se;
            Object callbackvalue = invocableEngine.invokeFunction("jlday"); /* 调用方法中的函数 */
            if (callbackvalue != null) {
                double numdb = Double.valueOf(callbackvalue.toString());
                return (int) numdb;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
    /**
     * 获取日期信息
     *
     * @param date
     * @return
     * @throws ParseException
     */
    public static DateInfo getDateInfo(Date date) throws ParseException {
        DateInfo dateInfo = new DateInfo();
        // 分裂成年、月、日
        splitDate(date);
        dateInfo.setDay(day);
        dateInfo.setMonth(month);
        dateInfo.setYear(year);
        // 星期几
        getWeekd(date);
        dateInfo.setWeekDay(weekDay);
        // 转换成农历日期
        toLunar(date);
        dateInfo.setLunar_year(lunar_year);
        dateInfo.setLunar_month(lunar_month);
        dateInfo.setLunar_day(lunar_day);
        // 天干地支
        horoscope(date);
        dateInfo.setAgenary_year(agenary_year);
        dateInfo.setAgenary_month(agenary_month);
        dateInfo.setAgenary_day(agenary_day);
        dateInfo.setAgenary_hour(agenary_hour);
        return dateInfo;
    }
    public static void main(String[] args) throws ParseException {
        Date date = new Date();
        String lunar = DateLunarUtil.toLunar(date);
        System.out.println(lunar);
        String horoscope = DateLunarUtil.horoscope(date);
        System.out.println(horoscope);
        System.out.println(getWeekd(date));
    }
}
utils/src/main/java/org/yeshi/utils/entity/DateInfo.java
New file
@@ -0,0 +1,121 @@
package org.yeshi.utils.entity;
public class DateInfo {
    // 当前年
    private Integer year;
    // 当前月
    private Integer month;
    // 当前日
    private Integer day;
    // 当前星期几
    private String weekDay;
    // 农历-年
    private String lunar_year;
    // 农历-月
    private String lunar_month;
    // 农历-日
    private String lunar_day;
    // 天干地支-年
    private String agenary_year;
    // 天干地支-月
    private String agenary_month;
    // 天干地支-日
    private String agenary_day;
    // 天干地支-时辰
    private String agenary_hour;
    public Integer getYear() {
        return year;
    }
    public void setYear(Integer year) {
        this.year = year;
    }
    public Integer getMonth() {
        return month;
    }
    public void setMonth(Integer month) {
        this.month = month;
    }
    public Integer getDay() {
        return day;
    }
    public void setDay(Integer day) {
        this.day = day;
    }
    public String getWeekDay() {
        return weekDay;
    }
    public void setWeekDay(String weekDay) {
        this.weekDay = weekDay;
    }
    public String getLunar_year() {
        return lunar_year;
    }
    public void setLunar_year(String lunar_year) {
        this.lunar_year = lunar_year;
    }
    public String getLunar_month() {
        return lunar_month;
    }
    public void setLunar_month(String lunar_month) {
        this.lunar_month = lunar_month;
    }
    public String getLunar_day() {
        return lunar_day;
    }
    public void setLunar_day(String lunar_day) {
        this.lunar_day = lunar_day;
    }
    public String getAgenary_year() {
        return agenary_year;
    }
    public void setAgenary_year(String agenary_year) {
        this.agenary_year = agenary_year;
    }
    public String getAgenary_month() {
        return agenary_month;
    }
    public void setAgenary_month(String agenary_month) {
        this.agenary_month = agenary_month;
    }
    public String getAgenary_day() {
        return agenary_day;
    }
    public void setAgenary_day(String agenary_day) {
        this.agenary_day = agenary_day;
    }
    public String getAgenary_hour() {
        return agenary_hour;
    }
    public void setAgenary_hour(String agenary_hour) {
        this.agenary_hour = agenary_hour;
    }
}