123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- package com.caimei.modules.user.service;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.caimei.modules.bulkpurchase.dao.CmClubDao;
- import com.caimei.modules.consult.entity.type.CmConsulttype;
- import com.caimei.modules.oss.service.CmOssArchiveService;
- import com.caimei.modules.oss.utils.OSSUtils;
- import com.caimei.modules.project.model.ServiceProviderModel;
- import com.caimei.modules.user.entity.*;
- import com.caimei.utils.AppUtils;
- import com.thinkgem.jeesite.common.utils.StringUtils;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.thinkgem.jeesite.common.persistence.Page;
- import com.thinkgem.jeesite.common.service.CrudService;
- import com.caimei.modules.user.dao.NewCmClubDao;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.xml.crypto.Data;
- /**
- * 用户模块重构--会所管理Service
- *
- * @author zcp
- * @version 2018-05-21
- */
- @Service
- @Transactional(readOnly = true)
- public class NewCmClubService extends CrudService<NewCmClubDao, NewCmClub> {
- @Autowired
- private NewCmClubDao newCmClubDao;
- @Autowired
- private CmClubDao cmClubDao;
- @Autowired
- private CmOssArchiveService cmOssArchiveService;
- public NewCmClub get(String id) {
- return super.get(id);
- }
- public NewCmClub getclubByUserId(Integer userId) {
- return newCmClubDao.getclubByUserId(userId);
- }
- public List<NewCmClub> findList(NewCmClub userClub) {
- return super.findList(userClub);
- }
- public Page<NewCmClub> findPage(Page<NewCmClub> page, NewCmClub userClub) {
- return super.findPage(page, userClub);
- }
- @Transactional(readOnly = false)
- public void save(NewCmClub userClub) {
- super.save(userClub);
- }
- @Transactional(readOnly = false)
- public void insert(NewCmClub userClub) {
- newCmClubDao.insert(userClub);
- }
- @Transactional(readOnly = false)
- public void delete(NewCmClub userClub) {
- super.delete(userClub);
- }
- @Transactional(readOnly = false)
- public void update(NewCmClub userClub) {
- newCmClubDao.update(userClub);
- }
- public NewCmClub findClubById(Integer clubId) {
- List<NewCmClub> newCmClubs = newCmClubDao.findClubById(clubId);
- if (CollectionUtils.isNotEmpty(newCmClubs) && newCmClubs.size() > 0) {
- return newCmClubs.get(0);
- } else {
- return null;
- }
- }
- @Transactional(readOnly = false)
- public void insertBeansHistory(UserBeansHistory beansHistory) {
- newCmClubDao.insertBeansHistory(beansHistory);
- }
- public Page<CmClubRemarks> findRemarksPage(Page<CmClubRemarks> page, CmClubRemarks cmClubRemarks) {
- cmClubRemarks.setPage(page);
- List<CmClubRemarks> remarksList = newCmClubDao.findRemarksList(cmClubRemarks);
- remarksList.forEach(remarks -> {
- if (StringUtils.isNotBlank(remarks.getConsult())) {
- StringBuilder cons = new StringBuilder();
- if (remarks.getConsult().contains(",")) {
- String[] split = remarks.getConsult().split(",");
- for (String string : split) {
- cons.append(newCmClubDao.findClassName(string)).append(",");
- }
- cons = new StringBuilder(cons.substring(0, cons.length() - 1));
- } else {
- cons = new StringBuilder(newCmClubDao.findClassName(remarks.getConsult()));
- }
- remarks.setConsultType(cons.toString());
- }
- List<String> imageList = newCmClubDao.getRemarksImageList(remarks.getRemarksId());
- List<RemarksFileVo> fileList = newCmClubDao.getRemarksFileList(remarks.getRemarksId());
- fileList.forEach(f -> f.setFileUrl(OSSUtils.getOssUrl(f.getOssName())));
- remarks.setImageList(imageList);
- remarks.setFileList(fileList);
- });
- page.setList(remarksList);
- return page;
- }
- public void downloadRemarks(String fileName, String ossName, HttpServletRequest request, HttpServletResponse response) throws IOException {
- OSSUtils.downFile(ossName, fileName);
- cmOssArchiveService.download(request, response, fileName);
- }
- public Page<CmClubRemarks> findRegistPage(Page<CmClubRemarks> cmClubRemarksPage, CmClubRemarks cmClubRemarks) {
- cmClubRemarks.setPage(cmClubRemarksPage);
- List<CmClubRemarks> remarksList = newCmClubDao.findRegistList(cmClubRemarks);
- remarksList.forEach(remarks -> {
- if (StringUtils.isNotBlank(remarks.getConsult())) {
- StringBuilder cons = new StringBuilder();
- if (remarks.getConsult().contains(",")) {
- String[] split = remarks.getConsult().split(",");
- for (String string : split) {
- cons.append(newCmClubDao.findClassName(string)).append(",");
- }
- cons = new StringBuilder(cons.substring(0, cons.length() - 1));
- } else {
- cons = new StringBuilder(newCmClubDao.findClassName(remarks.getConsult()));
- }
- remarks.setConsultType(cons.toString());
- }
- List<String> imageList = newCmClubDao.getRemarksImageList(remarks.getRemarksId());
- List<RemarksFileVo> fileList = newCmClubDao.getRemarksFileList(remarks.getRemarksId());
- fileList.forEach(f -> f.setFileUrl(OSSUtils.getOssUrl(f.getOssName())));
- if (StringUtils.isNotBlank(remarks.getMainImage())) {
- remarks.setMainImage(AppUtils.getImageURL("product", remarks.getMainImage(), 0, ""));
- }
- remarks.setImageList(imageList);
- remarks.setFileList(fileList);
- });
- if (StringUtils.isNotBlank(cmClubRemarks.getConsult())) {
- remarksList.removeIf(r -> !r.getConsult().contains(cmClubRemarks.getConsult()));
- }
- cmClubRemarksPage.setList(remarksList);
- return cmClubRemarksPage;
- }
- public List<CmConsulttype> findConsults() {
- return newCmClubDao.findConsults();
- }
- public List<CmSaleMan> findTeams() {
- return newCmClubDao.findTeams();
- }
- public List<ServiceProviderModel> findGroup(Integer leaderId) {
- return newCmClubDao.findGroup(leaderId);
- }
- @Transactional(readOnly = false)
- public String upremakasList(CmRemaks cmRemaks) {
- return newCmClubDao.upremakasList(cmRemaks);
- }
- @Transactional(readOnly = false)
- public void upremarks(CmRemaks cmRemaks) {
- newCmClubDao.upremarks(cmRemaks);
- }
- @Transactional(readOnly = false)
- public void addRemarks(CmRemaks cmRemaks) {
- newCmClubDao.addRemarks(cmRemaks);
- }
- @Transactional(readOnly = false)
- public void deleteRamarks(CmRemaks cmRemaks) {
- newCmClubDao.deleteRamarks(cmRemaks);
- }
- @Transactional(readOnly = false)
- public List<Integer> ClubsIds(ClubChangeSp clubChangeSp) {
- return newCmClubDao.ClubsIds(clubChangeSp);
- }
- @Transactional(readOnly = false)
- public void oldname(Integer oldserviceProviderId, Integer clubID, Integer oldSpID, Integer newSpID) {
- newCmClubDao.oldname(oldserviceProviderId, clubID, oldSpID, newSpID);
- }
- @Transactional(readOnly = false)
- public void oldnames(Integer clubID, Integer oldSpID, Integer newSpID) {
- newCmClubDao.oldnames(clubID, oldSpID, newSpID);
- }
- @Transactional(readOnly = false)
- public void updateServiceProvider(Integer clubId, Integer oldSpID, Integer newSpID) {
- cmClubDao.updateServiceProvider(clubId, oldSpID, newSpID);
- }
- public Page<CmReport> ReportList(Page<CmReport> cmReports, CmReport cmReport) {
- cmReport.setPage(cmReports);
- List<CmReport> list = newCmClubDao.ReportList(cmReport);
- cmReports.setList(list);
- return cmReports;
- }
- public Page<ClubStatistics> statisticsList(Page<ClubStatistics> page, ClubStatistics statistics) {
- statistics.setPage(page);
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = new Date();
- String monthStartTime = "";
- String yearStartTime = "";
- String endTime = "";
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- // 获取近一个月、近一年结束时间
- calendar.add(Calendar.DAY_OF_MONTH, -1);
- Date time = calendar.getTime();
- endTime = dateFormat.format(date);
- statistics.setMonthEndTime(endTime);
- statistics.setYearEndTime(endTime);
- // 近一个月开始时间
- calendar.setTime(time);
- calendar.add(Calendar.MONTH, -1);
- statistics.setMonthStartTime(dateFormat.format(calendar.getTime()));
- // 近一年开始时间
- calendar.setTime(time);
- calendar.add(Calendar.YEAR, -1);
- statistics.setYearStartTime(dateFormat.format(calendar.getTime()));
- List<ClubStatistics> selStatisticsList = new ArrayList<>();
- if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
- // 初始化查询条件,排除sql分页
- ClubStatistics clubData = new ClubStatistics();
- clubData.setMonthStartTime(statistics.getMonthStartTime());
- clubData.setMonthEndTime(statistics.getMonthEndTime());
- clubData.setYearStartTime(statistics.getYearStartTime());
- clubData.setYearEndTime(statistics.getYearEndTime());
- clubData.setClubDataIntegrity(statistics.getClubDataIntegrity());
- if (StringUtils.isNotBlank(statistics.getRegisterStartTime())) {
- clubData.setRegisterStartTime(statistics.getRegisterStartTime());
- }
- if (StringUtils.isNotBlank(statistics.getRegisterEndTime())) {
- clubData.setRegisterEndTime(statistics.getRegisterEndTime());
- }
- if (StringUtils.isNotBlank(statistics.getSearchStartTime())) {
- clubData.setSearchStartTime(statistics.getSearchStartTime());
- }
- if (StringUtils.isNotBlank(statistics.getSearchEndTime())) {
- clubData.setSearchEndTime(statistics.getSearchEndTime());
- }
- if (StringUtils.isNotBlank(statistics.getCustomerValue())) {
- clubData.setCustomerValue(statistics.getCustomerValue());
- }
- if (StringUtils.isNotBlank(statistics.getSearchUserIdentity())) {
- clubData.setSearchUserIdentity(statistics.getSearchUserIdentity());
- }
- if (StringUtils.isNotBlank(statistics.getSearchStatus())) {
- clubData.setSearchStatus(statistics.getSearchStatus());
- }
- clubData.setLinkManIdentity(statistics.getLinkManIdentity());
- clubData.setCustomStartTime(statistics.getCustomStartTime());
- clubData.setCustomEndTime(statistics.getCustomEndTime());
- clubData.setPayTotalMonth(statistics.getPayTotalMonth());
- clubData.setPayTotalYear(statistics.getPayTotalYear());
- clubData.setPayTotal(statistics.getPayTotal());
- clubData.setPayTotalMonthType(statistics.getPayTotalMonthType());
- clubData.setOrderCountMonthType(statistics.getOrderCountMonthType());
- clubData.setPayTotalYearType(statistics.getPayTotalYearType());
- clubData.setOrderCountYearType(statistics.getOrderCountYearType());
- clubData.setPayTotalType(statistics.getPayTotalType());
- selStatisticsList = newCmClubDao.selStatisticsList(clubData);
- } else {
- selStatisticsList = newCmClubDao.selStatisticsList(statistics);
- }
- List<ClubStatistics> statisticsList = setListData(selStatisticsList, statistics);
- if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
- int pageNo = page.getPageNo();
- int pageSize = page.getPageSize();
- int number = 0;
- if (pageNo == 1) {
- number = 0;
- } else {
- number = (pageNo - 1) * pageSize;
- }
- List<ClubStatistics> list = new ArrayList<>();
- for (int i = 0; i <= statisticsList.size() - 1; i++) {
- if (i >= number && i < number + pageSize) {
- list.add(statisticsList.get(i));
- }
- }
- page.setCount(statisticsList.size());
- page.setList(list);
- } else {
- page.setList(statisticsList);
- }
- return page;
- }
- public List<easyExcel> exportExcel(ClubStatistics statistics) {
- List<easyExcel> statisticsList = newCmClubDao.findExcelList(statistics);
- List<easyExcel> easyExcels = setExData(statisticsList, statistics);
- return easyExcels;
- }
- public List<easyExcel> setExData(List<easyExcel> selStatisticsList, ClubStatistics statistics) {
- int number = 0;
- String type = "";
- Integer item = 0;
- // List<ClubStatistics> clubStatisticsList = selStatisticsList;
- List<CmBehaviorRecord> pageLableList = newCmClubDao.selPageLable();
- for (easyExcel clubStatistics : selStatisticsList) {
- // 机构类型
- if (StringUtils.isNotBlank(clubStatistics.getFirstClubType())) {
- type += clubStatistics.getFirstClubType();
- }
- if (StringUtils.isNotBlank(clubStatistics.getClassify())) {
- type += "-" + clubStatistics.getClassify();
- }
- clubStatistics.setClubType(type);
- // 计算资料完整度
- if (StringUtils.isNotBlank(clubStatistics.getName())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getLinkMan())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractMobile())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getLinkManIdentity())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getAddress())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getBusinessLicenseImage())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getUserIdentity())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getSname())) {
- number += 3;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractEmail())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractPhone())) {
- number += 4;
- }
- if (StringUtils.isNotBlank(clubStatistics.getFax())) {
- number += 3;
- }
- if (StringUtils.isNotBlank(clubStatistics.getHeadpic())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getSocialCreditCode())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getInfo())) {
- number += 5;
- }
- clubStatistics.setNumber(number);
- clubStatistics.setClubDataIntegrity(number + "%");
- number = 0;
- type = "";
- // 处理最常搜索词
- List<CmBehaviorRecord> collect = pageLableList.stream().filter(data -> data.getUserID().equals(clubStatistics.getUserID())).collect(Collectors.toList());
- if (collect.size() > 0) {
- clubStatistics.setPageLabel(collect.get(0).getPageLabel());
- item = collect.get(0).getNumber();
- for (int i = 0; i < collect.size() - 1; i++) {
- if (item < collect.get(i).getNumber()) {
- item = collect.get(i).getNumber();
- clubStatistics.setPageLabel(collect.get(i).getPageLabel());
- }
- }
- }
- }
- // 资料完整度处理
- if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
- if ("1".equals(statistics.getClubDataIntegrity())) {
- selStatisticsList = selStatisticsList.stream().filter(data -> (data.getNumber() > 20 && data.getNumber() < 70)).collect(Collectors.toList());
- } else {
- selStatisticsList = selStatisticsList.stream().filter(data -> data.getNumber() > 70).collect(Collectors.toList());
- }
- }
- return selStatisticsList;
- }
- public List<ClubStatistics> setListData(List<ClubStatistics> selStatisticsList, ClubStatistics statistics) {
- int number = 0;
- String type = "";
- Integer item = 0;
- // List<ClubStatistics> clubStatisticsList = selStatisticsList;
- List<CmBehaviorRecord> pageLableList = newCmClubDao.selPageLable();
- for (ClubStatistics clubStatistics : selStatisticsList) {
- // 机构类型
- if (StringUtils.isNotBlank(clubStatistics.getFirstClubType())) {
- type += clubStatistics.getFirstClubType();
- }
- if (StringUtils.isNotBlank(clubStatistics.getClassify())) {
- type += "-" + clubStatistics.getClassify();
- }
- clubStatistics.setClubType(type);
- // 计算资料完整度
- if (StringUtils.isNotBlank(clubStatistics.getName())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getLinkMan())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractMobile())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getLinkManIdentity())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getAddress())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getBusinessLicenseImage())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getUserIdentity())) {
- number += 10;
- }
- if (StringUtils.isNotBlank(clubStatistics.getSname())) {
- number += 3;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractEmail())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getContractPhone())) {
- number += 4;
- }
- if (StringUtils.isNotBlank(clubStatistics.getFax())) {
- number += 3;
- }
- if (StringUtils.isNotBlank(clubStatistics.getHeadpic())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getSocialCreditCode())) {
- number += 5;
- }
- if (StringUtils.isNotBlank(clubStatistics.getInfo())) {
- number += 5;
- }
- clubStatistics.setNumber(number);
- clubStatistics.setClubDataIntegrity(number + "%");
- number = 0;
- type = "";
- // 处理最常搜索词
- List<CmBehaviorRecord> collect = pageLableList.stream().filter(data -> data.getUserID().equals(clubStatistics.getUserID())).collect(Collectors.toList());
- if (collect.size() > 0) {
- clubStatistics.setPageLabel(collect.get(0).getPageLabel());
- item = collect.get(0).getNumber();
- for (int i = 0; i < collect.size() - 1; i++) {
- if (item < collect.get(i).getNumber()) {
- item = collect.get(i).getNumber();
- clubStatistics.setPageLabel(collect.get(i).getPageLabel());
- }
- }
- }
- }
- // 资料完整度处理
- if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
- if ("1".equals(statistics.getClubDataIntegrity())) {
- selStatisticsList = selStatisticsList.stream().filter(data -> (data.getNumber() > 20 && data.getNumber() < 70)).collect(Collectors.toList());
- } else {
- selStatisticsList = selStatisticsList.stream().filter(data -> data.getNumber() > 70).collect(Collectors.toList());
- }
- }
- return selStatisticsList;
- }
- }
|