BusinessProjectServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. package com.goafanti.admin.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.admin.bo.BusinessProjectBo;
  12. import com.goafanti.admin.bo.ProjectSizeBo;
  13. import com.goafanti.admin.service.BusinessProjectService;
  14. import com.goafanti.app.bo.ProjectBo;
  15. import com.goafanti.app.bo.ProjectDetailBo;
  16. import com.goafanti.common.dao.BusinessProjectMapper;
  17. import com.goafanti.common.dao.BusinessVarietiesMapper;
  18. import com.goafanti.common.dao.ProjectInterestMapper;
  19. import com.goafanti.common.dao.ProjectSizeMapper;
  20. import com.goafanti.common.model.BusinessProject;
  21. import com.goafanti.common.model.BusinessVarieties;
  22. import com.goafanti.common.model.ProjectSize;
  23. import com.goafanti.common.utils.StringUtils;
  24. import com.goafanti.core.mybatis.BaseMybatisDao;
  25. import com.goafanti.core.mybatis.page.Pagination;
  26. import com.goafanti.core.shiro.token.TokenManager;
  27. @Service
  28. public class BusinessProjectServiceImpl extends BaseMybatisDao<BusinessProjectMapper> implements BusinessProjectService {
  29. @Autowired
  30. BusinessProjectMapper businessProjectMapper;
  31. @Autowired
  32. BusinessVarietiesMapper businessVarietiesMapper;
  33. @Autowired
  34. ProjectSizeMapper projectSizeMapper;
  35. @Autowired
  36. ProjectInterestMapper projectInterestMapper;
  37. @Override
  38. public int insert(String bname, String cid, String country, String province, String city, String district) {
  39. BusinessProject bp=new BusinessProject();
  40. bp.setId(UUID.randomUUID().toString());
  41. bp.setBname(bname);
  42. bp.setCid(cid);
  43. bp.setCountry(country);
  44. if (1!=Integer.valueOf(country)) {
  45. bp.setProvince(province);
  46. bp.setCity(city);
  47. bp.setDistrict(district);
  48. }
  49. bp.setDeleteSign(0);
  50. //bp.setCreateId("f31c0d1a-05bc-4f5c-b4a8-95f983d24131");
  51. if (StringUtils.isNotBlank(TokenManager.getAdminId())) {
  52. bp.setCreateId(TokenManager.getAdminId());
  53. }
  54. bp.setCreateTime(new Date());
  55. bp.setStatus("0");
  56. return businessProjectMapper.insert(bp);
  57. }
  58. @SuppressWarnings("unchecked")
  59. @Override
  60. public Pagination<BusinessProjectBo> listProject(String bname, String cid, String country,String province,String city,String district, String activityFlag,
  61. String status, Integer pNo, Integer pSize) {
  62. if (pNo == null || pNo < 0) {
  63. pNo = 1;
  64. }
  65. if (pSize == null || pSize < 0 || pSize > 10) {
  66. pSize = 10;
  67. }
  68. Pagination<BusinessProjectBo> pt=(Pagination<BusinessProjectBo>)findPage("findProjectListByPage", "findProjectListCount",
  69. disposeParams(bname, cid, country, province, city, district, activityFlag,
  70. status),pNo,pSize);
  71. List<BusinessProjectBo> list=(List<BusinessProjectBo>) pt.getList();
  72. for (BusinessProjectBo o : list) {
  73. o.setCname(getAllCname(o.getCid()));
  74. }
  75. return pt;
  76. }
  77. private Map<String, Object> disposeParams(String bname, String cid, String country,String province,String city,String district, String activityFlag,
  78. String status) {
  79. Map<String, Object> params = new HashMap<>();
  80. if (StringUtils.isNotBlank(bname)) {
  81. params.put("bname", bname);
  82. }
  83. if (StringUtils.isNotBlank(cid)) {
  84. params.put("cid", cid);
  85. }
  86. if (StringUtils.isNotBlank(country)) {
  87. params.put("country", country);
  88. }
  89. if (StringUtils.isNotBlank(province)) {
  90. params.put("province", province);
  91. }
  92. if (StringUtils.isNotBlank(city)) {
  93. params.put("city", city);
  94. }
  95. if (StringUtils.isNotBlank(district)) {
  96. params.put("district", district);
  97. }
  98. if (StringUtils.isNotBlank(activityFlag)) {
  99. params.put("activityFlag", activityFlag);
  100. }
  101. if (StringUtils.isNotBlank(status)) {
  102. params.put("status", status);
  103. }
  104. return params;
  105. }
  106. @Override
  107. public int getBnamecount(String bname) {
  108. return businessProjectMapper.getBnamecount(bname);
  109. }
  110. @Override
  111. public int deleteProject(String id) {
  112. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  113. if (bp.getDeleteSign()==0) {
  114. bp.setDeleteSign(1);
  115. }else {
  116. bp.setDeleteSign(0);
  117. }
  118. return businessProjectMapper.updateByPrimaryKey(bp);
  119. }
  120. @Override
  121. public int updateStopProject(String id) {
  122. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  123. if (Integer.valueOf(bp.getStatus())==0) {
  124. bp.setStatus("1");
  125. }else {
  126. bp.setStatus("0");
  127. }
  128. return businessProjectMapper.updateByPrimaryKey(bp);
  129. }
  130. @Override
  131. public BusinessProjectBo orgProjects(String id) {
  132. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  133. BusinessProjectBo bpo=new BusinessProjectBo();
  134. BeanUtils.copyProperties(bp,bpo);
  135. String cname=getAllCname(bpo.getCid());
  136. String createId=bpo.getCreateId();
  137. bpo.setCreateName(businessProjectMapper.getCreateName(createId));
  138. bpo.setCname(cname);
  139. return bpo;
  140. }
  141. @Override
  142. public List<Object> orgProject(String id) {
  143. ProjectDetailBo pd=businessProjectMapper.selectAppProjectDetail(id);
  144. if (StringUtils.isNotBlank(TokenManager.getUserId())&&projectInterestMapper.checkUidAndDid(id,TokenManager.getUserId())>0) {
  145. pd.setInterest("1");
  146. }else {
  147. pd.setInterest("0");
  148. }
  149. List<Object> l=new ArrayList<>();
  150. l.add(pd );
  151. List<String> l2=projectSizeMapper.selectPidList(id);
  152. l.add(l2);
  153. return l;
  154. }
  155. @Override
  156. public List<Map<String, String>> getAllCnames(Integer flag) {
  157. List<Map<String, String>> list=new ArrayList<Map<String, String>>();
  158. List<String> listcid=businessVarietiesMapper.getListId();
  159. for (String s : listcid) {
  160. Map<String, String> map=new HashMap<>();
  161. String cname=getAllCname(s);
  162. map.put("id", s);
  163. map.put("cname", cname);
  164. if (flag==1) {
  165. if (StringUtils.isBlank(cname)) {
  166. map.put("cname", "平台超级业务品类");
  167. }
  168. list.add(map);
  169. }else {
  170. if (StringUtils.isNotBlank(cname)) {
  171. list.add(map);
  172. }
  173. }
  174. }
  175. return list;
  176. }
  177. /**
  178. * 递归获取上级来获取全路径
  179. * @param s ID
  180. * @return 路径
  181. */
  182. private String getAllCname(String s) {
  183. String cid=businessVarietiesMapper.getThisCid(s);
  184. String cname=businessVarietiesMapper.getThisCname(cid);
  185. BusinessVarieties bv=businessVarietiesMapper.selectByPrimaryKey(s);
  186. String sid=bv.getSuperId();
  187. if (cid.length()>4) {
  188. if(bv.getSuperId().equals(bv.getId())){
  189. return "";
  190. }
  191. String w=getAllCname(sid)+"-"+cname;
  192. return w;
  193. }else{
  194. return cid.length()>3?cname:"";
  195. }
  196. }
  197. @Override
  198. public int updateProject(BusinessProject s) {
  199. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(s.getId());
  200. TheGinseng(s, bp);
  201. return businessProjectMapper.updateByPrimaryKey(bp);
  202. }
  203. private void TheGinseng(BusinessProject s, BusinessProject bp) {
  204. if (StringUtils.isNotBlank(s.getBname())) {
  205. bp.setBname(s.getBname());
  206. }
  207. if (StringUtils.isNotBlank(s.getCid())) {
  208. bp.setCid(s.getCid());
  209. }
  210. if (StringUtils.isNotBlank(s.getCountry())) {
  211. bp.setCountry(s.getCountry());
  212. }
  213. if (StringUtils.isNotBlank(s.getProvince())) {
  214. bp.setProvince(s.getProvince());
  215. bp.setCity(s.getCity());
  216. bp.setDistrict(s.getDistrict());
  217. }
  218. if (StringUtils.isNotBlank(s.getCity())) {
  219. bp.setCity(s.getCity());
  220. bp.setDistrict(s.getDistrict());
  221. }
  222. if (StringUtils.isNotBlank(s.getDistrict())) {
  223. bp.setDistrict(s.getDistrict());
  224. }
  225. bp.setPrice(s.getPrice());
  226. bp.setOffset(s.getOffset());
  227. bp.setActivityFlag(s.getActivityFlag());
  228. bp.setMemberPrice(s.getMemberPrice());
  229. bp.setActivityPrice(s.getActivityPrice());
  230. bp.setIntroduce(s.getIntroduce());
  231. bp.setValueEffect(s.getValueEffect());
  232. bp.setClientSize(s.getClientSize());
  233. bp.setMinLogo(s.getMinLogo());
  234. bp.setMaxLogo(s.getMaxLogo());
  235. if (null!=(s.getStatus())) {
  236. bp.setStatus(s.getStatus());
  237. }
  238. bp.setUpdateTime(new Date());
  239. }
  240. @Override
  241. public int addProjectSize(ProjectSize ps) {
  242. ps.setId(UUID.randomUUID().toString());
  243. if (StringUtils.isNotBlank(TokenManager.getAdminId())) {
  244. ps.setCreateId(TokenManager.getAdminId());
  245. }
  246. //ps.setCreateId("f31c0d1a-05bc-4f5c-b4a8-95f983d24131");
  247. ps.setCreateTime(new Date());
  248. ps.setStatus(0);
  249. return projectSizeMapper.insert(ps);
  250. }
  251. @Override
  252. public int updateOrgProjectSize(ProjectSize ps) {
  253. ProjectSize psz=projectSizeMapper.selectByPrimaryKey(ps.getId());
  254. projectSizeConfiguration(ps, psz);
  255. System.out.println(psz);
  256. return projectSizeMapper.updateByPrimaryKeySelective(psz);
  257. }
  258. private void projectSizeConfiguration(ProjectSize ps, ProjectSize psz) {
  259. if (StringUtils.isNotBlank(ps.getPid())) {
  260. psz.setId(ps.getPid());
  261. }
  262. if (StringUtils.isNotBlank(ps.getPname())) {
  263. psz.setPname(ps.getPname());
  264. }
  265. if (null!=ps.getPrice()) {
  266. psz.setPrice(ps.getPrice());
  267. }
  268. if (null!=(ps.getOffset())) {
  269. psz.setOffset(ps.getOffset());
  270. }
  271. if (null!=(ps.getActivityFlag())) {
  272. psz.setActivityFlag(ps.getActivityFlag());
  273. }
  274. if (null!=(ps.getMemberPrice())) {
  275. psz.setMemberPrice(ps.getMemberPrice());
  276. }
  277. if (null!=(ps.getActivityPrice())) {
  278. psz.setActivityPrice(ps.getActivityPrice());
  279. }
  280. if (null!=(ps.getStatus())) {
  281. psz.setStatus(ps.getStatus());
  282. }
  283. psz.setUpdateTime(new Date());
  284. }
  285. @SuppressWarnings("unchecked")
  286. @Override
  287. public Pagination<ProjectSizeBo> listProjectSize(String pid,Integer pNo,Integer pSize) {
  288. if (pNo == null || pNo < 0) {
  289. pNo = 1;
  290. }
  291. if (pSize == null || pSize < 0 || pSize > 10) {
  292. pSize = 10;
  293. }
  294. Map<String, Object>map=new HashMap<>();
  295. map.put("pid", pid);
  296. Pagination<ProjectSizeBo> pt=(Pagination<ProjectSizeBo>)findPage("findProjectSizeListByPage", "findProjectSizeListCount",
  297. map,pNo,pSize);
  298. return pt;
  299. }
  300. @Override
  301. public ProjectSizeBo getProjectSize(String id) {
  302. return projectSizeMapper.selectByBusinessId(id);
  303. }
  304. @Override
  305. public int deleteProjectSize(String id) {
  306. return projectSizeMapper.deleteByPrimaryKey(id);
  307. }
  308. @Override
  309. public int updateSotpProjectSize(String id) {
  310. ProjectSize ps=projectSizeMapper.selectByPrimaryKey(id);
  311. int i=ps.getStatus();
  312. if (i==0) {
  313. ps.setStatus(1);
  314. }else {
  315. ps.setStatus(0);
  316. }
  317. return projectSizeMapper.updateByPrimaryKey(ps);
  318. }
  319. @Override
  320. public boolean WhetherRepeat(ProjectSize ps) {
  321. List<ProjectSizeBo> list=projectSizeMapper.getgetPnamecount(ps.getPname());
  322. for (ProjectSizeBo p : list) {
  323. if (p.getPid().equals(ps.getPid())) {
  324. return true;
  325. }
  326. }
  327. return false;
  328. }
  329. @Override
  330. public boolean judgeStatus(ProjectSize ps) {
  331. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(ps.getPid());
  332. if (Integer.valueOf(bp.getStatus())==1) {
  333. return true;
  334. }else {
  335. return false;
  336. }
  337. }
  338. @Override
  339. public boolean judgeBeing(BusinessProject s) {
  340. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(s.getId());
  341. BusinessProject bp1=businessProjectMapper.selectByPrimaryBname(s.getBname());
  342. if (null==bp||null==bp1||bp.getId().equals(bp1.getId())) {
  343. return false;
  344. }else {
  345. return true;
  346. }
  347. }
  348. @SuppressWarnings("unchecked")
  349. @Override
  350. public Pagination<ProjectBo> getBusinessProject(String id,Integer pNo,Integer pSize) {
  351. if (pNo == null || pNo <= 0) {
  352. pNo = 1;
  353. }
  354. if (pSize == null || pSize < 0 || pSize > 10) {
  355. pSize = 10;
  356. }
  357. Map<String, Object> params = new HashMap<>();
  358. if (StringUtils.isNotBlank(id)) {
  359. params.put("id", id);
  360. }
  361. Pagination<ProjectBo> p=(Pagination<ProjectBo>)findPage("getBusinessProject", "getBusinessProjectCount",
  362. params,pNo,pSize);
  363. return p;
  364. }
  365. @SuppressWarnings("unchecked")
  366. @Override
  367. public Pagination<ProjectBo> recommendProjectList(Integer pNo, Integer pSize) {
  368. if (pNo == null || pNo <= 0) {
  369. pNo = 1;
  370. }
  371. if (pSize == null || pSize < 0 || pSize > 10) {
  372. pSize = 10;
  373. }
  374. Map<String, Object> params = new HashMap<>();
  375. Pagination<ProjectBo> p=(Pagination<ProjectBo>)findPage("findRecommendProjectListByPage", "findRecommendProjectListCount",
  376. params,pNo,pSize);
  377. List<ProjectBo> l=(List<ProjectBo>) p.getList();
  378. for (ProjectBo pb : l) {
  379. pb.setInterestCount(String.valueOf(projectInterestMapper.countInterest(pb.getId())));
  380. }
  381. return p;
  382. }
  383. }