| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- package platform.modules.carrier.service;
- import com.feilong.core.util.CollectionsUtil;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.env.Environment;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.StringUtils;
- 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.ShiroUtils;
- import platform.modules.build.entity.Company;
- import platform.modules.build.service.CompanyContactService;
- import platform.modules.build.service.CompanyService;
- import platform.modules.carrier.dao.RentalProjectCompanyDao;
- import platform.modules.carrier.dao.RentalProjectDao;
- import platform.modules.carrier.dto.*;
- import platform.modules.carrier.entity.Park;
- import platform.modules.carrier.entity.RentalProject;
- import platform.modules.carrier.entity.RentalProjectCompany;
- import platform.modules.government.dao.AttachmentDao;
- import platform.modules.government.entity.Attachment;
- import platform.modules.government.entity.FileDown;
- 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.government.service.UserService;
- import javax.servlet.http.HttpServletRequest;
- import java.util.*;
- @Service
- @Transactional
- public class RentalProjectService extends BaseService<RentalProject> {
- @Autowired
- private RentalProjectDao rentalProjectDao;
- @Autowired
- private DictionaryItemService dictionaryItemService;
- @Autowired
- private StreetService streetService;
- @Autowired
- private UserService userService;
- @Autowired
- private CompanyService companyService;
- @Autowired
- private CompanyContactService companyContactService;
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- private RentalProjectCompanyService rentalProjectCompanyService;
- //保存
- public int create(RentalProject rentalProject) {
- rentalProject.setStatus(1);
- int i = this.insertAndGetId(rentalProject);
- //项目主图
- if (isMainPicture(rentalProject.getMain_pic())){
- Attachment attachment = attachmentService.findById(rentalProject.getMain_pic().getFile_id());
- if (attachment != null){
- attachmentService.updateAttachment(Constant.Attachment.RENTAL_MAIN_PIC, i, rentalProject.getMain_pic().getFile_id());
- }
- }
- //相关资质文件
- List<FileDown> fileDownList = rentalProject.getFileDownList();
- attachmentService.deleteByBusiness(Constant.Attachment.RENTAL, rentalProject.getId());
- if (!CollectionUtils.isEmpty(fileDownList)) {
- for (FileDown fileDown : fileDownList) {
- attachmentService.updateAttachment(Constant.Attachment.RENTAL, rentalProject.getId(), fileDown.getFile_id());
- }
- }
- //街道代办企业
- if (rentalProject.getRentalProjectCompany() != null){
- RentalProjectCompany company =rentalProject.getRentalProjectCompany();
- company.setRental_id(i);
- rentalProjectCompanyService.insertAndGetId(company);
- }
- //给所有街道园区发送信息
- saveMessage(rentalProject);
- return i;
- }
- private boolean isMainPicture(FileDown main_pic) {
- return main_pic != null && main_pic.getFile_id() != null;
- }
- /**
- * 发送消息
- * @param rentalProject
- */
- private void saveMessage(RentalProject rentalProject) {
- }
- //修改
- public int modify(RentalProject rentalProject) {
- int i = this.updateSelective(rentalProject);
- attachmentService.deleteByBusiness(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId());
- if (isMainPicture(rentalProject.getMain_pic())){
- Attachment attachment = attachmentService.findById(rentalProject.getMain_pic().getFile_id());
- if (isChangePic(attachment)){
- attachmentService.updateAttachment(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(),
- rentalProject.getMain_pic().getFile_id());
- }
- }
- List<FileDown> fileDownList = rentalProject.getFileDownList();
- attachmentService.deleteByBusiness(Constant.Attachment.RENTAL, rentalProject.getId());
- if (!CollectionUtils.isEmpty(fileDownList)) {
- for (FileDown fileDown : fileDownList) {
- attachmentService.updateAttachment(Constant.Attachment.RENTAL, rentalProject.getId(), fileDown.getFile_id());
- }
- }
- //街道代办企业
- if (rentalProject.getRentalProjectCompany() != null){
- int companyId = rentalProjectCompanyService.findByRentalId(rentalProject.getId()).getId();
- RentalProjectCompany company = rentalProject.getRentalProjectCompany();
- company.setId(companyId);
- rentalProjectCompanyService.updateSelective(company);
- }
- return i;
- }
- private boolean isChangePic(Attachment attachment) {
- return attachment == null || attachment.getBusiness_id() == null;
- }
- //获取详情
- public RentalProject getById(Integer id) {
- RentalProject rentalProject = this.findById(id);
- int i = rentalProject.getRead_count() == null ? 0 : rentalProject.getRead_count();
- rentalProject.setRead_count(i + 1);
- this.update(rentalProject);
- if (rentalProject.getIntention_street() != null) {
- Street street = streetService.selectById(rentalProject.getIntention_street());
- rentalProject.setIntention_street_desc(street.getName());
- }
- if (rentalProject.getDemand() != null) {
- rentalProject.setDemand_desc(
- dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.DEMAND, rentalProject.getDemand().toString()).getName()
- );
- }
- User user = userService.getUser(rentalProject.getCreate_by());
- if (user != null) {
- Company company = companyService.getCompanyInfo(user.getCompany_id());
- if (null != company) {
- company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
- }
- if (Objects.equals(company.getIndustry_code(), "Empty")) {
- company.setIndustry_code(company.getIndustry_name());
- } else {
- company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
- }
- rentalProject.setCompany(company);
- }
- //获取街道代办的企业信息
- RentalProjectCompany rentalProjectCompany = rentalProjectCompanyService.findByRentalId(rentalProject.getId());
- rentalProject.setRentalProjectCompany(rentalProjectCompany);
- List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL, id, null);
- List<FileDown> fileDowns = new ArrayList<>();
- if (null != attachments && attachments.size() > 0) {
- for (Attachment attachment : attachments) {
- FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri());
- fileDowns.add(fileDown);
- }
- }
- rentalProject.setFileDownList(fileDowns);
- //获取主图
- List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, id, null);
- if (mainPic.size() > 0) {
- FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), mainPic.get(0).getDownload_uri());
- rentalProject.setMain_pic(fileDown);
- }
- return rentalProject;
- }
- //我的分页
- @Transactional(readOnly = true)
- public PageInfo<RentalProject> findMyList(Integer pageNum, Integer pageSize, CustomSearchCondition param) throws Exception {
- PageHelper.startPage(pageNum, pageSize);
- List<RentalProject> list = rentalProjectDao.findListByCreater(param, ShiroUtils.getUserId());
- List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
- for (RentalProject rentalProject : list) {
- if (null != typeList && typeList.size() > 0) {
- for (DictionaryItem dictionaryItem : typeList) {
- if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
- rentalProject.setDemand_desc(dictionaryItem.getName());
- }
- }
- }
- if (!Objects.isNull(rentalProject.getIntention_street())) {
- rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
- }
- User user = userService.getUser(rentalProject.getCreate_by());
- if (user != null) {
- Company company = companyService.getCompanyInfo(user.getCompany_id());
- if (null != company) {
- company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
- }
- if (Objects.equals(company.getIndustry_code(), "Empty")) {
- company.setIndustry_code(company.getIndustry_name());
- } else {
- company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
- }
- rentalProject.setCompany_name(company.getCompany_name());
- rentalProject.setIndustry_name(company.getIndustry_name());
- }
- if (rentalProject.getStatus() == 1) {
- rentalProject.setStatus_desc("已上架");
- } else if (rentalProject.getStatus() == 0) {
- rentalProject.setStatus_desc("已下架");
- }
- //获取主图
- List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(), null);
- if (mainPic.size() > 0) {
- FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), param.getFile_url());
- rentalProject.setMain_pic(fileDown);
- }
- }
- return new PageInfo<>(list);
- }
- //我的分页
- @Transactional(readOnly = true)
- public PageInfo<RentalProject> findMyList(Integer userId, CustomSearchCondition param) throws Exception {
- PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<RentalProject> list = rentalProjectDao.findListByCreater(param, userId);
- List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
- for (RentalProject rentalProject : list) {
- if (null != typeList && typeList.size() > 0) {
- for (DictionaryItem dictionaryItem : typeList) {
- if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
- rentalProject.setDemand_desc(dictionaryItem.getName());
- }
- }
- }
- if (!Objects.isNull(rentalProject.getIntention_street())) {
- rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
- }
- User user = userService.getUser(rentalProject.getCreate_by());
- if (user != null) {
- Company company = companyService.getCompanyInfo(user.getCompany_id());
- if (null != company) {
- company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
- }
- if (Objects.equals(company.getIndustry_code(), "Empty")) {
- company.setIndustry_code(company.getIndustry_name());
- } else {
- company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
- }
- rentalProject.setCompany_name(company.getCompany_name());
- rentalProject.setIndustry_name(company.getIndustry_name());
- }
- if (rentalProject.getStatus() == 1) {
- rentalProject.setStatus_desc("已上架");
- } else if (rentalProject.getStatus() == 0) {
- rentalProject.setStatus_desc("已下架");
- }
- //获取主图
- List<Attachment> mainPic = attachmentService.selectByIdAndBusinessId(Constant.Attachment.RENTAL_MAIN_PIC, rentalProject.getId(), null);
- if (mainPic.size() > 0) {
- FileDown fileDown = new FileDown(mainPic.get(0).getId(), mainPic.get(0).getFile_name(), mainPic.get(0).getFile_url(), param.getFile_url());
- rentalProject.setMain_pic(fileDown);
- }
- }
- return new PageInfo<>(list);
- }
- //前台分页
- @Transactional(readOnly = true)
- public PageInfo<RentalProject> findList(Integer pageNum, Integer pageSize, CustomSearchCondition param) throws Exception {
- PageHelper.startPage(pageNum, pageSize);
- List<RentalProject> list = rentalProjectDao.findList(param);
- List<DictionaryItem> typeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.DEMAND);
- for (RentalProject rentalProject : list) {
- if (null != typeList && typeList.size() > 0) {
- for (DictionaryItem dictionaryItem : typeList) {
- if (Objects.equals(rentalProject.getDemand() + "", dictionaryItem.getValue())) {
- rentalProject.setDemand_desc(dictionaryItem.getName());
- }
- }
- }
- if (!Objects.isNull(rentalProject.getIntention_street())) {
- rentalProject.setIntention_street_desc(streetService.getStreetName(rentalProject.getIntention_street()));
- }
- User user = userService.getUser(rentalProject.getCreate_by());
- if (user != null) {
- Company company = companyService.getCompanyInfo(user.getCompany_id());
- if (null != company) {
- company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
- }
- if (Objects.equals(company.getIndustry_code(), "Empty")) {
- company.setIndustry_code(company.getIndustry_name());
- } else {
- company.setIndustry_name(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
- }
- rentalProject.setCompany_name(company.getCompany_name());
- rentalProject.setIndustry_name(company.getIndustry_name());
- }
- //获取街道代办的企业信息
- RentalProjectCompany rentalProjectCompany = rentalProjectCompanyService.findByRentalId(rentalProject.getId());
- if (rentalProjectCompany != null && rentalProjectCompany.getType() != null){
- DictionaryItem item = dictionaryItemService.findByItemId(rentalProjectCompany.getType());
- if (item != null){
- rentalProjectCompany.setType_desc(item.getName());
- }
- }
- rentalProject.setRentalProjectCompany(rentalProjectCompany);
- }
- return new PageInfo<>(list);
- }
- //获取登录人所在企业信息
- public Company getCompanyInfoByCurrentUser() {
- Company company = companyService.getCompanyInfo(ShiroUtils.getCompanyId());
- if (null != company) {
- company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
- }
- if (Objects.equals(company.getIndustry_code(), "Empty")) {
- company.setIndustry_code(company.getIndustry_name());
- } else {
- company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code()));
- }
- return company;
- }
- /**
- * 批量删除
- *
- * @param ids
- */
- public void batchDelete(List<Integer> ids) {
- if (ids != null && ids.size() > 0) {
- for (Integer id : ids) {
- RentalProject rentalProject = new RentalProject();
- rentalProject.setId(id);
- rentalProject.setDel_flag(true);
- updateSelective(rentalProject);
- }
- }
- }
- public void updateStatusBatch(List<String> ids, String status) {
- rentalProjectDao.updateStatusBatch(ids, status);
- }
- public DrillInfoVo getInfoForDrill(CustomSearchCondition param) {
- DrillInfoVo drillInfoVo = new DrillInfoVo();
- List<RentalProject> list = rentalProjectDao.findList(param);
- Map<String, String> streetMap = new HashMap<>();
- for (RentalProject rentalProject : list) {
- if (!org.springframework.util.StringUtils.isEmpty(rentalProject.getIntention_street())) {
- streetMap.put(rentalProject.getStreet_id(), rentalProject.getStreet_name());
- }
- }
- List<StreetVo> streetVos = new ArrayList<>();
- Iterator<Map.Entry<String, String>> streetIiterator = streetMap.entrySet().iterator();
- while (streetIiterator.hasNext()) {
- Map.Entry<String, String> streetEntry = streetIiterator.next();
- StreetVo streetVo = new StreetVo();
- streetVo.setId(streetEntry.getKey());
- Street street = streetService.findById(Integer.parseInt(streetEntry.getKey()));
- if (street != null) {
- streetVo.setNo(street.getNo());
- }
- streetVo.setRegion(streetEntry.getValue());
- int streetCount = 0;
- List<DistrictVo> districtVos = new ArrayList<>();
- Map<String, String> parkMap = new HashMap<>();
- for (RentalProject rentalProject : list) {
- if (Objects.equals(rentalProject.getStreet_id(), streetEntry.getKey())) {
- streetCount++;
- }
- }
- streetVo.setPlates(districtVos);
- streetVo.setSum(streetCount);
- streetVos.add(streetVo);
- }
- drillInfoVo.setPlate(streetVos);
- return drillInfoVo;
- }
- public OutlineResultVo getInfoForSide(CustomSearchCondition param) {
- OutlineResultVo outlineResultVo = new OutlineResultVo();
- List<RentalProject> list = rentalProjectDao.findList(param);
- List<OutlineVo> outlineVos = new ArrayList<>();
- for (RentalProject rentalProject : list) {
- OutlineVo outlineVo = new OutlineVo();
- outlineVo.setId(rentalProject.getStreet_id());
- /*if (!StringUtils.isEmpty(rentalProject.getMain_picture_file())) {
- outlineVo.setImg(this.setFileUrl() + rentalProject.getMain_picture_file());
- }*/
- Street street = streetService.findById(Integer.parseInt(rentalProject.getStreet_id()));
- if (street != null) {
- outlineVo.setNo(street.getNo());
- }
- outlineVo.setTitle(rentalProject.getProject_name());
- outlineVo.setStreetName(rentalProject.getStreet_name());
- //outlineVo.setLocal(rentalProject.getLocation());
- outlineVo.setArea(rentalProject.getDemand_area() + "");
- outlineVo.setPrice(rentalProject.getDemand_price() + "");
- outlineVo.setDetailUrl(this.setFileUrl() + "/front/home/index.html#/projectDetail?id=" + rentalProject.getId());
- outlineVos.add(outlineVo);
- }
- outlineResultVo.setListData(outlineVos);
- return outlineResultVo;
- }
- @Autowired
- private Environment environment;
- @Autowired
- private HttpServletRequest request;
- protected static final String COMPANY_REPORT_ADD = "/government/companyReport/add";
- protected static final String OUT_HOME = "/home";
- public String setFileUrl() {
- //外网
- if (environment.getProperty("spring.profiles").equals(Constant.Environment.PROD_OUT)) {
- if (!request.getServletPath().contains(OUT_HOME) && !request.getServletPath().contains(COMPANY_REPORT_ADD)) {
- return environment.getProperty("fileOutUrl");
- }
- }
- return environment.getProperty("fileUrl");
- }
- }
|