JtBusinessServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package com.goafanti.business.service.impl;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.UUID;
  7. import org.apache.poi.poifs.property.Child;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import com.goafanti.business.bo.JtBusinessCategoryBo;
  11. import com.goafanti.business.bo.JtBusinessCategoryTree;
  12. import com.goafanti.business.bo.JtBusinessProjectResult;
  13. import com.goafanti.business.service.JtBusinessService;
  14. import com.goafanti.common.dao.JtBusinessCategoryMapper;
  15. import com.goafanti.common.dao.JtBusinessProjectMapper;
  16. import com.goafanti.common.dao.JtTagMapper;
  17. import com.goafanti.common.enums.ProjectAuditStatus;
  18. import com.goafanti.common.model.JtBusinessCategory;
  19. import com.goafanti.common.model.JtBusinessProject;
  20. import com.goafanti.common.model.JtTag;
  21. import com.goafanti.common.utils.StringUtils;
  22. import com.goafanti.core.mybatis.BaseMybatisDao;
  23. import com.goafanti.core.mybatis.page.Pagination;
  24. import com.goafanti.core.shiro.token.TokenManager;
  25. import com.goafanti.order.enums.AuditState;
  26. @Service
  27. public class JtBusinessServiceImpl extends BaseMybatisDao<JtBusinessProjectMapper> implements JtBusinessService{
  28. @Autowired
  29. JtBusinessCategoryMapper jtBusinessCategoryMapper;
  30. @Autowired
  31. JtBusinessProjectMapper jtBusinessProjectMapper;
  32. @Autowired
  33. private JtTagMapper jtTagMapper;
  34. @Override
  35. public JtBusinessCategory getBusinessCategoryByLayerAndName(Integer layer, String name) {
  36. // TODO Auto-generated method stub
  37. return jtBusinessCategoryMapper.getBusinessCategoryByLayerAndName(layer, name);
  38. }
  39. @Override
  40. public List<JtBusinessCategory> getBusinessCategoryBySuperId(String id,Integer size) {
  41. // TODO Auto-generated method stub
  42. return jtBusinessCategoryMapper.getBusinessCategoryBySuperId(id,size);
  43. }
  44. @Override
  45. public List<JtBusinessProject> getBusinessProjectByCategoryId(String id,Integer size,Integer isHot) {
  46. // TODO Auto-generated method stub
  47. return jtBusinessProjectMapper.getBusinessProjectByCategoryId(id,size,isHot);
  48. }
  49. @Override
  50. public JtBusinessProjectResult getBusinessProjectDetail(String id) {
  51. JtBusinessProjectResult j=jtBusinessProjectMapper.selectByPrimaryKeyWithModule(id);
  52. j.setTags(jtTagMapper.selectProjectTag(id));
  53. return j;
  54. }
  55. @Override
  56. public JtBusinessCategoryTree getCategoryTree(String id) {
  57. // TODO Auto-generated method stub
  58. return jtBusinessCategoryMapper.getCategoryTree(id);
  59. }
  60. public List<JtBusinessCategoryBo>getCategoryBoList(Integer module){
  61. return jtBusinessCategoryMapper.getCategoryBoList(module);
  62. }
  63. /*
  64. * 登录用户0 项目列表页1 privateProject
  65. * ownerId优先级高于privateProject
  66. *
  67. * ordetType---0 发布时间 1价格 2成交量
  68. * orderSort ----0大->小 1小->大
  69. *
  70. *
  71. * */
  72. @SuppressWarnings("unchecked")
  73. @Override
  74. public Pagination<JtBusinessProjectResult> getProjects(String topId, String secondId, String name, Integer pageSize,
  75. Integer pageNo,Integer privateProject,Integer auditStatus,Integer module,Integer isHot,Integer orderType,Integer orderSort,String ownerId) {
  76. if(orderType==null)orderType=0;
  77. if(orderSort==null)orderSort=0;
  78. // TODO Auto-generated method stub
  79. if (pageNo == null || pageNo < 0) {
  80. pageNo = 1;
  81. }
  82. if (pageSize == null || pageSize < 0 ) {
  83. pageSize = 10;
  84. }
  85. Map<String, Object> params=disposeParams(topId, secondId, name);
  86. if(auditStatus!=null ) {
  87. params.put("auditStatus", auditStatus);
  88. }
  89. if(privateProject!=null && privateProject ==0)
  90. params.put("ownerId", TokenManager.getUserId());
  91. if(StringUtils.isNotBlank(ownerId)) {
  92. params.put("ownerId", ownerId);
  93. }
  94. if(module!=null)params.put("module", module);
  95. if(isHot!=null)params.put("isHot", isHot);
  96. if(orderType!=null)params.put("orderType", orderType);
  97. if(orderSort!=null)params.put("orderSort", orderSort);
  98. return (Pagination<JtBusinessProjectResult>)findPage("findJtBusinessProjectByPage","findJtBusinessCountByPage",params,pageNo,pageSize);
  99. }
  100. private Map<String, Object> disposeParams(String topId, String secondId, String name) {
  101. Map<String, Object> params = new HashMap<>();
  102. if (StringUtils.isNotBlank(topId)) {
  103. params.put("topId", topId);
  104. }
  105. if (StringUtils.isNotBlank(secondId)) {
  106. params.put("secondId", secondId);
  107. }
  108. if (StringUtils.isNotBlank(name)) {
  109. params.put("name", name);
  110. }
  111. return params;
  112. }
  113. @Override
  114. public int insertCategory(JtBusinessCategory jtBusinessCategory) {
  115. // TODO Auto-generated method stub
  116. // jtBusinessCategoryMapper.autoIncreaseSort(jtBusinessCategory.getLayer(),jtBusinessCategory.getSort());
  117. if(jtBusinessCategory.getSuperId()!=null && jtBusinessCategory.getLayer().intValue()==1 && jtBusinessCategory.getSuperId().length()>0)return -2;
  118. String number="BC";
  119. if(jtBusinessCategory.getLayer().intValue()==2) {
  120. //2层,先加第一层
  121. //找到当前品类父级品类
  122. JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getSuperId());
  123. if(sp==null || sp.getLayer()!=1) {
  124. //找到的父级品类层数不是1 或者未找到
  125. return -2;
  126. }
  127. //加前层
  128. //父级品类层数为1的情况下 第一层编号为父级sort序号
  129. int size1=sp.getSort();
  130. if(size1>99)return -1;
  131. if(size1<10)number+="0";
  132. number+=size1;
  133. }
  134. //加层
  135. int size2;
  136. //通过父级id获取当前层列表
  137. List<JtBusinessCategory>businessCategories =jtBusinessCategoryMapper.getBusinessCategoryBySuperId(jtBusinessCategory.getSuperId(), null);
  138. //列表为0,当前层编号size2设置为1,大于0 设置为当前最大sort+1
  139. if(businessCategories.size()>0)
  140. size2=businessCategories.get(businessCategories.size()-1).getSort()+1;
  141. else size2=1;
  142. //每层最多99个
  143. if(size2>99)return -1;
  144. //增加0
  145. if(size2<10)number+="0";
  146. //完成编号
  147. number+=size2;
  148. jtBusinessCategory.setNumber(number);
  149. //设置sort序号
  150. jtBusinessCategory.setSort(size2);
  151. jtBusinessCategory.setCreateTime(new Date());
  152. jtBusinessCategory.setId(UUID.randomUUID().toString());
  153. return jtBusinessCategoryMapper.insertSelective(jtBusinessCategory);
  154. }
  155. @Override
  156. public int deleteCategoryById(String id) {
  157. // TODO Auto-generated method stub
  158. //查找品类
  159. JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(id);
  160. //查找子品类 存在子品类不允许删除
  161. List<JtBusinessCategory> chidren=jtBusinessCategoryMapper.getBusinessCategoryBySuperId(sp.getId(), null);
  162. if(chidren.size()>0) {
  163. return -1;
  164. }
  165. List<JtBusinessProject> childrenProject=jtBusinessProjectMapper.getBusinessProjectByCategoryId(id, 100,null);
  166. if(childrenProject!= null && childrenProject.size()>0) {
  167. return -1;
  168. }
  169. return jtBusinessCategoryMapper.deleteByPrimaryKey(id);
  170. }
  171. @Override
  172. public JtBusinessCategory getCategoryById(String id) {
  173. // TODO Auto-generated method stub
  174. return jtBusinessCategoryMapper.selectByPrimaryKey(id);
  175. }
  176. @Override
  177. public int updateCategory(JtBusinessCategory jtBusinessCategory) {
  178. // TODO Auto-generated method stub
  179. return jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
  180. }
  181. private Map<String, Object> disposeCategoryParams(String name,Integer layer ) {
  182. Map<String, Object> params = new HashMap<>();
  183. if (layer!=null) {
  184. params.put("layer", layer);
  185. }
  186. if (StringUtils.isNotBlank(name)) {
  187. params.put("name", name);
  188. }
  189. return params;
  190. }
  191. @Override
  192. public int insertProject(JtBusinessProject jtBusinessProject) {
  193. // TODO Auto-generated method stub
  194. jtBusinessProject.setCreateTime(new Date());
  195. jtBusinessProject.setId(UUID.randomUUID().toString());
  196. jtBusinessProject.setOwnerId(TokenManager.getUserId());
  197. jtBusinessProject.setAuditStatus(ProjectAuditStatus.CREATE.getCode());
  198. List<JtBusinessProject>projects=jtBusinessProjectMapper.findProjectOrderByNumber();
  199. int cSize = 1;
  200. if(projects!=null && projects.size()>0)
  201. {
  202. String number=projects.get(projects.size()-1).getNumber();
  203. if(number!=null && number.length()==6)
  204. {
  205. String nbString=number.substring(2);
  206. try {
  207. cSize=Integer.parseInt(nbString)+1;
  208. cSize=Math.max(cSize, projects.size()+1);
  209. }catch (Exception e) {
  210. // TODO: handle exception
  211. return -1;
  212. }
  213. }
  214. else cSize=1;
  215. }
  216. else cSize=1;
  217. String nbString="BP";
  218. String sizeString="000"+cSize;
  219. sizeString=sizeString.substring(sizeString.length()-4);
  220. nbString+=sizeString;
  221. jtBusinessProject.setNumber(nbString);
  222. jtBusinessProjectMapper.insertSelective(jtBusinessProject);
  223. return 1;
  224. }
  225. @Override
  226. public int deleteProjectById(String id) {
  227. return jtBusinessProjectMapper.deleteByPrimaryKey(id);
  228. }
  229. @Override
  230. public int updateProject(JtBusinessProject jtBusinessProject) {
  231. jtBusinessProjectMapper.updateByPrimaryKeySelective(jtBusinessProject);
  232. if(StringUtils.isNotBlank(jtBusinessProject.getTag())){
  233. String str=jtBusinessProject.getTag();
  234. String[] strs = str.split(",");
  235. jtTagMapper.deleteByProjectId(jtBusinessProject.getId());
  236. for (String s : strs) {
  237. jtTagMapper.insertProjectTag(UUID.randomUUID().toString(),s,jtBusinessProject.getId());
  238. }
  239. }
  240. return 1;
  241. }
  242. @Override
  243. public List<JtBusinessProject> getProjectsLimit(Integer size) {
  244. // TODO Auto-generated method stub
  245. return jtBusinessProjectMapper.findProjectOrderByNumber();
  246. }
  247. @Override
  248. public int deleteByIdAndUid(String id) {
  249. // TODO Auto-generated method stub
  250. if(TokenManager.getUserId()==null)return -1;
  251. return jtBusinessProjectMapper.deleteByIdAndUid(id,TokenManager.getUserId());
  252. }
  253. @SuppressWarnings("unchecked")
  254. @Override
  255. public Pagination<JtBusinessProject> listProjectIInterestedIn(Integer pageNo,Integer pageSize) {
  256. // TODO Auto-generated method stub
  257. if (pageNo == null || pageNo < 0) {
  258. pageNo = 1;
  259. }
  260. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  261. pageSize = 10;
  262. }
  263. Map<String,Object> params=new HashMap<String,Object>();
  264. params.put("uid", TokenManager.getUserId());
  265. return (Pagination<JtBusinessProject>) findPage("findInterestedProjcet", "findInterestedProjcetCount", params, pageNo, pageSize);
  266. }
  267. }