NewCmClubService.java 18 KB

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