Преглед на файлове

经销商发货管理新增【工厂发货/退货明细】及其他bug修复

hu преди 2 години
родител
ревизия
cf925dfe30

+ 109 - 5
src/custom/beans/remind/Remind.java

@@ -13,21 +13,23 @@ import common.websocket.WebSocket;
 import utility.email.Email;
 import utility.email.EmailContent;
 import utility.sms.Sms;
+import utility.tools.Encryption;
+import utility.wechat.WechatService;
 
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 
 /**
  * 系统提醒公共方法,包括弹窗、短信、邮件等相关功能
  */
 public class Remind {
-
-
     /**
      * 发送一个系统提醒,系统将自动判断发送的方式及自动生成发送的内容
      */
     public static void autoRemind(Controller controller, String remindname, long dataid) throws YosException {
-        Rows sys_remind_configsRows = controller.dbConnect.runSqlQuery("select t2.ownertable,t1.remindtitle,t1.remindmode,t1.content,t1.isrole,t1.roleids,t1.isuser,t1.userids,t1.issql,t1.sqlstr from sys_remind_configs t1 " +
+        Rows sys_remind_configsRows = controller.dbConnect.runSqlQuery("select t2.ownertable,t1.remindtitle,t1.remindmode,t1.content,t1.isrole,t1.roleids,t1.isuser,t1.userids,t1.issql,t1.sqlstr,t1.wechatservice_systemclient,t1.wechatservice_content,t1.systemappids from sys_remind_configs t1 " +
                 "inner join sys_remind_config t2 on t1.sys_remind_configid=t2.sys_remind_configid where siteid='" + controller.siteid + "' and t2.remindname='" + remindname + "'");
         if (sys_remind_configsRows.isNotEmpty()) {
             String ownertable = sys_remind_configsRows.get(0).getString("ownertable");
@@ -37,6 +39,7 @@ public class Remind {
             boolean isrole = sys_remind_configsRows.get(0).getBoolean("isrole");
             boolean isuser = sys_remind_configsRows.get(0).getBoolean("isuser");
             boolean issql = sys_remind_configsRows.get(0).getBoolean("issql");
+            JSONArray systemappids = sys_remind_configsRows.get(0).getJSONArray("systemappids");
 
             LinkedHashSet<Long> useridList = new LinkedHashSet<>();
             if (isrole) {
@@ -110,6 +113,8 @@ public class Remind {
                                 remind.setTitle(remindtitle);
                                 remind.setToemail(User.getUserMailAddress(controller, userid));
                                 remind.setContent(emailContent);
+                                remind.setSystemappids(systemappids);
+
                                 remind.sendByMail();
                             } catch (Exception e) {
                                 e.printStackTrace();
@@ -123,6 +128,7 @@ public class Remind {
                                 Remind remind = new Remind(controller);
                                 remind.setContent(content);
                                 remind.setTophonenumber(User.getUserPhonenumber(controller, userid));
+                                remind.setSystemappids(systemappids);
                                 remind.sendBySms();
                             } catch (Exception e) {
                                 e.printStackTrace();
@@ -138,6 +144,7 @@ public class Remind {
                                 remind.setContent(content);
                                 remind.setTouserid(userid);
                                 remind.setTophonenumber(User.getUserPhonenumber(controller, userid));
+                                remind.setSystemappids(systemappids);
                                 remind.sendByDialogMsg();
                             } catch (Exception e) {
                                 e.printStackTrace();
@@ -145,6 +152,79 @@ public class Remind {
                         }
                         break;
                     }
+                    case "微信公众号": {
+                        String wechatservice_systemclient = sys_remind_configsRows.get(0).getString("wechatservice_systemclient");
+                        JSONObject wechatservice_content = null;
+                        try {
+                            wechatservice_content = JSONObject.parseObject(Encryption.Decode_Base64(sys_remind_configsRows.get(0).getString("wechatservice_content").replace(" ", "\n")));
+                        } catch (Exception e) {
+                            wechatservice_content = new JSONObject();
+                        }
+                        if (wechatservice_content.isEmpty() || wechatservice_systemclient.equals("")) {
+                            break;
+                        }
+                        String template_id = wechatservice_content.getJSONObject("templates").getStringValue("template_id");
+                        if (template_id.equals("")) {
+                            break;
+                        }
+                        String tourl = wechatservice_content.getJSONObject("data").getString("tourl");
+
+                        JSONArray dataparams = wechatservice_content.getJSONObject("data").getJSONArray("param");
+
+                        HashMap<String, String> datamap = new HashMap<>();
+                        for (Object dataparam : dataparams) {
+                            JSONObject dataparamObject = (JSONObject) dataparam;
+                            String key = dataparamObject.getString("key");
+                            String value = String.valueOf(dataparamObject.get("value"));
+
+
+                            if (value.contains(":")) {
+                                Rows datarows = controller.dbConnect.runSqlQuery("select * from " + ownertable + " where " + controller.getuniquecolumnname(ownertable) + "=" + dataid);
+                                if (datarows.isNotEmpty()) {
+                                    for (String field : datarows.get(0).keySet()) {
+                                        if (value.contains(":" + field)) {
+                                            value = value.replace(":" + field, "'" + datarows.get(0).getString(field) + "'");
+                                        }
+                                    }
+                                }
+                            }
+                            int max2 = 10;
+                            while (value.contains("{") && value.contains("}")) {
+                                int start = value.indexOf("{");
+                                int end = value.indexOf("}");
+                                String parm = value.substring(start, end + 1);
+                                String sql = parm.replace("{", "").replace("}", "");
+                                Rows rows = controller.dbConnect.runSqlQuery(sql);
+                                if (rows.size() != 1 || rows.getFieldList().size() != 1) {
+                                    break;
+                                } else {
+                                    value = value.replace(parm, rows.get(0).getString(rows.getFieldList().get(0)));
+                                }
+                                if (max2-- == 0) {
+                                    break;
+                                }
+                            }
+                            datamap.put(key, value);
+                        }
+
+                        String tominiprogram_appid = "";
+                        String tominiprogram_pagepath = "";
+                        Rows wechatapps = controller.dbConnect.runSqlQuery("select *from sys_wechatapp where systemclient='" + wechatservice_content.getJSONObject("data").getString("tominiprogram_systemclient") + "'");
+                        if (wechatapps.isNotEmpty()) {
+                            tominiprogram_appid = wechatapps.get(0).getString("appid");
+                            tominiprogram_pagepath = wechatservice_content.getJSONObject("data").getString("tominiprogram_pagepath");
+                        }
+
+                        WechatService wechatService = new WechatService(wechatservice_systemclient);
+                        for (Long userid : useridList) {
+                            try {
+                                wechatService.send(userid, template_id, String.valueOf(Calendar.getInstance().getTimeInMillis()), tourl, datamap, tominiprogram_appid, tominiprogram_pagepath);
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                        break;
+                    }
                 }
             }
         }
@@ -153,6 +233,7 @@ public class Remind {
     private String type = "";
     private String title = "";
     private String content = "";
+    private JSONArray systemappids = new JSONArray();
     private ArrayList<String> tophonenumber = new ArrayList<>();
     private ArrayList<String> toemail = new ArrayList<>();
     private String objectname = "null";
@@ -247,6 +328,18 @@ public class Remind {
         this.toemail = User.getUserMailAddress(controller, userid);
     }
 
+    /**
+     * 邮件发送对象。邮件发送时必填
+     *
+     * @param userids
+     */
+    public void setToemails(ArrayList<Long> userids) throws YosException {
+        for (Long userid : userids) {
+            this.toemail.addAll(User.getUserMailAddress(controller, userid));
+        }
+
+    }
+
     public void setObjectname(String objectname) {
         this.objectname = objectname;
     }
@@ -283,6 +376,15 @@ public class Remind {
         this.type = type;
     }
 
+    /**
+     * 设置跳转应用id
+     *
+     * @return
+     */
+    public void setSystemappids(JSONArray systemappids) {
+        this.systemappids = systemappids;
+    }
+
     /**
      * 邮件发送
      *
@@ -299,8 +401,8 @@ public class Remind {
             Email email = new Email(siteid, title, toemail);
             if (emailContent == null) {
                 EmailContent content = new EmailContent();
-                content.addText(title);
-                content.addBr();
+//                content.addText(title);
+//                content.addBr();
                 content.addText(this.content);
                 email.send(siteid, content);
             } else {
@@ -366,11 +468,13 @@ public class Remind {
         }
         for (Long userid : touserid) {
             SQLFactory factory = new SQLFactory("系统消息插入");
+            factory.addParameter("messageid", controller.createTableID("sys_message"));
             factory.addParameter("siteid", siteid);
             factory.addParameter("type", type);
             factory.addParameter("title", title);
             factory.addParameter("message", content);
             factory.addParameter("userid", userid);
+            factory.addParameter("systemappids", systemappids);
             factory.addParameter("objectid", objectid == 0 ? "null" : objectid);
             factory.addParameter("objectname", objectname);
             controller.dbConnect.runSqlUpdate(factory.getSQL());

+ 4 - 0
src/custom/restcontroller/R.java

@@ -4780,6 +4780,10 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230626104003 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 51 - 0
src/custom/restcontroller/webmanage/sale/dispatch/SQL/工厂发货及退货明细(经销商).sql

@@ -0,0 +1,51 @@
+select t.* from (SELECT t1.sa_dispatch_itemsid detailid,
+       t1.sa_dispatchid id,
+       t1.sa_orderitemsid,
+       t4.billno,
+       t4.status,
+       t8.sa_orderid,
+       t8.sonum,
+       '发货' type,
+			 t1.outwarehousedate date,
+       t2.itemno,
+       t2.itemname,
+       t3.unitname,
+       ifnull(t1.outwarehouseqty, 0) qty,
+       t5.price,
+       cast((ifnull(t1.outwarehouseqty, 0) * t5.price) AS CHAR) amount,
+			 t2.packageqty,
+       t1.remarks
+FROM sa_dispatch_items t1
+         left join plm_item t2 on t1.itemid = t2.itemid and t1.siteid = t2.siteid
+         LEFT JOIN plm_unit t3 ON t3.unitid = t2.unitid AND t3.siteid = t2.siteid
+         LEFT JOIN sa_dispatch t4 ON t4.sa_dispatchid = t1.sa_dispatchid AND t4.siteid = t1.siteid
+         left join sa_orderitems t5 on t1.sa_orderitemsid = t5.sa_orderitemsid and t1.siteid = t5.siteid
+         left join sa_order t8 on t8.sa_orderid=t5.sa_orderid and t8.siteid=t5.siteid
+         left join plm_itemextend t6 on t2.siteid = t6.siteid and t2.itemid = t6.itemid
+where t1.siteid = $siteid$ and t4.sys_enterpriseid=$sys_enterpriseid$ and ifnull(t1.outwarehouseqty, 0)>0
+union all
+SELECT t1.sa_aftersalesmag_itemsid detailid,
+       t1.sa_aftersalesmagid id,
+       t1.sa_orderitemsid,
+       t4.billno,
+       t4.status,
+       t8.sa_orderid,
+       t8.sonum,
+       '退货' type,
+			 t4.recheckdate date,
+       t2.itemno,
+       t2.itemname,
+       t3.unitname,
+       t1.qty,
+       t1.price,
+       t1.amount,
+			 t2.packageqty,
+       t1.reason remarks
+FROM sa_aftersalesmag_items t1
+         left join plm_item t2 on t1.itemid = t2.itemid and t1.siteid = t2.siteid
+         LEFT JOIN plm_unit t3 ON t3.unitid = t2.unitid AND t3.siteid = t2.siteid
+         LEFT JOIN sa_aftersalesmag t4 ON t4.sa_aftersalesmagid = t1.sa_aftersalesmagid AND t4.siteid = t1.siteid
+         left join sa_orderitems t5 on t1.sa_orderitemsid = t5.sa_orderitemsid and t1.siteid = t5.siteid
+         left join sa_order t8 on t8.sa_orderid=t5.sa_orderid and t8.siteid=t5.siteid
+         left join plm_itemextend t6 on t2.siteid = t6.siteid and t2.itemid = t6.itemid
+where t1.siteid = $siteid$ and t4.type='退货单' and t4.status='复核' and t4.sys_enterpriseid=$sys_enterpriseid$) t where $where$

+ 71 - 1
src/custom/restcontroller/webmanage/sale/dispatch/dispatchItems.java

@@ -327,7 +327,7 @@ public class dispatchItems extends Controller {
                 where.append(" and DATE_FORMAT(t4.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
             }
             if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
-                where.append(" and tDATE_FORMAT(t4.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
+                where.append(" and DATE_FORMAT(t4.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
             }
             if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
                 where.append(" and t4.status ='").append(whereObject.getString("status")).append("' ");
@@ -412,6 +412,76 @@ public class dispatchItems extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+
+    @API(title = "工厂发货/退货明细", apiversion = R.ID20230626104003.v1.class)
+    @CACHEING
+    public String queryDispatchAndAftersalesmagItemsList() throws YosException, IOException {
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+
+
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t.sonum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
+                where.append(" and(");
+                where.append("t.type ='").append(whereObject.getString("type")).append("' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
+                where.append(" and DATE_FORMAT(t.date, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
+            }
+            if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
+                where.append(" and DATE_FORMAT(t.date, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
+            }
+            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
+                where.append(" and t.status ='").append(whereObject.getString("status")).append("' ");
+            }
+        }
+        boolean isExport = content.getBooleanValue("isExport");
+        SQLFactory sqlFactory = new SQLFactory(this, "工厂发货及退货明细(经销商)", pageSize, pageNumber, pageSorting);
+        if (isExport) {
+            sqlFactory = new SQLFactory(this, "工厂发货及退货明细(经销商)");
+        }
+        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+
+
+        if (isExport) {
+//            //去除不需要导出项
+//            rows.getFieldList().remove("sa_dispatch_itemsid");
+//            rows.getFieldList().remove("sa_dispatchid");
+//            rows.getFieldList().remove("sa_orderitemsid");
+//            rows.getFieldList().remove("sa_orderid");
+//            rows.getFieldList().remove("sys_enterpriseid");
+//            rows.getFieldList().remove("isclose");
+//            rows.getFieldList().remove("rowno");
+//            rows.getFieldList().remove("itemid");
+//            rows.getFieldList().remove("batchno");
+//            Rows rowsrolename= dbConnect.runSqlQuery("select * from sys_userrole t1 inner join sys_role t2 on t1.roleid=t2.roleid and t1.siteid=t2.siteid where t2.rolename='经销商员工' and t1.userid="+userid);
+//            if(!rowsrolename.isEmpty()){
+//                rows.getFieldList().remove("price");
+//                rows.getFieldList().remove("amount");
+//            }
+//            rows.getFieldList().remove("undeliqty");
+//            rows.getFieldList().remove("deliedqty");
+//            rows.getFieldList().remove("outwarehousedate");
+//            Rows uploadRows = uploadExcelToObs("dispatch", "发货单明细列表", rows, getTitleMap());
+//            return getSucReturnObject().setData(uploadRows).toString();
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
     //返回导出的标题
     public HashMap<String, String> getTitleMap() throws YosException {
         HashMap<String, String> titleMap = new HashMap<>();

+ 28 - 0
src/custom/restcontroller/webmanage/sale/order/Order.java

@@ -34,6 +34,7 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 
@@ -1507,6 +1508,14 @@ public class Order extends Controller {
             return getErrReturnObject().setErrMsg("订单不存在").toString();
         }
         Row row = rows.get(0);
+        Date submitdate =new Date();
+        Date date = new Date();
+        if(!StringUtils.isBlank(row.getString("submitdate"))){
+             submitdate = row.getDate("submitdate");
+        }
+        if(!isMonth(submitdate,date) && row.getString("type").equals("标准订单")){
+            return getErrReturnObject().setErrMsg("标准订单无法跨月退回").toString();
+        }
         Long sa_accountclassid = row.getLong("sa_accountclassid");
         //验证结算企业
         Long pay_enterpriseid = row.getLong("pay_enterpriseid");
@@ -2599,6 +2608,25 @@ public class Order extends Controller {
         return getSucReturnObject().setData(rolename).toString();
     }
 
+
+    /**
+     * 判断是否在同一个月
+     *
+     * @return false:不在同一个月内,true在同一个月内
+     */
+    public boolean isMonth(Date date1, Date date2) {
+        Calendar calendar1 = Calendar.getInstance();
+        calendar1.setTime(date1);
+        Calendar calendar2 = Calendar.getInstance();
+        calendar2.setTime(date2);
+        int year1 = calendar1.get(Calendar.YEAR);
+        int year2 = calendar2.get(Calendar.YEAR);
+        int month1 = calendar1.get(Calendar.MONTH);
+        int month2 = calendar2.get(Calendar.MONTH);
+        return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
+
+    }
+
 //    @API(title = "发货单手动关闭", apiversion = R.ID20230406155302.v1.class)
 //    @Deprecated
 //    public String closeDispatch() throws YosException {