Compare commits
8 Commits
e53b5715e2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 33b6e1fd47 | |||
| 8e7944a1ea | |||
| 67ea253fc9 | |||
| e5615a0068 | |||
| e366c682a2 | |||
| 624ccfb50a | |||
| 8fe015cda7 | |||
| e5850ebf64 |
@@ -0,0 +1,28 @@
|
|||||||
|
package com.seeyon.apps.src_leasebill.config;
|
||||||
|
|
||||||
|
import com.seeyon.aicloud.common.JsonUtils;
|
||||||
|
import com.seeyon.apps.src_leasebill.constant.LeaseBillConstant;
|
||||||
|
import com.seeyon.ctp.common.AppContext;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FieldDisplayNameQueryService {
|
||||||
|
|
||||||
|
private LeaseBillConfigProvider configProvider = (LeaseBillConfigProvider) AppContext.getBean("leaseBillConfigProvider");
|
||||||
|
|
||||||
|
public String getDisplayName(String fieldName) {
|
||||||
|
String jsonStr = configProvider.getBizConfigByKey(LeaseBillConstant.fieldDisplayMap);
|
||||||
|
if (jsonStr == null || jsonStr.trim().isEmpty()) {
|
||||||
|
throw new RuntimeException("字段显示名称映射配置为空,请检查插件配置 fieldDisplayMap");
|
||||||
|
}
|
||||||
|
Map<String,String> map = (Map<String,String>)JsonUtils.parseObject(jsonStr, Map.class);
|
||||||
|
if (map == null) {
|
||||||
|
throw new RuntimeException("字段显示名称映射解析失败,配置内容:" + jsonStr);
|
||||||
|
}
|
||||||
|
String displayName = map.get(fieldName);
|
||||||
|
if (displayName == null) {
|
||||||
|
throw new RuntimeException("字段显示名称映射中未找到key:" + fieldName);
|
||||||
|
}
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,10 @@ public enum LeaseBillConstant {
|
|||||||
annualPaymentTypeOneMapName("年方案一","年缴费方式一取值映射名称"),
|
annualPaymentTypeOneMapName("年方案一","年缴费方式一取值映射名称"),
|
||||||
annualPaymentTypeTwoMapName("年方案二","年缴费方式二取值映射名称"),
|
annualPaymentTypeTwoMapName("年方案二","年缴费方式二取值映射名称"),
|
||||||
assistiveFormNo("ZJZDMX","账单生成辅助表表单编码"),
|
assistiveFormNo("ZJZDMX","账单生成辅助表表单编码"),
|
||||||
loginName("shenxian","辅助表创建人");
|
loginName("shenxian","辅助表创建人"),
|
||||||
|
billAssistiveTableName("账单生成辅助表","账单生成辅助表明细表名称"),
|
||||||
|
fieldDisplayMap("","字段显示名称映射"),
|
||||||
|
;
|
||||||
// u8cUrl("http://ip:port", "U8C地址"),
|
// u8cUrl("http://ip:port", "U8C地址"),
|
||||||
|
|
||||||
LeaseBillConstant(String defaultValue, String description) {
|
LeaseBillConstant(String defaultValue, String description) {
|
||||||
@@ -0,0 +1,295 @@
|
|||||||
|
package com.seeyon.apps.src_leasebill.controller;
|
||||||
|
|
||||||
|
import cn.hutool.log.Log;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.seeyon.apps.common.config.ICstConfigApi;
|
||||||
|
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
||||||
|
import com.seeyon.apps.src_leasebill.config.FieldDisplayNameQueryService;
|
||||||
|
import com.seeyon.apps.src_leasebill.config.LeaseBillConfigProvider;
|
||||||
|
import com.seeyon.apps.src_leasebill.constant.LeaseBillConstant;
|
||||||
|
import com.seeyon.apps.src_leasebill.dao.ILeaseBillDao;
|
||||||
|
import com.seeyon.apps.src_leasebill.util.DateUtil;
|
||||||
|
import com.seeyon.apps.src_leasebill.util.FormExportUtil;
|
||||||
|
import com.seeyon.apps.src_leasebill.util.LeaseBillUtil;
|
||||||
|
import com.seeyon.ctp.common.AppContext;
|
||||||
|
import com.seeyon.ctp.common.controller.BaseController;
|
||||||
|
import com.seeyon.ctp.util.json.JSONUtil;
|
||||||
|
import com.seeyon.v3x.services.form.FormFactory;
|
||||||
|
import com.seeyon.v3x.services.form.bean.FormExport;
|
||||||
|
import com.seeyon.v3x.services.form.bean.SubordinateFormExport;
|
||||||
|
import com.seeyon.v3x.services.form.bean.ValueExport;
|
||||||
|
import nc.vo.jcom.lang.StringUtil;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租金账单控制器
|
||||||
|
* 功能:接收前端参数 → 调用账单工具类生成账单 → 保存至表单
|
||||||
|
*/
|
||||||
|
public class LeaseBillController extends BaseController {
|
||||||
|
|
||||||
|
private static final Log log = Log.get(LeaseBillController.class);
|
||||||
|
|
||||||
|
/** 配置提供者 */
|
||||||
|
private final LeaseBillConfigProvider configProvider =
|
||||||
|
(LeaseBillConfigProvider) AppContext.getBean("leaseBillConfigProvider");
|
||||||
|
|
||||||
|
/** 配置API */
|
||||||
|
protected final ICstConfigApi cstConfigApi =
|
||||||
|
(ICstConfigApi) AppContext.getBean("cstConfigApi");
|
||||||
|
|
||||||
|
/** 字段名称查询服务 */
|
||||||
|
private final FieldDisplayNameQueryService fieldDisplayNameQueryService =
|
||||||
|
(FieldDisplayNameQueryService) AppContext.getBean("fieldDisplayNameQueryService");
|
||||||
|
|
||||||
|
/** 表单工厂 */
|
||||||
|
private FormFactory formFactory;
|
||||||
|
|
||||||
|
/** 账单DAO */
|
||||||
|
private ILeaseBillDao leaseBillDao;
|
||||||
|
|
||||||
|
// ======================== 注入 ========================
|
||||||
|
public FormFactory getFormFactory() {
|
||||||
|
if (formFactory == null) {
|
||||||
|
formFactory = (FormFactory) AppContext.getBean("formFactory");
|
||||||
|
}
|
||||||
|
return formFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormFactory(FormFactory formFactory) {
|
||||||
|
this.formFactory = formFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILeaseBillDao getLeaseBillDao() {
|
||||||
|
if (leaseBillDao == null) {
|
||||||
|
leaseBillDao = (ILeaseBillDao) AppContext.getBean("leaseBillDao");
|
||||||
|
}
|
||||||
|
return leaseBillDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeaseBillDao(ILeaseBillDao leaseBillDao) {
|
||||||
|
this.leaseBillDao = leaseBillDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 主入口 ========================
|
||||||
|
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
String action = request.getParameter("action");
|
||||||
|
if ("getFieldDisplayMap".equals(action)) {
|
||||||
|
return getFieldDisplayMap(request, response);
|
||||||
|
}
|
||||||
|
return generateBill(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 获取字段显示名称映射 ========================
|
||||||
|
private ModelAndView getFieldDisplayMap(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
log.info("====== 获取字段显示名称映射 ======");
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
try {
|
||||||
|
String jsonStr = configProvider.getBizConfigByKey(LeaseBillConstant.fieldDisplayMap);
|
||||||
|
res.put("success", true);
|
||||||
|
res.put("data", jsonStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取字段映射异常", e);
|
||||||
|
res.put("success", false);
|
||||||
|
res.put("s", "获取字段映射失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
render(response, JSONUtil.toJSONString(res));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 生成账单 ========================
|
||||||
|
private ModelAndView generateBill(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
log.info("====== 进入生成账单Ajax方法 ======");
|
||||||
|
|
||||||
|
ConfigVo configVo = getYdctLeaseBillConfig();
|
||||||
|
DateUtil dateUtil = new DateUtil();
|
||||||
|
LeaseBillUtil leaseBillUtil = new LeaseBillUtil();
|
||||||
|
FormExportUtil formExportUtil = new FormExportUtil();
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
SimpleDateFormat sdfNo = new SimpleDateFormat("yyyyMMddHHmmsssss");
|
||||||
|
|
||||||
|
request.setCharacterEncoding("UTF-8");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
|
||||||
|
// ===================== 1. 读取请求体参数 =====================
|
||||||
|
BufferedReader reader = request.getReader();
|
||||||
|
StringBuilder requestBody = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
requestBody.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
String data = requestBody.toString();
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
res.put("success", false);
|
||||||
|
res.put("s", "请求参数为空");
|
||||||
|
render(response, JSONUtil.toJSONString(res));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String decodedParam = URLDecoder.decode(data, "UTF-8");
|
||||||
|
String[] datas = decodedParam.split("&");
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
for (String paramStr : datas) {
|
||||||
|
if (paramStr.isEmpty()) continue;
|
||||||
|
String[] params = paramStr.split("=");
|
||||||
|
if (params.length > 1) {
|
||||||
|
jsonObject.put(params[0], params[1]);
|
||||||
|
} else if (params[0].equals("bdid")) {
|
||||||
|
jsonObject.put("bdid", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("前端入参:{}", jsonObject.toString());
|
||||||
|
try {
|
||||||
|
// ===================== 2. 账单编号处理 =====================
|
||||||
|
String bdidValue = jsonObject.getString("bdid");
|
||||||
|
if (bdidValue == null) {
|
||||||
|
bdidValue = "";
|
||||||
|
}
|
||||||
|
log.info("当前账单编号:{}", bdidValue);
|
||||||
|
|
||||||
|
String code = bdidValue;
|
||||||
|
if ("0".equals(bdidValue) || bdidValue.isEmpty()) {
|
||||||
|
// 编号为0 → 新建编号
|
||||||
|
code = sdfNo.format(new Date());
|
||||||
|
log.info("生成新账单编号:{}", code);
|
||||||
|
} else {
|
||||||
|
// 已有编号 → 删除旧数据
|
||||||
|
log.info("删除旧账单数据,编号:{}", bdidValue);
|
||||||
|
List<String> ids = getLeaseBillDao().leaseBillByCode(bdidValue);
|
||||||
|
for (String id : ids) {
|
||||||
|
getLeaseBillDao().deleteBillsByBillId(id);
|
||||||
|
getLeaseBillDao().deleteBillById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== 3. 租赁起止时间 =====================
|
||||||
|
String startDateStr = jsonObject.getString("startDate");
|
||||||
|
String endDateStr = jsonObject.getString("endDate");
|
||||||
|
Date startDate = sdf.parse(startDateStr);
|
||||||
|
Date endDate = sdf.parse(endDateStr);
|
||||||
|
|
||||||
|
// 开始时间
|
||||||
|
Calendar startTime = Calendar.getInstance();
|
||||||
|
startTime.setTime(startDate);
|
||||||
|
|
||||||
|
// 判断是否为月底
|
||||||
|
boolean isMaxDay = false;
|
||||||
|
int currentDay = startTime.get(Calendar.DAY_OF_MONTH);
|
||||||
|
int maxDay = startTime.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||||
|
if (currentDay == maxDay) {
|
||||||
|
isMaxDay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 结束时间(+1天,左闭右开)
|
||||||
|
Calendar endTime = Calendar.getInstance();
|
||||||
|
endTime.setTime(endDate);
|
||||||
|
endTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
|
||||||
|
// ===================== 4. 缴费方式 =====================
|
||||||
|
String jiaofeifs = jsonObject.getString("jiaofeifs");
|
||||||
|
int jfzqNum = dateUtil.getCycleNum(jiaofeifs);
|
||||||
|
String jifeifs = jsonObject.getString("jifeifs");
|
||||||
|
|
||||||
|
log.info("缴费方式:{},周期月数:{},计费方式:{}", jiaofeifs, jfzqNum, jifeifs);
|
||||||
|
|
||||||
|
// ===================== 5. 生成账单 =====================
|
||||||
|
List<Map<String, String>> rents = new ArrayList<>();
|
||||||
|
FormExport formExport = new FormExport();
|
||||||
|
|
||||||
|
if (jfzqNum == 12) {
|
||||||
|
// 年缴 → 判断年缴计算方式
|
||||||
|
String njiaofeifs = jsonObject.getString("njiaofeifs");
|
||||||
|
if (StringUtil.isEmpty(njiaofeifs)) {
|
||||||
|
res.put("success", false);
|
||||||
|
res.put("s", "请选择年缴费计算方式");
|
||||||
|
render(response, JSONUtil.toJSONString(res));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String type1 = configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeOneMapName);
|
||||||
|
String type2 = configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeTwoMapName);
|
||||||
|
|
||||||
|
if (njiaofeifs.equals(type1)) {
|
||||||
|
log.info("【年缴方式1】按周期年度生成账单");
|
||||||
|
rents = leaseBillUtil.getLeaseBillYear1(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||||
|
} else if (njiaofeifs.equals(type2)) {
|
||||||
|
log.info("【年缴方式2】按自然年度生成账单");
|
||||||
|
rents = leaseBillUtil.getLeaseBillYear2(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 月/季/半年/一次性
|
||||||
|
log.info("【标准方式】生成账单");
|
||||||
|
rents = leaseBillUtil.getLeaseBill(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rents.isEmpty()) {
|
||||||
|
log.info("====== 账单数据为空,无需生成 ======");
|
||||||
|
} else {
|
||||||
|
log.info("====== 共生成 {} 期账单 ======", rents.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== 6. 保存到表单 =====================
|
||||||
|
log.info("====== 开始保存账单到表单 ======");
|
||||||
|
List<SubordinateFormExport> detailList = formExportUtil.setSubordinateFormValue(rents);
|
||||||
|
|
||||||
|
Map<String, String> mainData = new HashMap<>();
|
||||||
|
mainData.put(fieldDisplayNameQueryService.getDisplayName("账单编号"), code);
|
||||||
|
|
||||||
|
List<ValueExport> mainFields = formExportUtil.setFormValue(mainData);
|
||||||
|
|
||||||
|
formExport.setSubordinateForms(detailList);
|
||||||
|
formExport.setValues(mainFields);
|
||||||
|
|
||||||
|
String loginName = configProvider.getBizConfigByKey(LeaseBillConstant.loginName);
|
||||||
|
String formNo = configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo);
|
||||||
|
|
||||||
|
getFormFactory().importBusinessFormData(loginName, formNo, formExport, new String[]{});
|
||||||
|
|
||||||
|
// ===================== 7. 返回结果 =====================
|
||||||
|
res.put("success", true);
|
||||||
|
res.put("name", AppContext.currentUserLoginName());
|
||||||
|
res.put("s", "");
|
||||||
|
res.put("num", code);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("生成账单异常", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
res.put("success", false);
|
||||||
|
res.put("s", "生成账单失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
render(response, JSONUtil.toJSONString(res));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ======================== 输出JSON ========================
|
||||||
|
private void render(HttpServletResponse response, String text) {
|
||||||
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
|
try {
|
||||||
|
response.getWriter().write(text);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("输出JSON异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 配置 ========================
|
||||||
|
|
||||||
|
public ConfigVo getYdctLeaseBillConfig() {
|
||||||
|
return cstConfigApi.getConfig(getPluginId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPluginId() {
|
||||||
|
return LeaseBillConstant.getPluginId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.seeyon.apps.src_leasebill.dao.impl;
|
package com.seeyon.apps.src_leasebill.dao.impl;
|
||||||
|
|
||||||
|
import com.seeyon.apps.src_leasebill.config.FieldDisplayNameQueryService;
|
||||||
import com.seeyon.apps.src_leasebill.config.LeaseBillConfigProvider;
|
import com.seeyon.apps.src_leasebill.config.LeaseBillConfigProvider;
|
||||||
import com.seeyon.apps.src_leasebill.constant.LeaseBillConstant;
|
import com.seeyon.apps.src_leasebill.constant.LeaseBillConstant;
|
||||||
import com.seeyon.apps.src_leasebill.dao.ILeaseBillDao;
|
import com.seeyon.apps.src_leasebill.dao.ILeaseBillDao;
|
||||||
@@ -14,21 +15,36 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租金账单DAO实现类
|
||||||
|
* 功能:查询、删除账单主表和明细表数据
|
||||||
|
*/
|
||||||
public class LeaseBillDaoImpl implements ILeaseBillDao {
|
public class LeaseBillDaoImpl implements ILeaseBillDao {
|
||||||
|
|
||||||
private LeaseBillConfigProvider configProvider = (LeaseBillConfigProvider) AppContext.getBean("leaseBillConfigProvider");
|
/** 配置提供者 */
|
||||||
|
private final LeaseBillConfigProvider configProvider =
|
||||||
|
(LeaseBillConfigProvider) AppContext.getBean("leaseBillConfigProvider");
|
||||||
|
|
||||||
|
/** 字段名称查询服务 */
|
||||||
|
private final FieldDisplayNameQueryService fieldDisplayNameQueryService =
|
||||||
|
(FieldDisplayNameQueryService) AppContext.getBean("fieldDisplayNameQueryService");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单编号
|
||||||
|
*/
|
||||||
private String getFormNo() {
|
private String getFormNo() {
|
||||||
return configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo);
|
return configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据账单编号查询账单ID列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> leaseBillByCode(String code) throws BusinessException, SQLException {
|
public List<String> leaseBillByCode(String code) throws BusinessException, SQLException {
|
||||||
List<String> lists = new ArrayList<String>();
|
List<String> lists = new ArrayList<String>();
|
||||||
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
||||||
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
|
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
|
||||||
conditions.add(FormWhereCondition.build().display("账单编号").value(code));
|
conditions.add(FormWhereCondition.build().display(fieldDisplayNameQueryService.getDisplayName("账单编号")).value(code));
|
||||||
List<String> queryColumns = new ArrayList<String>();
|
List<String> queryColumns = new ArrayList<String>();
|
||||||
queryColumns.add("ID");
|
queryColumns.add("ID");
|
||||||
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, queryColumns, conditions, false);
|
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, queryColumns, conditions, false);
|
||||||
@@ -38,6 +54,9 @@ public class LeaseBillDaoImpl implements ILeaseBillDao {
|
|||||||
return lists;
|
return lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除账单主表数据
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int deleteBillById(String id) throws BusinessException, SQLException {
|
public int deleteBillById(String id) throws BusinessException, SQLException {
|
||||||
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
||||||
@@ -46,9 +65,13 @@ public class LeaseBillDaoImpl implements ILeaseBillDao {
|
|||||||
return FormTableExecutor.delete(tableContext, conditions);
|
return FormTableExecutor.delete(tableContext, conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据主表ID删除账单明细表数据
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int deleteBillsByBillId(String formmainId) throws BusinessException, SQLException {
|
public int deleteBillsByBillId(String formmainId) throws BusinessException, SQLException {
|
||||||
TableContext sub = FormTableExecutor.sub(getFormNo(), "明细表1");
|
String tableName = configProvider.getBizConfigByKey(LeaseBillConstant.billAssistiveTableName);
|
||||||
|
TableContext sub = FormTableExecutor.sub(getFormNo(), tableName);
|
||||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||||
conditions.add(FormWhereCondition.build().display("formmain_id").value(formmainId));
|
conditions.add(FormWhereCondition.build().display("formmain_id").value(formmainId));
|
||||||
return FormTableExecutor.delete(sub, conditions);
|
return FormTableExecutor.delete(sub, conditions);
|
||||||
@@ -23,7 +23,20 @@ public class DateUtil {
|
|||||||
|
|
||||||
int yearsDiff = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
|
int yearsDiff = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
|
||||||
int monthsDiff = yearsDiff * 12 + endCalendar.get(Calendar.MONTH)- startCalendar.get(Calendar.MONTH);
|
int monthsDiff = yearsDiff * 12 + endCalendar.get(Calendar.MONTH)- startCalendar.get(Calendar.MONTH);
|
||||||
if (endCalendar.get(Calendar.DAY_OF_MONTH) > startCalendar.get(Calendar.DAY_OF_MONTH)) {
|
|
||||||
|
// 月末日期规范化:将起始日为月末的日期规范化为相同参考日,避免不同月份天数差异导致误判
|
||||||
|
// 例如:1月31日→2月28日,规范化为 1月28日→2月28日,day相同不加月
|
||||||
|
int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
int endDay = endCalendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
int startMaxDay = startCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||||
|
int endMaxDay = endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||||
|
if (startDay == startMaxDay) {
|
||||||
|
startDay = Math.min(startDay, endMaxDay);
|
||||||
|
}
|
||||||
|
if (endDay == endMaxDay) {
|
||||||
|
endDay = Math.min(endDay, startMaxDay);
|
||||||
|
}
|
||||||
|
if (endDay > startDay) {
|
||||||
monthsDiff++;
|
monthsDiff++;
|
||||||
}
|
}
|
||||||
return monthsDiff;
|
return monthsDiff;
|
||||||
@@ -106,19 +119,19 @@ public class DateUtil {
|
|||||||
|
|
||||||
|
|
||||||
public int getCycleNum (String cycle){
|
public int getCycleNum (String cycle){
|
||||||
int cycleNum = 1;
|
|
||||||
if("月".equals(cycle)||"月付".equals(cycle)){
|
if("月".equals(cycle)||"月付".equals(cycle)||"月缴".equals(cycle) ||"月度".equals(cycle)){
|
||||||
cycleNum = 1;
|
return 1;
|
||||||
}else if("季".equals(cycle)||"季付".equals(cycle)){
|
}else if("季".equals(cycle)||"季付".equals(cycle)||"季缴".equals(cycle) ||"季度缴".equals(cycle) ||"季度".equals(cycle)){
|
||||||
cycleNum = 3;
|
return 3;
|
||||||
}else if("半年".equals(cycle)||"半年付".equals(cycle)){
|
}else if("半年".equals(cycle)||"半年付".equals(cycle)||"半年缴".equals(cycle)){
|
||||||
cycleNum = 6;
|
return 6;
|
||||||
}else if("年".equals(cycle)||"年付".equals(cycle)){
|
}else if("年".equals(cycle)||"年付".equals(cycle)||"年缴".equals(cycle)){
|
||||||
cycleNum = 12;
|
return 12;
|
||||||
}else if("一次性".equals(cycle)||"其他".equals(cycle)){
|
}else if("一次性".equals(cycle)){
|
||||||
cycleNum = 99;
|
return 1;
|
||||||
}
|
}
|
||||||
return cycleNum;
|
throw new IllegalArgumentException("未识别的缴费方式:" + cycle + ",请检查表单缴费方式字段值");
|
||||||
}
|
}
|
||||||
|
|
||||||
public double stringToNum(String str){
|
public double stringToNum(String str){
|
||||||
@@ -0,0 +1,308 @@
|
|||||||
|
package com.seeyon.apps.src_leasebill.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.seeyon.apps.src_leasebill.config.FieldDisplayNameQueryService;
|
||||||
|
import com.seeyon.ctp.common.AppContext;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租金账单生成工具类
|
||||||
|
* 功能:根据租赁周期、缴费方式、计费方式,自动拆分生成多期租金账单
|
||||||
|
*/
|
||||||
|
public class LeaseBillUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称查询服务(用于获取表单显示名称)
|
||||||
|
*/
|
||||||
|
private final FieldDisplayNameQueryService fieldDisplayNameService =
|
||||||
|
(FieldDisplayNameQueryService) AppContext.getBean("fieldDisplayNameQueryService");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日期格式化工具(线程安全)
|
||||||
|
*/
|
||||||
|
private SimpleDateFormat getSdf() {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期工具类实例
|
||||||
|
*/
|
||||||
|
private final DateUtil dateUtil = new DateUtil();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 金额精度:保留2位小数
|
||||||
|
*/
|
||||||
|
private static final int MONEY_SCALE = 2;
|
||||||
|
|
||||||
|
// ======================== 【1】主方法:生成租金账单(支持一次性/周期) ========================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成租金账单(对外主方法)
|
||||||
|
*
|
||||||
|
* @param startTime 租赁开始时间
|
||||||
|
* @param endTime 租赁结束时间
|
||||||
|
* @param isMonthLastDay 是否每月最后一天
|
||||||
|
* @param payCycleMonths 缴费周期(月):1=月缴,3=季度缴,6=半年缴,12=年缴,99=一次性
|
||||||
|
* @param params 表单参数JSON
|
||||||
|
* @param chargeType 计费方式:面积计费 / 固定租金
|
||||||
|
* @return 每期账单集合(开始日期、结束日期、租费)
|
||||||
|
*/
|
||||||
|
public List<Map<String, String>> getLeaseBill(Calendar startTime, Calendar endTime, boolean isMonthLastDay,
|
||||||
|
int payCycleMonths, JSONObject params, String chargeType) {
|
||||||
|
// ====================== 控制台打印:生成账单入参 ======================
|
||||||
|
System.out.println("======================================");
|
||||||
|
System.out.println("【主方法】生成账单参数开始");
|
||||||
|
System.out.println("租赁开始时间:" + getSdf().format(startTime.getTime()));
|
||||||
|
System.out.println("租赁结束时间:" + getSdf().format(endTime.getTime()));
|
||||||
|
System.out.println("是否每月最后一天:" + isMonthLastDay);
|
||||||
|
System.out.println("缴费周期(月):" + payCycleMonths);
|
||||||
|
System.out.println("计费方式:" + chargeType);
|
||||||
|
System.out.println("表单参数:" + params.toString());
|
||||||
|
System.out.println("【主方法】生成账单参数结束");
|
||||||
|
System.out.println("======================================");
|
||||||
|
|
||||||
|
List<Map<String, String>> billList = new ArrayList<>();
|
||||||
|
int totalLeaseMonths = dateUtil.betweenMonthByTwoCalendar(startTime, endTime);
|
||||||
|
|
||||||
|
// 一次性缴费
|
||||||
|
if (payCycleMonths == 99) {
|
||||||
|
Map<String, String> bill = createOneTimeBill(startTime, endTime, totalLeaseMonths, params, chargeType);
|
||||||
|
billList.add(bill);
|
||||||
|
return billList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 周期缴费:月/季/半年
|
||||||
|
return createCycleBills(startTime, endTime, isMonthLastDay, payCycleMonths, params, chargeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ======================== 【2】按年周期账单(版本1) ========================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按年生成账单(版本1:按周期月数计算)
|
||||||
|
*/
|
||||||
|
public List<Map<String, String>> getLeaseBillYear1(Calendar startTime, Calendar endTime, boolean isMonthLastDay,
|
||||||
|
int payCycleMonths, JSONObject params, String chargeType) {
|
||||||
|
// ====================== 控制台打印:生成账单入参 ======================
|
||||||
|
System.out.println("======================================");
|
||||||
|
System.out.println("【按年方法1】生成账单参数开始");
|
||||||
|
System.out.println("租赁开始时间:" + getSdf().format(startTime.getTime()));
|
||||||
|
System.out.println("租赁结束时间:" + getSdf().format(endTime.getTime()));
|
||||||
|
System.out.println("是否每月最后一天:" + isMonthLastDay);
|
||||||
|
System.out.println("缴费周期(月):" + payCycleMonths);
|
||||||
|
System.out.println("计费方式:" + chargeType);
|
||||||
|
System.out.println("表单参数:" + params.toString());
|
||||||
|
System.out.println("【按年方法1】生成账单参数结束");
|
||||||
|
System.out.println("======================================");
|
||||||
|
|
||||||
|
return createCycleBills(startTime, endTime, isMonthLastDay, payCycleMonths, params, chargeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ======================== 【3】按自然年切割账单(版本2) ========================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按自然年生成账单(版本2:按自然年12.31切割)
|
||||||
|
*/
|
||||||
|
public List<Map<String, String>> getLeaseBillYear2(Calendar startTime, Calendar endTime, boolean isMonthLastDay,
|
||||||
|
int payCycleMonths, JSONObject params, String chargeType) {
|
||||||
|
// ====================== 控制台打印:生成账单入参 ======================
|
||||||
|
System.out.println("======================================");
|
||||||
|
System.out.println("【按年方法2】生成账单参数开始");
|
||||||
|
System.out.println("租赁开始时间:" + getSdf().format(startTime.getTime()));
|
||||||
|
System.out.println("租赁结束时间:" + getSdf().format(endTime.getTime()));
|
||||||
|
System.out.println("是否每月最后一天:" + isMonthLastDay);
|
||||||
|
System.out.println("缴费周期(月):" + payCycleMonths);
|
||||||
|
System.out.println("计费方式:" + chargeType);
|
||||||
|
System.out.println("表单参数:" + params.toString());
|
||||||
|
System.out.println("【按年方法2】生成账单参数结束");
|
||||||
|
System.out.println("======================================");
|
||||||
|
|
||||||
|
List<Map<String, String>> billList = new ArrayList<>();
|
||||||
|
int startYear = startTime.get(Calendar.YEAR);
|
||||||
|
int endYear = endTime.get(Calendar.YEAR);
|
||||||
|
int totalYears = endYear - startYear + 1;
|
||||||
|
|
||||||
|
Calendar tempStart = (Calendar) startTime.clone();
|
||||||
|
Calendar yearBaseCal = (Calendar) tempStart.clone();
|
||||||
|
|
||||||
|
for (int i = 0; i < totalYears; i++) {
|
||||||
|
if (!tempStart.before(endTime)) break;
|
||||||
|
|
||||||
|
Map<String, String> bill = new HashMap<>();
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("开始日期"), getSdf().format(tempStart.getTime()));
|
||||||
|
|
||||||
|
// 设置为当年最后一天:12月31日
|
||||||
|
tempStart.set(Calendar.MONTH, 11);
|
||||||
|
tempStart.set(Calendar.DATE, 31);
|
||||||
|
|
||||||
|
if (tempStart.before(endTime)) {
|
||||||
|
// 当前年度在结束时间之前 → 完整年度账单
|
||||||
|
Calendar nextYearStart = (Calendar) tempStart.clone();
|
||||||
|
nextYearStart.add(Calendar.DATE, 1);
|
||||||
|
|
||||||
|
int monthCount = dateUtil.betweenMonthByTwoCalendar(yearBaseCal, nextYearStart);
|
||||||
|
String rent = calculateRent(monthCount, params, chargeType);
|
||||||
|
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("租费"), rent);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("结束日期"), getSdf().format(tempStart.getTime()));
|
||||||
|
|
||||||
|
yearBaseCal = (Calendar) tempStart.clone();
|
||||||
|
} else {
|
||||||
|
// 最后一个年度 → 不足一年
|
||||||
|
int monthCount = dateUtil.betweenMonthByTwoCalendar(yearBaseCal, endTime);
|
||||||
|
String rent = calculateRent(monthCount, params, chargeType);
|
||||||
|
|
||||||
|
Calendar realEnd = (Calendar) endTime.clone();
|
||||||
|
realEnd.add(Calendar.DATE, -1);
|
||||||
|
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("租费"), rent);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("结束日期"), getSdf().format(realEnd.getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下一期开始时间 = 当前结束时间 + 1天
|
||||||
|
tempStart.add(Calendar.DATE, 1);
|
||||||
|
|
||||||
|
// 如果是月末模式,设置为当月最后一天
|
||||||
|
if (isMonthLastDay) {
|
||||||
|
tempStart.set(Calendar.DATE, tempStart.getActualMaximum(Calendar.DATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
billList.add(bill);
|
||||||
|
}
|
||||||
|
|
||||||
|
return billList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 【核心工具方法】 ========================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一次性缴费账单
|
||||||
|
*/
|
||||||
|
private Map<String, String> createOneTimeBill(Calendar startTime, Calendar endTime, int totalMonths,
|
||||||
|
JSONObject params, String chargeType) {
|
||||||
|
Map<String, String> bill = new HashMap<>();
|
||||||
|
String rent = calculateRent(totalMonths, params, chargeType);
|
||||||
|
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("开始日期"), getSdf().format(startTime.getTime()));
|
||||||
|
|
||||||
|
// 结束时间 = 原结束时间 -1天
|
||||||
|
Calendar realEnd = (Calendar) endTime.clone();
|
||||||
|
realEnd.add(Calendar.DATE, -1);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("结束日期"), getSdf().format(realEnd.getTime()));
|
||||||
|
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("租费"), rent);
|
||||||
|
return bill;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建周期缴费账单(月缴/季度/半年/年缴)
|
||||||
|
*/
|
||||||
|
private List<Map<String, String>> createCycleBills(Calendar startTime, Calendar endTime, boolean isMonthLastDay,
|
||||||
|
int payCycleMonths, JSONObject params, String chargeType) {
|
||||||
|
List<Map<String, String>> billList = new ArrayList<>();
|
||||||
|
int totalLeaseMonths = dateUtil.betweenMonthByTwoCalendar(startTime, endTime);
|
||||||
|
|
||||||
|
// 计算总缴费期数:向上取整
|
||||||
|
int periodCount = totalLeaseMonths / payCycleMonths;
|
||||||
|
if (totalLeaseMonths % payCycleMonths != 0) {
|
||||||
|
periodCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar tempStart = (Calendar) startTime.clone();
|
||||||
|
|
||||||
|
// 循环生成每一期账单
|
||||||
|
for (int i = 0; i < periodCount; i++) {
|
||||||
|
if (!tempStart.before(endTime)) break;
|
||||||
|
|
||||||
|
Map<String, String> bill = new HashMap<>();
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("开始日期"), getSdf().format(tempStart.getTime()));
|
||||||
|
|
||||||
|
// 计算本期结束日 = 开始时间 + 周期月数 - 1天
|
||||||
|
Calendar periodEnd = (Calendar) tempStart.clone();
|
||||||
|
periodEnd.add(Calendar.MONTH, payCycleMonths);
|
||||||
|
periodEnd.add(Calendar.DATE, -1);
|
||||||
|
|
||||||
|
if (periodEnd.before(endTime)) {
|
||||||
|
// 正常完整周期
|
||||||
|
String rent = calculateRent(payCycleMonths, params, chargeType);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("租费"), rent);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("结束日期"), getSdf().format(periodEnd.getTime()));
|
||||||
|
} else {
|
||||||
|
// 最后一期:不足一个缴费周期
|
||||||
|
int realMonths = dateUtil.betweenMonthByTwoCalendar(tempStart, endTime);
|
||||||
|
String rent = calculateRent(realMonths, params, chargeType);
|
||||||
|
|
||||||
|
Calendar realEnd = (Calendar) endTime.clone();
|
||||||
|
realEnd.add(Calendar.DATE, -1);
|
||||||
|
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("租费"), rent);
|
||||||
|
bill.put(fieldDisplayNameService.getDisplayName("结束日期"), getSdf().format(realEnd.getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下一期开始时间
|
||||||
|
tempStart = (Calendar) periodEnd.clone();
|
||||||
|
tempStart.add(Calendar.DATE, 1);
|
||||||
|
|
||||||
|
// 月末规则处理
|
||||||
|
if (isMonthLastDay) {
|
||||||
|
tempStart.set(Calendar.DATE, tempStart.getActualMaximum(Calendar.DATE));
|
||||||
|
}
|
||||||
|
|
||||||
|
billList.add(bill);
|
||||||
|
}
|
||||||
|
|
||||||
|
return billList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一租金计算逻辑(抽离重复代码)
|
||||||
|
*
|
||||||
|
* @param months 计费月数
|
||||||
|
* @param params 表单参数
|
||||||
|
* @param chargeType 计费方式
|
||||||
|
* @return 计算后租金金额(保留2位小数)
|
||||||
|
*/
|
||||||
|
private String calculateRent(int months, JSONObject params, String chargeType) {
|
||||||
|
BigDecimal rent = BigDecimal.ZERO;
|
||||||
|
boolean isAreaCharge = "面积计费".equals(chargeType);
|
||||||
|
boolean isFixedRent = "固定租金".equals(chargeType);
|
||||||
|
|
||||||
|
if (isAreaCharge) {
|
||||||
|
// 面积计费:租金 = 面积 × 每平单价
|
||||||
|
BigDecimal area = parseBigDecimal(params.getString("mj"));
|
||||||
|
BigDecimal pricePerArea = parseBigDecimal(params.getString("mjzj"));
|
||||||
|
rent = area.multiply(pricePerArea);
|
||||||
|
} else if (isFixedRent) {
|
||||||
|
// 固定租金:直接取固定金额
|
||||||
|
rent = parseBigDecimal(params.getString("gdzj"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 固定租金不乘月数,其他计费方式 × 月数
|
||||||
|
if (!isFixedRent) {
|
||||||
|
rent = rent.multiply(new BigDecimal(months));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保留2位小数,四舍五入
|
||||||
|
return rent.setScale(MONEY_SCALE, RoundingMode.HALF_UP).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串解析为BigDecimal,处理逗号分隔符
|
||||||
|
*
|
||||||
|
* @param str 数字字符串(可能包含逗号分隔符)
|
||||||
|
* @return BigDecimal对象
|
||||||
|
*/
|
||||||
|
private BigDecimal parseBigDecimal(String str) {
|
||||||
|
if (str == null || str.trim().isEmpty()) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
// 移除逗号分隔符
|
||||||
|
String cleanStr = str.replace(",", "").trim();
|
||||||
|
return new BigDecimal(cleanStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,4 +2,5 @@
|
|||||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||||
<beans default-autowire="byName">
|
<beans default-autowire="byName">
|
||||||
<bean id="leaseBillDao" class="com.seeyon.apps.src_leasebill.dao.impl.LeaseBillDaoImpl" />
|
<bean id="leaseBillDao" class="com.seeyon.apps.src_leasebill.dao.impl.LeaseBillDaoImpl" />
|
||||||
|
<bean id="fieldDisplayNameQueryService" class="com.seeyon.apps.src_leasebill.config.FieldDisplayNameQueryService" />
|
||||||
</beans>
|
</beans>
|
||||||
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
@@ -55,103 +55,79 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
doBiz: function(privateId, messageObj, adaptation) {
|
doBiz: function(privateId, messageObj, adaptation) {
|
||||||
var url2 = window.location.origin;
|
var self = this;
|
||||||
messageObj = adaptation.childrenGetData(privateId);
|
messageObj = adaptation.childrenGetData(privateId);
|
||||||
const targetObj = messageObj.formdata.formmains[adaptation.formMessage.tableName]
|
var targetObj = messageObj.formdata.formmains[adaptation.formMessage.tableName];
|
||||||
var jifeifs;// 计费方式
|
|
||||||
var jiaofeifs;// 缴费方式
|
// 先获取字段显示名称映射,再执行业务逻辑
|
||||||
var njiaofeifs;// 年缴费方式类型
|
$.ajax({
|
||||||
var mjzj;// 面积单价
|
type: 'get',
|
||||||
var gdzj;// 固定租金单价
|
async: true,
|
||||||
var startDate;// 合同开始日期
|
url: encodeURI('/seeyon/leaseBillController.do?action=getFieldDisplayMap&datetime=' + Math.random()),
|
||||||
var endDate;// 合同结束日期
|
dataType: 'json',
|
||||||
var mj;// 租赁面积
|
success: function(mappingRes) {
|
||||||
var bdid; // 账单编号
|
if (!mappingRes.success) {
|
||||||
var bdidFieldName;
|
$.alert(mappingRes.s || "获取字段映射失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var fieldMap = JSON.parse(mappingRes.data);
|
||||||
|
self.doGenerateBill(targetObj, fieldMap, adaptation, privateId);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$.alert("获取字段映射请求失败");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
doGenerateBill: function(targetObj, fieldMap, adaptation, privateId) {
|
||||||
|
// 校验字段映射配置完整性
|
||||||
|
var requiredKeys = ["计费方式", "缴费方式", "计租日期", "合同截止日期", "账单编号"];
|
||||||
|
for (var i = 0; i < requiredKeys.length; i++) {
|
||||||
|
if (!fieldMap[requiredKeys[i]]) {
|
||||||
|
$.alert("字段映射配置缺少必要key:" + requiredKeys[i] + ",请联系管理员检查插件配置");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var jifeifs, jiaofeifs, njiaofeifs, mjzj, gdzj, startDate, endDate, mj, bdid, bdidFieldName;
|
||||||
|
|
||||||
if (targetObj) {
|
if (targetObj) {
|
||||||
for (const key in targetObj) {
|
for (var key in targetObj) {
|
||||||
console.log(targetObj)
|
|
||||||
if (targetObj.hasOwnProperty(key) && !/^auxiliary/.test(key)) {
|
if (targetObj.hasOwnProperty(key) && !/^auxiliary/.test(key)) {
|
||||||
if (targetObj[key].display === "计费方式") {
|
var display = targetObj[key].display;
|
||||||
jifeifs = targetObj[key].showValue
|
if (display === fieldMap["计费方式"]) {
|
||||||
}
|
jifeifs = targetObj[key].showValue;
|
||||||
if(targetObj[key].display === "缴费方式") {
|
} else if (display === fieldMap["缴费方式"]) {
|
||||||
jiaofeifs = targetObj[key].showValue
|
jiaofeifs = targetObj[key].showValue;
|
||||||
}
|
} else if (display === fieldMap["年缴费方案选项"]) {
|
||||||
if(targetObj[key].display === "年缴费方案选项") {
|
njiaofeifs = targetObj[key].showValue;
|
||||||
njiaofeifs = targetObj[key].showValue
|
} else if (display === fieldMap["租赁单价"]) {
|
||||||
}
|
mjzj = targetObj[key].showValue;
|
||||||
if(targetObj[key].display === "实租单价") {
|
} else if (display === fieldMap["固定租金标准"]) {
|
||||||
mjzj = targetObj[key].showValue
|
gdzj = targetObj[key].showValue;
|
||||||
}
|
} else if (display === fieldMap["计租日期"]) {
|
||||||
if(targetObj[key].display === "固定租金标准") {
|
startDate = targetObj[key].showValue;
|
||||||
gdzj = targetObj[key].showValue
|
} else if (display === fieldMap["合同截止日期"]) {
|
||||||
}
|
endDate = targetObj[key].showValue;
|
||||||
if(targetObj[key].display === "计租开始日期") {
|
} else if (display === fieldMap["租赁面积"]) {
|
||||||
startDate = targetObj[key].showValue
|
mj = targetObj[key].showValue;
|
||||||
}
|
} else if (display === fieldMap["账单编号"]) {
|
||||||
if(targetObj[key].display === "合同截止日期") {
|
bdidFieldName = key;
|
||||||
endDate = targetObj[key].showValue
|
bdid = targetObj[key].showValue;
|
||||||
}
|
|
||||||
if(targetObj[key].display === "租赁总面积") {
|
|
||||||
mj = targetObj[key].showValue
|
|
||||||
}
|
|
||||||
if(targetObj[key].display === "账单编号") {
|
|
||||||
bdidFieldName = key
|
|
||||||
bdid = targetObj[key].showValue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// var s = self;
|
|
||||||
// var recordId = self.messageObj.formdata.formsons.front_formson_7.records[0].recordId;
|
// 校验表单必填字段是否已匹配
|
||||||
// 计费方式
|
if (isEmpty(jifeifs)) {
|
||||||
// var jifeifsfield = {
|
$.alert("未找到计费方式字段或值为空,请检查表单");
|
||||||
// fieldId: 'field0032'
|
return;
|
||||||
// };
|
}
|
||||||
// var jifeifs = csdk.core.getFieldData(jifeifsfield).showValue;
|
if (isEmpty(jiaofeifs)) {
|
||||||
// 缴费方式
|
$.alert("未找到缴费方式字段或值为空,请检查表单");
|
||||||
// var jiaofeifsfield = {
|
return;
|
||||||
// fieldId: 'field0033'
|
}
|
||||||
// };
|
|
||||||
// var jiaofeifs = csdk.core.getFieldData(jiaofeifsfield).showValue;
|
|
||||||
// 年缴费方式类型
|
|
||||||
// var njiaofeifsfield = {
|
|
||||||
// fieldId: 'field0034'
|
|
||||||
// };
|
|
||||||
// var njiaofeifs = csdk.core.getFieldData(njiaofeifsfield).showValue;
|
|
||||||
// 面积单价
|
|
||||||
// var mjzjfield = {
|
|
||||||
// fieldId: 'field0035'
|
|
||||||
// };
|
|
||||||
// var mjzj = csdk.core.getFieldData(mjzjfield).value;
|
|
||||||
// 固定租金单价
|
|
||||||
// var gdzjfield = {
|
|
||||||
// fieldId: 'field0038'
|
|
||||||
// };
|
|
||||||
// var gdzj = csdk.core.getFieldData(gdzjfield).value;
|
|
||||||
// 合同开始日期
|
|
||||||
// var startDatefield = {
|
|
||||||
// fieldId: 'field0041'
|
|
||||||
// };
|
|
||||||
// var startDate = csdk.core.getFieldData(startDatefield).value;
|
|
||||||
// 合同结束日期
|
|
||||||
// var endDatefield = {
|
|
||||||
// fieldId: 'field0042'
|
|
||||||
// };
|
|
||||||
// var endDate = csdk.core.getFieldData(endDatefield).value;
|
|
||||||
// 租赁面积
|
|
||||||
// var mjfield = {
|
|
||||||
// fieldId: 'field0081'
|
|
||||||
// };
|
|
||||||
// var mj = csdk.core.getFieldData(mjfield).value;
|
|
||||||
// 账单编号
|
|
||||||
// var field0083 = {fieldId: 'field0083'};
|
|
||||||
// var field0083value = csdk.core.getFieldData(field0083).value;
|
|
||||||
// var bdidfield = {
|
|
||||||
// fieldId: 'field0101'
|
|
||||||
// };
|
|
||||||
// var bdid = csdk.core.getFieldData(bdidfield).value;
|
|
||||||
|
|
||||||
// 判断合同开始日期是否在合同结束日期之前
|
// 判断合同开始日期是否在合同结束日期之前
|
||||||
if (!isEmpty(startDate) || !isEmpty(endDate)) {
|
if (!isEmpty(startDate) || !isEmpty(endDate)) {
|
||||||
@@ -172,11 +148,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var str = "";
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'post',
|
type: 'post',
|
||||||
async: true,
|
async: true,
|
||||||
// 记得加随机数,不然如果ajax轮询请求会不执行
|
|
||||||
url: encodeURI('/seeyon/leaseBillController.do?datetime=' + Math.random()),
|
url: encodeURI('/seeyon/leaseBillController.do?datetime=' + Math.random()),
|
||||||
data: {
|
data: {
|
||||||
"jifeifs": jifeifs,
|
"jifeifs": jifeifs,
|
||||||
@@ -192,23 +166,18 @@
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json; charset=UTF-8',
|
contentType: 'application/json; charset=UTF-8',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
var randomNum = Math.floor(Math.random() * 10001);
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
// $.alert("账单明细生成完成");
|
if (bdid == "" || bdid == "0") {
|
||||||
if (bdid == "") {
|
|
||||||
var data = {
|
var data = {
|
||||||
fieldId: bdidFieldName,
|
fieldId: bdidFieldName,
|
||||||
fieldData: {
|
fieldData: {
|
||||||
value: res.num + '', //数据值,存入数据库中的value值
|
value: res.num + '',
|
||||||
display: res.num + '', //字段渲染在页面上的显示值,通常是经过format后的值
|
display: res.num + '',
|
||||||
auth: ''
|
auth: ''
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
csdk.core.setFieldData(data);
|
csdk.core.setFieldData(data);
|
||||||
}
|
}
|
||||||
// messageObj.formdata.formmains[adaptation.formMessage.tableName]
|
|
||||||
// self.adaptation.formdata.field0095.formmains.formmain_0228.field0064.value = randomNum;
|
|
||||||
// self.adaptation.formdata.field0100__.formmains.formmain_0033.field0102.value = randomNum;
|
|
||||||
} else {
|
} else {
|
||||||
$.alert(res.s);
|
$.alert(res.s);
|
||||||
}
|
}
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
package com.seeyon.apps.src_leasebill.controller;
|
|
||||||
|
|
||||||
import cn.hutool.log.Log;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.seeyon.aicloud.common.JsonUtils;
|
|
||||||
import com.seeyon.apps.common.config.ICstConfigApi;
|
|
||||||
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
|
||||||
import com.seeyon.apps.src_leasebill.config.LeaseBillConfigProvider;
|
|
||||||
import com.seeyon.apps.src_leasebill.constant.LeaseBillConstant;
|
|
||||||
import com.seeyon.apps.src_leasebill.dao.ILeaseBillDao;
|
|
||||||
import com.seeyon.apps.src_leasebill.util.DateUtil;
|
|
||||||
import com.seeyon.apps.src_leasebill.util.FormExportUtil;
|
|
||||||
import com.seeyon.apps.src_leasebill.util.LeaseBillUtil;
|
|
||||||
import com.seeyon.ctp.common.AppContext;
|
|
||||||
import com.seeyon.ctp.common.controller.BaseController;
|
|
||||||
import com.seeyon.ctp.util.json.JSONUtil;
|
|
||||||
import com.seeyon.v3x.services.form.FormFactory;
|
|
||||||
import com.seeyon.v3x.services.form.bean.FormExport;
|
|
||||||
import com.seeyon.v3x.services.form.bean.SubordinateFormExport;
|
|
||||||
import com.seeyon.v3x.services.form.bean.ValueExport;
|
|
||||||
import nc.vo.jcom.lang.StringUtil;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class LeaseBillController extends BaseController {
|
|
||||||
|
|
||||||
private static Log log = Log.get(LeaseBillController.class);
|
|
||||||
private LeaseBillConfigProvider configProvider = (LeaseBillConfigProvider) AppContext.getBean("leaseBillConfigProvider");
|
|
||||||
protected ICstConfigApi cstConfigApi = (ICstConfigApi) AppContext.getBean("cstConfigApi");
|
|
||||||
|
|
||||||
private FormFactory formFactory;
|
|
||||||
|
|
||||||
public FormFactory getFormFactory() {
|
|
||||||
if (formFactory == null) {
|
|
||||||
formFactory = (FormFactory) AppContext.getBean("formFactory");
|
|
||||||
}
|
|
||||||
return formFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormFactory(FormFactory formFactory) {
|
|
||||||
this.formFactory = formFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ILeaseBillDao leaseBillDao;
|
|
||||||
public void setLeaseBillDao(ILeaseBillDao leaseBillDao) {
|
|
||||||
this.leaseBillDao = leaseBillDao;
|
|
||||||
}
|
|
||||||
public ILeaseBillDao getLeaseBillDao() {
|
|
||||||
if (leaseBillDao == null) {
|
|
||||||
leaseBillDao = (ILeaseBillDao) AppContext.getBean("leaseBillDao");
|
|
||||||
}
|
|
||||||
return leaseBillDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
||||||
log.info("进入生成账单ajax方法");
|
|
||||||
ConfigVo configVo = getYdctLeaseBillConfig();
|
|
||||||
DateUtil dateUtil = new DateUtil();
|
|
||||||
LeaseBillUtil leaseBillUtil = new LeaseBillUtil();
|
|
||||||
FormExportUtil formExportUtil = new FormExportUtil();
|
|
||||||
// 设置返回值对象
|
|
||||||
Map<String, Object> res = new HashMap<>();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmsssss");
|
|
||||||
request.setCharacterEncoding("UTF-8");
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
|
|
||||||
BufferedReader reader = request.getReader();
|
|
||||||
String line;
|
|
||||||
StringBuilder requestBody = new StringBuilder();
|
|
||||||
while((line = reader.readLine())!=null){
|
|
||||||
requestBody.append(line);
|
|
||||||
}
|
|
||||||
String data = requestBody.toString();
|
|
||||||
String decodedParam = URLDecoder.decode(data, "UTF-8");
|
|
||||||
String[] datas = decodedParam.split("&");
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
for(int i = 0 ; i < datas.length ; i ++ ){
|
|
||||||
String[] params = datas[i].split("=");
|
|
||||||
if(params.length>1){
|
|
||||||
jsonObject.put(params[0],params[1]);
|
|
||||||
}else{
|
|
||||||
if(params[0].equals("bdid")){
|
|
||||||
jsonObject.put("bdid","0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
String bdidValue = jsonObject.getString("bdid");
|
|
||||||
log.info("当前账单编号为:"+bdidValue);
|
|
||||||
if("0".equals(bdidValue)){
|
|
||||||
Date formDate = new Date();
|
|
||||||
String formId = simpleDateFormat.format(formDate);
|
|
||||||
// 账单编号
|
|
||||||
bdidValue = formId;
|
|
||||||
// formDataVo.getNewFieldDataMap().put("账单编号", formId);
|
|
||||||
}else {
|
|
||||||
List<String> ids = leaseBillDao.leaseBillByCode(bdidValue);
|
|
||||||
for (int i = 0; i < ids.size(); i++) {
|
|
||||||
// 删除明细账单
|
|
||||||
leaseBillDao.deleteBillsByBillId(ids.get(i));
|
|
||||||
// 删除主表数据
|
|
||||||
leaseBillDao.deleteBillById(ids.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String code = bdidValue;
|
|
||||||
// 开始日期
|
|
||||||
String startDateStr = jsonObject.getString("startDate");
|
|
||||||
Date startDate = sdf.parse(startDateStr);
|
|
||||||
// 结束日期
|
|
||||||
String endDateStr = jsonObject.getString("endDate");
|
|
||||||
Date endDate = sdf.parse(endDateStr);
|
|
||||||
// 设置面积
|
|
||||||
String jifeifs = jsonObject.getString("jifeifs");
|
|
||||||
// 设置合同开始日期
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTime(startDate);
|
|
||||||
// 判断合同开始时间是否为月底
|
|
||||||
log.info("入参: " + jsonObject.toString());
|
|
||||||
boolean isMaxDay = false;
|
|
||||||
int currentDay = startTime.get(Calendar.DAY_OF_MONTH);
|
|
||||||
int maxDay = startTime.getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
||||||
if(currentDay==maxDay){
|
|
||||||
isMaxDay = true;
|
|
||||||
}
|
|
||||||
// 设置合同结束日期
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
endTime.setTime(endDate);
|
|
||||||
endTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
|
|
||||||
// 根据缴费方式设置开始结束时间
|
|
||||||
String jiaofeifs = jsonObject.getString("jiaofeifs");
|
|
||||||
int jfzqNum = dateUtil.getCycleNum(jiaofeifs);
|
|
||||||
|
|
||||||
FormExport formExport = new FormExport();
|
|
||||||
// 租金
|
|
||||||
List<Map<String,String>> rents = new ArrayList<Map<String,String>>();
|
|
||||||
if(jfzqNum==12){
|
|
||||||
String njiaofeifs = jsonObject.getString("njiaofeifs");
|
|
||||||
if(StringUtil.isEmpty(njiaofeifs)){
|
|
||||||
res.put("success", true);
|
|
||||||
res.put("name", AppContext.currentUserLoginName());
|
|
||||||
res.put("s", "请选择年缴费计算方式");
|
|
||||||
res.put("num", "");
|
|
||||||
render(response, JSONUtil.toJSONString(res));
|
|
||||||
return null;
|
|
||||||
}else{
|
|
||||||
if(njiaofeifs.equals(configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeOneMapName))){
|
|
||||||
// 采用方式一/正常年度
|
|
||||||
System.out.println("开始生成账单数据");
|
|
||||||
log.info("正常年度-生成账单数据");
|
|
||||||
rents = leaseBillUtil.getLeaseBillYers1(startTime,endTime,isMaxDay,jfzqNum,jsonObject,jifeifs);
|
|
||||||
}else if(njiaofeifs.equals(configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeTwoMapName))){
|
|
||||||
// 采用方式二/非正常年度
|
|
||||||
System.out.println("开始生成账单数据");
|
|
||||||
log.info("非正常年度-生成账单数据");
|
|
||||||
rents = leaseBillUtil.getLeaseBillYers2(startTime,endTime,isMaxDay,jfzqNum,jsonObject,jifeifs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// 根据标准方法生成
|
|
||||||
System.out.println("开始生成账单数据");
|
|
||||||
log.info("开始用标准方法生成账单数据");
|
|
||||||
rents = leaseBillUtil.getLeaseBill(startTime,endTime,isMaxDay,jfzqNum,jsonObject,jifeifs);
|
|
||||||
}
|
|
||||||
if(rents.size() == 0){
|
|
||||||
log.info("要生成账单的数据为空");
|
|
||||||
}
|
|
||||||
log.info("创建档案");
|
|
||||||
List<SubordinateFormExport> subordinateFormExports = formExportUtil.setSubordinateFormValue(rents);
|
|
||||||
Map<String , String > billMap = new HashMap<String, String>();
|
|
||||||
billMap.put("账单编号", code);
|
|
||||||
List<ValueExport> valueExports = formExportUtil.setFormValue(billMap);
|
|
||||||
formExport.setSubordinateForms(subordinateFormExports);
|
|
||||||
formExport.setValues(valueExports);
|
|
||||||
String loginName = configProvider.getBizConfigByKey(LeaseBillConstant.loginName);
|
|
||||||
getFormFactory().importBusinessFormData(loginName, configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo),
|
|
||||||
formExport, new String[] {});
|
|
||||||
res.put("success", true);
|
|
||||||
res.put("name", AppContext.currentUserLoginName());
|
|
||||||
res.put("s", "");
|
|
||||||
res.put("num", code);
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
render(response, JSONUtil.toJSONString(res));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给前台渲染json数据
|
|
||||||
* @param response
|
|
||||||
* @param text
|
|
||||||
*/
|
|
||||||
private void render(HttpServletResponse response, String text) {
|
|
||||||
response.setContentType("application/json;charset=UTF-8");
|
|
||||||
try {
|
|
||||||
response.setContentLength(text.getBytes("UTF-8").length);
|
|
||||||
response.getWriter().write(text);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigVo getYdctLeaseBillConfig() {
|
|
||||||
return cstConfigApi.getConfig(getPluginId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPluginId() {
|
|
||||||
return LeaseBillConstant.getPluginId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,280 +0,0 @@
|
|||||||
package com.seeyon.apps.src_leasebill.util;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class LeaseBillUtil {
|
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成租金账单
|
|
||||||
* @param startTime 开始时间
|
|
||||||
* @param endTime 结束时间
|
|
||||||
* @param isMaxDay 是否每月最后一天
|
|
||||||
* @param jfzqNum 缴费周期月
|
|
||||||
* @param jsonObject 请求参数
|
|
||||||
* @param jifeifs 计费方式
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<Map<String,String>> getLeaseBill(Calendar startTime, Calendar endTime, boolean isMaxDay, int jfzqNum,
|
|
||||||
JSONObject jsonObject,String jifeifs){
|
|
||||||
List<Map<String,String>> rents = new ArrayList<>();
|
|
||||||
System.out.println("生成账单的参数: " + startTime + ","+ endTime+"," + isMaxDay+"," + jfzqNum +","+ jsonObject.toString() +","+ jifeifs);
|
|
||||||
DateUtil dateUtil = new DateUtil();
|
|
||||||
// 两个日期相差多少月
|
|
||||||
int monthNum = dateUtil.betweenMonthByTwoCalendar(startTime,endTime);
|
|
||||||
if(jfzqNum==99){
|
|
||||||
// 一次性账单生成
|
|
||||||
Map<String,String> rent = new HashMap<>();
|
|
||||||
float zlmjFloat = 0;
|
|
||||||
double zf = 0;
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
String mjStr = jsonObject.getString("mj");
|
|
||||||
zlmjFloat = Float.parseFloat(mjStr);
|
|
||||||
String mjzjStr = jsonObject.getString("mjzj");
|
|
||||||
double mjzj = dateUtil.stringToNum(mjzjStr);
|
|
||||||
zf = mjzj*zlmjFloat*monthNum;
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
zlmjFloat = 1;
|
|
||||||
String gdzjStr = jsonObject.getString("gdzj");
|
|
||||||
double gdzj = dateUtil.stringToNum(gdzjStr);
|
|
||||||
// zf = gdzj*zlmjFloat*monthNum;
|
|
||||||
zf = gdzj*zlmjFloat;
|
|
||||||
}
|
|
||||||
rent.put("开始日期",sdf.format(startTime.getTime()));
|
|
||||||
endTime.add(Calendar.DATE, -1);
|
|
||||||
rent.put("结束日期",sdf.format(endTime.getTime()));
|
|
||||||
rent.put("租费",zf+"");
|
|
||||||
rents.add(rent);
|
|
||||||
}else{
|
|
||||||
// 月,季,半年,账单生成
|
|
||||||
int termNum = monthNum/jfzqNum;
|
|
||||||
int mo = monthNum%jfzqNum;
|
|
||||||
if(mo!=0){
|
|
||||||
termNum++;
|
|
||||||
}
|
|
||||||
float zlmjFloat = 0;
|
|
||||||
double zf = 0;
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
String mjStr = jsonObject.getString("mj");
|
|
||||||
zlmjFloat = Float.parseFloat(mjStr);
|
|
||||||
String mjzjStr = jsonObject.getString("mjzj");
|
|
||||||
double mjzj = dateUtil.stringToNum(mjzjStr);
|
|
||||||
zf = mjzj*zlmjFloat;
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
zlmjFloat = 1;
|
|
||||||
String gdzjStr = jsonObject.getString("gdzj");
|
|
||||||
double gdzj = dateUtil.stringToNum(gdzjStr);
|
|
||||||
zf = gdzj*zlmjFloat;
|
|
||||||
}
|
|
||||||
for(int i = 0 ; i < termNum ; i ++) {
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
Map<String, String> rentMap = new HashMap<String, String>();
|
|
||||||
// 设置租费时间
|
|
||||||
rentMap.put("开始日期", sdf.format(startTime.getTime()));
|
|
||||||
if (!isMaxDay) {
|
|
||||||
startTime.add(Calendar.MONTH, jfzqNum);
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
}else{
|
|
||||||
startTime.add(Calendar.MONTH, jfzqNum);
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH)-1);
|
|
||||||
}
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
// rentMap.put("期间月数-租金",jfzqNum+"");
|
|
||||||
// rentMap.put("租费", (zf * jfzqNum) + "");
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * jfzqNum) + "");
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}
|
|
||||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
|
||||||
} else {
|
|
||||||
//两个日期相差多少月
|
|
||||||
startTime.add(Calendar.MONTH, jfzqNum*-1);
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
int qijianyueshu = dateUtil.betweenMonthByTwoCalendar(startTime, endTime);
|
|
||||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}
|
|
||||||
|
|
||||||
endTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
rentMap.put("结束日期", sdf.format(endTime.getTime()));
|
|
||||||
}
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
if (isMaxDay) {
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
||||||
}
|
|
||||||
rents.add(rentMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rents;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成租金账单
|
|
||||||
* @param startTime 开始时间
|
|
||||||
* @param endTime 结束时间
|
|
||||||
* @param isMaxDay 是否每月最后一天
|
|
||||||
* @param jfzqNum 缴费周期月
|
|
||||||
* @param jsonObject 请求参数
|
|
||||||
* @param jifeifs 计费方式
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<Map<String,String>> getLeaseBillYers1(Calendar startTime, Calendar endTime, boolean isMaxDay, int jfzqNum,
|
|
||||||
JSONObject jsonObject,String jifeifs){
|
|
||||||
System.out.println("生成账单的参数: " + startTime + ","+ endTime+"," + isMaxDay+"," + jfzqNum +","+ jsonObject.toString() +","+ jifeifs);
|
|
||||||
List<Map<String,String>> rents = new ArrayList<>();
|
|
||||||
DateUtil dateUtil = new DateUtil();
|
|
||||||
// 两个日期相差多少月
|
|
||||||
int monthNum = dateUtil.betweenMonthByTwoCalendar(startTime,endTime);
|
|
||||||
int termNum = monthNum/jfzqNum;
|
|
||||||
int mo = monthNum%jfzqNum;
|
|
||||||
if(mo!=0){
|
|
||||||
termNum++;
|
|
||||||
}
|
|
||||||
float zlmjFloat = 0;
|
|
||||||
double zf = 0;
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
String mjStr = jsonObject.getString("mj");
|
|
||||||
zlmjFloat = Float.parseFloat(mjStr);
|
|
||||||
String mjzjStr = jsonObject.getString("mjzj");
|
|
||||||
double mjzj = dateUtil.stringToNum(mjzjStr);
|
|
||||||
zf = mjzj*zlmjFloat;
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
zlmjFloat = 1;
|
|
||||||
String gdzjStr = jsonObject.getString("gdzj");
|
|
||||||
double gdzj = dateUtil.stringToNum(gdzjStr);
|
|
||||||
zf = gdzj*zlmjFloat;
|
|
||||||
}
|
|
||||||
for(int i = 0 ; i < termNum ; i ++) {
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
Map<String, String> rentMap = new HashMap<String, String>();
|
|
||||||
// 设置租费时间
|
|
||||||
rentMap.put("开始日期", sdf.format(startTime.getTime()));
|
|
||||||
startTime.add(Calendar.MONTH, jfzqNum);
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
// rentMap.put("期间月数-租金",jfzqNum+"");
|
|
||||||
// rentMap.put("租费", (zf * jfzqNum) + "");
|
|
||||||
if("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}else{
|
|
||||||
rentMap.put("租费", (zf * jfzqNum) + "");
|
|
||||||
}
|
|
||||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
|
||||||
} else {
|
|
||||||
//两个日期相差多少月
|
|
||||||
startTime.add(Calendar.MONTH, jfzqNum*-1);
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
int qijianyueshu = dateUtil.betweenMonthByTwoCalendar(startTime, endTime);
|
|
||||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
|
||||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
if("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}else{
|
|
||||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
}
|
|
||||||
endTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
rentMap.put("结束日期", sdf.format(endTime.getTime()));
|
|
||||||
}
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
if (isMaxDay) {
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
||||||
}
|
|
||||||
rents.add(rentMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rents;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成租金账单
|
|
||||||
* @param startTime 开始时间
|
|
||||||
* @param endTime 结束时间
|
|
||||||
* @param isMaxDay 是否每月最后一天
|
|
||||||
* @param jfzqNum 缴费周期月
|
|
||||||
* @param jsonObject 请求参数
|
|
||||||
* @param jifeifs 计费方式
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<Map<String,String>> getLeaseBillYers2(Calendar startTime, Calendar endTime, boolean isMaxDay, int jfzqNum,
|
|
||||||
JSONObject jsonObject,String jifeifs){
|
|
||||||
System.out.println("生成账单的参数: " + startTime + ","+ endTime+"," + isMaxDay+"," + jfzqNum +","+ jsonObject.toString() +","+ jifeifs);
|
|
||||||
List<Map<String,String>> rents = new ArrayList<>();
|
|
||||||
DateUtil dateUtil = new DateUtil();
|
|
||||||
// 两个日期相差多少年
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(startTime.getTime());
|
|
||||||
int starYear = startTime.get(Calendar.YEAR);
|
|
||||||
int endYear = endTime.get(Calendar.YEAR);
|
|
||||||
int termNum = endYear-starYear+1;
|
|
||||||
float zlmjFloat = 0;
|
|
||||||
double zf = 0;
|
|
||||||
if("面积计费".equals(jifeifs)){
|
|
||||||
String mjStr = jsonObject.getString("mj");
|
|
||||||
zlmjFloat = Float.parseFloat(mjStr);
|
|
||||||
String mjzjStr = jsonObject.getString("mjzj");
|
|
||||||
double mjzj = dateUtil.stringToNum(mjzjStr);
|
|
||||||
zf = mjzj*zlmjFloat;
|
|
||||||
}else if ("固定租金".equals(jifeifs)){
|
|
||||||
zlmjFloat = 1;
|
|
||||||
String gdzjStr = jsonObject.getString("gdzj");
|
|
||||||
double gdzj = dateUtil.stringToNum(gdzjStr);
|
|
||||||
zf = gdzj*zlmjFloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0 ; i < termNum ; i ++) {
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
Map<String, String> rentMap = new HashMap<String, String>();
|
|
||||||
// 设置租费时间
|
|
||||||
rentMap.put("开始日期", sdf.format(startTime.getTime()));
|
|
||||||
startTime.set(Calendar.MONTH, 11);
|
|
||||||
startTime.set(Calendar.DATE, 31);
|
|
||||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
|
||||||
// rentMap.put("期间月数-租金",jfzqNum+"");
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
int qijianyueshu = dateUtil.betweenMonthByTwoCalendar(calendar, startTime);
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
if ("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}else{
|
|
||||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
}
|
|
||||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
|
||||||
calendar.set(Calendar.MONTH, 11);
|
|
||||||
calendar.set(Calendar.DATE, 31);
|
|
||||||
} else {
|
|
||||||
//两个日期相差多少月
|
|
||||||
int qijianyueshu = dateUtil.betweenMonthByTwoCalendar(calendar, endTime);
|
|
||||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
|
||||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
if ("固定租金".equals(jifeifs)){
|
|
||||||
rentMap.put("租费", (zf * 1) + "");
|
|
||||||
}else{
|
|
||||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
|
||||||
}
|
|
||||||
endTime.add(Calendar.DAY_OF_MONTH, -1);
|
|
||||||
rentMap.put("结束日期", sdf.format(endTime.getTime()));
|
|
||||||
}
|
|
||||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
if (isMaxDay) {
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
||||||
}
|
|
||||||
rents.add(rentMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rents;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user