Browse Source

增加类目关注接口

dongbw 7 years ago
parent
commit
5082fcdd05

+ 101 - 0
src/main/java/com/uas/ps/inquiry/controller/KindController.java

@@ -0,0 +1,101 @@
+package com.uas.ps.inquiry.controller;
+
+import com.uas.ps.httplog.annotation.HttpLog;
+import com.uas.ps.inquiry.domain.IPage;
+import com.uas.ps.inquiry.model.kind.KindConcern;
+import com.uas.ps.inquiry.page.PageParams;
+import com.uas.ps.inquiry.service.KindService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 类目相关接口
+ * @author  dongbw
+ * 18/06/13 16:02.
+ */
+@RequestMapping("/kind")
+@RestController
+public class KindController {
+
+    @Autowired
+    private KindService kindService;
+
+    /**
+     * 已关注
+     */
+    private static final String HAS_CONCERN = "yes";
+
+    /**
+     * 未关注
+     */
+    private static final String NOT_CONCERN = "no";
+
+
+//    /**
+//     * 根据分页参数和关键词查询未关注类目
+//     * @param pageParams  分页参数
+//     * @param keyword  关键词
+//     * @param enUU 企业UU
+//     * @return
+//     */
+//    @RequestMapping(value = "/concern/list", method = RequestMethod.GET, params = "type=no")
+//    public IPage<KindConcern> getNotConcernKindByPage(@RequestParam PageParams pageParams, String keyword, @RequestParam Long enUU) {
+//        return kindService.getNotConcernKindByPage(pageParams, keyword, enUU);
+//    }
+//
+//    /**
+//     * 根据分页参数和关键词查询已关注类目
+//     * @param pageParams  分页参数
+//     * @param keyword  关键词
+//     * @param enUU 企业UU
+//     * @return
+//     */
+//    @RequestMapping(value = "/concern/list", method = RequestMethod.GET, params = "type=yes")
+//    public IPage<KindConcern> getConcernKindByPage(@RequestParam PageParams pageParams, String keyword, @RequestParam Long enUU) {
+//        return kindService.getConcernKindByPage(pageParams, keyword, enUU);
+//    }
+
+    /**
+     * 根据分页参数和关键词查询已关注类目
+     * @param pageParams  分页参数
+     * @param keyword  关键词
+     * @param enUU 企业UU
+     * @return
+     */
+    @HttpLog
+    @RequestMapping(value = "/concern/list", method = RequestMethod.GET)
+    public IPage<KindConcern> getConcernKindByPage(PageParams pageParams, String keyword, Long enUU, String type) {
+        if (HAS_CONCERN.equals(type)) {
+            return kindService.getConcernKindByPage(pageParams, keyword, enUU);
+        } else if (NOT_CONCERN.equals(type)) {
+            return kindService.getNotConcernKindByPage(pageParams, keyword, enUU);
+        }
+        return null;
+    }
+
+    /**
+     * 设置关注接口
+     * @param kindConcern  类目关注实体
+     * @return
+     */
+    @HttpLog
+    @RequestMapping(value = "/concern", method = RequestMethod.POST, params = "type=add")
+    public ModelMap addKindConcern(KindConcern kindConcern) {
+        return kindService.addKindConcern(kindConcern);
+    }
+
+    /**
+     * 设置关注接口
+     * @param kindConcern  类目关注实体
+     * @return
+     */
+    @HttpLog
+    @RequestMapping(value = "/concern", method = RequestMethod.POST, params = "type=del")
+    public ModelMap deleteKindConcern(KindConcern kindConcern) {
+        return kindService.deleteKindConcern(kindConcern);
+    }
+}
+

+ 26 - 0
src/main/java/com/uas/ps/inquiry/dao/KindConcernDao.java

@@ -0,0 +1,26 @@
+package com.uas.ps.inquiry.dao;
+
+import com.uas.ps.inquiry.model.kind.KindConcern;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 类目关注Dao
+ * @author dongbw
+ */
+@Repository
+public interface KindConcernDao extends JpaRepository<KindConcern, Long>, JpaSpecificationExecutor<KindConcern> {
+
+    /**
+     * 根据企业UU获取本企业所有已收藏类目名称
+     * @param enUU  企业UU
+     * @return 名称List
+     */
+    @Query("select k.nameCn from KindConcern k where k.enUU = :enUU")
+    List<String> findNameByEnUU(@Param("enUU") Long enUU);
+}

+ 16 - 0
src/main/java/com/uas/ps/inquiry/dao/KindDao.java

@@ -0,0 +1,16 @@
+package com.uas.ps.inquiry.dao;
+
+import com.uas.ps.inquiry.model.kind.Kind;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 类目Dao
+ * @author dongbw
+ * @version 2018年6月13日 17:18:03
+ */
+@Repository
+public interface KindDao extends JpaRepository<Kind, Long>, JpaSpecificationExecutor<Kind> {
+
+}

+ 215 - 0
src/main/java/com/uas/ps/inquiry/model/kind/Kind.java

@@ -0,0 +1,215 @@
+package com.uas.ps.inquiry.model.kind;
+
+import com.uas.ps.inquiry.entity.Constant;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.io.Serializable;
+
+/**
+ * 产品类目
+ * 
+ * @author suntg
+ * @version  2016年3月10日下午3:08:40 suntg 创建
+ * @version 2018年6月13日 17:14:52 询价服务简要信息,用于查看
+ */
+@Entity
+@Table(name = "product$kind")
+public class Kind implements Serializable {
+
+	/**
+	 * 序列号
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * ID号
+	 */
+	@Id
+	@Column(name = "ki_id")
+	@GeneratedValue
+	private Long id;
+
+	/**
+	 * 父级类目的id号
+	 */
+	@Column(name = "ki_parentid")
+	private Long parentid;
+
+	/**
+	 * 是否为叶子类目 1是 0否
+	 */
+	@Column(name = "ki_isleaf")
+	private Short isLeaf;
+
+	/**
+	 * 在父级类目中的排序序号
+	 */
+	@Column(name = "ki_detno")
+	private Short detno;
+
+	/**
+	 * 类目的名称
+	 */
+	@Column(name = "ki_name")
+	private String nameCn;
+
+	/**
+	 * 类目的英文名称
+	 */
+	@Column(name = "ki_name_en")
+	private String nameEn;
+
+	/**
+	 * 类目包含的器件总数,包括其所有子类目下的
+	 */
+	@Column(name = "ki_count")
+	private Long count;
+
+	/**
+	 * 类目的层级,从1开始,1、2、3、4
+	 */
+	@Column(name = "ki_level")
+	private Short level;
+
+	/**
+	 * 器件编号前缀
+	 */
+	@Column(name = "ki_cmpprefix")
+	private String componentPrefix;
+
+	/**
+	 * 当前器件编号后缀游标
+	 */
+	@Column(name = "ki_cmpsuffix")
+	private Long componentsuffix;
+
+	/**
+	 * 类目的点击次数
+	 */
+	@Column(name = "ki_visit_count")
+	private Long visitCount;
+
+	/**
+	 * 类目的搜索次数
+	 */
+	@Column(name = "ki_search_count")
+	private Long searchCount;
+
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getParentid() {
+		return parentid;
+	}
+
+	public void setParentid(Long parentid) {
+		this.parentid = parentid;
+	}
+
+	public Short getIsLeaf() {
+		return isLeaf;
+	}
+
+	public void setIsLeaf(Short isLeaf) {
+		this.isLeaf = isLeaf;
+	}
+
+	public boolean isLeaf() {
+		return this.isLeaf == null ? false : getIsLeaf() == Constant.YES;
+	}
+
+	public Short getDetno() {
+		return detno;
+	}
+
+	public void setDetno(Short detno) {
+		this.detno = detno;
+	}
+
+	public String getNameCn() {
+		return nameCn;
+	}
+
+	public void setNameCn(String nameCn) {
+		this.nameCn = nameCn;
+	}
+
+	public String getNameEn() {
+		return nameEn;
+	}
+
+	public void setNameEn(String nameEn) {
+		this.nameEn = nameEn;
+	}
+
+	public Long getCount() {
+		return count;
+	}
+
+	public void setCount(Long count) {
+		this.count = count;
+	}
+
+	public void addCount() {
+		this.count = this.count + 1;
+	}
+
+	public void addCount(Long count) {
+		this.count = this.count + count;
+	}
+
+	public void decreaseCount() {
+		this.count = this.count - 1;
+	}
+
+	public Short getLevel() {
+		return level;
+	}
+
+	public void setLevel(Short level) {
+		this.level = level;
+	}
+
+	public String getComponentPrefix() {
+		return componentPrefix;
+	}
+
+	public void setComponentPrefix(String componentPrefix) {
+		this.componentPrefix = componentPrefix;
+	}
+
+	public Long getComponentsuffix() {
+		return componentsuffix;
+	}
+
+	public void setComponentsuffix(Long componentsuffix) {
+		this.componentsuffix = componentsuffix;
+	}
+
+	public Long getVisitCount() {
+		return visitCount;
+	}
+
+	public void setVisitCount(Long visitCount) {
+		this.visitCount = visitCount;
+	}
+
+	public Long getSearchCount() {
+		return searchCount;
+	}
+
+	public void setSearchCount(Long searchCount) {
+		this.searchCount = searchCount;
+	}
+
+}

+ 127 - 0
src/main/java/com/uas/ps/inquiry/model/kind/KindConcern.java

@@ -0,0 +1,127 @@
+package com.uas.ps.inquiry.model.kind;
+
+import com.uas.ps.inquiry.entity.Constant;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 类目关注
+ *
+ * @author dongbw
+ * @version 2018年6月13日 15:50:23
+ */
+@Entity
+@Table(name = "product$kind$concern", indexes = {
+        @Index(name = "unique_kindconcern_enuu_name", columnList = "kc_enuu, kc_name", unique = true)})
+public class KindConcern implements Serializable {
+
+    /**
+     * default serialVersionUID
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "kc_id")
+    private Long id;
+
+    /**
+     * 中文类目名称
+     */
+    @Column(name = "kc_name")
+    private String nameCn;
+
+    /**
+     * 英文类目名称
+     */
+    @Column(name = "kc_name_en")
+    private String nameEn;
+
+    /**
+     * 所属企业UU
+     */
+    @Column(name = "kc_enuu")
+    private Long enUU;
+
+    /**
+     * 关注状态 (1已关注 0 未关注)
+     */
+    @Column(name = "kc_status")
+    private Short status = 1;
+
+    /**
+     * 最近更新时间
+     */
+    @Column(name = "kc_date")
+    private Date date;
+
+    public KindConcern() {
+
+    }
+
+    public KindConcern(Kind kind) {
+        this.date = new Date();
+        this.nameCn = kind.getNameCn();
+        this.nameEn = kind.getNameEn();
+        this.status = Constant.NO;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getNameCn() {
+        return nameCn;
+    }
+
+    public void setNameCn(String nameCn) {
+        this.nameCn = nameCn;
+    }
+
+    public String getNameEn() {
+        return nameEn;
+    }
+
+    public void setNameEn(String nameEn) {
+        this.nameEn = nameEn;
+    }
+
+    public Long getEnUU() {
+        return enUU;
+    }
+
+    public void setEnUU(Long enUU) {
+        this.enUU = enUU;
+    }
+
+    public Short getStatus() {
+        return status;
+    }
+
+    public void setStatus(Short status) {
+        this.status = status;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+}

+ 46 - 0
src/main/java/com/uas/ps/inquiry/service/KindService.java

@@ -0,0 +1,46 @@
+package com.uas.ps.inquiry.service;
+
+import com.uas.ps.inquiry.domain.IPage;
+import com.uas.ps.inquiry.model.kind.KindConcern;
+import com.uas.ps.inquiry.page.PageParams;
+import org.springframework.ui.ModelMap;
+
+/**
+ * 类目接口
+ * @author dongbw
+ */
+public interface KindService {
+
+
+    /**
+     * 添加关注
+     * @param kindConcern 实体
+     * @return 处理结果
+     */
+    ModelMap addKindConcern(KindConcern kindConcern);
+
+    /**
+     * 取消关注
+     * @param kindConcern 实体
+     * @return 处理结果
+     */
+    ModelMap deleteKindConcern(KindConcern kindConcern);
+
+    /**
+     * 获取未关注类目列表
+     * @param pageParams  分页参数
+     * @param keyword  关键词
+     * @param enUU 企业UU
+     * @return 类目收藏分页
+     */
+    IPage<KindConcern> getNotConcernKindByPage(PageParams pageParams, String keyword, Long enUU);
+
+    /**
+     * 获取已关注类目列表
+     * @param pageParams  分页参数
+     * @param keyword  关键词
+     * @param enUU 企业UU
+     * @return 类目收藏分页
+     */
+    IPage<KindConcern> getConcernKindByPage(PageParams pageParams, String keyword, Long enUU);
+}

+ 195 - 0
src/main/java/com/uas/ps/inquiry/service/impl/KindServiceImpl.java

@@ -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);
+    }
+}