GenerateBillTemplate.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. package com.java110.job.task.fee;
  2. import com.java110.core.factory.GenerateCodeFactory;
  3. import com.java110.dto.RoomDto;
  4. import com.java110.dto.community.CommunityDto;
  5. import com.java110.dto.fee.*;
  6. import com.java110.dto.owner.OwnerCarDto;
  7. import com.java110.dto.owner.OwnerRoomRelDto;
  8. import com.java110.dto.parking.ParkingSpaceDto;
  9. import com.java110.dto.task.TaskDto;
  10. import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
  11. import com.java110.intf.community.IRoomInnerServiceSMO;
  12. import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
  13. import com.java110.intf.fee.IFeeDetailInnerServiceSMO;
  14. import com.java110.intf.fee.IFeeInnerServiceSMO;
  15. import com.java110.intf.user.IOwnerCarInnerServiceSMO;
  16. import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO;
  17. import com.java110.job.quartz.TaskSystemQuartz;
  18. import com.java110.utils.constant.ResponseConstant;
  19. import com.java110.utils.exception.TaskTemplateException;
  20. import com.java110.utils.util.DateUtil;
  21. import com.java110.utils.util.StringUtil;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Component;
  24. import java.math.BigDecimal;
  25. import java.math.RoundingMode;
  26. import java.util.Calendar;
  27. import java.util.Date;
  28. import java.util.List;
  29. /**
  30. * @ClassName GenerateOwnerBillTemplate
  31. * @Description TODO 房屋费用账单生成
  32. * @Author wuxw
  33. * @Date 2020/6/4 8:33
  34. * @Version 1.0
  35. * add by wuxw 2020/6/4
  36. **/
  37. @Component
  38. public class GenerateBillTemplate extends TaskSystemQuartz {
  39. private static final String TASK_ATTR_BILL_TYPE = "10002"; // 出账类型
  40. private static final String TASK_ATTR_VALUE_MONTH = "002"; //按月出账
  41. private static final String TASK_ATTR_VALUE_DAY = "003"; //按日出账
  42. private static final String TASK_ATTR_VALUE_YEAR = "001"; //按年出账
  43. private static final String TASK_ATTR_VALUE_ONCE_MONTH = "005"; //一次性按月出账
  44. @Autowired
  45. private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
  46. @Autowired
  47. private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
  48. @Autowired
  49. private IFeeDetailInnerServiceSMO feeDetailInnerServiceSMOImpl;
  50. @Autowired
  51. private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
  52. @Autowired
  53. private IOwnerRoomRelInnerServiceSMO ownerRoomRelInnerServiceSMOImpl;
  54. @Autowired
  55. private IParkingSpaceInnerServiceSMO parkingSpaceInnerServiceSMOImpl;
  56. @Autowired
  57. private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
  58. @Override
  59. protected void process(TaskDto taskDto) throws Exception {
  60. // 获取小区
  61. List<CommunityDto> communityDtos = getAllCommunity();
  62. for (CommunityDto communityDto : communityDtos) {
  63. GenerateBill(taskDto, communityDto);
  64. }
  65. }
  66. /**
  67. * 根据小区生成账单
  68. *
  69. * @param communityDto
  70. */
  71. private void GenerateBill(TaskDto taskDto, CommunityDto communityDto) {
  72. //查询费用项
  73. FeeConfigDto feeConfigDto = new FeeConfigDto();
  74. feeConfigDto.setCommunityId(communityDto.getCommunityId());
  75. feeConfigDto.setBillType(getCurTaskAttr(taskDto, TASK_ATTR_BILL_TYPE).getValue());
  76. if (StringUtil.isEmpty(feeConfigDto.getBillType())) {
  77. throw new IllegalArgumentException("配置错误 未拿到属性值");
  78. }
  79. List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
  80. for (FeeConfigDto tmpFeeConfigDto : feeConfigDtos) {
  81. try {
  82. GenerateBillByFeeConfig(taskDto, tmpFeeConfigDto);
  83. } catch (Exception e) {
  84. logger.error("费用出账失败" + tmpFeeConfigDto.getConfigId(), e);
  85. }
  86. }
  87. }
  88. /**
  89. * 按费用项来出账
  90. *
  91. * @param taskDto
  92. * @param feeConfigDto
  93. */
  94. private void GenerateBillByFeeConfig(TaskDto taskDto, FeeConfigDto feeConfigDto) throws Exception {
  95. //当前费用项是否
  96. BillDto tmpBillDto = new BillDto();
  97. tmpBillDto.setCurBill("T");
  98. tmpBillDto.setConfigId(feeConfigDto.getConfigId());
  99. tmpBillDto.setCommunityId(feeConfigDto.getCommunityId());
  100. Date startTime = getDefaultStartTime(feeConfigDto.getBillType());
  101. tmpBillDto.setCurBillTime(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A));
  102. List<BillDto> billDtos = feeInnerServiceSMOImpl.queryBills(tmpBillDto);
  103. //Assert.listOnlyOne(billDtos, "当前存在多个有效账单" + feeConfigDto.getConfigId());
  104. if (billDtos != null && billDtos.size() > 0) {
  105. throw new TaskTemplateException(ResponseConstant.RESULT_CODE_ERROR, "已经出过账了");
  106. }
  107. String billId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_billId);
  108. BillDto billDto = new BillDto();
  109. billDto.setBillId(billId);
  110. billDto.setBillName(feeConfigDto.getFeeName() + "-" + DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_H));
  111. billDto.setBillTime(DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_A));
  112. billDto.setCommunityId(feeConfigDto.getCommunityId());
  113. billDto.setConfigId(feeConfigDto.getConfigId());
  114. billDto.setCurBill("T");
  115. //查询历史有效账单
  116. tmpBillDto = new BillDto();
  117. tmpBillDto.setCurBill("T");
  118. tmpBillDto.setConfigId(feeConfigDto.getConfigId());
  119. tmpBillDto.setCommunityId(feeConfigDto.getCommunityId());
  120. billDtos = feeInnerServiceSMOImpl.queryBills(tmpBillDto);
  121. startTime = (billDtos == null || billDtos.size() < 1) ? getDefaultStartTime(feeConfigDto.getBillType())
  122. : DateUtil.getDateFromString(billDtos.get(0).getBillTime(), DateUtil.DATE_FORMATE_STRING_A);
  123. FeeDto feeDto = new FeeDto();
  124. feeDto.setConfigId(feeConfigDto.getConfigId());
  125. feeDto.setCommunityId(feeConfigDto.getCommunityId());
  126. List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
  127. //没有关联费用不做出账
  128. if (feeDto == null || feeDtos.size() < 1) {
  129. return;
  130. }
  131. billDto.setReceivable("0");
  132. billDto.setReceipts("0");
  133. billDto.setCurReceivable("0");
  134. for (FeeDto tmpFeeDto : feeDtos) {
  135. try {
  136. generateFee(startTime, tmpFeeDto, billDto, feeConfigDto);
  137. } catch (Exception e) {
  138. logger.error("生成费用失败", e);
  139. }
  140. }
  141. //生成本次账单
  142. Date billEndTime = DateUtil.getCurrentDate();
  143. billDto.setRemark(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A) +
  144. "-" + DateUtil.getFormatTimeString(billEndTime, DateUtil.DATE_FORMATE_STRING_A) + "账单数据");
  145. feeInnerServiceSMOImpl.insertBill(billDto);
  146. }
  147. /**
  148. * 生成 费用
  149. *
  150. * @param feeDto
  151. */
  152. private void generateFee(Date startTime, FeeDto feeDto, BillDto billDto, FeeConfigDto feeConfigDto) {
  153. Date billEndTime = DateUtil.getCurrentDate();
  154. if ("2009001".equals(feeDto.getState())) { //判断是否缴费结束
  155. FeeDetailDto feeDetailDto = new FeeDetailDto();
  156. feeDetailDto.setCommunityId(feeDto.getCommunityId());
  157. feeDetailDto.setFeeId(feeDto.getFeeId());
  158. List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
  159. if (feeDetailDtos == null || feeDetailDtos.size() < 1) {
  160. return;//这种数据有问题 不做出账处理
  161. }
  162. Date detailTime = feeDetailDtos.get(0).getCreateTime();
  163. if (detailTime.getTime() < startTime.getTime()) {
  164. //说明上次出账已经出国 无需再出
  165. return;
  166. }
  167. }
  168. if (feeDto.getEndTime().getTime() > billEndTime.getTime()) { //当期没有欠费
  169. return;
  170. }
  171. if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(feeDto.getPayerObjType())) {
  172. computeFeePriceByRoom(feeDto);
  173. } else if (FeeDto.PAYER_OBJ_TYPE_PARKING_SPACE.equals(feeDto.getPayerObjType())) {
  174. computeFeePriceByParkingSpace(feeDto);
  175. } else {
  176. return;//这个没有欠费可算
  177. //throw new IllegalArgumentException("暂不支持该类型出账" + feeDto.getFeeId());
  178. }
  179. if (feeDto.getFeePrice() <= 0) {
  180. return;//这个没有欠费可算
  181. }
  182. BillOweFeeDto billOweFeeDto = new BillOweFeeDto();
  183. billOweFeeDto.setOweId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oweId));
  184. billOweFeeDto.setFeeId(feeDto.getFeeId());
  185. billOweFeeDto.setBillId(billDto.getBillId());
  186. double month = 0.0;
  187. if (TASK_ATTR_VALUE_DAY.equals(feeConfigDto.getBillType())) {
  188. month = dayCompare(feeDto.getEndTime(), billEndTime);
  189. } else {
  190. month = monthCompare(feeDto.getEndTime(), billEndTime);
  191. }
  192. BigDecimal curFeePrice = new BigDecimal(feeDto.getFeePrice());
  193. curFeePrice = curFeePrice.multiply(new BigDecimal(month));
  194. billOweFeeDto.setAmountOwed(curFeePrice.doubleValue() + "");
  195. if (TASK_ATTR_VALUE_DAY.equals(feeConfigDto.getBillType())) {
  196. month = dayCompare(feeDto.getEndTime(), billEndTime);
  197. } else {
  198. month = monthCompare(feeDto.getEndTime(), billEndTime);
  199. }
  200. BigDecimal feePrice = new BigDecimal(feeDto.getFeePrice());
  201. feePrice = feePrice.multiply(new BigDecimal(month));
  202. billOweFeeDto.setBillAmountOwed(feePrice.doubleValue() + "");
  203. billOweFeeDto.setFeeEndTime(DateUtil.getFormatTimeString(feeDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
  204. billOweFeeDto.setCommunityId(feeDto.getCommunityId());
  205. billOweFeeDto.setPayerObjType(feeDto.getPayerObjType());
  206. billOweFeeDto.setState("1000");
  207. if ("3333".equals(feeDto.getPayerObjType())) {
  208. getRoomInfo(billOweFeeDto, feeDto);
  209. } else {
  210. getParkingSpaceInfo(billOweFeeDto, feeDto);
  211. }
  212. feeInnerServiceSMOImpl.insertBillOweFees(billOweFeeDto);
  213. double recFee = StringUtil.isEmpty(billDto.getReceivable()) ? 0.0 : Double.parseDouble(billDto.getReceivable());
  214. BigDecimal recFeeBig = new BigDecimal(recFee);
  215. BigDecimal newRecFee = recFeeBig.add(feePrice);
  216. //应收
  217. billDto.setReceivable(newRecFee.doubleValue() + "");
  218. //当期应收
  219. double curRecFee = StringUtil.isEmpty(billDto.getCurReceivable()) ? 0.0 : Double.parseDouble(billDto.getCurReceivable());
  220. BigDecimal curRecFeeBig = new BigDecimal(curRecFee);
  221. BigDecimal curNewRecFee = curRecFeeBig.add(curFeePrice);
  222. billDto.setCurReceivable(curNewRecFee.doubleValue() + "");
  223. FeeDetailDto feeDetailDto = new FeeDetailDto();
  224. feeDetailDto.setFeeId(feeDto.getFeeId());
  225. feeDetailDto.setCommunityId(feeDto.getCommunityId());
  226. feeDetailDto.setStartTime(startTime);
  227. feeDetailDto.setEndTime(billEndTime);
  228. List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
  229. double curReceiptFee = StringUtil.isEmpty(billDto.getReceipts()) ? 0.0 : Double.parseDouble(billDto.getReceipts());
  230. BigDecimal curReceipts = new BigDecimal(curReceiptFee);
  231. if (feeDetailDtos != null && feeDetailDtos.size() > 0) {
  232. for (FeeDetailDto tmpFeeDetailDto : feeDetailDtos) {
  233. BigDecimal recAmount = new BigDecimal(Double.parseDouble(tmpFeeDetailDto.getReceivedAmount()));
  234. curReceipts = recAmount.add(curReceipts);
  235. }
  236. }
  237. billDto.setReceipts(curReceipts.doubleValue() + "");
  238. }
  239. /**
  240. * 查询车位信息
  241. *
  242. * @param billOweFeeDto
  243. * @param feeDto
  244. */
  245. private void getParkingSpaceInfo(BillOweFeeDto billOweFeeDto, FeeDto feeDto) {
  246. ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
  247. parkingSpaceDto.setPsId(feeDto.getPayerObjId());
  248. parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
  249. List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
  250. if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) {
  251. //车位可能被删除了
  252. billOweFeeDto.setOwnerId("1");
  253. billOweFeeDto.setOwnerName("未知");
  254. billOweFeeDto.setOwnerTel("19999999999");
  255. billOweFeeDto.setPayerObjName("未知");
  256. return;
  257. }
  258. billOweFeeDto.setPayerObjName(parkingSpaceDtos.get(0).getAreaNum() + "停车场" + parkingSpaceDtos.get(0).getNum() + "车位");
  259. OwnerCarDto ownerCarDto = new OwnerCarDto();
  260. ownerCarDto.setWithOwner(true);
  261. ownerCarDto.setPsId(parkingSpaceDtos.get(0).getPsId());
  262. ownerCarDto.setCommunityId(feeDto.getCommunityId());
  263. List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
  264. if (ownerCarDtos == null || ownerCarDtos.size() < 1) {
  265. //房屋可能被删除了
  266. billOweFeeDto.setOwnerId("1");
  267. billOweFeeDto.setOwnerName("未知");
  268. billOweFeeDto.setOwnerTel("19999999999");
  269. return;
  270. }
  271. billOweFeeDto.setOwnerId(ownerCarDtos.get(0).getOwnerId());
  272. billOweFeeDto.setOwnerName(ownerCarDtos.get(0).getOwnerName());
  273. billOweFeeDto.setOwnerTel(ownerCarDtos.get(0).getLink());
  274. }
  275. /**
  276. * 查询房屋信息
  277. *
  278. * @param billOweFeeDto
  279. * @param feeDto
  280. */
  281. private void getRoomInfo(BillOweFeeDto billOweFeeDto, FeeDto feeDto) {
  282. RoomDto roomDto = new RoomDto();
  283. roomDto.setRoomId(feeDto.getPayerObjId());
  284. roomDto.setCommunityId(feeDto.getCommunityId());
  285. List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
  286. if (roomDtos == null || roomDtos.size() < 1) {
  287. //房屋可能被删除了
  288. billOweFeeDto.setOweId("1");
  289. billOweFeeDto.setOwnerName("未知");
  290. billOweFeeDto.setOwnerTel("19999999999");
  291. billOweFeeDto.setPayerObjName("未知");
  292. return;
  293. }
  294. RoomDto tmpRoomDto = roomDtos.get(0);
  295. //billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
  296. if (RoomDto.ROOM_TYPE_ROOM.equals(tmpRoomDto.getRoomType())) {
  297. billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
  298. } else {
  299. billOweFeeDto.setPayerObjName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getRoomNum() + "室");
  300. }
  301. OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
  302. ownerRoomRelDto.setByOwnerInfo(true);
  303. ownerRoomRelDto.setRoomId(tmpRoomDto.getRoomId());
  304. List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
  305. if (ownerRoomRelDtos == null || ownerRoomRelDtos.size() < 1) {
  306. //房屋可能被删除了
  307. billOweFeeDto.setOweId("1");
  308. billOweFeeDto.setOwnerName("未知");
  309. billOweFeeDto.setOwnerTel("19999999999");
  310. return;
  311. }
  312. billOweFeeDto.setOwnerId(ownerRoomRelDtos.get(0).getOwnerId());
  313. billOweFeeDto.setOwnerName(ownerRoomRelDtos.get(0).getOwnerName());
  314. billOweFeeDto.setOwnerTel(ownerRoomRelDtos.get(0).getLink());
  315. }
  316. private Date getDefaultStartTime(String billType) {
  317. Calendar calendar = Calendar.getInstance();
  318. calendar.setTime(new Date());
  319. if (billType.equals(TASK_ATTR_VALUE_MONTH)) {
  320. calendar.add(Calendar.MONTH, -1);
  321. return calendar.getTime();
  322. }
  323. if (billType.equals(TASK_ATTR_VALUE_DAY)) {
  324. calendar.add(Calendar.DATE, -1);
  325. return calendar.getTime();
  326. }
  327. if (billType.equals(TASK_ATTR_VALUE_DAY)) {
  328. calendar.add(Calendar.DATE, -1);
  329. return calendar.getTime();
  330. }
  331. if (billType.equals(TASK_ATTR_VALUE_YEAR)) {
  332. calendar.add(Calendar.YEAR, -1);
  333. return calendar.getTime();
  334. }
  335. return calendar.getTime();
  336. }
  337. /**
  338. * 根据房屋来算单价
  339. *
  340. * @param feeDto
  341. */
  342. private void computeFeePriceByRoom(FeeDto feeDto) {
  343. RoomDto roomDto = new RoomDto();
  344. roomDto.setCommunityId(feeDto.getCommunityId());
  345. roomDto.setRoomId(feeDto.getPayerObjId());
  346. List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
  347. if (roomDtos == null || roomDtos.size() < 1) { //数据有问题
  348. return;
  349. }
  350. String computingFormula = feeDto.getComputingFormula();
  351. double feePrice = 0.00;
  352. if ("1001".equals(computingFormula)) { //面积*单价+附加费
  353. BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
  354. BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDtos.get(0).getBuiltUpArea()));
  355. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
  356. feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  357. } else if ("2002".equals(computingFormula)) { // 固定费用
  358. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
  359. feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  360. } else if ("3003".equals(computingFormula)) { // 固定费用
  361. BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
  362. BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDto.getRoomArea()));
  363. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
  364. feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  365. } else if ("1101".equals(computingFormula)) { // 租金
  366. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(roomDto.getRoomRent()));
  367. feePrice = additionalAmount.setScale(3, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  368. } else {
  369. feePrice = -1.00;
  370. }
  371. feeDto.setFeePrice(feePrice);
  372. //查询业主信息
  373. }
  374. /**
  375. * 根据车位来算单价
  376. *
  377. * @param feeDto
  378. */
  379. private void computeFeePriceByParkingSpace(FeeDto feeDto) {
  380. ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
  381. parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
  382. parkingSpaceDto.setPsId(feeDto.getPayerObjId());
  383. List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
  384. if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //数据有问题
  385. return;
  386. }
  387. String computingFormula = feeDto.getComputingFormula();
  388. double feePrice = 0.00;
  389. if ("1001".equals(computingFormula)) { //面积*单价+附加费
  390. BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
  391. BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(parkingSpaceDtos.get(0).getArea()));
  392. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
  393. feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  394. } else if ("2002".equals(computingFormula)) { // 固定费用
  395. BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
  396. feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
  397. } else if ("3003".equals(computingFormula)) { // 固定费用
  398. feePrice = 0;
  399. } else if ("1101".equals(computingFormula)) { // 租金
  400. feePrice = 0;
  401. } else {
  402. feePrice = -1.00;
  403. }
  404. feeDto.setFeePrice(feePrice);
  405. }
  406. /**
  407. * 计算2个日期之间相差的 以年、月、日为单位,各自计算结果是多少
  408. * 比如:2011-02-02 到 2017-03-02
  409. * 以年为单位相差为:6年
  410. * 以月为单位相差为:73个月
  411. * 以日为单位相差为:2220天
  412. *
  413. * @param fromDate
  414. * @param toDate
  415. * @return
  416. */
  417. public static int monthCompare(Date fromDate, Date toDate) {
  418. Calendar from = Calendar.getInstance();
  419. from.setTime(fromDate);
  420. Calendar to = Calendar.getInstance();
  421. to.setTime(toDate);
  422. //只要年月
  423. int fromYear = from.get(Calendar.YEAR);
  424. int fromMonth = from.get(Calendar.MONTH);
  425. int toYear = to.get(Calendar.YEAR);
  426. int toMonth = to.get(Calendar.MONTH);
  427. int month = toYear * 12 + toMonth - (fromYear * 12 + fromMonth);
  428. return month;
  429. }
  430. /**
  431. * 计算2个日期之间相差的 以年、月、日为单位,各自计算结果是多少
  432. * 比如:2011-02-02 到 2017-03-02
  433. * 以年为单位相差为:6年
  434. * 以月为单位相差为:73个月
  435. * 以日为单位相差为:2220天
  436. *
  437. * @param fromDate
  438. * @param toDate
  439. * @return
  440. */
  441. public static double dayCompare(Date fromDate, Date toDate) {
  442. Calendar from = Calendar.getInstance();
  443. from.setTime(fromDate);
  444. Calendar to = Calendar.getInstance();
  445. to.setTime(toDate);
  446. long t1 = from.getTimeInMillis();
  447. long t2 = to.getTimeInMillis();
  448. double days = (t2 - t1) * 1.00 / (24 * 60 * 60 * 1000);
  449. BigDecimal tmpDays = new BigDecimal(days);
  450. BigDecimal monthDay = new BigDecimal(30);
  451. return tmpDays.divide(monthDay, 2, RoundingMode.HALF_UP).doubleValue();
  452. }
  453. }