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