NewCmClubService.java 20 KB

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