Selaa lähdekoodia

销售订单增加h5列表、新增、修改、删除接口

wwh 1 kuukausi sitten
vanhempi
commit
7728d21d24

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

@@ -0,0 +1,208 @@
+package com.ruoyi.web.sales.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.sales.domain.SalesOrder;
+import com.ruoyi.web.sales.domain.SalesOrderGoods;
+import com.ruoyi.web.sales.service.ISalesOrderGoodsService;
+import com.ruoyi.web.sales.service.ISalesOrderService;
+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.List;
+import java.util.Map;
+
+import static com.ruoyi.common.core.domain.AjaxResult.success;
+import static com.ruoyi.common.utils.SecurityUtils.getUsername;
+
+/**
+ * ERP H5 端销售订单接口;校验与明细持久化复用 {@link SalesOrderController} 包内方法。
+ */
+@RestController
+@Api(tags = "H5销售订单")
+@RequestMapping("/h5/sales-order")
+public class H5SalesOrderController {
+
+    @Autowired
+    private SalesOrderController salesOrderController;
+    @Autowired
+    private ISalesOrderService salesOrderService;
+    @Autowired
+    private ISalesOrderGoodsService salesOrderGoodsService;
+    @Autowired
+    private TokenService tokenService;
+
+    @ApiOperation("H5销售订单分页")
+    @GetMapping("/page")
+    public AjaxResult page(@RequestParam("pageNum") Integer pageNum,
+                           @RequestParam("pageSize") Integer pageSize,
+                           SalesOrder query,
+                           HttpServletRequest request) {
+        String orgId = tokenService.getLoginOrgId(request);
+        String username = getUsername();
+        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);
+        for (SalesOrder row : pageObj.getRecords()) {
+            salesOrderController.enrichSalesOrderDisplay(row, orgId);
+        }
+        return success(pageObj);
+    }
+
+    @ApiOperation("H5销售订单新增")
+    @PostMapping("/add")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult add(@RequestBody SalesOrder order, HttpServletRequest request) throws Exception {
+        String orgId = tokenService.getLoginOrgId(request);
+        String username = getUsername();
+        if (StringUtils.isBlank(order.getOrderNum())) {
+            order.setOrderNum(salesOrderController.generateSalesOrderNum(orgId));
+        }
+        salesOrderController.validateBeforeSave(order, orgId, true);
+        salesOrderController.fillCustomerAndMarketInfo(order, orgId);
+        salesOrderController.recalcGoodsSubTotalsAndOrderTotal(order);
+        order.setOrgId(orgId);
+        order.setDelFlag("0");
+        order.setAuditStatus(0);
+        order.setSource(2);
+        order.setId(null);
+        order.setCreateBy(username);
+        order.setCreateTime(new Date());
+        order.setUpdateBy(null);
+        order.setUpdateTime(null);
+        salesOrderService.save(order);
+        salesOrderController.saveGoods(order, orgId, username);
+        return success();
+    }
+
+    @ApiOperation("H5销售订单修改")
+    @PostMapping("/edit")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult edit(@RequestBody SalesOrder order, HttpServletRequest request) throws Exception {
+        if (order.getId() == null) {
+            throw new Exception("id不能为空");
+        }
+        SalesOrder old = salesOrderService.getById(order.getId());
+        if (old == null || !"0".equals(old.getDelFlag())) {
+            throw new Exception("销售订单不存在");
+        }
+        String orgId = tokenService.getLoginOrgId(request);
+        if (!orgId.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("只能修改本人创建的订单");
+        }
+        salesOrderController.validateBeforeSave(order, orgId, false);
+        salesOrderController.fillCustomerAndMarketInfo(order, orgId);
+        salesOrderController.recalcGoodsSubTotalsAndOrderTotal(order);
+        order.setOrgId(orgId);
+        order.setAuditStatus(0);
+        order.setSource(2);
+        Date now = new Date();
+        order.setCreateBy(getUsername());
+        order.setCreateTime(now);
+        order.setUpdateBy(getUsername());
+        order.setUpdateTime(now);
+        salesOrderService.updateById(order);
+        String oldOrderNum = StringUtils.isNotBlank(old.getOrderNum()) ? old.getOrderNum().trim() : null;
+        salesOrderController.deleteSalesOrderGoodsByOrderNum(orgId, oldOrderNum);
+        salesOrderController.saveGoods(order, orgId, getUsername());
+        return success();
+    }
+
+    @ApiOperation("H5销售订单删除")
+    @PostMapping("/delete")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult delete(@RequestBody Map<String, String> params) throws Exception {
+        String ids = params.get("ids");
+        if (StringUtils.isBlank(ids)) {
+            throw new Exception("ids不能为空");
+        }
+        String me = getUsername();
+        for (String id : ids.split(",")) {
+            if (StringUtils.isBlank(id)) {
+                continue;
+            }
+            SalesOrder order = salesOrderService.getById(id.trim());
+            if (order == null || !"0".equals(order.getDelFlag())) {
+                continue;
+            }
+            int src = order.getSource() == null ? 1 : order.getSource();
+            if (src != 2) {
+                throw new Exception("非H5来源销售订单不能在此删除");
+            }
+            if (!StringUtils.equals(me, order.getCreateBy())) {
+                throw new Exception("只能删除本人创建的订单");
+            }
+            if (order.getAuditStatus() != null && order.getAuditStatus() == 1) {
+                throw new Exception("已审核的销售订单不能删除");
+            }
+            String orgId = order.getOrgId();
+            String orderNum = order.getOrderNum();
+            salesOrderController.deleteSalesOrderGoodsByOrderNum(orgId, orderNum);
+            SalesOrder up = new SalesOrder();
+            up.setId(order.getId());
+            up.setDelFlag("2");
+            up.setUpdateBy(me);
+            up.setUpdateTime(new Date());
+            salesOrderService.updateById(up);
+        }
+        return success();
+    }
+
+    @ApiOperation("H5销售订单详情")
+    @PostMapping("/listById")
+    public AjaxResult listById(@ApiParam("详情参数: id") @RequestBody Map<String, String> params, HttpServletRequest request) throws Exception {
+        String id = params.get("id");
+        SalesOrder order = salesOrderService.getById(id);
+        if (order == null || !"0".equals(order.getDelFlag())) {
+            return success(null);
+        }
+        String orgId = tokenService.getLoginOrgId(request);
+        if (!orgId.equals(order.getOrgId())) {
+            throw new Exception("销售订单不存在");
+        }
+        int src = order.getSource() == null ? 1 : order.getSource();
+        if (src != 2) {
+            throw new Exception("非H5来源销售订单不能在此查看");
+        }
+        if (!StringUtils.equals(getUsername(), order.getCreateBy())) {
+            throw new Exception("只能查看本人创建的订单");
+        }
+        List<SalesOrderGoods> goods = salesOrderGoodsService.list(new QueryWrapper<SalesOrderGoods>()
+                .eq("org_id", orgId)
+                .eq("order_num", order.getOrderNum())
+                .eq("del_flag", "0"));
+        salesOrderController.enrichGoodsFromMaterial(goods, orgId);
+        order.setGoods(goods);
+        salesOrderController.enrichSalesOrderDisplay(order, orgId);
+        return success(order);
+    }
+}

+ 35 - 11
ruoyi-admin/src/main/java/com/ruoyi/web/sales/controller/SalesOrderController.java

@@ -94,6 +94,7 @@ public class SalesOrderController {
         order.setOrgId(orgId);
         order.setDelFlag("0");
         order.setAuditStatus(1);
+        order.setSource(1);
         String username = getUsername();
         order.setId(null);
         order.setCreateBy(username);
@@ -120,11 +121,24 @@ public class SalesOrderController {
             throw new Exception("已审核的销售订单不能修改,请先反审核");
         }
         String orgId = tokenService.getLoginOrgId(request);
+        if (!orgId.equals(old.getOrgId())) {
+            throw new Exception("销售订单不存在");
+        }
         validateBeforeSave(order, orgId, false);
         fillCustomerAndMarketInfo(order, orgId);
         recalcGoodsSubTotalsAndOrderTotal(order);
         order.setOrgId(orgId);
-        order.setAuditStatus(1);
+        int oldSrc = old.getSource() == null ? 1 : old.getSource();
+        boolean h5Pending = oldSrc == 2 && (old.getAuditStatus() == null || old.getAuditStatus() == 0);
+        if (h5Pending) {
+            order.setAuditStatus(0);
+            order.setSource(2);
+        } else {
+            order.setAuditStatus(1);
+            if (order.getSource() == null) {
+                order.setSource(old.getSource() != null ? old.getSource() : 1);
+            }
+        }
         String username = getUsername();
         order.setCreateBy(old.getCreateBy());
         order.setCreateTime(old.getCreateTime());
@@ -547,6 +561,10 @@ public class SalesOrderController {
     public AjaxResult audit(@RequestBody Map<String, String> params) throws Exception {
         String id = params.get("id");
         SalesOrder order = getActiveById(id);
+        int src = order.getSource() == null ? 1 : order.getSource();
+        if (src == 2 && order.getAuditStatus() != null && order.getAuditStatus() != 0) {
+            throw new Exception("仅待审核的H5销售订单可审核");
+        }
         order.setAuditStatus(1);
         order.setUpdateBy(getUsername());
         order.setUpdateTime(new Date());
@@ -1045,11 +1063,12 @@ public class SalesOrderController {
         return null;
     }
 
-    private QueryWrapper<SalesOrder> buildWrapper(SalesOrder query, String orgId) {
+    QueryWrapper<SalesOrder> buildWrapper(SalesOrder query, String orgId) {
         QueryWrapper<SalesOrder> wrapper = new QueryWrapper<SalesOrder>()
                 .eq("org_id", orgId)
                 .eq("del_flag", "0");
         if (query == null) {
+            wrapper.eq("audit_status", 1);
             return wrapper;
         }
         if (query.getDocumentDateStart() != null) {
@@ -1081,12 +1100,17 @@ public class SalesOrderController {
         }
         if (query.getAuditStatus() != null) {
             wrapper.eq("audit_status", query.getAuditStatus());
+        } else {
+            wrapper.eq("audit_status", 1);
+        }
+        if (query.getSource() != null && (query.getSource() == 1 || query.getSource() == 2)) {
+            wrapper.eq("source", query.getSource());
         }
         wrapper.orderByDesc("id");
         return wrapper;
     }
 
-    private void validateBeforeSave(SalesOrder order, String orgId, boolean isAdd) throws Exception {
+    void validateBeforeSave(SalesOrder order, String orgId, boolean isAdd) throws Exception {
         if (order == null) {
             throw new Exception("参数不能为空");
         }
@@ -1131,7 +1155,7 @@ public class SalesOrderController {
         }
     }
 
-    private void fillCustomerAndMarketInfo(SalesOrder order, String orgId) throws Exception {
+    void fillCustomerAndMarketInfo(SalesOrder order, String orgId) throws Exception {
         BaseCustomer customer = customerService.getOne(new QueryWrapper<BaseCustomer>()
                 .eq("org_id", orgId)
                 .eq("customer_num", order.getCustomerNum())
@@ -1158,7 +1182,7 @@ public class SalesOrderController {
         }
     }
 
-    private void enrichSalesOrderDisplay(SalesOrder order, String orgId) {
+    void enrichSalesOrderDisplay(SalesOrder order, String orgId) {
         if (order == null) {
             return;
         }
@@ -1189,7 +1213,7 @@ public class SalesOrderController {
         }
     }
 
-    private void enrichGoodsFromMaterial(List<SalesOrderGoods> goods, String orgId) {
+    void enrichGoodsFromMaterial(List<SalesOrderGoods> goods, String orgId) {
         if (goods == null || goods.isEmpty()) {
             return;
         }
@@ -1227,7 +1251,7 @@ public class SalesOrderController {
      * 单据编号规则:
      * XSDD + 当前日期后一天的yyyyMMdd + 3位机器标识 + 3位递增序号(不足补零,从001开始)
      */
-    private String generateSalesOrderNum(String orgId) throws Exception {
+    String generateSalesOrderNum(String orgId) throws Exception {
         if (StringUtils.isBlank(orgId)) {
             throw new Exception("orgId不能为空");
         }
@@ -1301,7 +1325,7 @@ public class SalesOrderController {
     }
 
     /** 小计=单价×基本计量数量;总计金额=各明细小计之和 */
-    private void recalcGoodsSubTotalsAndOrderTotal(SalesOrder order) {
+    void recalcGoodsSubTotalsAndOrderTotal(SalesOrder order) {
         List<SalesOrderGoods> goods = order.getGoods();
         if (goods == null || goods.isEmpty()) {
             order.setTotalAmount(null);
@@ -1375,7 +1399,7 @@ public class SalesOrderController {
     }
 
     /** 按单据编号将原明细逻辑删除(修改订单时先标记旧清单 del_flag=2) */
-    private void deleteSalesOrderGoodsByOrderNum(String orgId, String orderNum) {
+    void deleteSalesOrderGoodsByOrderNum(String orgId, String orderNum) {
         if (StringUtils.isBlank(orgId) || StringUtils.isBlank(orderNum)) {
             return;
         }
@@ -1389,7 +1413,7 @@ public class SalesOrderController {
                 .eq("del_flag", "0"));
     }
 
-    private void saveGoods(SalesOrder order, String orgId, String username) {
+    void saveGoods(SalesOrder order, String orgId, String username) {
         List<SalesOrderGoods> goods = order.getGoods();
         if (goods == null) {
             goods = Collections.emptyList();
@@ -1408,7 +1432,7 @@ public class SalesOrderController {
         }
     }
 
-    private SalesOrder getActiveById(String id) throws Exception {
+    SalesOrder getActiveById(String id) throws Exception {
         SalesOrder order = salesOrderService.getById(id);
         if (order == null || !"0".equals(order.getDelFlag())) {
             throw new Exception("销售订单不存在");

+ 4 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/sales/domain/SalesOrder.java

@@ -88,6 +88,10 @@ public class SalesOrder extends Base {
     @Excel(name = "审核状态", readConverterExp = "0=未审核,1=已审核")
     private Integer auditStatus;
 
+    @ApiModelProperty(value = "来源(1ERP-Web 2ERP-H5)")
+    @Excel(name = "来源", readConverterExp = "1=Web,2=H5")
+    private Integer source;
+
     @TableField(exist = false)
     @ApiModelProperty(value = "货品清单")
     private List<SalesOrderGoods> goods;

+ 1 - 0
ruoyi-admin/src/main/resources/i18n/messages.properties

@@ -20,6 +20,7 @@ user.password.not.valid=* 5-50个字符
 user.email.not.valid=邮箱格式错误
 user.mobile.phone.number.not.valid=手机号格式错误
 user.login.success=登录成功
+user.login.h5.denied=当前账号无H5访问权限,请由管理员在菜单权限标识或角色权限字符中配置「h5」并分配给本账号角色
 user.register.success=注册成功
 user.notfound=请重新登录
 user.forcelogout=管理员强制退出,请重新登录

+ 1 - 0
sql/sales_order.sql

@@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS `sales_order` (
   `total_amount` varchar(64) DEFAULT NULL COMMENT '总计金额',
   `remark1` varchar(500) DEFAULT NULL COMMENT '备注1',
   `audit_status` tinyint(1) DEFAULT 1 COMMENT '审核状态(0未审核1已审核)',
+  `source` tinyint(1) NOT NULL DEFAULT 1 COMMENT '来源(1ERP-Web 2ERP-H5)',
   `remark` varchar(500) DEFAULT NULL COMMENT '备注',
   `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
   `create_by` varchar(64) DEFAULT '' COMMENT '创建者',