WzHouseContracServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package com.example.service.impl;
  2. import com.example.dao.WzHouseContracDao;
  3. import com.example.entity.OtnAreaEntity;
  4. import com.example.entity.WzHouseContracEntity;
  5. import com.example.service.WzHouseContracService;
  6. import com.example.service.WzOtnAreaService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import java.text.DecimalFormat;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. @Service
  15. public class WzHouseContracServiceImpl implements WzHouseContracService {
  16. @Autowired
  17. private WzOtnAreaService otnAreaService;
  18. @Autowired
  19. private WzHouseContracDao wzHouseContracDao;
  20. @Override
  21. public List<WzHouseContracEntity> queryList(Map<String, Object> map) {
  22. dealMap(map);
  23. return wzHouseContracDao.queryList(map);
  24. }
  25. //综合评价
  26. public List<WzHouseContracEntity> dealHouseContracList(Map<String, Object> map){
  27. dealMap(map);
  28. List<WzHouseContracEntity> wzHouseContracEntityList= wzHouseContracDao.queryList(map);
  29. Map<String,List<WzHouseContracEntity>> cityMap=new HashMap<>();
  30. for (WzHouseContracEntity leaveUseVo : wzHouseContracEntityList) {
  31. List<WzHouseContracEntity> list;
  32. if(cityMap.get(leaveUseVo.getCity())!=null){
  33. list=cityMap.get(leaveUseVo.getCity());
  34. list.add(leaveUseVo);
  35. }else{
  36. list=new ArrayList<>();
  37. list.add(leaveUseVo);
  38. }
  39. cityMap.put(leaveUseVo.getCity(),list);
  40. }
  41. List<WzHouseContracEntity> resultList=new ArrayList<>();
  42. List<WzHouseContracEntity> cityList=new ArrayList<>();
  43. double allContractQuantity=0l;
  44. double allarrearsQuantity=0l;
  45. double allNoTaxContractAmount=0l;
  46. double allRentArea=0l;
  47. double allUnitPricePerSquareMeter=0l;
  48. int cityNum=0;
  49. for(Map.Entry<String,List<WzHouseContracEntity>> entry:cityMap.entrySet()){
  50. List<WzHouseContracEntity> list=entry.getValue();
  51. if (list.get(0).getCounty().equals("全省")) {
  52. continue;
  53. }
  54. //县的Map集合
  55. Map<String, List<WzHouseContracEntity>> countyMap = new HashMap<>();
  56. for (WzHouseContracEntity leaveUseVo : list) {
  57. if (leaveUseVo.getCounty() == null || leaveUseVo.getCounty().equals("")) {
  58. continue;
  59. }
  60. if (countyMap.get(leaveUseVo.getCounty()) != null) {
  61. list = countyMap.get(leaveUseVo.getCounty());
  62. list.add(leaveUseVo);
  63. } else {
  64. list = new ArrayList<>();
  65. list.add(leaveUseVo);
  66. }
  67. countyMap.put(leaveUseVo.getCounty(), list);
  68. }
  69. double cityContractQuantity=0l;
  70. double cityarrearsQuantity=0l;
  71. double cityNoTaxContractAmount=0l;
  72. double cityRentArea=0l;
  73. double cityUnitPricePerSquareMeter=0l;
  74. List<WzHouseContracEntity> countyList=new ArrayList<>();
  75. for (Map.Entry<String, List<WzHouseContracEntity>> countyEntry : countyMap.entrySet()) {
  76. double contractQuantity=0l;
  77. double noTaxContractAmount=0l;
  78. double rentArea=0l;
  79. double unitPricePerSquareMeter=0l;
  80. double arrearsQuantity=0l;
  81. for (WzHouseContracEntity leaveUseVo : countyEntry.getValue()) {
  82. contractQuantity+=leaveUseVo.getContractQuantity();
  83. arrearsQuantity+=leaveUseVo.getArrearsQuantity();
  84. noTaxContractAmount+=leaveUseVo.getNoTaxContractAmount();
  85. rentArea+=leaveUseVo.getRentArea();
  86. unitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter();
  87. cityContractQuantity+=leaveUseVo.getContractQuantity();
  88. cityarrearsQuantity+=leaveUseVo.getArrearsQuantity();
  89. cityNoTaxContractAmount+=leaveUseVo.getNoTaxContractAmount();
  90. cityRentArea+=leaveUseVo.getRentArea();
  91. cityUnitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter();
  92. allContractQuantity+=leaveUseVo.getContractQuantity();
  93. allarrearsQuantity+=leaveUseVo.getArrearsQuantity();
  94. allNoTaxContractAmount+=leaveUseVo.getNoTaxContractAmount();
  95. allRentArea+=leaveUseVo.getRentArea();
  96. allUnitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter();
  97. }
  98. double average=0l;
  99. if(contractQuantity==0){
  100. average=0;
  101. }else{
  102. average=arrearsQuantity/contractQuantity;
  103. average=formatDouble(average);
  104. }
  105. WzHouseContracEntity wzHouseInCustomerEntity = new WzHouseContracEntity();
  106. wzHouseInCustomerEntity.setAverage(formatDouble1(average*100));
  107. wzHouseInCustomerEntity.setContractQuantity(formatDouble(contractQuantity));
  108. wzHouseInCustomerEntity.setCity(countyEntry.getKey());
  109. wzHouseInCustomerEntity.setNoTaxContractAmount(formatDouble(noTaxContractAmount));
  110. wzHouseInCustomerEntity.setRentArea(formatDouble(rentArea));
  111. wzHouseInCustomerEntity.setUnitPricePerSquareMeter(formatDouble(unitPricePerSquareMeter));
  112. countyList.add(wzHouseInCustomerEntity);
  113. }
  114. List<WzHouseContracEntity> orderCountyList=new ArrayList<>();
  115. try{
  116. //对countList 进行排序
  117. String city=list.get(0).getCity();
  118. if(city.contains("市")){
  119. city=city.split("市")[0];
  120. }
  121. OtnAreaEntity area=otnAreaService.queryObject(city);
  122. List<OtnAreaEntity> countyAreaList=otnAreaService.getCityOption(area.getId());
  123. int i=0;
  124. for (OtnAreaEntity otnAreaEntity : countyAreaList) {
  125. for (WzHouseContracEntity wzCity : countyList) {
  126. if(wzCity.getCity().contains(otnAreaEntity.getName())){
  127. i++;
  128. wzCity.setFlag(i%2==0);
  129. orderCountyList.add(wzCity);
  130. }
  131. }
  132. }
  133. }catch (Exception e){
  134. orderCountyList=countyList;
  135. e.printStackTrace();
  136. }
  137. WzHouseContracEntity wzHouseInCustomerEntity = new WzHouseContracEntity();
  138. wzHouseInCustomerEntity.setCity(entry.getKey());
  139. wzHouseInCustomerEntity.setContractQuantity(formatDouble(cityContractQuantity));
  140. wzHouseInCustomerEntity.setNoTaxContractAmount(formatDouble(cityNoTaxContractAmount));
  141. wzHouseInCustomerEntity.setRentArea(formatDouble(cityRentArea));
  142. double num=cityUnitPricePerSquareMeter/countyMap.size();
  143. cityNum+=countyMap.size();
  144. wzHouseInCustomerEntity.setUnitPricePerSquareMeter(formatDouble(num));
  145. //出租欠费率
  146. double average=0l;
  147. if(cityContractQuantity==0){
  148. average=0;
  149. }else{
  150. average=cityarrearsQuantity/cityContractQuantity;
  151. average=formatDouble(average);
  152. }
  153. wzHouseInCustomerEntity.setAverage(formatDouble1(average*100));
  154. wzHouseInCustomerEntity.setChildren(orderCountyList);
  155. cityList.add(wzHouseInCustomerEntity);
  156. }
  157. //对cityList 进行排序
  158. List<OtnAreaEntity> areaList=otnAreaService.getCityOption("018");
  159. List<WzHouseContracEntity> orderList=new ArrayList<>();
  160. int i=0;
  161. for (OtnAreaEntity otnAreaEntity : areaList) {
  162. for (WzHouseContracEntity wzCity : cityList) {
  163. if(wzCity.getCity().contains(otnAreaEntity.getName())){
  164. wzCity.setFlag(i%2==0);
  165. orderList.add(wzCity);
  166. i++;
  167. }
  168. }
  169. }
  170. WzHouseContracEntity province=new WzHouseContracEntity();
  171. //出租欠费率
  172. double average=0l;
  173. if(allContractQuantity==0){
  174. average=0;
  175. }else{
  176. average=allarrearsQuantity/allContractQuantity;
  177. average=formatDouble(average);
  178. }
  179. province.setAverage(formatDouble1(average*100));
  180. province.setCity("全省");
  181. province.setContractQuantity(formatDouble(allContractQuantity));
  182. province.setNoTaxContractAmount(formatDouble(allNoTaxContractAmount));
  183. province.setRentArea(formatDouble(allRentArea));
  184. if(cityList.size()!=0){
  185. province.setUnitPricePerSquareMeter(formatDouble(allUnitPricePerSquareMeter/cityNum ));
  186. }
  187. province.setChildren(orderList);
  188. if(orderList.size()>0){
  189. resultList.add(province);
  190. }
  191. return resultList;
  192. }
  193. @Override
  194. public int queryTotal(Map<String, Object> map) {
  195. dealMap(map);
  196. return wzHouseContracDao.queryTotal(map);
  197. }
  198. public void dealMap(Map<String, Object> map){
  199. if(map.get("city")!=null&&!map.get("city").toString().equals("全省")&&!map.get("city").toString().equals("")){
  200. OtnAreaEntity city = otnAreaService.queryObjectById(map.get("city").toString());
  201. map.put("city",city.getName());
  202. }
  203. if(map.get("city")!=null&&map.get("city").toString().equals("全省")){
  204. map.remove("city");
  205. }
  206. if(map.get("city")!=null&&map.get("city").toString().equals("")){
  207. map.remove("city");
  208. }
  209. if(map.get("county")!=null&&!map.get("county").toString().equals("区县")&&!map.get("county").toString().equals("")){
  210. OtnAreaEntity city = otnAreaService.queryObjectById(map.get("county").toString());
  211. map.put("county",city.getName());
  212. }
  213. if(map.get("county")!=null&&map.get("county").toString().equals("区县")){
  214. map.remove("county");
  215. }
  216. if(map.get("county")!=null&&map.get("county").toString().equals("")){
  217. map.remove("county");
  218. }
  219. if(map.get("statisticalMonth")!=null&&!map.get("statisticalMonth").toString().equals("")&&!map.get("statisticalMonth").toString().equals("账期")){
  220. map.put("statisticalMonth",Integer.valueOf(map.get("statisticalMonth").toString()));
  221. }else{
  222. map.remove("statisticalMonth");
  223. }
  224. }
  225. public double formatDouble(double num){
  226. double avera=0l;
  227. try{
  228. DecimalFormat format2 = new DecimalFormat("#.0000");
  229. String str2 = format2.format(num);
  230. avera = Double.parseDouble(str2);
  231. }catch (Exception e){
  232. e.printStackTrace();
  233. }
  234. return avera;
  235. }
  236. public double formatDouble1(double num) {
  237. if (num == 0) return 0;
  238. DecimalFormat format2 = new DecimalFormat("#.00");
  239. String str2 = format2.format(num);
  240. double avera = Double.parseDouble(str2);
  241. return avera;
  242. }
  243. }