BusinessProjectServiceImpl.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package com.goafanti.admin.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.admin.bo.BusinessProjectBo;
  13. import com.goafanti.admin.bo.ProjectSizeBo;
  14. import com.goafanti.admin.service.BusinessProjectService;
  15. import com.goafanti.common.dao.BusinessProjectMapper;
  16. import com.goafanti.common.dao.BusinessVarietiesMapper;
  17. import com.goafanti.common.model.BusinessProject;
  18. import com.goafanti.common.model.BusinessVarieties;
  19. import com.goafanti.common.utils.StringUtils;
  20. import com.goafanti.core.mybatis.BaseMybatisDao;
  21. import com.goafanti.core.mybatis.page.Pagination;
  22. @Service
  23. public class BusinessProjectServiceImpl extends BaseMybatisDao<BusinessProjectMapper> implements BusinessProjectService {
  24. @Autowired
  25. BusinessProjectMapper businessProjectMapper;
  26. @Autowired
  27. BusinessVarietiesMapper businessVarietiesMapper;
  28. @Override
  29. public int insert(String bname, String cid, String country, String province, String city, String district) {
  30. BusinessProject bp=new BusinessProject();
  31. bp.setId(UUID.randomUUID().toString());
  32. bp.setBname(bname);
  33. bp.setCid(cid);
  34. bp.setCountry(country);
  35. if (1!=Integer.valueOf(country)) {
  36. bp.setProvince(province);
  37. bp.setCity(city);
  38. bp.setDistrict(district);
  39. }
  40. bp.setDeleteSign(0);
  41. //bp.setCreateId(TokenManager.getAdminId());
  42. bp.setCreateId("f31c0d1a-05bc-4f5c-b4a8-95f983d24131");
  43. bp.setCreateTime(new Date());
  44. bp.setStatus("0");
  45. return businessProjectMapper.insert(bp);
  46. }
  47. @SuppressWarnings("unchecked")
  48. @Override
  49. public Pagination<BusinessProjectBo> listProject(String bname, String cid, String country,String province,String city,String district, String activityFlag,
  50. String status, Integer pNo, Integer pSize) {
  51. if (pNo == null || pNo < 0) {
  52. pNo = 1;
  53. }
  54. if (pSize == null || pSize < 0 || pSize > 10) {
  55. pSize = 10;
  56. }
  57. return (Pagination<BusinessProjectBo>)findPage("findProjectListByPage", "findProjectListCount",
  58. disposeParams(bname, cid, country, province, city, district, activityFlag,
  59. status),pNo,pSize);
  60. }
  61. private Map<String, Object> disposeParams(String bname, String cid, String country,String province,String city,String district, String activityFlag,
  62. String status) {
  63. Map<String, Object> params = new HashMap<>();
  64. if (StringUtils.isNotBlank(bname)) {
  65. params.put("bname", bname);
  66. }
  67. if (StringUtils.isNotBlank(cid)) {
  68. params.put("cid", cid);
  69. }
  70. if (StringUtils.isNotBlank(country)) {
  71. params.put("country", country);
  72. }
  73. if (StringUtils.isNotBlank(province)) {
  74. params.put("province", province);
  75. }
  76. if (StringUtils.isNotBlank(city)) {
  77. params.put("city", city);
  78. }
  79. if (StringUtils.isNotBlank(district)) {
  80. params.put("district", district);
  81. }
  82. if (StringUtils.isNotBlank(activityFlag)) {
  83. params.put("activityFlag", activityFlag);
  84. }
  85. if (StringUtils.isNotBlank(status)) {
  86. params.put("status", status);
  87. }
  88. return params;
  89. }
  90. @Override
  91. public int getBnamecount(String bname) {
  92. return businessProjectMapper.getBnamecount(bname);
  93. }
  94. @Override
  95. public int deleteProject(String id) {
  96. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  97. if (bp.getDeleteSign()==0) {
  98. bp.setDeleteSign(1);
  99. }else {
  100. bp.setDeleteSign(0);
  101. }
  102. return businessProjectMapper.updateByPrimaryKey(bp);
  103. }
  104. @Override
  105. public int updateStopProject(String id) {
  106. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  107. if (Integer.valueOf(bp.getStatus())==0) {
  108. bp.setStatus("1");
  109. }else {
  110. bp.setStatus("0");
  111. }
  112. return businessProjectMapper.updateByPrimaryKey(bp);
  113. }
  114. @Override
  115. public BusinessProjectBo orgProject(String id) {
  116. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  117. BusinessProjectBo bpo=new BusinessProjectBo();
  118. BeanUtils.copyProperties(bp,bpo);
  119. String cname=getAllCname(bpo.getCid());
  120. System.out.println(cname);
  121. bpo.setCname(cname);
  122. return bpo;
  123. }
  124. @Override
  125. public List<Map<String, String>> getAllCname() {
  126. List<Map<String, String>> list=new ArrayList<Map<String, String>>();
  127. List<String> listcid=businessVarietiesMapper.getListId();
  128. for (String s : listcid) {
  129. Map<String, String> map=new HashMap<>();
  130. String cname=getAllCname(s);
  131. map.put("id", s);
  132. map.put("cname", cname);
  133. if (StringUtils.isNotBlank(cname)) {
  134. list.add(map);
  135. }
  136. }
  137. return list;
  138. }
  139. /**
  140. * 递归获取上级来获取全路径
  141. * @param s ID
  142. * @return 路径
  143. */
  144. private String getAllCname(String s) {
  145. String cid=businessVarietiesMapper.getThisCid(s);
  146. String cname=businessVarietiesMapper.getThisCname(cid);
  147. BusinessVarieties bv=businessVarietiesMapper.selectByPrimaryKey(s);
  148. String sid=bv.getSuperId();
  149. if (cid.length()>4) {
  150. String w=getAllCname(sid)+"-"+cname;
  151. return w;
  152. }else{
  153. return cid.length()>3?cname:"";
  154. }
  155. }
  156. @Override
  157. public int updateAddOffset(String id) {
  158. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  159. if (null==bp.getOffset()) {
  160. bp.setOffset(new BigDecimal(1));
  161. }
  162. if (bp.getOffset().compareTo(new BigDecimal(1))==-1) {
  163. bp.setOffset(bp.getOffset().add(new BigDecimal(0.01)));
  164. }
  165. return businessProjectMapper.updateByPrimaryKey(bp);
  166. }
  167. @Override
  168. public int updateSubtractOffset(String id) {
  169. BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id);
  170. if (null==bp.getOffset()) {
  171. bp.setOffset(new BigDecimal(1));
  172. }
  173. if (bp.getOffset().compareTo(new BigDecimal(0))==1) {
  174. bp.setOffset(bp.getOffset().subtract(new BigDecimal(0.01)));
  175. }
  176. return businessProjectMapper.updateByPrimaryKey(bp);
  177. }
  178. /*public ProjectSizeBo orgProjectSize(String id) {
  179. return null;
  180. }*/
  181. }