BusinessProjectServiceImpl.java 14 KB

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