JtBusinessServiceImpl.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.service.JtBusinessService;
  13. import com.goafanti.common.dao.JtBusinessCategoryMapper;
  14. import com.goafanti.common.dao.JtBusinessProjectMapper;
  15. import com.goafanti.common.model.JtBusinessCategory;
  16. import com.goafanti.common.model.JtBusinessProject;
  17. import com.goafanti.common.utils.StringUtils;
  18. import com.goafanti.core.mybatis.BaseMybatisDao;
  19. import com.goafanti.core.mybatis.page.Pagination;
  20. @Service
  21. public class JtBusinessServiceImpl extends BaseMybatisDao<JtBusinessProjectMapper> implements JtBusinessService{
  22. @Autowired
  23. JtBusinessCategoryMapper jtBusinessCategoryMapper;
  24. @Autowired
  25. JtBusinessProjectMapper jtBusinessProjectMapper;
  26. @Override
  27. public JtBusinessCategory getBusinessCategoryByLayerAndName(Integer layer, String name) {
  28. // TODO Auto-generated method stub
  29. return jtBusinessCategoryMapper.getBusinessCategoryByLayerAndName(layer, name);
  30. }
  31. @Override
  32. public List<JtBusinessCategory> getBusinessCategoryBySuperId(String id,Integer size) {
  33. // TODO Auto-generated method stub
  34. return jtBusinessCategoryMapper.getBusinessCategoryBySuperId(id,size);
  35. }
  36. @Override
  37. public List<JtBusinessProject> getBusinessProjectByCategoryId(String id,Integer size) {
  38. // TODO Auto-generated method stub
  39. return jtBusinessProjectMapper.getBusinessProjectByCategoryId(id,size);
  40. }
  41. @Override
  42. public JtBusinessProject getBusinessProjectDetail(String id) {
  43. // TODO Auto-generated method stub
  44. return jtBusinessProjectMapper.selectByPrimaryKey(id);
  45. }
  46. @Override
  47. public JtBusinessCategoryTree getCategoryTree(String id) {
  48. // TODO Auto-generated method stub
  49. return jtBusinessCategoryMapper.getCategoryTree(id);
  50. }
  51. public List<JtBusinessCategoryBo>getCategoryBoList(){
  52. return jtBusinessCategoryMapper.getCategoryBoList();
  53. }
  54. @SuppressWarnings("unchecked")
  55. @Override
  56. public Pagination<JtBusinessProject> getProjects(String topId, String secondId, String name, Integer pageSize,
  57. Integer pageNo) {
  58. // TODO Auto-generated method stub
  59. if (pageNo == null || pageNo < 0) {
  60. pageNo = 1;
  61. }
  62. if (pageSize == null || pageSize < 0 ) {
  63. pageSize = 10;
  64. }
  65. return (Pagination<JtBusinessProject>)findPage("findJtBusinessProjectByPage","findJtBusinessCountByPage",disposeParams(topId, secondId, name),pageNo,pageSize);
  66. }
  67. private Map<String, Object> disposeParams(String topId, String secondId, String name) {
  68. Map<String, Object> params = new HashMap<>();
  69. if (StringUtils.isNotBlank(topId)) {
  70. params.put("topId", topId);
  71. }
  72. if (StringUtils.isNotBlank(secondId)) {
  73. params.put("secondId", secondId);
  74. }
  75. if (StringUtils.isNotBlank(name)) {
  76. params.put("name", name);
  77. }
  78. return params;
  79. }
  80. @Override
  81. public int insertCategory(JtBusinessCategory jtBusinessCategory) {
  82. // TODO Auto-generated method stub
  83. // jtBusinessCategoryMapper.autoIncreaseSort(jtBusinessCategory.getLayer(),jtBusinessCategory.getSort());
  84. if(jtBusinessCategory.getSuperId()!=null && jtBusinessCategory.getLayer().intValue()==1 && jtBusinessCategory.getSuperId().length()>0)return -2;
  85. String number="BC";
  86. if(jtBusinessCategory.getLayer().intValue()==2) {
  87. //2层,先加第一层
  88. //找到当前品类父级品类
  89. JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getSuperId());
  90. if(sp==null || sp.getLayer()!=1) {
  91. //找到的父级品类层数不是1 或者未找到
  92. return -2;
  93. }
  94. //加前层
  95. //父级品类层数为1的情况下 第一层编号为父级sort序号
  96. int size1=sp.getSort();
  97. if(size1>99)return -1;
  98. if(size1<10)number+="0";
  99. number+=size1;
  100. }
  101. //加层
  102. int size2;
  103. //通过父级id获取当前层列表
  104. List<JtBusinessCategory>businessCategories =jtBusinessCategoryMapper.getBusinessCategoryBySuperId(jtBusinessCategory.getSuperId(), null);
  105. //列表为0,当前层编号size2设置为1,大于0 设置为当前最大sort+1
  106. if(businessCategories.size()>0)
  107. size2=businessCategories.get(businessCategories.size()-1).getSort()+1;
  108. else size2=1;
  109. //每层最多99个
  110. if(size2>99)return -1;
  111. //增加0
  112. if(size2<10)number+="0";
  113. //完成编号
  114. number+=size2;
  115. jtBusinessCategory.setNumber(number);
  116. //设置sort序号
  117. jtBusinessCategory.setSort(size2);
  118. jtBusinessCategory.setCreateTime(new Date());
  119. jtBusinessCategory.setId(UUID.randomUUID().toString());
  120. return jtBusinessCategoryMapper.insertSelective(jtBusinessCategory);
  121. }
  122. @Override
  123. public int deleteCategoryById(String id) {
  124. // TODO Auto-generated method stub
  125. //查找品类
  126. JtBusinessCategory sp=jtBusinessCategoryMapper.selectByPrimaryKey(id);
  127. //查找子品类 存在子品类不允许删除
  128. List<JtBusinessCategory> chidren=jtBusinessCategoryMapper.getBusinessCategoryBySuperId(sp.getId(), null);
  129. if(chidren.size()>0) {
  130. return -1;
  131. }
  132. List<JtBusinessProject> childrenProject=jtBusinessProjectMapper.getBusinessProjectByCategoryId(id, 100);
  133. if(childrenProject!= null && childrenProject.size()>0) {
  134. return -1;
  135. }
  136. return jtBusinessCategoryMapper.deleteByPrimaryKey(id);
  137. }
  138. @Override
  139. public JtBusinessCategory getCategoryById(String id) {
  140. // TODO Auto-generated method stub
  141. return jtBusinessCategoryMapper.selectByPrimaryKey(id);
  142. }
  143. @Override
  144. public int updateCategory(JtBusinessCategory jtBusinessCategory) {
  145. // TODO Auto-generated method stub
  146. return jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
  147. }
  148. private Map<String, Object> disposeCategoryParams(String name,Integer layer ) {
  149. Map<String, Object> params = new HashMap<>();
  150. if (layer!=null) {
  151. params.put("layer", layer);
  152. }
  153. if (StringUtils.isNotBlank(name)) {
  154. params.put("name", name);
  155. }
  156. return params;
  157. }
  158. @Override
  159. public int insertProject(JtBusinessProject jtBusinessProject) {
  160. // TODO Auto-generated method stub
  161. jtBusinessProject.setCreateTime(new Date());
  162. jtBusinessProject.setId(UUID.randomUUID().toString());
  163. List<JtBusinessProject>projects=jtBusinessProjectMapper.findProjectOrderByNumber();
  164. int cSize = 1;
  165. if(projects!=null && projects.size()>0)
  166. {
  167. String number=projects.get(projects.size()-1).getNumber();
  168. if(number!=null && number.length()==6)
  169. {
  170. String nbString=number.substring(2);
  171. try {
  172. cSize=Integer.parseInt(nbString)+1;}catch (Exception e) {
  173. // TODO: handle exception
  174. return -1;
  175. }
  176. }
  177. else cSize=1;
  178. }
  179. else cSize=1;
  180. String nbString="BP";
  181. String sizeString="000"+cSize;
  182. sizeString=sizeString.substring(sizeString.length()-4);
  183. nbString+=sizeString;
  184. jtBusinessProject.setNumber(nbString);
  185. jtBusinessProjectMapper.insertSelective(jtBusinessProject);
  186. return 1;
  187. }
  188. @Override
  189. public int deleteProjectById(String id) {
  190. // TODO Auto-generated method stub
  191. return jtBusinessProjectMapper.deleteByPrimaryKey(id);
  192. }
  193. @Override
  194. public int updateProject(JtBusinessProject jtBusinessProject) {
  195. // TODO Auto-generated method stub
  196. return jtBusinessProjectMapper.updateByPrimaryKeySelective(jtBusinessProject);
  197. }
  198. @Override
  199. public List<JtBusinessProject> getProjectsLimit(Integer size) {
  200. // TODO Auto-generated method stub
  201. return jtBusinessProjectMapper.findProjectOrderByNumber();
  202. }
  203. }