Quellcode durchsuchen

采购报价单增加h5列表、新增、修改、删除接口

wwh vor 1 Monat
Ursprung
Commit
a6e8b1314d

+ 182 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/base/controller/H5ProcureQuotationController.java

@@ -0,0 +1,182 @@
+package com.ruoyi.web.base.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.web.base.domain.ProcureQuotation;
+import com.ruoyi.web.base.domain.ProcureQuotationGoods;
+import com.ruoyi.web.base.service.IProcureQuotationGoodsService;
+import com.ruoyi.web.base.service.IProcureQuotationService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+import java.util.Map;
+
+import static com.ruoyi.common.core.domain.AjaxResult.success;
+import static com.ruoyi.common.utils.SecurityUtils.getUsername;
+
+/**
+ * ERP H5 端采购报价单接口;复用 {@link ProcureQuotationController} 的 buildWrapper、attachGoods、persistGoods。
+ */
+@RestController
+@Api(tags = "H5采购报价单")
+@RequestMapping("/h5/procure-quotation")
+public class H5ProcureQuotationController {
+
+    @Autowired
+    private ProcureQuotationController procureQuotationController;
+    @Autowired
+    private IProcureQuotationService procureQuotationService;
+    @Autowired
+    private IProcureQuotationGoodsService goodsService;
+    @Autowired
+    private TokenService tokenService;
+
+    @ApiOperation("H5采购报价单分页")
+    @GetMapping("/page")
+    public AjaxResult page(@RequestParam("pageNum") Integer pageNum,
+                           @RequestParam("pageSize") Integer pageSize,
+                           ProcureQuotation query,
+                           HttpServletRequest request) {
+        String orgId = tokenService.getLoginOrgId(request);
+        String username = getUsername();
+        if (query == null) {
+            query = new ProcureQuotation();
+        }
+        QueryWrapper<ProcureQuotation> wrapper = procureQuotationController.buildWrapper(query, orgId);
+        wrapper.eq("source", 2).eq("create_by", username);
+        Page<ProcureQuotation> pageObj = procureQuotationService.page(new Page<>(pageNum, pageSize), wrapper);
+        for (ProcureQuotation row : pageObj.getRecords()) {
+            procureQuotationController.attachGoods(row);
+        }
+        return success(pageObj);
+    }
+
+    @ApiOperation("H5采购报价单新增")
+    @PostMapping("/add")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult add(@RequestBody ProcureQuotation procureQuotation, HttpServletRequest request) throws Exception {
+        String loginOrgId = tokenService.getLoginOrgId(request);
+        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().eq("org_id", loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) > 0) {
+            throw new Exception("该编号已存在");
+        }
+        String username = getUsername();
+        Date now = new Date();
+        procureQuotation.setOrgId(loginOrgId);
+        procureQuotation.setSource(2);
+        procureQuotation.setAuditStatus(0);
+        procureQuotation.setCreateBy(username);
+        procureQuotation.setCreateTime(now);
+        procureQuotation.setUpdateBy(null);
+        procureQuotation.setUpdateTime(null);
+        procureQuotationController.persistGoods(procureQuotation, loginOrgId, username, false);
+        return success(procureQuotationService.save(procureQuotation));
+    }
+
+    @ApiOperation("H5采购报价单修改")
+    @PostMapping("/edit")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult edit(@RequestBody ProcureQuotation procureQuotation, HttpServletRequest request) throws Exception {
+        if (procureQuotation.getId() == null) {
+            throw new Exception("id不能为空");
+        }
+        ProcureQuotation old = procureQuotationService.getById(procureQuotation.getId());
+        if (old == null || !tokenService.getLoginOrgId(request).equals(old.getOrgId())) {
+            throw new Exception("报价单不存在");
+        }
+        int oldSrc = old.getSource() == null ? 1 : old.getSource();
+        if (oldSrc != 2) {
+            throw new Exception("非H5来源采购报价单不能在此修改");
+        }
+        if (old.getAuditStatus() != null && old.getAuditStatus() == 1) {
+            throw new Exception("已审核的报价单不能修改");
+        }
+        if (!StringUtils.equals(getUsername(), old.getCreateBy())) {
+            throw new Exception("只能修改本人创建的报价单");
+        }
+        String loginOrgId = tokenService.getLoginOrgId(request);
+        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().ne("id", procureQuotation.getId()).eq("org_id", loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) > 0) {
+            throw new Exception("该编号已存在");
+        }
+        Date now = new Date();
+        String me = getUsername();
+        procureQuotation.setOrgId(loginOrgId);
+        procureQuotation.setSource(2);
+        procureQuotation.setAuditStatus(0);
+        procureQuotation.setCreateBy(me);
+        procureQuotation.setCreateTime(now);
+        procureQuotation.setUpdateBy(me);
+        procureQuotation.setUpdateTime(now);
+        procureQuotationController.persistGoods(procureQuotation, loginOrgId, me, true);
+        return success(procureQuotationService.updateById(procureQuotation));
+    }
+
+    @ApiOperation("H5采购报价单删除")
+    @PostMapping("/delete")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) throws Exception {
+        String ids = paramsMap.get("ids");
+        if (StringUtils.isBlank(ids)) {
+            throw new Exception("ids不能为空");
+        }
+        String me = getUsername();
+        for (String s : ids.split(",")) {
+            if (StringUtils.isBlank(s)) {
+                continue;
+            }
+            ProcureQuotation q = procureQuotationService.getById(s.trim());
+            if (q == null) {
+                continue;
+            }
+            int src = q.getSource() == null ? 1 : q.getSource();
+            if (src != 2) {
+                throw new Exception("非H5来源采购报价单不能在此删除");
+            }
+            if (!StringUtils.equals(me, q.getCreateBy())) {
+                throw new Exception("只能删除本人创建的报价单");
+            }
+            if (q.getAuditStatus() != null && q.getAuditStatus() == 1) {
+                throw new Exception("已审核的报价单不能删除");
+            }
+            goodsService.remove(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num", q.getQuotationNum()));
+            procureQuotationService.removeById(s.trim());
+        }
+        return success();
+    }
+
+    @ApiOperation("H5采购报价单详情")
+    @PostMapping("/listById")
+    public AjaxResult listById(@ApiParam("详情参数: id") @RequestBody Map<String, String> paramsMap, HttpServletRequest request) throws Exception {
+        String id = paramsMap.get("id");
+        ProcureQuotation byId = procureQuotationService.getById(id);
+        if (byId == null) {
+            return success(null);
+        }
+        String orgId = tokenService.getLoginOrgId(request);
+        if (!orgId.equals(byId.getOrgId())) {
+            throw new Exception("报价单不存在");
+        }
+        int src = byId.getSource() == null ? 1 : byId.getSource();
+        if (src != 2) {
+            throw new Exception("非H5来源采购报价单不能在此查看");
+        }
+        if (!StringUtils.equals(getUsername(), byId.getCreateBy())) {
+            throw new Exception("只能查看本人创建的报价单");
+        }
+        procureQuotationController.attachGoods(byId);
+        return success(byId);
+    }
+}

+ 141 - 43
ruoyi-admin/src/main/java/com/ruoyi/web/base/controller/ProcureQuotationController.java

@@ -5,18 +5,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.web.base.domain.ProcureQuotation;
 import com.ruoyi.web.base.domain.ProcureQuotationGoods;
 import com.ruoyi.web.base.service.IProcureQuotationService;
 import com.ruoyi.web.base.service.IProcureQuotationGoodsService;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.models.auth.In;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -25,15 +26,8 @@ import static com.ruoyi.common.utils.SecurityUtils.getUsername;
 import static com.ruoyi.web.base.util.NumUtils.generateString;
 import static com.ruoyi.web.base.util.NumUtils.substringToInt;
 
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
 /**
- * <p>
- * 供应商报价单 前端控制器
- * </p>
- *
- * @author author
- * @since 2026-02-05
+ * 供应商报价单(采购报价单)前端控制器
  */
 @RestController
 @RequestMapping("/procure-quotation")
@@ -47,88 +41,146 @@ public class ProcureQuotationController {
 
     @ApiOperation("供应商报价单添加")
     @PostMapping("/add")
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public AjaxResult add(@RequestBody ProcureQuotation procureQuotation, HttpServletRequest request) throws Exception {
         String loginOrgId = tokenService.getLoginOrgId(request);
-        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().eq("org_id",loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) >0 ){
+        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().eq("org_id", loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) > 0) {
             throw new Exception("该编号已存在");
         }
         String username = getUsername();
+        Date now = new Date();
         procureQuotation.setOrgId(loginOrgId);
         procureQuotation.setCreateBy(username);
-        List<ProcureQuotationGoods> goods = procureQuotation.getGoods();
-        for (ProcureQuotationGoods good : goods) {
-            good.setOrgId(loginOrgId);
-            good.setCreateBy(username);
-            good.setQuotationNum(procureQuotation.getQuotationNum());
-            goodsService.save(good);
-        }
-
+        procureQuotation.setCreateTime(now);
+        procureQuotation.setSource(1);
+        procureQuotation.setAuditStatus(1);
+        persistGoods(procureQuotation, loginOrgId, username, false);
         return success(procureQuotationService.save(procureQuotation));
     }
 
     @ApiOperation("供应商报价单修改")
     @PostMapping("/edit")
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public AjaxResult edit(@RequestBody ProcureQuotation procureQuotation, HttpServletRequest request) throws Exception {
+        if (procureQuotation.getId() == null) {
+            throw new Exception("id不能为空");
+        }
         String loginOrgId = tokenService.getLoginOrgId(request);
-        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().ne("id",procureQuotation.getId()).eq("org_id",loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) >0 ){
+        ProcureQuotation old = procureQuotationService.getById(procureQuotation.getId());
+        if (old == null || !loginOrgId.equals(old.getOrgId())) {
+            throw new Exception("报价单不存在");
+        }
+        if (procureQuotationService.count(new QueryWrapper<ProcureQuotation>().ne("id", procureQuotation.getId()).eq("org_id", loginOrgId).eq("quotation_num", procureQuotation.getQuotationNum())) > 0) {
             throw new Exception("该编号已存在");
         }
 
         String username = getUsername();
         procureQuotation.setOrgId(loginOrgId);
-        procureQuotation.setCreateBy(username);
-        List<ProcureQuotationGoods> goods = procureQuotation.getGoods();
-        goodsService.remove(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num",procureQuotation.getQuotationNum()));
-        for (ProcureQuotationGoods good : goods) {
-            good.setOrgId(loginOrgId);
-            good.setCreateBy(username);
-            good.setQuotationNum(procureQuotation.getQuotationNum());
-            goodsService.save(good);
+        int oldSrc = old.getSource() == null ? 1 : old.getSource();
+        boolean h5Pending = oldSrc == 2 && (old.getAuditStatus() == null || old.getAuditStatus() == 0);
+        if (h5Pending) {
+            procureQuotation.setAuditStatus(0);
+            procureQuotation.setSource(2);
+            procureQuotation.setCreateBy(old.getCreateBy());
+            procureQuotation.setCreateTime(old.getCreateTime());
+        } else {
+            if (old.getAuditStatus() != null && old.getAuditStatus() == 1) {
+                throw new Exception("已审核的报价单不能修改");
+            }
+            procureQuotation.setAuditStatus(1);
+            if (procureQuotation.getSource() == null) {
+                procureQuotation.setSource(old.getSource() != null ? old.getSource() : 1);
+            }
+            procureQuotation.setCreateBy(old.getCreateBy());
+            procureQuotation.setCreateTime(old.getCreateTime());
         }
         procureQuotation.setUpdateBy(username);
-
+        procureQuotation.setUpdateTime(new Date());
+        persistGoods(procureQuotation, loginOrgId, username, true);
         return success(procureQuotationService.updateById(procureQuotation));
     }
 
+    @ApiOperation("供应商报价单审核")
+    @PostMapping("/audit")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult audit(@RequestBody Map<String, String> params) throws Exception {
+        String id = params.get("id");
+        if (StringUtils.isBlank(id)) {
+            throw new Exception("id不能为空");
+        }
+        ProcureQuotation q = procureQuotationService.getById(id);
+        if (q == null) {
+            throw new Exception("报价单不存在");
+        }
+        int src = q.getSource() == null ? 1 : q.getSource();
+        if (src == 2 && q.getAuditStatus() != null && q.getAuditStatus() != 0) {
+            throw new Exception("仅待审核的H5采购报价单可审核");
+        }
+        if (src != 2) {
+            throw new Exception("仅H5来源采购报价单需在此审核");
+        }
+        q.setAuditStatus(1);
+        q.setUpdateBy(getUsername());
+        q.setUpdateTime(new Date());
+        return success(procureQuotationService.updateById(q));
+    }
+
     @ApiOperation("供应商报价单删除")
     @PostMapping("/delete")
+    @Transactional(rollbackFor = Exception.class)
     public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
         String ids = paramsMap.get("ids");
         for (String s : ids.split(",")) {
-            procureQuotationService.removeById(s);
+            if (StringUtils.isBlank(s)) {
+                continue;
+            }
+            ProcureQuotation q = procureQuotationService.getById(s.trim());
+            if (q == null) {
+                continue;
+            }
+            goodsService.remove(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num", q.getQuotationNum()));
+            procureQuotationService.removeById(s.trim());
         }
         return success();
     }
 
     @ApiOperation("供应商报价单列表")
     @PostMapping("/list")
-    public AjaxResult listAll( HttpServletRequest request){
-        List<ProcureQuotation> org_id = procureQuotationService.list(new QueryWrapper<ProcureQuotation>().eq("org_id", tokenService.getLoginOrgId(request)));
+    public AjaxResult listAll(HttpServletRequest request) {
+        String orgId = tokenService.getLoginOrgId(request);
+        List<ProcureQuotation> org_id = procureQuotationService.list(new QueryWrapper<ProcureQuotation>().eq("org_id", orgId));
         for (ProcureQuotation procureQuotation : org_id) {
-            procureQuotation.setGoods(goodsService.list(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num",procureQuotation.getQuotationNum())));
+            attachGoods(procureQuotation);
         }
         return success(org_id);
     }
 
     @ApiOperation("供应商报价单分页")
     @GetMapping("/page")
-    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
-            , HttpServletRequest request) {
-        Page<ProcureQuotation> org_id = procureQuotationService.page(new Page<ProcureQuotation>(pageNum, pageSize), new QueryWrapper<ProcureQuotation>().eq("org_id", tokenService.getLoginOrgId(request)));
+    public AjaxResult page(@RequestParam("pageNum") Integer pageNum,
+                           @RequestParam("pageSize") Integer pageSize,
+                           ProcureQuotation query,
+                           HttpServletRequest request) {
+        String orgId = tokenService.getLoginOrgId(request);
+        if (query == null) {
+            query = new ProcureQuotation();
+        }
+        Page<ProcureQuotation> org_id = procureQuotationService.page(new Page<>(pageNum, pageSize), buildWrapper(query, orgId));
         for (ProcureQuotation procureQuotation : org_id.getRecords()) {
-            procureQuotation.setGoods(goodsService.list(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num",procureQuotation.getQuotationNum())));
+            attachGoods(procureQuotation);
         }
         return success(org_id);
     }
 
     @ApiOperation("供应商报价单详情")
     @PostMapping("/listById")
-    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
+    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
         String id = paramsMap.get("id");
         ProcureQuotation byId = procureQuotationService.getById(id);
-        byId.setGoods(goodsService.list(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num",byId.getQuotationNum())));
+        if (byId == null) {
+            return success(null);
+        }
+        attachGoods(byId);
         return success(byId);
     }
 
@@ -138,15 +190,61 @@ public class ProcureQuotationController {
         String loginOrgId = tokenService.getLoginOrgId(request);
 
         ProcureQuotation one = procureQuotationService.getOne(new QueryWrapper<ProcureQuotation>().eq("org_id", loginOrgId).orderByDesc("id").last("limit 1"));
-        if (ObjectUtils.isEmpty(one)){
+        if (ObjectUtils.isEmpty(one)) {
 
-            return success(generateString("bj",1));
+            return success(generateString("bj", 1));
         }
         String quotationNum = one.getQuotationNum();
 
-        return success(generateString("bj",substringToInt(quotationNum)));
+        return success(generateString("bj", substringToInt(quotationNum)));
 
     }
 
+    QueryWrapper<ProcureQuotation> buildWrapper(ProcureQuotation query, String orgId) {
+        QueryWrapper<ProcureQuotation> w = new QueryWrapper<ProcureQuotation>().eq("org_id", orgId);
+        if (query == null) {
+            w.eq("audit_status", 1);
+            w.orderByDesc("id");
+            return w;
+        }
+        if (query.getAuditStatus() != null) {
+            w.eq("audit_status", query.getAuditStatus());
+        } else {
+            w.eq("audit_status", 1);
+        }
+        if (query.getSource() != null && (query.getSource() == 1 || query.getSource() == 2)) {
+            w.eq("source", query.getSource());
+        }
+        w.orderByDesc("id");
+        return w;
+    }
+
+    void attachGoods(ProcureQuotation row) {
+        if (row == null || StringUtils.isBlank(row.getQuotationNum())) {
+            return;
+        }
+        row.setGoods(goodsService.list(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num", row.getQuotationNum())));
+    }
 
+    /**
+     * @param removeExisting true:先按 quotation_num 删除旧明细再插入(修改);false:仅追加(新增)
+     */
+    void persistGoods(ProcureQuotation procureQuotation, String loginOrgId, String username, boolean removeExisting) throws Exception {
+        List<ProcureQuotationGoods> goods = procureQuotation.getGoods();
+        if (goods == null || goods.isEmpty()) {
+            throw new Exception("货品明细不能为空");
+        }
+        if (removeExisting) {
+            goodsService.remove(new QueryWrapper<ProcureQuotationGoods>().eq("quotation_num", procureQuotation.getQuotationNum()));
+        }
+        Date now = new Date();
+        for (ProcureQuotationGoods good : goods) {
+            good.setId(null);
+            good.setOrgId(loginOrgId);
+            good.setCreateBy(username);
+            good.setCreateTime(now);
+            good.setQuotationNum(procureQuotation.getQuotationNum());
+            goodsService.save(good);
+        }
+    }
 }

+ 6 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/base/domain/ProcureQuotation.java

@@ -69,6 +69,12 @@ public class ProcureQuotation extends Base {
     @ApiModelProperty(value = "总金额")
     private String totalAmount;
 
+    @ApiModelProperty(value = "来源(1ERP-Web 2ERP-H5)")
+    private Integer source;
+
+    @ApiModelProperty(value = "审核状态(0未审核1已审核)")
+    private Integer auditStatus;
+
     @TableField(exist =  false)
     private List<ProcureQuotationGoods> goods;
 

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/sales/controller/BaseCustomerController.java

@@ -90,7 +90,6 @@ public class BaseCustomerController {
     }
 
     @ApiOperation("客户管理列表")
-    @PreAuthorize("@ss.hasPermi('base:customer:list')")
     @PostMapping("/list")
     public AjaxResult listAll(HttpServletRequest request) {
         return success(baseCustomerService.list(new QueryWrapper<BaseCustomer>()

+ 0 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/sales/controller/H5SalesOrderController.java

@@ -57,8 +57,6 @@ public class H5SalesOrderController {
         if (query == null) {
             query = new SalesOrder();
         }
-        query.setSource(null);
-        query.setAuditStatus(0);
         QueryWrapper<SalesOrder> wrapper = salesOrderController.buildWrapper(query, orgId);
         wrapper.eq("source", 2).eq("create_by", username);
         Page<SalesOrder> pageObj = salesOrderService.page(new Page<>(pageNum, pageSize), wrapper);