|
|
|
@ -0,0 +1,272 @@
|
|
|
|
|
package weaver.interfaces.akx.cronjob;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.weaver.formmodel.mobile.appio.exports.beans.SqlDataBean;
|
|
|
|
|
import com.weaver.formmodel.util.DateHelper;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import weaver.common.DateUtil;
|
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
|
import weaver.conn.StringUtil;
|
|
|
|
|
import weaver.formmode.setup.ModeRightInfo;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 安科讯宿舍水电费计算计划任务
|
|
|
|
|
*
|
|
|
|
|
* @author:dxfeng
|
|
|
|
|
* @createTime: 2024/04/10
|
|
|
|
|
* @version: 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class CalculateCostsJob extends BaseCronJob {
|
|
|
|
|
private String calculateDate;
|
|
|
|
|
private String modeId;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
String currentDate = DateUtil.getCurrentDate();
|
|
|
|
|
// 未指定计算月份,默认计算当前月份
|
|
|
|
|
if (StringUtils.isBlank(calculateDate)) {
|
|
|
|
|
calculateDate = currentDate;
|
|
|
|
|
}
|
|
|
|
|
// 需要计算的月份
|
|
|
|
|
String calculateMonth = calculateDate.substring(0, 7);
|
|
|
|
|
// 当前月份
|
|
|
|
|
String currentMonth = currentDate.substring(0, 7);
|
|
|
|
|
// 计算的开始时间
|
|
|
|
|
String startDay = DateUtil.getFirstDayOfMonth(calculateDate);
|
|
|
|
|
// 计算的结束时间
|
|
|
|
|
String endDay = DateUtil.getLastDayOfMonth(calculateDate);
|
|
|
|
|
// 当前月的最后一天取当前时间,非当前月的取指定月的最后一天
|
|
|
|
|
endDay = calculateMonth.equals(currentMonth) ? currentDate : endDay;
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
String updateSql = "update uf_rysdftz set ts = ?, sdf = ? where ry = ? and ld = ? and yf = ? ";
|
|
|
|
|
String insertSql = "insert into uf_rysdftz ( formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime, modeuuid, ts, yf, cs, qy, ld, ry, sdf) values(" + modeId + ", 1, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
|
|
|
|
|
try {
|
|
|
|
|
rs.writeLog("当前计算日期:" + calculateDate + ",水电费计算计划任务开始------");
|
|
|
|
|
// 查询入住日期<=当前日期,且转出日期>=当前日期,或未转出的数据
|
|
|
|
|
String sql = "select * from uf_rygl where rzsj <= ?";
|
|
|
|
|
rs.executeQuery(sql, calculateDate);
|
|
|
|
|
List<PersonnelManagement> personnelManagementList = new ArrayList<>();
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
String zcsj = rs.getString("zcsj");
|
|
|
|
|
if (StringUtils.isNotBlank(zcsj)) {
|
|
|
|
|
boolean equals = zcsj.substring(0, 7).equals(calculateDate);
|
|
|
|
|
if (!equals) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PersonnelManagement personnelManagement = new PersonnelManagement();
|
|
|
|
|
personnelManagement.setLd(rs.getString("ld"));
|
|
|
|
|
personnelManagement.setYg(rs.getString("yg"));
|
|
|
|
|
personnelManagement.setRzsj(rs.getString("rzsj"));
|
|
|
|
|
personnelManagement.setZcsj(zcsj);
|
|
|
|
|
personnelManagementList.add(personnelManagement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询当月所有楼栋的水电费标准
|
|
|
|
|
Map<String, Double> costMap = new HashMap<>();
|
|
|
|
|
sql = "select * from uf_sdfbz where yf = ?";
|
|
|
|
|
rs.executeQuery(sql, calculateMonth);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
costMap.put(rs.getString("ld"), rs.getDouble("sdfbz"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算当月的入住天数和费用
|
|
|
|
|
Map<String, Map<String, List<PersonnelManagement>>> managementMap = personnelManagementList.stream().collect(Collectors.groupingBy(PersonnelManagement::getYg, Collectors.groupingBy(PersonnelManagement::getLd)));
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Map<String, List<PersonnelManagement>>> entry : managementMap.entrySet()) {
|
|
|
|
|
String yg = entry.getKey();
|
|
|
|
|
Map<String, List<PersonnelManagement>> ldMap = entry.getValue();
|
|
|
|
|
for (Map.Entry<String, List<PersonnelManagement>> item : ldMap.entrySet()) {
|
|
|
|
|
String ld = item.getKey();
|
|
|
|
|
Double sdfbz = costMap.get(ld);
|
|
|
|
|
// 未查询到当前楼栋、当前月份的水电费标准,不做计算
|
|
|
|
|
if (null == sdfbz || -1 == sdfbz) {
|
|
|
|
|
rs.writeLog("当前楼栋[" + ld + "],未查询到[" + calculateMonth + "]月份的水电费标准,跳过本楼栋水电费计算");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<PersonnelManagement> ldList = item.getValue();
|
|
|
|
|
// 计算入住的所有的天数
|
|
|
|
|
int currentMonthCount = 0;
|
|
|
|
|
for (PersonnelManagement management : ldList) {
|
|
|
|
|
String rzsj = management.getRzsj();
|
|
|
|
|
String zcsj = management.getZcsj();
|
|
|
|
|
currentMonthCount += calculateDays(rzsj, zcsj, startDay, endDay);
|
|
|
|
|
}
|
|
|
|
|
// 计算当前人员、当前楼栋的水电费,总入住天数*水电费标准
|
|
|
|
|
Double total = currentMonthCount * sdfbz;
|
|
|
|
|
// 查询当前人员,当前月份、当前楼栋,是否在水电费管理台账存在
|
|
|
|
|
sql = "select * from uf_rysdftz where ry = ? and ld = ? and yf = ? ";
|
|
|
|
|
rs.executeQuery(sql, yg, ld, calculateMonth);
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
// 做更新操作
|
|
|
|
|
List<String> paramList = new ArrayList<>();
|
|
|
|
|
paramList.add(String.valueOf(currentMonthCount));
|
|
|
|
|
paramList.add(String.valueOf(total));
|
|
|
|
|
paramList.add(yg);
|
|
|
|
|
paramList.add(ld);
|
|
|
|
|
paramList.add(calculateMonth);
|
|
|
|
|
rs.executeUpdate(updateSql, paramList);
|
|
|
|
|
rs.writeLog("updateSql:" + updateSql + "------params=" + JSON.toJSONString(paramList));
|
|
|
|
|
} else {
|
|
|
|
|
String cs = "";
|
|
|
|
|
String qy = "";
|
|
|
|
|
sql = "select * from uf_ldwh where id = ?";
|
|
|
|
|
rs.executeQuery(sql, ld);
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
cs = rs.getString("cs");
|
|
|
|
|
qy = rs.getString("qy");
|
|
|
|
|
}
|
|
|
|
|
List<String> paramList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// modedatacreatedate
|
|
|
|
|
paramList.add(DateHelper.getCurrentDate());
|
|
|
|
|
// modedatacreatetime
|
|
|
|
|
paramList.add(DateHelper.getCurrentTime());
|
|
|
|
|
// modeuuid
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
paramList.add(uuid);
|
|
|
|
|
// ts
|
|
|
|
|
paramList.add(String.valueOf(currentMonthCount));
|
|
|
|
|
// yf
|
|
|
|
|
paramList.add(calculateMonth);
|
|
|
|
|
// cs
|
|
|
|
|
paramList.add(cs);
|
|
|
|
|
// qy
|
|
|
|
|
paramList.add(qy);
|
|
|
|
|
// ld
|
|
|
|
|
paramList.add(ld);
|
|
|
|
|
// ry
|
|
|
|
|
paramList.add(yg);
|
|
|
|
|
// sdf
|
|
|
|
|
paramList.add(String.valueOf(total));
|
|
|
|
|
|
|
|
|
|
// 做插入操作
|
|
|
|
|
rs.executeUpdate(insertSql, paramList);
|
|
|
|
|
rs.writeLog("insertSql:" + insertSql + "------params=" + JSON.toJSONString(paramList));
|
|
|
|
|
// 刷新权限
|
|
|
|
|
rs.executeQuery("select id from uf_rysdftz where modeuuid='" + uuid + "'");
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
//建模数据的id
|
|
|
|
|
int bid = Util.getIntValue(rs.getString("id"));
|
|
|
|
|
ModeRightInfo modeRightInfo = new ModeRightInfo();
|
|
|
|
|
modeRightInfo.setNewRight(true);
|
|
|
|
|
//新建的时候添加共享
|
|
|
|
|
modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), bid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rs.writeLog("当前计算日期:" + calculateDate + ",水电费计算计划任务结束------");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
rs.writeLog("当前计算日期:" + calculateDate + ",水电费计算计划任务异常");
|
|
|
|
|
rs.writeLog(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算实际入住的天数
|
|
|
|
|
*
|
|
|
|
|
* @param rzsj 入住时间
|
|
|
|
|
* @param zcsj 转出时间
|
|
|
|
|
* @param startDay 计算开始时间
|
|
|
|
|
* @param endDay 计算结束时间
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private int calculateDays(String rzsj, String zcsj, String startDay, String endDay) {
|
|
|
|
|
String firstDate = rzsj;
|
|
|
|
|
// 比较入住时间和当月开始时间
|
|
|
|
|
int compStartDate = DateUtil.compDate(rzsj, startDay);
|
|
|
|
|
// 开始时间大于入职时间,取开始时间
|
|
|
|
|
if (compStartDate > 0) {
|
|
|
|
|
firstDate = startDay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String lastDate = zcsj;
|
|
|
|
|
if (StringUtils.isBlank(zcsj)) {
|
|
|
|
|
lastDate = endDay;
|
|
|
|
|
}
|
|
|
|
|
int compEndDate = DateUtil.compDate(zcsj, endDay);
|
|
|
|
|
// 结束时间小于转出时间,取结束时间
|
|
|
|
|
if (compEndDate < 0) {
|
|
|
|
|
lastDate = endDay;
|
|
|
|
|
}
|
|
|
|
|
// 实际天数为相差的天数+1
|
|
|
|
|
return DateUtil.compDate(firstDate, lastDate) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人员管理对象
|
|
|
|
|
*/
|
|
|
|
|
private static class PersonnelManagement {
|
|
|
|
|
// 楼栋
|
|
|
|
|
private String ld;
|
|
|
|
|
// 员工
|
|
|
|
|
private String yg;
|
|
|
|
|
// 入住日期
|
|
|
|
|
private String rzsj;
|
|
|
|
|
// 转出日期
|
|
|
|
|
private String zcsj;
|
|
|
|
|
|
|
|
|
|
public String getLd() {
|
|
|
|
|
return ld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLd(String ld) {
|
|
|
|
|
this.ld = ld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getYg() {
|
|
|
|
|
return yg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setYg(String yg) {
|
|
|
|
|
this.yg = yg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getRzsj() {
|
|
|
|
|
return rzsj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRzsj(String rzsj) {
|
|
|
|
|
this.rzsj = rzsj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getZcsj() {
|
|
|
|
|
return zcsj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setZcsj(String zcsj) {
|
|
|
|
|
this.zcsj = zcsj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getCalculateDate() {
|
|
|
|
|
return calculateDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCalculateDate(String calculateDate) {
|
|
|
|
|
this.calculateDate = calculateDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getModeId() {
|
|
|
|
|
return modeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setModeId(String modeId) {
|
|
|
|
|
this.modeId = modeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String startDate = "2024-03-01";
|
|
|
|
|
String endDate = "2024-03-31";
|
|
|
|
|
int i = DateUtil.compDate(startDate, endDate);
|
|
|
|
|
System.out.println(i);
|
|
|
|
|
}
|
|
|
|
|
}
|