NewCmClubService.java 21 KB

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