NewCmClubService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. package com.caimei.modules.user.service;
  2. import java.io.IOException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6. import com.caimei.modules.bulkpurchase.dao.CmClubDao;
  7. import com.caimei.modules.consult.entity.type.CmConsulttype;
  8. import com.caimei.modules.order.utils.OSSUtils;
  9. import com.caimei.modules.product.service.CmOssArchiveService;
  10. import com.caimei.modules.project.model.ServiceProviderModel;
  11. import com.caimei.modules.user.entity.*;
  12. import com.caimei.utils.AppUtils;
  13. import com.thinkgem.jeesite.common.utils.StringUtils;
  14. import org.apache.commons.collections.CollectionUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import com.thinkgem.jeesite.common.persistence.Page;
  19. import com.thinkgem.jeesite.common.service.CrudService;
  20. import com.caimei.modules.user.dao.NewCmClubDao;
  21. import javax.annotation.Resource;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. /**
  25. * 用户模块重构--会所管理Service
  26. *
  27. * @author zcp
  28. * @version 2018-05-21
  29. */
  30. @Service
  31. @Transactional(readOnly = true)
  32. public class NewCmClubService extends CrudService<NewCmClubDao, NewCmClub> {
  33. @Resource
  34. private NewCmClubDao newCmClubDao;
  35. @Resource
  36. private CmClubDao cmClubDao;
  37. @Resource
  38. private CmOssArchiveService cmOssArchiveService;
  39. public NewCmClub get(String id) {
  40. return super.get(id);
  41. }
  42. public NewCmClub getclubByUserId(Integer userId) {
  43. return newCmClubDao.getclubByUserId(userId);
  44. }
  45. public List<NewCmClub> findList(NewCmClub userClub) {
  46. return super.findList(userClub);
  47. }
  48. public Page<NewCmClub> findPage(Page<NewCmClub> page, NewCmClub userClub) {
  49. return super.findPage(page, userClub);
  50. }
  51. public Page<NewCmClub> findProviderList(Page<NewCmClub> page,NewCmClub userClub) {
  52. userClub.setPage(page);
  53. List<NewCmClub> providerList = newCmClubDao.findProviderList(userClub);
  54. page.setList(providerList);
  55. return page;
  56. }
  57. @Transactional(readOnly = false)
  58. public void save(NewCmClub userClub) {
  59. super.save(userClub);
  60. }
  61. @Transactional(readOnly = false)
  62. public void insert(NewCmClub userClub) {
  63. newCmClubDao.insert(userClub);
  64. }
  65. @Transactional(readOnly = false)
  66. public void delete(NewCmClub userClub) {
  67. super.delete(userClub);
  68. }
  69. @Transactional(readOnly = false)
  70. public void update(NewCmClub userClub) {
  71. newCmClubDao.update(userClub);
  72. }
  73. public NewCmClub findClubById(Integer clubId) {
  74. List<NewCmClub> newCmClubs = newCmClubDao.findClubById(clubId);
  75. if (CollectionUtils.isNotEmpty(newCmClubs) && newCmClubs.size() > 0) {
  76. return newCmClubs.get(0);
  77. } else {
  78. return null;
  79. }
  80. }
  81. @Transactional(readOnly = false)
  82. public void insertBeansHistory(UserBeansHistory beansHistory) {
  83. newCmClubDao.insertBeansHistory(beansHistory);
  84. }
  85. public Page<CmClubRemarks> findRemarksPage(Page<CmClubRemarks> page, CmClubRemarks cmClubRemarks) {
  86. cmClubRemarks.setPage(page);
  87. List<CmClubRemarks> remarksList = newCmClubDao.findRemarksList(cmClubRemarks);
  88. remarksList.forEach(remarks -> {
  89. if (StringUtils.isNotBlank(remarks.getConsult())) {
  90. StringBuilder cons = new StringBuilder();
  91. if (remarks.getConsult().contains(",")) {
  92. String[] split = remarks.getConsult().split(",");
  93. for (String string : split) {
  94. cons.append(newCmClubDao.findClassName(string)).append(",");
  95. }
  96. cons = new StringBuilder(cons.substring(0, cons.length() - 1));
  97. } else {
  98. cons = new StringBuilder(newCmClubDao.findClassName(remarks.getConsult()));
  99. }
  100. remarks.setConsultType(cons.toString());
  101. }
  102. List<String> imageList = newCmClubDao.getRemarksImageList(remarks.getRemarksId());
  103. List<RemarksFileVo> fileList = newCmClubDao.getRemarksFileList(remarks.getRemarksId());
  104. fileList.forEach(f -> f.setFileUrl(OSSUtils.getOssUrl(f.getOssName())));
  105. remarks.setImageList(imageList);
  106. remarks.setFileList(fileList);
  107. });
  108. page.setList(remarksList);
  109. return page;
  110. }
  111. public void downloadRemarks(String fileName, String ossName, HttpServletRequest request, HttpServletResponse response) throws IOException {
  112. OSSUtils.downFile(ossName, fileName);
  113. cmOssArchiveService.download(request, response, fileName);
  114. }
  115. public Page<CmClubRemarks> findRegistPage(Page<CmClubRemarks> cmClubRemarksPage, CmClubRemarks cmClubRemarks) {
  116. cmClubRemarks.setPage(cmClubRemarksPage);
  117. List<CmClubRemarks> remarksList = newCmClubDao.findRegistList(cmClubRemarks);
  118. remarksList.forEach(remarks -> {
  119. if (StringUtils.isNotBlank(remarks.getConsult())) {
  120. StringBuilder cons = new StringBuilder();
  121. if (remarks.getConsult().contains(",")) {
  122. String[] split = remarks.getConsult().split(",");
  123. for (String string : split) {
  124. cons.append(newCmClubDao.findClassName(string)).append(",");
  125. }
  126. cons = new StringBuilder(cons.substring(0, cons.length() - 1));
  127. } else {
  128. cons = new StringBuilder(newCmClubDao.findClassName(remarks.getConsult()));
  129. }
  130. remarks.setConsultType(cons.toString());
  131. }
  132. List<String> imageList = newCmClubDao.getRemarksImageList(remarks.getRemarksId());
  133. List<RemarksFileVo> fileList = newCmClubDao.getRemarksFileList(remarks.getRemarksId());
  134. fileList.forEach(f -> f.setFileUrl(OSSUtils.getOssUrl(f.getOssName())));
  135. if (StringUtils.isNotBlank(remarks.getMainImage())) {
  136. remarks.setMainImage(AppUtils.getImageURL("product", remarks.getMainImage(), 0, ""));
  137. }
  138. remarks.setImageList(imageList);
  139. remarks.setFileList(fileList);
  140. });
  141. if (StringUtils.isNotBlank(cmClubRemarks.getConsult())) {
  142. remarksList.removeIf(r -> !r.getConsult().contains(cmClubRemarks.getConsult()));
  143. }
  144. cmClubRemarksPage.setList(remarksList);
  145. return cmClubRemarksPage;
  146. }
  147. public List<CmConsulttype> findConsults() {
  148. return newCmClubDao.findConsults();
  149. }
  150. public List<CmSaleMan> findTeams() {
  151. return newCmClubDao.findTeams();
  152. }
  153. public List<ServiceProviderModel> findGroup(Integer leaderId) {
  154. return newCmClubDao.findGroup(leaderId);
  155. }
  156. @Transactional(readOnly = false)
  157. public String upremakasList(CmRemaks cmRemaks) {
  158. return newCmClubDao.upremakasList(cmRemaks);
  159. }
  160. @Transactional(readOnly = false)
  161. public void upremarks(CmRemaks cmRemaks) {
  162. newCmClubDao.upremarks(cmRemaks);
  163. }
  164. @Transactional(readOnly = false)
  165. public void addRemarks(CmRemaks cmRemaks) {
  166. newCmClubDao.addRemarks(cmRemaks);
  167. }
  168. @Transactional(readOnly = false)
  169. public void deleteRamarks(CmRemaks cmRemaks) {
  170. newCmClubDao.deleteRamarks(cmRemaks);
  171. }
  172. @Transactional(readOnly = false)
  173. public List<Integer> ClubsIds(ClubChangeSp clubChangeSp) {
  174. return newCmClubDao.ClubsIds(clubChangeSp);
  175. }
  176. @Transactional(readOnly = false)
  177. public void oldname(Integer oldserviceProviderId, Integer clubID, Integer oldSpID, Integer newSpID) {
  178. newCmClubDao.oldname(oldserviceProviderId, clubID, oldSpID, newSpID);
  179. }
  180. @Transactional(readOnly = false)
  181. public void oldnames(Integer clubID, Integer oldSpID, Integer newSpID) {
  182. newCmClubDao.oldnames(clubID, oldSpID, newSpID);
  183. }
  184. @Transactional(readOnly = false)
  185. public void updateServiceProvider(Integer clubId, Integer oldSpID, Integer newSpID) {
  186. cmClubDao.updateServiceProvider(clubId, oldSpID, newSpID);
  187. }
  188. public Page<CmReport> ReportList(Page<CmReport> cmReports, CmReport cmReport) {
  189. cmReport.setPage(cmReports);
  190. List<CmReport> list = newCmClubDao.ReportList(cmReport);
  191. cmReports.setList(list);
  192. return cmReports;
  193. }
  194. public Page<ClubStatistics> statisticsList(Page<ClubStatistics> page, ClubStatistics statistics) {
  195. statistics.setPage(page);
  196. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  197. Date date = new Date();
  198. String monthStartTime = "";
  199. String yearStartTime = "";
  200. String endTime = "";
  201. Calendar calendar = Calendar.getInstance();
  202. calendar.setTime(date);
  203. // 获取近一个月、近一年结束时间
  204. calendar.add(Calendar.DAY_OF_MONTH, -1);
  205. Date time = calendar.getTime();
  206. endTime = dateFormat.format(date);
  207. statistics.setMonthEndTime(endTime);
  208. statistics.setYearEndTime(endTime);
  209. // 近一个月开始时间
  210. calendar.setTime(time);
  211. calendar.add(Calendar.MONTH, -1);
  212. statistics.setMonthStartTime(dateFormat.format(calendar.getTime()));
  213. // 近一年开始时间
  214. calendar.setTime(time);
  215. calendar.add(Calendar.YEAR, -1);
  216. statistics.setYearStartTime(dateFormat.format(calendar.getTime()));
  217. List<ClubStatistics> selStatisticsList = new ArrayList<>();
  218. if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
  219. // 初始化查询条件,排除sql分页
  220. ClubStatistics clubData = new ClubStatistics();
  221. clubData.setMonthStartTime(statistics.getMonthStartTime());
  222. clubData.setMonthEndTime(statistics.getMonthEndTime());
  223. clubData.setYearStartTime(statistics.getYearStartTime());
  224. clubData.setYearEndTime(statistics.getYearEndTime());
  225. clubData.setClubDataIntegrity(statistics.getClubDataIntegrity());
  226. if (StringUtils.isNotBlank(statistics.getRegisterStartTime())) {
  227. clubData.setRegisterStartTime(statistics.getRegisterStartTime());
  228. }
  229. if (StringUtils.isNotBlank(statistics.getRegisterEndTime())) {
  230. clubData.setRegisterEndTime(statistics.getRegisterEndTime());
  231. }
  232. if (StringUtils.isNotBlank(statistics.getSearchStartTime())) {
  233. clubData.setSearchStartTime(statistics.getSearchStartTime());
  234. }
  235. if (StringUtils.isNotBlank(statistics.getSearchEndTime())) {
  236. clubData.setSearchEndTime(statistics.getSearchEndTime());
  237. }
  238. if (StringUtils.isNotBlank(statistics.getCustomerValue())) {
  239. clubData.setCustomerValue(statistics.getCustomerValue());
  240. }
  241. if (StringUtils.isNotBlank(statistics.getSearchUserIdentity())) {
  242. clubData.setSearchUserIdentity(statistics.getSearchUserIdentity());
  243. }
  244. if (StringUtils.isNotBlank(statistics.getSearchStatus())) {
  245. clubData.setSearchStatus(statistics.getSearchStatus());
  246. }
  247. clubData.setLinkManIdentity(statistics.getLinkManIdentity());
  248. clubData.setCustomStartTime(statistics.getCustomStartTime());
  249. clubData.setCustomEndTime(statistics.getCustomEndTime());
  250. clubData.setPayTotalMonth(statistics.getPayTotalMonth());
  251. clubData.setPayTotalYear(statistics.getPayTotalYear());
  252. clubData.setPayTotal(statistics.getPayTotal());
  253. clubData.setPayTotalMonthType(statistics.getPayTotalMonthType());
  254. clubData.setOrderCountMonthType(statistics.getOrderCountMonthType());
  255. clubData.setPayTotalYearType(statistics.getPayTotalYearType());
  256. clubData.setOrderCountYearType(statistics.getOrderCountYearType());
  257. clubData.setPayTotalType(statistics.getPayTotalType());
  258. selStatisticsList = newCmClubDao.selStatisticsList(clubData);
  259. } else {
  260. selStatisticsList = newCmClubDao.selStatisticsList(statistics);
  261. }
  262. List<ClubStatistics> statisticsList = setListData(selStatisticsList, statistics);
  263. if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
  264. int pageNo = page.getPageNo();
  265. int pageSize = page.getPageSize();
  266. int number = 0;
  267. if (pageNo == 1) {
  268. number = 0;
  269. } else {
  270. number = (pageNo - 1) * pageSize;
  271. }
  272. List<ClubStatistics> list = new ArrayList<>();
  273. for (int i = 0; i <= statisticsList.size() - 1; i++) {
  274. if (i >= number && i < number + pageSize) {
  275. list.add(statisticsList.get(i));
  276. }
  277. }
  278. page.setCount(statisticsList.size());
  279. page.setList(list);
  280. } else {
  281. page.setList(statisticsList);
  282. }
  283. return page;
  284. }
  285. public List<easyExcel> exportExcel(ClubStatistics statistics) {
  286. List<easyExcel> statisticsList = newCmClubDao.findExcelList(statistics);
  287. List<easyExcel> easyExcels = setExData(statisticsList, statistics);
  288. return easyExcels;
  289. }
  290. public List<easyExcel> setExData(List<easyExcel> selStatisticsList, ClubStatistics statistics) {
  291. int number = 0;
  292. String type = "";
  293. Integer item = 0;
  294. // List<ClubStatistics> clubStatisticsList = selStatisticsList;
  295. List<CmBehaviorRecord> pageLableList = newCmClubDao.selPageLable();
  296. for (easyExcel clubStatistics : selStatisticsList) {
  297. // 机构类型
  298. if (StringUtils.isNotBlank(clubStatistics.getFirstClubType())) {
  299. type += clubStatistics.getFirstClubType();
  300. }
  301. if (StringUtils.isNotBlank(clubStatistics.getClassify())) {
  302. type += "-" + clubStatistics.getClassify();
  303. }
  304. clubStatistics.setClubType(type);
  305. // 计算资料完整度
  306. if (StringUtils.isNotBlank(clubStatistics.getName())) {
  307. number += 10;
  308. }
  309. if (StringUtils.isNotBlank(clubStatistics.getLinkMan())) {
  310. number += 10;
  311. }
  312. if (StringUtils.isNotBlank(clubStatistics.getContractMobile())) {
  313. number += 10;
  314. }
  315. if (StringUtils.isNotBlank(clubStatistics.getLinkManIdentity())) {
  316. number += 10;
  317. }
  318. if (StringUtils.isNotBlank(clubStatistics.getAddress())) {
  319. number += 10;
  320. }
  321. if (StringUtils.isNotBlank(clubStatistics.getBusinessLicenseImage())) {
  322. number += 10;
  323. }
  324. if (StringUtils.isNotBlank(clubStatistics.getUserIdentity())) {
  325. number += 10;
  326. }
  327. if (StringUtils.isNotBlank(clubStatistics.getSname())) {
  328. number += 3;
  329. }
  330. if (StringUtils.isNotBlank(clubStatistics.getContractEmail())) {
  331. number += 5;
  332. }
  333. if (StringUtils.isNotBlank(clubStatistics.getContractPhone())) {
  334. number += 4;
  335. }
  336. if (StringUtils.isNotBlank(clubStatistics.getFax())) {
  337. number += 3;
  338. }
  339. if (StringUtils.isNotBlank(clubStatistics.getHeadpic())) {
  340. number += 5;
  341. }
  342. if (StringUtils.isNotBlank(clubStatistics.getSocialCreditCode())) {
  343. number += 5;
  344. }
  345. if (StringUtils.isNotBlank(clubStatistics.getInfo())) {
  346. number += 5;
  347. }
  348. clubStatistics.setNumber(number);
  349. clubStatistics.setClubDataIntegrity(number + "%");
  350. number = 0;
  351. type = "";
  352. // 处理最常搜索词
  353. List<CmBehaviorRecord> collect = pageLableList.stream().filter(data -> data.getUserID().equals(clubStatistics.getUserID())).collect(Collectors.toList());
  354. if (collect.size() > 0) {
  355. clubStatistics.setPageLabel(collect.get(0).getPageLabel());
  356. item = collect.get(0).getNumber();
  357. for (int i = 0; i < collect.size() - 1; i++) {
  358. if (item < collect.get(i).getNumber()) {
  359. item = collect.get(i).getNumber();
  360. clubStatistics.setPageLabel(collect.get(i).getPageLabel());
  361. }
  362. }
  363. }
  364. }
  365. // 资料完整度处理
  366. if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
  367. if ("1".equals(statistics.getClubDataIntegrity())) {
  368. selStatisticsList = selStatisticsList.stream().filter(data -> (data.getNumber() > 20 && data.getNumber() < 70)).collect(Collectors.toList());
  369. } else {
  370. selStatisticsList = selStatisticsList.stream().filter(data -> data.getNumber() > 70).collect(Collectors.toList());
  371. }
  372. }
  373. return selStatisticsList;
  374. }
  375. public List<ClubStatistics> setListData(List<ClubStatistics> selStatisticsList, ClubStatistics statistics) {
  376. int number = 0;
  377. String type = "";
  378. Integer item = 0;
  379. // List<ClubStatistics> clubStatisticsList = selStatisticsList;
  380. List<CmBehaviorRecord> pageLableList = newCmClubDao.selPageLable();
  381. for (ClubStatistics clubStatistics : selStatisticsList) {
  382. // 机构类型
  383. if (StringUtils.isNotBlank(clubStatistics.getFirstClubType())) {
  384. type += clubStatistics.getFirstClubType();
  385. }
  386. if (StringUtils.isNotBlank(clubStatistics.getClassify())) {
  387. type += "-" + clubStatistics.getClassify();
  388. }
  389. clubStatistics.setClubType(type);
  390. // 计算资料完整度
  391. if (StringUtils.isNotBlank(clubStatistics.getName())) {
  392. number += 10;
  393. }
  394. if (StringUtils.isNotBlank(clubStatistics.getLinkMan())) {
  395. number += 10;
  396. }
  397. if (StringUtils.isNotBlank(clubStatistics.getContractMobile())) {
  398. number += 10;
  399. }
  400. if (StringUtils.isNotBlank(clubStatistics.getLinkManIdentity())) {
  401. number += 10;
  402. }
  403. if (StringUtils.isNotBlank(clubStatistics.getAddress())) {
  404. number += 10;
  405. }
  406. if (StringUtils.isNotBlank(clubStatistics.getBusinessLicenseImage())) {
  407. number += 10;
  408. }
  409. if (StringUtils.isNotBlank(clubStatistics.getUserIdentity())) {
  410. number += 10;
  411. }
  412. if (StringUtils.isNotBlank(clubStatistics.getSname())) {
  413. number += 3;
  414. }
  415. if (StringUtils.isNotBlank(clubStatistics.getContractEmail())) {
  416. number += 5;
  417. }
  418. if (StringUtils.isNotBlank(clubStatistics.getContractPhone())) {
  419. number += 4;
  420. }
  421. if (StringUtils.isNotBlank(clubStatistics.getFax())) {
  422. number += 3;
  423. }
  424. if (StringUtils.isNotBlank(clubStatistics.getHeadpic())) {
  425. number += 5;
  426. }
  427. if (StringUtils.isNotBlank(clubStatistics.getSocialCreditCode())) {
  428. number += 5;
  429. }
  430. if (StringUtils.isNotBlank(clubStatistics.getInfo())) {
  431. number += 5;
  432. }
  433. clubStatistics.setNumber(number);
  434. clubStatistics.setClubDataIntegrity(number + "%");
  435. number = 0;
  436. type = "";
  437. // 处理最常搜索词
  438. List<CmBehaviorRecord> collect = pageLableList.stream().filter(data -> data.getUserID().equals(clubStatistics.getUserID())).collect(Collectors.toList());
  439. if (collect.size() > 0) {
  440. clubStatistics.setPageLabel(collect.get(0).getPageLabel());
  441. item = collect.get(0).getNumber();
  442. for (int i = 0; i < collect.size() - 1; i++) {
  443. if (item < collect.get(i).getNumber()) {
  444. item = collect.get(i).getNumber();
  445. clubStatistics.setPageLabel(collect.get(i).getPageLabel());
  446. }
  447. }
  448. }
  449. }
  450. // 资料完整度处理
  451. if (StringUtils.isNotBlank(statistics.getClubDataIntegrity())) {
  452. if ("1".equals(statistics.getClubDataIntegrity())) {
  453. selStatisticsList = selStatisticsList.stream().filter(data -> (data.getNumber() > 20 && data.getNumber() < 70)).collect(Collectors.toList());
  454. } else {
  455. selStatisticsList = selStatisticsList.stream().filter(data -> data.getNumber() > 70).collect(Collectors.toList());
  456. }
  457. }
  458. return selStatisticsList;
  459. }
  460. }