Browse Source

产品管理

wjj 3 năm trước cách đây
mục cha
commit
2a11077dcf

+ 141 - 0
src/main/java/com/ydtech/modules/protocol/controller/EsProductController.java

@@ -0,0 +1,141 @@
+package com.ydtech.modules.protocol.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ydtech.core.page.BaseController;
+import com.ydtech.core.page.HttpResult;
+import com.ydtech.core.page.PageRequest;
+import com.ydtech.core.page.PageResult;
+import com.ydtech.modules.protocol.entity.po.EsProduct;
+import com.ydtech.modules.protocol.service.EsProductService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/emProduct")
+public class EsProductController extends BaseController {
+
+    @Autowired
+    EsProductService esProductService;
+
+    /**
+     * 新增产品信息
+     *
+     * @param record
+     * @return
+     */
+    @PostMapping(value = "/addProduct")
+    public HttpResult save(@RequestBody EsProduct record) {
+
+        record.setCreateBy(getUserName());
+        record.setCreateTime(new Date());
+        record.setLastUpdateBy(getUserName());
+        record.setLastUpdateTime(new Date());
+        esProductService.save(record);
+        return HttpResult.ok("产品新增成功");
+    }
+
+    /**
+     * 修改产品信息
+     *
+     * @param record
+     * @return
+     */
+    @PostMapping(value = "/editProduct")
+    public HttpResult edit(@RequestBody EsProduct record) {
+        record.setLastUpdateBy(getUserName());
+        record.setLastUpdateTime(new Date());
+        esProductService.updateById(record);
+        return HttpResult.ok("产品修改成功");
+    }
+
+    /**
+     * 删除产品信息
+     *
+     * @param idList
+     * @return
+     */
+    @PostMapping(value = "/deleteProduct")
+    public HttpResult delete(@RequestParam List<String> idList) {
+
+        esProductService.removeBatchByIds(idList);
+        if (idList != null && idList.size() > 0) {
+            return HttpResult.ok("产品删除成功");
+
+        }
+        return HttpResult.error("产品删除失败");
+
+
+    }
+
+    /**
+     * 产品列表
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping(value = "/productList")
+    public HttpResult query(@RequestParam String id) {
+        QueryWrapper<EsProduct> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("del_flag ", 0);
+        if (id != null && id.length() > 0) {
+            queryWrapper.like("id", id);
+        }
+        return HttpResult.ok(esProductService.selectList(queryWrapper));
+    }
+
+    /**
+     * 基础分页查询
+     *
+     * @param
+     * @return
+     */
+    @PostMapping(value = "/findPage")
+    public HttpResult findPage(@RequestBody PageRequest pageRequest) {
+
+        int pageNum = pageRequest.getPageNum();
+        int pageSize = pageRequest.getPageSize();
+
+        LambdaQueryWrapper<EsProduct> queryWrapper = new LambdaQueryWrapper<>();
+        String id = pageRequest.getColumnFilterValue(pageRequest, "id");
+        String name = pageRequest.getColumnFilterValue(pageRequest, "name");
+        String parentId = pageRequest.getColumnFilterValue(pageRequest, "parentId");
+
+        StringBuffer whereStr = new StringBuffer(" where 1=1 and del_flag=0");  //不含已删除
+        ArrayList<String> params = new ArrayList<String>();
+
+        if (id != null) {
+            whereStr.append(" and id = ?");
+            params.add(id);
+        }
+
+      /*  if (name != null) {
+            whereStr.append(" and name like ?");
+            params.add("%" + name + "%");
+
+        }*/
+        queryWrapper.like(name != null, EsProduct::getName, name);
+        queryWrapper.orderByDesc(EsProduct::getLastUpdateTime);
+
+        if (parentId != null && !parentId.equalsIgnoreCase("")) {
+            whereStr.append(" and t.parent_id = ?");
+            params.add(parentId);
+        }
+
+        Page<EsProduct> pageInfo = new Page<>();
+        pageInfo.setSize(pageSize);
+        pageInfo.setPages(pageNum);
+
+        //传入查询条件
+        Page<EsProduct> page = esProductService.page(pageInfo, queryWrapper);
+        PageResult<EsProduct> pageResult = new PageResult<>(pageNum, pageSize, (int) page.getTotal(), page.getRecords());
+        return HttpResult.ok(pageResult);
+    }
+
+}

+ 9 - 0
src/main/java/com/ydtech/modules/protocol/dao/EsProductMapper.java

@@ -0,0 +1,9 @@
+package com.ydtech.modules.protocol.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ydtech.modules.protocol.entity.po.EsProduct;
+
+
+public interface EsProductMapper extends BaseMapper<EsProduct> {
+
+}

+ 76 - 0
src/main/java/com/ydtech/modules/protocol/entity/po/EsProduct.java

@@ -0,0 +1,76 @@
+package com.ydtech.modules.protocol.entity.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@TableName(value = "esm_product")
+public class EsProduct implements Serializable {
+
+    private static final long serialVersionUID = 4994740158025000549L;
+
+    /**
+     * 编号
+     */
+    private String id;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 父编号
+     */
+    private String parentId;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 排序
+     */
+    private Integer orderNum;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    private String lastUpdateBy;
+
+    /**
+     * 更新时间
+     */
+    @JsonFormat(locale = "zm", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date lastUpdateTime;
+
+    /**
+     * 是否删除 -1: 已删除   0:正常
+     */
+    private Integer delFlag;
+
+    /**
+     * 是否启用  0:启用  1:不启用
+     */
+    private Integer isvalid;
+
+}
+
+
+

+ 17 - 0
src/main/java/com/ydtech/modules/protocol/service/EsProductService.java

@@ -0,0 +1,17 @@
+package com.ydtech.modules.protocol.service;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ydtech.modules.protocol.entity.po.EsProduct;
+
+import java.util.List;
+
+public interface EsProductService extends IService<EsProduct> {
+
+    List<EsProduct> selectList(QueryWrapper queryWrapper);
+
+}
+
+
+

+ 29 - 0
src/main/java/com/ydtech/modules/protocol/service/impl/EsProductServiceImpl.java

@@ -0,0 +1,29 @@
+package com.ydtech.modules.protocol.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ydtech.modules.protocol.dao.EsProductMapper;
+import com.ydtech.modules.protocol.entity.po.EsProduct;
+import com.ydtech.modules.protocol.service.EsProductService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+
+@Service
+public class EsProductServiceImpl extends ServiceImpl<EsProductMapper, EsProduct> implements EsProductService {
+
+    @Resource
+    EsProductMapper productMapper;
+
+    @Override
+    public List selectList(QueryWrapper queryWrapper) {
+        return productMapper.selectList(queryWrapper);
+    }
+
+
+}
+
+
+

+ 6 - 0
src/main/resources/mapper/modules/protocol/EsProductMapper.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ydtech.modules.protocol.dao.EsProductMapper">
+
+
+</mapper>