调整
This commit is contained in:
@@ -49,6 +49,7 @@ public class LeaseBillController extends BaseController {
|
||||
}
|
||||
|
||||
private ILeaseBillDao leaseBillDao;
|
||||
|
||||
public void setLeaseBillDao(ILeaseBillDao leaseBillDao) {
|
||||
this.leaseBillDao = leaseBillDao;
|
||||
}
|
||||
@@ -60,138 +61,216 @@ public class LeaseBillController extends BaseController {
|
||||
}
|
||||
|
||||
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
log.info("进入生成账单ajax方法");
|
||||
System.out.println("进入生成账单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 requestBody = getRequestBody(request);
|
||||
if (requestBody == null || requestBody.isEmpty()) {
|
||||
System.out.println("【错误】请求体为空,直接返回默认结果");
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
// 解析参数
|
||||
JSONObject jsonObject = parseRequestParams(requestBody);
|
||||
if (jsonObject == null || jsonObject.isEmpty()) {
|
||||
System.out.println("【错误】解析后请求参数为空,返回默认结果");
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
System.out.println("入参: " + jsonObject.toString());
|
||||
|
||||
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 {
|
||||
if (bdidValue == null || bdidValue.trim().isEmpty()) {
|
||||
bdidValue = "0";
|
||||
}
|
||||
System.out.println("当前账单编号为:" + bdidValue);
|
||||
|
||||
String code;
|
||||
if ("0".equals(bdidValue)) {
|
||||
code = simpleDateFormat.format(new Date());
|
||||
System.out.println("自动生成新账单编号:" + code);
|
||||
} else {
|
||||
code = bdidValue;
|
||||
List<String> ids = leaseBillDao.leaseBillByCode(bdidValue);
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
// 删除明细账单
|
||||
leaseBillDao.deleteBillsByBillId(ids.get(i));
|
||||
// 删除主表数据
|
||||
leaseBillDao.deleteBillById(ids.get(i));
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
System.out.println("根据账单编号[" + bdidValue + "]未查询到需要删除的旧数据");
|
||||
} else {
|
||||
for (String id : ids) {
|
||||
leaseBillDao.deleteBillsByBillId(id);
|
||||
leaseBillDao.deleteBillById(id);
|
||||
}
|
||||
System.out.println("账单编号[" + bdidValue + "]旧数据删除完成");
|
||||
}
|
||||
}
|
||||
String code = bdidValue;
|
||||
// 开始日期
|
||||
|
||||
// 日期
|
||||
String startDateStr = jsonObject.getString("startDate");
|
||||
Date startDate = sdf.parse(startDateStr);
|
||||
// 结束日期
|
||||
String endDateStr = jsonObject.getString("endDate");
|
||||
if (startDateStr == null || startDateStr.isEmpty() || endDateStr == null || endDateStr.isEmpty()) {
|
||||
System.out.println("【错误】开始日期或结束日期为空,生成账单失败");
|
||||
res.put("success", false);
|
||||
res.put("s", "开始日期/结束日期不能为空");
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
|
||||
Date startDate = sdf.parse(startDateStr);
|
||||
Date endDate = sdf.parse(endDateStr);
|
||||
// 设置面积
|
||||
|
||||
// 计费面积
|
||||
String jifeifs = jsonObject.getString("jifeifs");
|
||||
// 设置合同开始日期
|
||||
if (jifeifs == null || jifeifs.isEmpty()) {
|
||||
System.out.println("【错误】计费面积为空,生成账单失败");
|
||||
res.put("success", false);
|
||||
res.put("s", "计费面积不能为空");
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
|
||||
// 日期处理
|
||||
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;
|
||||
}
|
||||
// 设置合同结束日期
|
||||
boolean isMaxDay = startTime.get(Calendar.DAY_OF_MONTH) == startTime.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
|
||||
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){
|
||||
List<Map<String, String>> rents = new ArrayList<>();
|
||||
if (jfzqNum == 12) {
|
||||
String njiaofeifs = jsonObject.getString("njiaofeifs");
|
||||
if(StringUtil.isEmpty(njiaofeifs)){
|
||||
if (StringUtil.isEmpty(njiaofeifs)) {
|
||||
System.out.println("【错误】年缴费计算方式未选择,终止生成");
|
||||
res.put("success", true);
|
||||
res.put("name", AppContext.currentUserLoginName());
|
||||
res.put("s", "请选择年缴费计算方式");
|
||||
res.put("num", "");
|
||||
render(response, JSONUtil.toJSONString(res));
|
||||
render(response, JSONObject.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);
|
||||
|
||||
String type1 = configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeOneMapName);
|
||||
String type2 = configProvider.getBizConfigByKey(LeaseBillConstant.annualPaymentTypeTwoMapName);
|
||||
if (njiaofeifs.equals(type1)) {
|
||||
System.out.println("正常年度-生成账单数据");
|
||||
rents = leaseBillUtil.getLeaseBillYers1(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||
} else if (njiaofeifs.equals(type2)) {
|
||||
System.out.println("非正常年度-生成账单数据");
|
||||
rents = leaseBillUtil.getLeaseBillYers2(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||
}
|
||||
} else {
|
||||
System.out.println("标准方式生成账单数据");
|
||||
rents = leaseBillUtil.getLeaseBill(startTime, endTime, isMaxDay, jfzqNum, jsonObject, jifeifs);
|
||||
}
|
||||
if(rents.size() == 0){
|
||||
log.info("要生成账单的数据为空");
|
||||
|
||||
// 租金为空判断
|
||||
if (rents == null || rents.isEmpty()) {
|
||||
System.out.println("【错误】生成账单数据为空,无法继续导入");
|
||||
res.put("success", false);
|
||||
res.put("s", "生成账单明细为空");
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
log.info("创建档案");
|
||||
List<SubordinateFormExport> subordinateFormExports = formExportUtil.setSubordinateFormValue(rents);
|
||||
Map<String , String > billMap = new HashMap<String, String>();
|
||||
|
||||
// 创建档案
|
||||
System.out.println("开始创建档案,账单编号:" + code);
|
||||
List<SubordinateFormExport> subordinateList = formExportUtil.setSubordinateFormValue(rents);
|
||||
|
||||
Map<String, String> billMap = new HashMap<>();
|
||||
billMap.put("账单编号", code);
|
||||
List<ValueExport> valueExports = formExportUtil.setFormValue(billMap);
|
||||
formExport.setSubordinateForms(subordinateFormExports);
|
||||
|
||||
FormExport formExport = new FormExport();
|
||||
formExport.setSubordinateForms(subordinateList);
|
||||
formExport.setValues(valueExports);
|
||||
|
||||
String loginName = configProvider.getBizConfigByKey(LeaseBillConstant.loginName);
|
||||
getFormFactory().importBusinessFormData(loginName, configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo),
|
||||
formExport, new String[] {});
|
||||
String formNo = configProvider.getBizConfigByKey(LeaseBillConstant.assistiveFormNo);
|
||||
|
||||
getFormFactory().importBusinessFormData(loginName, formNo, formExport, new String[]{});
|
||||
System.out.println("账单[" + code + "]导入表单数据成功");
|
||||
|
||||
// 成功返回
|
||||
res.put("success", true);
|
||||
res.put("name", AppContext.currentUserLoginName());
|
||||
res.put("s", "");
|
||||
res.put("num", code);
|
||||
}catch (Exception e){
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("【异常】生成账单发生异常:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
res.put("success", false);
|
||||
res.put("s", "系统异常");
|
||||
}
|
||||
|
||||
// 最终 res 为空判断
|
||||
if (res == null || res.isEmpty()) {
|
||||
System.out.println("【严重】最终返回结果 res 为空,返回空JSON");
|
||||
render(response, "{}");
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("生成账单完成,返回结果:" + res);
|
||||
render(response, JSONObject.toJSONString(res));
|
||||
return null;
|
||||
}
|
||||
|
||||
// 读取请求体
|
||||
private String getRequestBody(HttpServletRequest request) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = request.getReader();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
System.out.println("【错误】读取请求体异常");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
private JSONObject parseRequestParams(String requestBody) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
String decoded = URLDecoder.decode(requestBody, "UTF-8");
|
||||
String[] paramsArray = decoded.split("&");
|
||||
for (String param : paramsArray) {
|
||||
String[] kv = param.split("=", 2);
|
||||
if (kv.length == 2) {
|
||||
json.put(kv[0], kv[1]);
|
||||
} else if ("bdid".equals(kv[0])) {
|
||||
json.put("bdid", "0");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("【错误】解析请求参数异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
render(response, JSONUtil.toJSONString(res));
|
||||
return null;
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class LeaseBillDaoImpl implements ILeaseBillDao {
|
||||
|
||||
@Override
|
||||
public int deleteBillsByBillId(String formmainId) throws BusinessException, SQLException {
|
||||
TableContext sub = FormTableExecutor.sub(getFormNo(), "明细表1");
|
||||
TableContext sub = FormTableExecutor.sub(getFormNo(), "账单明细");
|
||||
List<FormWhereCondition> conditions = new ArrayList<>();
|
||||
conditions.add(FormWhereCondition.build().display("formmain_id").value(formmainId));
|
||||
return FormTableExecutor.delete(sub,conditions);
|
||||
|
||||
@@ -44,10 +44,10 @@ public class LeaseBillUtil {
|
||||
// zf = gdzj*zlmjFloat*monthNum;
|
||||
zf = gdzj*zlmjFloat;
|
||||
}
|
||||
rent.put("开始日期",sdf.format(startTime.getTime()));
|
||||
rent.put("明细-开始日期",sdf.format(startTime.getTime()));
|
||||
endTime.add(Calendar.DATE, -1);
|
||||
rent.put("结束日期",sdf.format(endTime.getTime()));
|
||||
rent.put("租费",zf+"");
|
||||
rent.put("明细-结束日期",sdf.format(endTime.getTime()));
|
||||
rent.put("明细-租费",zf+"");
|
||||
rents.add(rent);
|
||||
}else{
|
||||
// 月,季,半年,账单生成
|
||||
@@ -74,7 +74,7 @@ public class LeaseBillUtil {
|
||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
||||
Map<String, String> rentMap = new HashMap<String, String>();
|
||||
// 设置租费时间
|
||||
rentMap.put("开始日期", sdf.format(startTime.getTime()));
|
||||
rentMap.put("明细-开始日期", sdf.format(startTime.getTime()));
|
||||
if (!isMaxDay) {
|
||||
startTime.add(Calendar.MONTH, jfzqNum);
|
||||
startTime.add(Calendar.DAY_OF_MONTH, -1);
|
||||
@@ -88,9 +88,9 @@ public class LeaseBillUtil {
|
||||
if("面积计费".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * jfzqNum) + "");
|
||||
}else if ("固定租金".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * 1) + "");
|
||||
rentMap.put("明细-租费", (zf * 1) + "");
|
||||
}
|
||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
||||
rentMap.put("明细-结束日期", sdf.format(startTime.getTime()));
|
||||
} else {
|
||||
//两个日期相差多少月
|
||||
startTime.add(Calendar.MONTH, jfzqNum*-1);
|
||||
@@ -98,13 +98,13 @@ public class LeaseBillUtil {
|
||||
int qijianyueshu = dateUtil.betweenMonthByTwoCalendar(startTime, endTime);
|
||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
||||
if("面积计费".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
}else if ("固定租金".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * 1) + "");
|
||||
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()));
|
||||
rentMap.put("明细-结束日期", sdf.format(endTime.getTime()));
|
||||
}
|
||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||
if (isMaxDay) {
|
||||
@@ -158,18 +158,18 @@ public class LeaseBillUtil {
|
||||
if (startTime.getTime().getTime() < endTime.getTime().getTime()) {
|
||||
Map<String, String> rentMap = new HashMap<String, String>();
|
||||
// 设置租费时间
|
||||
rentMap.put("开始日期", sdf.format(startTime.getTime()));
|
||||
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) + "");
|
||||
rentMap.put("明细-租费", (zf * 1) + "");
|
||||
}else{
|
||||
rentMap.put("租费", (zf * jfzqNum) + "");
|
||||
rentMap.put("明细-租费", (zf * jfzqNum) + "");
|
||||
}
|
||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
||||
rentMap.put("明细-结束日期", sdf.format(startTime.getTime()));
|
||||
} else {
|
||||
//两个日期相差多少月
|
||||
startTime.add(Calendar.MONTH, jfzqNum*-1);
|
||||
@@ -178,12 +178,12 @@ public class LeaseBillUtil {
|
||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
if("固定租金".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * 1) + "");
|
||||
rentMap.put("明细-租费", (zf * 1) + "");
|
||||
}else{
|
||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
rentMap.put("明细-租费", (zf * qijianyueshu) + "");
|
||||
}
|
||||
endTime.add(Calendar.DAY_OF_MONTH, -1);
|
||||
rentMap.put("结束日期", sdf.format(endTime.getTime()));
|
||||
rentMap.put("明细-结束日期", sdf.format(endTime.getTime()));
|
||||
}
|
||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||
if (isMaxDay) {
|
||||
@@ -246,11 +246,11 @@ public class LeaseBillUtil {
|
||||
startTime.add(Calendar.DAY_OF_MONTH, -1);
|
||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
if ("固定租金".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * 1) + "");
|
||||
rentMap.put("明细-租费", (zf * 1) + "");
|
||||
}else{
|
||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
rentMap.put("明细-租费", (zf * qijianyueshu) + "");
|
||||
}
|
||||
rentMap.put("结束日期", sdf.format(startTime.getTime()));
|
||||
rentMap.put("明细-结束日期", sdf.format(startTime.getTime()));
|
||||
calendar.set(Calendar.MONTH, 11);
|
||||
calendar.set(Calendar.DATE, 31);
|
||||
} else {
|
||||
@@ -259,12 +259,12 @@ public class LeaseBillUtil {
|
||||
// rentMap.put("期间月数-租金",qijianyueshu+"");
|
||||
// rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
if ("固定租金".equals(jifeifs)){
|
||||
rentMap.put("租费", (zf * 1) + "");
|
||||
rentMap.put("明细-租费", (zf * 1) + "");
|
||||
}else{
|
||||
rentMap.put("租费", (zf * qijianyueshu) + "");
|
||||
rentMap.put("明细-租费", (zf * qijianyueshu) + "");
|
||||
}
|
||||
endTime.add(Calendar.DAY_OF_MONTH, -1);
|
||||
rentMap.put("结束日期", sdf.format(endTime.getTime()));
|
||||
rentMap.put("明细-结束日期", sdf.format(endTime.getTime()));
|
||||
}
|
||||
startTime.add(Calendar.DAY_OF_MONTH, 1);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
@@ -81,19 +81,19 @@
|
||||
if(targetObj[key].display === "年缴费方案选项") {
|
||||
njiaofeifs = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "实租单价") {
|
||||
if(targetObj[key].display === "租赁单价") {
|
||||
mjzj = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "固定租金标准") {
|
||||
gdzj = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "计租开始日期") {
|
||||
if(targetObj[key].display === "计租日期") {
|
||||
startDate = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "合同截止日期") {
|
||||
endDate = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "租赁总面积") {
|
||||
if(targetObj[key].display === "租赁面积") {
|
||||
mj = targetObj[key].showValue
|
||||
}
|
||||
if(targetObj[key].display === "账单编号") {
|
||||
|
||||
Reference in New Issue
Block a user