RentalProjectService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. package platform.modules.carrier.service;
  2. import com.feilong.core.util.CollectionsUtil;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.core.env.Environment;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import org.springframework.util.CollectionUtils;
  10. import org.springframework.util.StringUtils;
  11. import platform.common.Constant;
  12. import platform.common.base.model.DictionaryItem;
  13. import platform.common.base.service.BaseService;
  14. import platform.common.base.service.DictionaryItemService;
  15. import platform.common.util.ShiroUtils;
  16. import platform.modules.build.entity.Company;
  17. import platform.modules.build.service.CompanyContactService;
  18. import platform.modules.build.service.CompanyService;
  19. import platform.modules.carrier.dao.RentalProjectCompanyDao;
  20. import platform.modules.carrier.dao.RentalProjectDao;
  21. import platform.modules.carrier.dto.*;
  22. import platform.modules.carrier.entity.Park;
  23. import platform.modules.carrier.entity.RentalProject;
  24. import platform.modules.carrier.entity.RentalProjectCompany;
  25. import platform.modules.government.dao.AttachmentDao;
  26. import platform.modules.government.entity.Attachment;
  27. import platform.modules.government.entity.FileDown;
  28. import platform.modules.government.entity.Street;
  29. import platform.modules.government.entity.User;
  30. import platform.modules.government.service.AttachmentService;
  31. import platform.modules.government.service.StreetService;
  32. import platform.modules.government.service.UserService;
  33. import javax.servlet.http.HttpServletRequest;
  34. import java.util.*;
  35. @Service
  36. @Transactional
  37. public class RentalProjectService extends BaseService<RentalProject> {
  38. @Autowired
  39. private RentalProjectDao rentalProjectDao;
  40. @Autowired
  41. private DictionaryItemService dictionaryItemService;
  42. @Autowired
  43. private StreetService streetService;
  44. @Autowired
  45. private UserService userService;
  46. @Autowired
  47. private CompanyService companyService;
  48. @Autowired
  49. private CompanyContactService companyContactService;
  50. @Autowired
  51. private AttachmentService attachmentService;
  52. @Autowired
  53. private RentalProjectCompanyService rentalProjectCompanyService;
  54. //保存
  55. public int create(RentalProject rentalProject) {
  56. rentalProject.setStatus(1);
  57. int i = this.insertAndGetId(rentalProject);
  58. //项目主图
  59. if (isMainPicture(rentalProject.getMain_pic())){
  60. Attachment attachment = attachmentService.findById(rentalProject.getMain_pic().getFile_id());
  61. if (attachment != null){
  62. attachmentService.updateAttachment(Constant.Attachment.RENTAL_MAIN_PIC, i, rentalProject.getMain_pic().getFile_id());
  63. }
  64. }
  65. //相关资质文件
  66. List<FileDown> fileDownList = rentalProject.getFileDownList();
  67. attachmentService.deleteByBusiness(Constant.Attachment.RENTAL, rentalProject.getId());
  68. if (!CollectionUtils.isEmpty(fileDownList)) {
  69. for (FileDown fileDown : fileDownList) {
  70. attachmentService.updateAttachment(Constant.Attachment.RENTAL, rentalProject.getId(), fileDown.getFile_id());
  71. }
  72. }
  73. //街道代办企业
  74. if (rentalProject.getRentalProjectCompany() != null){
  75. RentalProjectCompany company =rentalProject.getRentalProjectCompany();
  76. company.setRental_id(i);
  77. rentalProjectCompanyService.insertAndGetId(company);
  78. }
  79. //给所有街道园区发送信息
  80. saveMessage(rentalProject);
  81. return i;
  82. }
  83. private boolean isMainPicture(FileDown main_pic) {
  84. return main_pic != null && main_pic.getFile_id() != null;
  85. }
  86. /**
  87. * 发送消息
  88. * @param rentalProject
  89. */
  90. private void saveMessage(RentalProject rentalProject) {
  91. }
  92. //修改
  93. public int modify(RentalProject rentalProject) {
  94. int i = this.updateSelective(rentalProject);
  95. attachmentService.deleteByBusiness(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId());
  96. if (isMainPicture(rentalProject.getMain_pic())){
  97. Attachment attachment = attachmentService.findById(rentalProject.getMain_pic().getFile_id());
  98. if (isChangePic(attachment)){
  99. attachmentService.updateAttachment(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(),
  100. rentalProject.getMain_pic().getFile_id());
  101. }
  102. }
  103. List<FileDown> fileDownList = rentalProject.getFileDownList();
  104. attachmentService.deleteByBusiness(Constant.Attachment.RENTAL, rentalProject.getId());
  105. if (!CollectionUtils.isEmpty(fileDownList)) {
  106. for (FileDown fileDown : fileDownList) {
  107. attachmentService.updateAttachment(Constant.Attachment.RENTAL, rentalProject.getId(), fileDown.getFile_id());
  108. }
  109. }
  110. //街道代办企业
  111. if (rentalProject.getRentalProjectCompany() != null){
  112. int companyId = rentalProjectCompanyService.findByRentalId(rentalProject.getId()).getId();
  113. RentalProjectCompany company = rentalProject.getRentalProjectCompany();
  114. company.setId(companyId);
  115. rentalProjectCompanyService.updateSelective(company);
  116. }
  117. return i;
  118. }
  119. private boolean isChangePic(Attachment attachment) {
  120. return attachment == null || attachment.getBusiness_id() == null;
  121. }
  122. //获取详情
  123. public RentalProject getById(Integer id) {
  124. RentalProject rentalProject = this.findById(id);
  125. int i = rentalProject.getRead_count() == null ? 0 : rentalProject.getRead_count();
  126. rentalProject.setRead_count(i + 1);
  127. this.update(rentalProject);
  128. if (rentalProject.getIntention_street() != null) {
  129. Street street = streetService.selectById(rentalProject.getIntention_street());
  130. rentalProject.setIntention_street_desc(street.getName());
  131. }
  132. if (rentalProject.getDemand() != null) {
  133. rentalProject.setDemand_desc(
  134. dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.DEMAND, rentalProject.getDemand().toString()).getName()
  135. );
  136. }
  137. User user = userService.getUser(rentalProject.getCreate_by());
  138. if (user != null) {
  139. Company company = companyService.getCompanyInfo(user.getCompany_id());
  140. if (null != company) {
  141. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  142. }
  143. if (Objects.equals(company.getIndustry_code(), "Empty")) {
  144. company.setIndustry_code(company.getIndustry_name());
  145. } else {
  146. company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
  147. }
  148. rentalProject.setCompany(company);
  149. }
  150. //获取街道代办的企业信息
  151. RentalProjectCompany rentalProjectCompany = rentalProjectCompanyService.findByRentalId(rentalProject.getId());
  152. rentalProject.setRentalProjectCompany(rentalProjectCompany);
  153. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL, id, null);
  154. List<FileDown> fileDowns = new ArrayList<>();
  155. if (null != attachments && attachments.size() > 0) {
  156. for (Attachment attachment : attachments) {
  157. FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri());
  158. fileDowns.add(fileDown);
  159. }
  160. }
  161. rentalProject.setFileDownList(fileDowns);
  162. //获取主图
  163. List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, id, null);
  164. if (mainPic.size() > 0) {
  165. FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), mainPic.get(0).getDownload_uri());
  166. rentalProject.setMain_pic(fileDown);
  167. }
  168. return rentalProject;
  169. }
  170. //我的分页
  171. @Transactional(readOnly = true)
  172. public PageInfo<RentalProject> findMyList(Integer pageNum, Integer pageSize, CustomSearchCondition param) throws Exception {
  173. PageHelper.startPage(pageNum, pageSize);
  174. List<RentalProject> list = rentalProjectDao.findListByCreater(param, ShiroUtils.getUserId());
  175. List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
  176. for (RentalProject rentalProject : list) {
  177. if (null != typeList && typeList.size() > 0) {
  178. for (DictionaryItem dictionaryItem : typeList) {
  179. if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
  180. rentalProject.setDemand_desc(dictionaryItem.getName());
  181. }
  182. }
  183. }
  184. if (!Objects.isNull(rentalProject.getIntention_street())) {
  185. rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
  186. }
  187. User user = userService.getUser(rentalProject.getCreate_by());
  188. if (user != null) {
  189. Company company = companyService.getCompanyInfo(user.getCompany_id());
  190. if (null != company) {
  191. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  192. }
  193. if (Objects.equals(company.getIndustry_code(), "Empty")) {
  194. company.setIndustry_code(company.getIndustry_name());
  195. } else {
  196. company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
  197. }
  198. rentalProject.setCompany_name(company.getCompany_name());
  199. rentalProject.setIndustry_name(company.getIndustry_name());
  200. }
  201. if (rentalProject.getStatus() == 1) {
  202. rentalProject.setStatus_desc("已上架");
  203. } else if (rentalProject.getStatus() == 0) {
  204. rentalProject.setStatus_desc("已下架");
  205. }
  206. //获取主图
  207. List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(), null);
  208. if (mainPic.size() > 0) {
  209. FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), param.getFile_url());
  210. rentalProject.setMain_pic(fileDown);
  211. }
  212. }
  213. return new PageInfo<>(list);
  214. }
  215. //我的分页
  216. @Transactional(readOnly = true)
  217. public PageInfo<RentalProject> findMyList(Integer userId, CustomSearchCondition param) throws Exception {
  218. PageHelper.startPage(param.getPageNum(), param.getPageSize());
  219. List<RentalProject> list = rentalProjectDao.findListByCreater(param, userId);
  220. List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
  221. for (RentalProject rentalProject : list) {
  222. if (null != typeList && typeList.size() > 0) {
  223. for (DictionaryItem dictionaryItem : typeList) {
  224. if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
  225. rentalProject.setDemand_desc(dictionaryItem.getName());
  226. }
  227. }
  228. }
  229. if (!Objects.isNull(rentalProject.getIntention_street())) {
  230. rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
  231. }
  232. User user = userService.getUser(rentalProject.getCreate_by());
  233. if (user != null) {
  234. Company company = companyService.getCompanyInfo(user.getCompany_id());
  235. if (null != company) {
  236. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  237. }
  238. if (Objects.equals(company.getIndustry_code(), "Empty")) {
  239. company.setIndustry_code(company.getIndustry_name());
  240. } else {
  241. company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
  242. }
  243. rentalProject.setCompany_name(company.getCompany_name());
  244. rentalProject.setIndustry_name(company.getIndustry_name());
  245. }
  246. if (rentalProject.getStatus() == 1) {
  247. rentalProject.setStatus_desc("已上架");
  248. } else if (rentalProject.getStatus() == 0) {
  249. rentalProject.setStatus_desc("已下架");
  250. }
  251. //获取主图
  252. List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(), null);
  253. if (mainPic.size() > 0) {
  254. FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), param.getFile_url());
  255. rentalProject.setMain_pic(fileDown);
  256. }
  257. }
  258. return new PageInfo<>(list);
  259. }
  260. //前台分页
  261. @Transactional(readOnly = true)
  262. public PageInfo<RentalProject> findList(Integer pageNum, Integer pageSize, CustomSearchCondition param) throws Exception {
  263. PageHelper.startPage(pageNum, pageSize);
  264. List<RentalProject> list = rentalProjectDao.findList(param);
  265. List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
  266. for (RentalProject rentalProject : list) {
  267. if (null != typeList && typeList.size() > 0) {
  268. for (DictionaryItem dictionaryItem : typeList) {
  269. if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
  270. rentalProject.setDemand_desc(dictionaryItem.getName());
  271. }
  272. }
  273. }
  274. if (!Objects.isNull(rentalProject.getIntention_street())) {
  275. rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
  276. }
  277. User user = userService.getUser(rentalProject.getCreate_by());
  278. if (user != null) {
  279. Company company = companyService.getCompanyInfo(user.getCompany_id());
  280. if (null != company) {
  281. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  282. }
  283. if (Objects.equals(company.getIndustry_code(), "Empty")) {
  284. company.setIndustry_code(company.getIndustry_name());
  285. } else {
  286. company.setIndustry_name(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
  287. }
  288. rentalProject.setCompany_name(company.getCompany_name());
  289. rentalProject.setIndustry_name(company.getIndustry_name());
  290. }
  291. //获取街道代办的企业信息
  292. RentalProjectCompany rentalProjectCompany = rentalProjectCompanyService.findByRentalId(rentalProject.getId());
  293. if (rentalProjectCompany != null && rentalProjectCompany.getType() != null){
  294. DictionaryItem item = dictionaryItemService.findByItemId(rentalProjectCompany.getType());
  295. if (item != null){
  296. rentalProjectCompany.setType_desc(item.getName());
  297. }
  298. }
  299. rentalProject.setRentalProjectCompany(rentalProjectCompany);
  300. }
  301. return new PageInfo<>(list);
  302. }
  303. //获取登录人所在企业信息
  304. public Company getCompanyInfoByCurrentUser() {
  305. Company company = companyService.getCompanyInfo(ShiroUtils.getCompanyId());
  306. if (null != company) {
  307. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  308. }
  309. if (Objects.equals(company.getIndustry_code(), "Empty")) {
  310. company.setIndustry_code(company.getIndustry_name());
  311. } else {
  312. company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
  313. }
  314. return company;
  315. }
  316. /**
  317. * 批量删除
  318. *
  319. * @param ids
  320. */
  321. public void batchDelete(List<Integer> ids) {
  322. if (ids != null && ids.size() > 0) {
  323. for (Integer id : ids) {
  324. RentalProject rentalProject = new RentalProject();
  325. rentalProject.setId(id);
  326. rentalProject.setDel_flag(true);
  327. updateSelective(rentalProject);
  328. }
  329. }
  330. }
  331. public void updateStatusBatch(List<String> ids, String status) {
  332. rentalProjectDao.updateStatusBatch(ids, status);
  333. }
  334. public DrillInfoVo getInfoForDrill(CustomSearchCondition param) {
  335. DrillInfoVo drillInfoVo = new DrillInfoVo();
  336. List<RentalProject> list = rentalProjectDao.findList(param);
  337. Map<String, String> streetMap = new HashMap<>();
  338. for (RentalProject rentalProject : list) {
  339. if (!org.springframework.util.StringUtils.isEmpty(rentalProject.getIntention_street())) {
  340. streetMap.put(rentalProject.getStreet_id(), rentalProject.getStreet_name());
  341. }
  342. }
  343. List<StreetVo> streetVos = new ArrayList<>();
  344. Iterator<Map.Entry<String, String>> streetIiterator = streetMap.entrySet().iterator();
  345. while (streetIiterator.hasNext()) {
  346. Map.Entry<String, String> streetEntry = streetIiterator.next();
  347. StreetVo streetVo = new StreetVo();
  348. streetVo.setId(streetEntry.getKey());
  349. Street street = streetService.findById(Integer.parseInt(streetEntry.getKey()));
  350. if (street != null) {
  351. streetVo.setNo(street.getNo());
  352. }
  353. streetVo.setRegion(streetEntry.getValue());
  354. int streetCount = 0;
  355. List<DistrictVo> districtVos = new ArrayList<>();
  356. Map<String, String> parkMap = new HashMap<>();
  357. for (RentalProject rentalProject : list) {
  358. if (Objects.equals(rentalProject.getStreet_id(), streetEntry.getKey())) {
  359. streetCount++;
  360. }
  361. }
  362. streetVo.setPlates(districtVos);
  363. streetVo.setSum(streetCount);
  364. streetVos.add(streetVo);
  365. }
  366. drillInfoVo.setPlate(streetVos);
  367. return drillInfoVo;
  368. }
  369. public OutlineResultVo getInfoForSide(CustomSearchCondition param) {
  370. OutlineResultVo outlineResultVo = new OutlineResultVo();
  371. List<RentalProject> list = rentalProjectDao.findList(param);
  372. List<OutlineVo> outlineVos = new ArrayList<>();
  373. for (RentalProject rentalProject : list) {
  374. OutlineVo outlineVo = new OutlineVo();
  375. outlineVo.setId(rentalProject.getStreet_id());
  376. /*if (!StringUtils.isEmpty(rentalProject.getMain_picture_file())) {
  377. outlineVo.setImg(this.setFileUrl() + rentalProject.getMain_picture_file());
  378. }*/
  379. Street street = streetService.findById(Integer.parseInt(rentalProject.getStreet_id()));
  380. if (street != null) {
  381. outlineVo.setNo(street.getNo());
  382. }
  383. outlineVo.setTitle(rentalProject.getProject_name());
  384. outlineVo.setStreetName(rentalProject.getStreet_name());
  385. //outlineVo.setLocal(rentalProject.getLocation());
  386. outlineVo.setArea(rentalProject.getDemand_area() + "");
  387. outlineVo.setPrice(rentalProject.getDemand_price() + "");
  388. outlineVo.setDetailUrl(this.setFileUrl() + "/front/home/index.html#/projectDetail?id=" + rentalProject.getId());
  389. outlineVos.add(outlineVo);
  390. }
  391. outlineResultVo.setListData(outlineVos);
  392. return outlineResultVo;
  393. }
  394. @Autowired
  395. private Environment environment;
  396. @Autowired
  397. private HttpServletRequest request;
  398. protected static final String COMPANY_REPORT_ADD = "/government/companyReport/add";
  399. protected static final String OUT_HOME = "/home";
  400. public String setFileUrl() {
  401. //外网
  402. if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
  403. if (!request.getServletPath().contains(OUT_HOME) && !request.getServletPath().contains(COMPANY_REPORT_ADD)) {
  404. return environment.getProperty("fileOutUrl");
  405. }
  406. }
  407. return environment.getProperty("fileUrl");
  408. }
  409. }