| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- package platform.modules.carrier.service;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import platform.common.Constant;
- import platform.common.base.model.DictionaryItem;
- import platform.common.base.service.BaseService;
- import platform.common.base.service.DictionaryItemService;
- import platform.common.util.Reflections;
- import platform.common.util.ShiroUtils;
- import platform.modules.carrier.dao.ParkDao;
- import platform.modules.carrier.dto.CarrierLibraryResult;
- import platform.modules.carrier.dto.CustomSearchCondition;
- import platform.modules.carrier.dto.ParkDto;
- import platform.modules.carrier.dto.SearchCondition;
- import platform.modules.carrier.entity.*;
- import platform.modules.government.entity.Attachment;
- import platform.modules.government.entity.Street;
- import platform.modules.government.entity.User;
- import platform.modules.government.service.AttachmentService;
- import platform.modules.government.service.StreetService;
- import platform.modules.sys.web.ResponseMessage;
- import tk.mybatis.mapper.entity.Example;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- /**
- * @author kevin
- * @since 2019/3/31 3:04 PM
- */
- @Service
- @Transactional
- public class ParkService extends BaseService<Park> {
- @Autowired
- private ParkDao parkDao;
- @Autowired
- private StreetService streetService;
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- private ParkAttachmentService parkAttachmentService;
- @Autowired
- private ParkSupportService parkSupportService;
- @Autowired
- private ParkSupportAttachmentService parkSupportAttachmentService;
- @Autowired
- private ParkTypicalCompanyService parkTypicalCompanyService;
- @Autowired
- private ParkTypicalCompanyAttachmentService parkTypicalCompanyAttachmentService;
- @Autowired
- private DictionaryItemService dictionaryItemService;
- @Autowired
- private CarrierStatisticService carrierStatisticService;
- @Autowired
- private BuildingService buildingService;
- @Autowired
- private ParkDraftService parkDraftService;
- /**
- * 通过组合条件查询工业小区,返回符合条件的id集合
- *
- * @param condition
- * @return
- */
- public List<Park> getParkListByCondition(SearchCondition condition) {
- return parkDao.getParkListByCondition(condition);
- }
- /**
- * 获取所有园区
- *
- * @param pageNum
- * @param pageSize
- * @return
- */
- public PageInfo<Park> findParkList(Integer pageNum, Integer pageSize, SearchCondition condition) {
- if (!condition.getIs_front()) {
- User user = ShiroUtils.getUserEntity();
- if (user.getUser_type() != null && user.getUser_type().equals(Constant.UserType.STREET)) {
- condition.setStreetId(user.getStreet_id());
- }
- if (user.getUser_type() != null && user.getUser_type().equals(Constant.UserType.BUILD)) {
- condition.setParkId(user.getBuild_id());
- }
- }
- PageHelper.startPage(pageNum, pageSize);
- List<Park> parkList = parkDao.findParkList(condition);
- for (Park park : parkList) {
- double sumBuildingArea = carrierStatisticService.getSumParkBuildingArea(park.getId());
- park.setSumBuildArea(sumBuildingArea);
- park.setFile_down_url(condition.getFileUrl());
- Attachment attachment = attachmentService.findMainPicture(park.getId());
- if (attachment != null) {
- park.setMain_pic_url(attachment.getFile_url());
- }
- Double sumRentArea = getParkRentAreaStatistic(park.getId());
- park.setSumRentArea(sumRentArea);
- if (park.getType() != null){
- park.setType_desc(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PARK_TYPE, park.getType().toString()));
- }
- }
- return new PageInfo<>(parkList);
- }
- /**
- * 获取小区信息
- *
- * @param id
- * @return
- */
- public Park parkDetailById(Integer id) {
- ParkDraft draft = parkDraftService.findById(id);
- if (draft != null){
- Park park = new Park();
- Reflections.copyFieldToBean(draft, park);
- park.setId(id);
- park.setStreetName(streetService.findById(park.getStreet_id()).getName());
- getParkDraftInfo(park);
- return park;
- }
- Park park = this.findById(id);
- if (park != null) {
- getParkInfo(park);
- park.setStreetName(streetService.findById(park.getStreet_id()).getName());
- }
- return park;
- }
- /**
- * 获取小区其他草稿信息
- *
- * @param park
- */
- private void getParkDraftInfo(Park park) {
- Street street = streetService.findById(park.getStreet_id());
- park.setStreetName(street.getName());
- if (park.getType() != null){
- park.setType_desc(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PARK_TYPE, park.getType().toString()));
- }
- //获取小区图片
- List<ParkAttachmentDraft> attachmentList = parkDraftService.findParkAttachmentDraftList(park.getId());
- List<FileDown> fileDownList = new ArrayList<>();
- for (ParkAttachmentDraft parkAtt : attachmentList) {
- Attachment attachment = attachmentService.findById(parkAtt.getAttachment_id());
- if (attachment != null) {
- FileDown fileDown = new FileDown();
- fileDown.setFile_id(attachment.getId());
- fileDown.setDownload_uri(attachment.getDownload_uri());
- fileDown.setFile_url(attachment.getFile_url());
- fileDown.setFile_name(attachment.getFile_name());
- fileDown.setIs_main(parkAtt.getIs_main());
- fileDownList.add(fileDown);
- }
- }
- park.setFileDowns(fileDownList);
- // 获取小区配套
- List<ParkSupport> supportList = new ArrayList<>();
- List<ParkSupportDraft> draftList = parkDraftService.findSupportDraftByParkId(park.getId());
- for (ParkSupportDraft draft : draftList) {
- ParkSupport support = new ParkSupport();
- Reflections.copyFieldToBean(draft, support);
- String attachmentType = Constant.Attachment.PARK_SUPPORT_DRAFT;
- List<Attachment> attachments =
- attachmentService.findListBySupport(draft.getId(), draft.getType(), attachmentType);
- support.setFileDowns(getFileDownList(attachments));
- //获取item
- DictionaryItem item = dictionaryItemService.
- findByTypeAndValue(Constant.DictionaryType.PARK_SUPPORT, draft.getType().toString());
- support.setType_desc(item.getName());
- supportList.add(support);
- }
- park.setSupportList(supportList);
- //获取典型企业
- List<ParkTypicalCompany> companyList = new ArrayList<>();
- List<ParkTypicalCompanyDraft> companyDraftList = parkDraftService.findTypicalCompanyDraft(park.getId());
- for (ParkTypicalCompanyDraft draft : companyDraftList) {
- ParkTypicalCompany company = new ParkTypicalCompany();
- Reflections.copyFieldToBean(draft, company);
- String attachmentType = Constant.Attachment.TYPICAL_COMPANY_DRAFT;
- List<Attachment> attachments =
- attachmentService.findListByTypicalCompany(draft.getId(), attachmentType);
- company.setFileDowns(getFileDownList(attachments));
- companyList.add(company);
- }
- park.setTypicalCompanyList(companyList);
- }
- /**
- * 获取小区信息
- *
- * @param id
- * @return
- */
- public Park frontParkDetailById(Integer id) {
- Park park = findById(id);
- if (park != null) {
- double sumBuildingArea = carrierStatisticService.getSumParkBuildingArea(id);
- park.setBuild_area(sumBuildingArea);
- park.setRest_area(findParkRemainArea(id));
- park.setBuild_num(parkDao.findBuildingNum(id));
- this.updateSelective(park);
- //获取其他信息
- getParkInfo(park);
- }
- return park;
- }
- /**
- * 获取园区剩余面积
- *
- * @param park_id
- */
- public Double findParkRemainArea(Integer park_id) {
- return parkDao.findParkRemainArea(park_id);
- }
- /**
- * 获取小区其他信息
- *
- * @param park
- */
- public void getParkInfo(Park park) {
- Street street = streetService.findById(park.getStreet_id());
- park.setStreetName(street.getName());
- if (park.getType() != null){
- park.setType_desc(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PARK_TYPE, park.getType().toString()));
- }
- //获取小区图片
- ParkAttachment parkAttachment = new ParkAttachment();
- parkAttachment.setPark_id(park.getId());
- List<ParkAttachment> attachmentList = parkAttachmentService.findListByWhere(parkAttachment);
- List<FileDown> fileDownList = new ArrayList<>();
- for (ParkAttachment parkAtt : attachmentList) {
- Attachment attachment = attachmentService.findById(parkAtt.getAttachment_id());
- if (attachment != null) {
- FileDown fileDown = new FileDown();
- fileDown.setFile_id(attachment.getId());
- fileDown.setDownload_uri(attachment.getDownload_uri());
- fileDown.setFile_url(attachment.getFile_url());
- fileDown.setFile_name(attachment.getFile_name());
- fileDown.setIs_main(parkAtt.getIs_main());
- fileDownList.add(fileDown);
- }
- }
- park.setFileDowns(fileDownList);
- // 获取小区配套
- ParkSupport support = new ParkSupport();
- support.setPark_id(park.getId());
- List<ParkSupport> supportList = parkSupportService.findListByWhere(support);
- if (supportList != null && supportList.size() > 0) {
- for (ParkSupport parkSupport : supportList) {
- String attachmentType = Constant.Attachment.PARK_SUPPORT;
- List<Attachment> attachments =
- attachmentService.findListBySupport(parkSupport.getId(), parkSupport.getType(), attachmentType);
- parkSupport.setFileDowns(getFileDownList(attachments));
- //获取item
- DictionaryItem item = dictionaryItemService.
- findByTypeAndValue(Constant.DictionaryType.PARK_SUPPORT, parkSupport.getType().toString());
- parkSupport.setType_desc(item.getName());
- }
- }
- park.setSupportList(supportList);
- //获取典型企业
- ParkTypicalCompany typicalCompany = new ParkTypicalCompany();
- typicalCompany.setPark_id(park.getId());
- List<ParkTypicalCompany> companyList = parkTypicalCompanyService.findListByWhere(typicalCompany);
- if (companyList != null && companyList.size() > 0) {
- for (ParkTypicalCompany company : companyList) {
- String attachmentType = Constant.Attachment.TYPICAL_COMPANY;
- List<Attachment> attachments =
- attachmentService.findListByTypicalCompany(company.getId(), attachmentType);
- company.setFileDowns(getFileDownList(attachments));
- }
- }
- park.setTypicalCompanyList(companyList);
- }
- /**
- * 编辑小区信息
- *
- * @param park
- */
- public void editParkInfo(Park park) {
- if (park.getId() != null) {
- // this.updateSelective(park);
- if (park.getIs_draft()){
- this.updateSelective(park);
- ParkDraft draft = parkDraftService.findById(park.getId());
- if (draft != null){
- parkDraftService.deleteById(draft.getId());
- }
- parkAttachmentService.deleteByParkId(park.getId());
- saveAttachment(park);
- //删除图片草稿
- deleteDraftAttachment(park);
- //配套信息
- parkSupportService.deleteParkSupport(park.getId());
- if (park.getSupportList() != null && park.getSupportList().size() > 0) {
- saveParkSupport(park.getSupportList(), park.getId());
- }
- //删除草稿中的园区配套及图片
- parkDraftService.deleteDraftSupport(park.getId());
- //典型企业
- ParkTypicalCompany typical = new ParkTypicalCompany();
- typical.setPark_id(park.getId());
- List<ParkTypicalCompany> typicalCompanys = parkTypicalCompanyService.findListByWhere(typical);
- for (ParkTypicalCompany company : typicalCompanys) {
- parkTypicalCompanyService.deleteById(company.getId());
- parkTypicalCompanyAttachmentService.deleteByTypicalCompanyId(company.getId());
- }
- if (park.getTypicalCompanyList() != null && park.getTypicalCompanyList().size() > 0) {
- saveparkTypicalCompany(park.getTypicalCompanyList(), park.getId());
- }
- //删除草稿中的典型企业及图片
- parkDraftService.deleteDraftTypicalCompany(park.getId());
- }
- else {//保存草稿
- ParkDraft draft = parkDraftService.findById(park.getId());
- if (draft != null){
- Reflections.copyFieldToBean(park, draft);
- parkDraftService.updateSelective(draft);
- }
- else {
- ParkDraft insert = new ParkDraft();
- Reflections.copyFieldToBean(park, insert);
- insert.setId(park.getId());
- insert.setIs_draft(true);
- parkDraftService.save(insert);
- }
- deleteDraftAttachment(park);
- //园区图片草稿
- if (park.getFileDowns() != null && park.getFileDowns().size() > 0) {
- saveAttachmentDraft(park.getFileDowns(), park.getId());
- }
-
- parkDraftService.deleteDraftSupport(park.getId());
- //配套信息
- if (park.getSupportList() != null && park.getSupportList().size() > 0) {
- saveParkSupportDraft(park.getSupportList(), park.getId());
- }
- parkDraftService.deleteDraftTypicalCompany(park.getId());
- //典型企业
- if (park.getTypicalCompanyList() != null && park.getTypicalCompanyList().size() > 0) {
- saveparkTypicalCompanyDraft(park.getTypicalCompanyList(), park.getId());
- }
- }
- }
- }
- /**
- * 保存典型企业草稿
- */
- private void saveparkTypicalCompanyDraft(List<ParkTypicalCompany> typicalCompanyList, Integer id) {
- for (ParkTypicalCompany parkTypicalCompany : typicalCompanyList) {
- parkTypicalCompany.setPark_id(id);
- parkDraftService.insertTypicalCompanyDraft(parkTypicalCompany);
- }
- }
- /**
- * 保存配套信息草稿
- */
- private void saveParkSupportDraft(List<ParkSupport> supportList, Integer id) {
- for (ParkSupport parkSupport : supportList) {
- parkSupport.setPark_id(id);
- parkDraftService.insertSupportDraft(parkSupport);
- }
- }
- /**
- * 保存园区图片草稿
- */
- private void saveAttachmentDraft(List<FileDown> fileDowns, Integer park_id) {
- for (FileDown fileDown : fileDowns) {
- int fileId = fileDown.getFile_id();
- ParkAttachmentDraft newAttach = new ParkAttachmentDraft();
- newAttach.setPark_id(park_id);
- newAttach.setAttachment_id(fileId);
- newAttach.setIs_main(fileDown.getIs_main());
- int newAttachId = parkDraftService.insertAttachmentDraft(newAttach);
- //图片已存在
- Attachment attachment = attachmentService.findById(fileId);
- if (attachment != null){
- attachment.setBusiness_id(newAttachId);
- attachment.setBusiness_type(Constant.Attachment.PARK_DRAFT);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- /**
- * 保存园区典型企业
- */
- private void saveparkTypicalCompany(List<ParkTypicalCompany> typicalCompanyList, Integer park_id) {
- for (ParkTypicalCompany typicalCompany : typicalCompanyList) {
- typicalCompany.setPark_id(park_id);
- int id = parkTypicalCompanyService.insertAndGetId(typicalCompany);
- //删除原来图片
- ParkTypicalCompanyAttachment companyAttachment = new ParkTypicalCompanyAttachment();
- companyAttachment.setTypical_company_id(id);
- //保存新图片
- List<FileDown> fileDowns = typicalCompany.getFileDowns();
- if (fileDowns != null && fileDowns.size() > 0) {
- for (FileDown fileDown : fileDowns) {
- int fileId = fileDown.getFile_id();
- companyAttachment.setAttachment_id(fileId);
- int typicalCompanyId = parkTypicalCompanyAttachmentService.insertAndGetId(companyAttachment);
- Attachment attachment = attachmentService.findById(fileDown.getFile_id());
- if (attachment != null) {
- attachment.setBusiness_type(Constant.Attachment.TYPICAL_COMPANY);
- attachment.setBusiness_id(typicalCompanyId);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- }
- }
- /**
- * 保存园区配套
- */
- private void saveParkSupport(List<ParkSupport> supportList, Integer park_id) {
- for (ParkSupport parkSupport : supportList) {
- Integer supportId = parkSupport.getId();
- parkSupport.setPark_id(park_id);
- ParkSupportAttachment oldAttachment = new ParkSupportAttachment();
- oldAttachment.setType(parkSupport.getType());
- if (parkSupport.getId() != null) {
- parkSupportService.updateSelective(parkSupport);
- } else {
- supportId = parkSupportService.insertAndGetId(parkSupport);
- }
- //删除原来图片
- oldAttachment.setSupport_id(supportId);
- List<ParkSupportAttachment> supportAttachments = parkSupportAttachmentService.findListByWhere(oldAttachment);
- if (supportAttachments != null && supportAttachments.size() > 0) {
- for (ParkSupportAttachment attachment : supportAttachments) {
- attachment.setDel_flag(true);
- parkSupportAttachmentService.updateSelective(attachment);
- }
- }
- //保存新图片
- List<FileDown> fileDowns = parkSupport.getFileDowns();
- if (fileDowns != null && fileDowns.size() > 0) {
- for (FileDown fileDown : fileDowns) {
- ParkSupportAttachment supportAttachment = new ParkSupportAttachment();
- supportAttachment.setSupport_id(supportId);
- supportAttachment.setType(parkSupport.getType());
- supportAttachment.setAttachment_id(fileDown.getFile_id());
- parkSupportAttachmentService.insertAndGetId(supportAttachment);
- //更新配套图片信息
- Attachment attachment = new Attachment();
- attachment.setId(fileDown.getFile_id());
- attachment.setBusiness_id(supportAttachment.getId());
- attachment.setBusiness_type(Constant.Attachment.PARK_SUPPORT);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- }
- /**
- * 删除草稿图片
- */
- private void deleteDraftAttachment(Park park) {
- parkDraftService.deleteDraftAttachment(park.getId());
- }
- /**
- * 保存园区图片
- */
- private void saveAttachment(Park park) {
- if (park.getFileDowns() != null && park.getFileDowns().size() > 0) {
- //保存新图片
- for (FileDown fileDown : park.getFileDowns()) {
- int fileId = fileDown.getFile_id();
- ParkAttachment newAttach = new ParkAttachment();
- newAttach.setPark_id(park.getId());
- newAttach.setAttachment_id(fileId);
- newAttach.setIs_main(fileDown.getIs_main());
- int newAttachId = parkAttachmentService.insertAndGetId(newAttach);
- //图片已存在
- if (attachmentService.findById(fileId) != null) {
- continue;
- }
- Attachment attachment = new Attachment();
- attachment.setId(fileId);
- attachment.setBusiness_id(newAttachId);
- attachment.setBusiness_type(Constant.Attachment.PARK);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- /**
- * 获取fileDowns
- *
- * @param attachmentList
- * @return
- */
- public List<FileDown> getFileDownList(List<Attachment> attachmentList) {
- List<FileDown> fileDowns = new ArrayList<>();
- if (attachmentList != null && attachmentList.size() > 0) {
- for (Attachment attachment : attachmentList) {
- FileDown fileDown = new FileDown();
- fileDown.setFile_url(attachment.getFile_url());
- fileDown.setFile_id(attachment.getId());
- fileDown.setDownload_uri(attachment.getDownload_uri());
- fileDown.setFile_name(attachment.getFile_name());
- fileDowns.add(fileDown);
- }
- }
- return fileDowns;
- }
- public List<Park> findParkListByStreetId(Integer streetId) {
- SearchCondition condition = new SearchCondition();
- condition.setStreetId(streetId);
- return parkDao.findParkList(condition);
- }
- @Transactional(readOnly = true)
- public List<Park> findList() {
- Example example = new Example(Park.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", 0);
- //倒序
- //example.orderBy("create_time").desc();
- example.setOrderByClause("id");
- List<Park> parks = this.selectByExample(example);
- return parks;
- }
- @Transactional(readOnly = true)
- public List<Park> findParkOnUseList() {
- Example example = new Example(Park.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", 0);
- criteria.andEqualTo("is_start", 1);
- criteria.andEqualTo("is_draft", 1);
- //倒序
- //example.orderBy("create_time").desc();
- example.setOrderByClause("id");
- List<Park> parks = this.selectByExample(example);
- return parks;
- }
- public int updateNoBatch(List<Park> parks) {
- return parkDao.updateNoBatch(parks);
- }
- /**
- * 载体库园区列表
- *
- * @param id
- * @return
- */
- public List<CarrierLibraryResult> getParkStatistic(Integer id) {
- return parkDao.getParkStatistic(id);
- }
- public CarrierLibraryResult getParkAreaStatistic(Integer id) {
- return parkDao.getParkAreaStatistic(id);
- }
- public List<ParkDto> findParkBuildingList(CustomSearchCondition customSearchCondition) {
- return parkDao.findParkBuildingList(customSearchCondition);
- }
- public List<Park> findByStreetId(Integer id) {
- return parkDao.findByStreetId(id);
- }
- public Double getParkRentAreaStatistic(Integer id) {
- return parkDao.getParkRentAreaStatistic(id);
- }
- /**
- * 更具园区名字查找园区
- *
- * @param name
- * @return
- */
- public Park findByName(String name) {
- Example example = new Example(Park.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", 0);
- criteria.andEqualTo("name", name);
- List<Park> parks = this.selectByExample(example);
- if (parks.size() > 0){
- return parks.get(0);
- }
- return null;
- }
- public PageInfo<Park> findParkNames(SearchCondition condition) {
- if (!condition.getIs_front()) {
- User user = ShiroUtils.getUserEntity();
- if (user.getUser_type() != null && user.getUser_type().equals(Constant.UserType.STREET)) {
- condition.setStreetId(user.getStreet_id());
- }
- if (user.getUser_type() != null && user.getUser_type().equals(Constant.UserType.BUILD)) {
- condition.setParkId(user.getBuild_id());
- }
- }
- PageHelper.startPage(condition.getPageNum(), condition.getPageSize());
- List<Park> parkList = parkDao.findParkNames(condition);
- return new PageInfo<>(parkList);
- }
- /**
- * 找到子园区
- *
- * @param park_id
- * @return
- */
- public List<SubPark> findParentParkById(String park_id) {
- return parkDao.findParentParkById(park_id);
- }
- }
|