|
|
@@ -0,0 +1,195 @@
|
|
|
+package com.uas.ps.inquiry.service.impl;
|
|
|
+
|
|
|
+import com.uas.ps.inquiry.dao.KindConcernDao;
|
|
|
+import com.uas.ps.inquiry.dao.KindDao;
|
|
|
+import com.uas.ps.inquiry.domain.IPage;
|
|
|
+import com.uas.ps.inquiry.entity.Constant;
|
|
|
+import com.uas.ps.inquiry.model.kind.Kind;
|
|
|
+import com.uas.ps.inquiry.model.kind.KindConcern;
|
|
|
+import com.uas.ps.inquiry.page.PageInfo;
|
|
|
+import com.uas.ps.inquiry.page.PageParams;
|
|
|
+import com.uas.ps.inquiry.page.criteria.PredicateUtils;
|
|
|
+import com.uas.ps.inquiry.service.KindService;
|
|
|
+import com.uas.ps.inquiry.util.IPageUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 类目接口实现
|
|
|
+ *
|
|
|
+ * @author dongbw
|
|
|
+ * @version 2018年6月13日 16:11:21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class KindServiceImpl implements KindService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KindConcernDao kindConcernDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KindDao kindDao;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加关注
|
|
|
+ *
|
|
|
+ * @param kindConcern 实体
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap addKindConcern(KindConcern kindConcern) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ try {
|
|
|
+ if (null == kindConcern) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入参数为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (null == kindConcern.getEnUU()) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入企业为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(kindConcern.getNameCn())) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入类目名称为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ kindConcern.setDate(new Date());
|
|
|
+ kindConcern.setStatus(Constant.YES);
|
|
|
+ kindConcernDao.save(kindConcern);
|
|
|
+ map.put("success", true);
|
|
|
+ return map;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", e.getMessage());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消关注
|
|
|
+ *
|
|
|
+ * @param kindConcern 实体
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap deleteKindConcern(KindConcern kindConcern) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ try {
|
|
|
+ if (null == kindConcern) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入参数为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (null == kindConcern.getId()) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入id为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (null == kindConcern.getEnUU()) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入企业为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(kindConcern.getNameCn())) {
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", "传入类目名称为空");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ KindConcern concern = kindConcernDao.findOne(kindConcern.getId());
|
|
|
+ concern.setStatus(Constant.NO);
|
|
|
+ concern.setDate(new Date());
|
|
|
+ kindConcernDao.save(concern);
|
|
|
+ map.put("success", true);
|
|
|
+ return map;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("message", e.getMessage());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取未关注类目列表
|
|
|
+ *
|
|
|
+ * @param pageParams 分页参数
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @return 类目收藏分页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<KindConcern> getNotConcernKindByPage(PageParams pageParams, String keyword, Long enUU) {
|
|
|
+ final PageInfo pageInfo = new PageInfo(pageParams);
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ pageInfo.expression(PredicateUtils.like("nameCn", keyword, false));
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.eq("isLeaf", Constant.YES, false));
|
|
|
+ List<String> kindConcernNameList = kindConcernDao.findNameByEnUU(enUU);
|
|
|
+ if (!CollectionUtils.isEmpty(kindConcernNameList)) {
|
|
|
+ pageInfo.expression(PredicateUtils.notIn("nameCn", kindConcernNameList, false));
|
|
|
+ }
|
|
|
+ Page<Kind> kindPage = kindDao.findAll(new Specification<Kind>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<Kind> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ List<KindConcern> kindConcerns = new ArrayList<>();
|
|
|
+ for (Kind kind : kindPage) {
|
|
|
+ KindConcern kindConcern = new KindConcern(kind);
|
|
|
+ kindConcern.setEnUU(enUU);
|
|
|
+ kindConcerns.add(kindConcern);
|
|
|
+ }
|
|
|
+ IPage<KindConcern> page = new IPage<>();
|
|
|
+ page.setContent(kindConcerns);
|
|
|
+ page.setFirst(kindPage.isFirst());
|
|
|
+ page.setLast(kindPage.isLast());
|
|
|
+ page.setNumber(kindPage.getNumber());
|
|
|
+ page.setSize(kindPage.getSize());
|
|
|
+ page.setTotalElements(kindPage.getTotalElements());
|
|
|
+ page.setNumberOfElements(kindPage.getNumberOfElements());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取已关注类目列表
|
|
|
+ *
|
|
|
+ * @param pageParams 分页参数
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @return 类目收藏分页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<KindConcern> getConcernKindByPage(PageParams pageParams, String keyword, Long enUU) {
|
|
|
+ final PageInfo pageInfo = new PageInfo(pageParams);
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ pageInfo.expression(PredicateUtils.like("nameCn", keyword, false));
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.eq("enUU", enUU, false));
|
|
|
+ Page<KindConcern> kindConcernPage = kindConcernDao.findAll(new Specification<KindConcern>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<KindConcern> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ return IPageUtils.covert(kindConcernPage);
|
|
|
+ }
|
|
|
+}
|