Browse Source

1、公用日志新增自定义方法。
2、抄表算费:新增按用户、按抄表册调用存储过程的方法。
3、优化公用的系统配置mapper获取处理。

shudong 1 year ago
parent
commit
7b174938f9

+ 64 - 5
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/common/dbhelper/LogHelper.java

@@ -64,7 +64,7 @@ public class LogHelper {
                         Object newValue = newField.get(tNew);
                         if (newValue != null && !oldValue.equals(newValue)) {
                             //不相同证明有更改
-                            setSaveInfo(tNew, oldValue, sbResult, jsonArray, newField, LogOperateEnum.Modif);
+                            setSaveInfo(tNew, oldValue, sbResult, jsonArray, newField, LogOperateEnum.Modify);
                         }
                         break;
                     }
@@ -80,7 +80,7 @@ public class LogHelper {
                 //数据库表名
                 String strDbTableName = ((TableName) getTableNameAnnotation(tOld)).value();
                 //返回存储的日志SQL
-                strResult = saveLogSQL(strCause, strNotes, jsonArray.toJSONString(), LogOperateEnum.Modif, strDbTableName);
+                strResult = saveLogSQL(strCause, strNotes, jsonArray.toJSONString(), LogOperateEnum.Modify, strDbTableName);
             }
         } catch (Exception ex) {
             strResult = "";
@@ -124,7 +124,7 @@ public class LogHelper {
                 }
                 if (newValue != null) {
                     Object oldValue = hashMap.get(newField.getName());
-                    setSaveInfo(tNew, oldValue, sbResult, jsonArray, newField, LogOperateEnum.Modif);
+                    setSaveInfo(tNew, oldValue, sbResult, jsonArray, newField, LogOperateEnum.Modify);
                 }
             }
 
@@ -136,7 +136,7 @@ public class LogHelper {
                 strNotes = strNotes.substring(0, strNotes.length() - 1);
 
                 //返回存储的日志SQL
-                strResult = saveLogSQL(strCause, strNotes, jsonArray.toJSONString(), LogOperateEnum.Modif, strDbTableName);
+                strResult = saveLogSQL(strCause, strNotes, jsonArray.toJSONString(), LogOperateEnum.Modify, strDbTableName);
             }
         } catch (Exception ex) {
             strResult = "";
@@ -167,6 +167,30 @@ public class LogHelper {
     public static <T> String getDeleteSQL(T tNew, String strCause) {
         return getAddOrDeleteSQL(tNew, strCause, LogOperateEnum.Delete);
     }
+
+    /**
+     * 获取自定义日志的SQL语句
+     *
+     * @param t        实体类名,使用【类名.class】调用,如:BwMeterReadPlan.class
+     * @param strCause 处理原因,不能为空否则直接返回null
+     * @param strNotes 日志描述内容
+     * @return SQL语句
+     */
+    public static String getCustomSQL(Class t, String strCause, String strNotes) {
+        //数据库表名
+        String strDbTableName = ((TableName) getTableNameAnnotation(t)).value();
+
+        //详情添加到json对象中
+        JSONArray jsonArray = new JSONArray();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("text", "备注信息");
+        jsonObject.put("value", strNotes);
+        jsonArray.add(jsonObject);
+
+        //返回存储的日志SQL
+        return saveLogSQL(strCause, strNotes, jsonArray.toJSONString(), LogOperateEnum.Custom, strDbTableName);
+    }
+
     //endregion
 
     //region 直接调用的方法
@@ -245,6 +269,25 @@ public class LogHelper {
             return false;
         }
     }
+
+    /**
+     * 执行自定义记录日志的方法
+     *
+     * @param t        实体类名,使用【类名.class】调用,如:BwMeterReadPlan.class
+     * @param strCause 日志原因
+     * @param strNotes 日志描述
+     * @return truefalse true=成功,false=失败
+     * @throws Exception
+     */
+    public static boolean excuteCustom(Class t, String strCause, String strNotes) throws Exception {
+        String strLog = getCustomSQL(t, strCause, strNotes);
+        if (!StringUtils.isBlank(strLog)) {
+            return DbHelper.getDbHelper().executeCmd(strLog) > 0;
+        } else {
+            return false;
+        }
+    }
+
     //endregion
 
     //endregion
@@ -331,7 +374,7 @@ public class LogHelper {
         }
 
         switch (logOperateEnum) {
-            case Modif:
+            case Modify:
                 sbResult.append(MessageFormat.format("「{0}({1})」由{2}修改为{3};", fieldText, fieldValue, oldValue, newValue));
                 break;
             case Add:
@@ -392,6 +435,22 @@ public class LogHelper {
         return null;
     }
 
+    /**
+     * 获取泛型实体类对应的TableName注解对象
+     *
+     * @param t 泛型实体类
+     * @return 实体类对应的TableName注解对象
+     */
+    private static Annotation getTableNameAnnotation(Class t) {
+        Annotation[] annotations = t.getDeclaredAnnotations();
+        for (Annotation annotation : annotations) {
+            if (annotation instanceof TableName) {
+                return annotation;
+            }
+        }
+        return null;
+    }
+
     /**
      * 保存日志SQL
      *

+ 3 - 7
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/common/enums/LogOperateEnum.java

@@ -13,17 +13,13 @@ public enum LogOperateEnum {
     /**
      * 修改
      */
-    Modif,
+    Modify,
     /**
      * 删除
      */
     Delete,
     /**
-     * 查询
+     * 自定义
      */
-    Search,
-    /**
-     * 事件
-     */
-    Event
+    Custom
 }

+ 20 - 5
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/common/util/DateUtils.java

@@ -9,20 +9,21 @@ import java.util.Date;
 
 public class DateUtils {
     private static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
     public static boolean isValidDateFormat(String dateString) {
         try {
             LocalDate.parse(dateString);
             return true;
-        } catch (DateTimeParseException e)
-        {
+        } catch (DateTimeParseException e) {
             return false;
         }
     }
 
     /**
      * 将日期字符串按照指定格式转换成另一个格式的字符串
-     * @param dateStr 日期字符串
-     * @param srcFormat 原日期格式
+     *
+     * @param dateStr      日期字符串
+     * @param srcFormat    原日期格式
      * @param targetFormat 目标日期格式
      * @return 转换后的日期字符串
      */
@@ -41,7 +42,8 @@ public class DateUtils {
 
     /**
      * 将日期字符串按照指定格式转换成另一个格式的字符串
-     * @param date 日期字符串
+     *
+     * @param date      日期字符串
      * @param srcFormat 原日期格式
      * @return 转换后的日期字符串
      */
@@ -50,6 +52,7 @@ public class DateUtils {
         String formattedDate = srcSdf.format(date);
         return formattedDate;
     }
+
     /**
      * 将日期转换为默认格式的字符串
      *
@@ -59,6 +62,7 @@ public class DateUtils {
     public static String formatDate(Date date) {
         return formatDate(date, DEFAULT_PATTERN);
     }
+
     /**
      * 将日期转换为指定格式的字符串
      *
@@ -74,4 +78,15 @@ public class DateUtils {
         return dateFormat.format(date);
     }
 
+    /**
+     * 计算两个日期的相差秒数
+     *
+     * @param dateBegin 开始时间
+     * @param dateEnd   结束时间
+     * @return 秒数差值(结束时间-开始时间)
+     */
+    public static long getSecond(Date dateBegin, Date dateEnd) {
+        long timeValue = dateEnd.getTime() - dateBegin.getTime();
+        return timeValue / 1000;
+    }
 }

+ 129 - 0
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/meterreadingmgt/controller/BwMeterReadPlanController.java

@@ -16,7 +16,10 @@ import com.tofly.fees.common.dbhelper.DbHelper;
 import com.tofly.fees.common.dbhelper.LogHelper;
 import com.tofly.fees.common.dbhelper.PageSortHelper;
 import com.tofly.fees.common.dbhelper.ProduceSql;
+import com.tofly.fees.common.model.ProcParamModel;
+import com.tofly.fees.common.util.DateUtils;
 import com.tofly.fees.common.util.NumberUtils;
+import com.tofly.fees.common.util.SysConfigUtils;
 import com.tofly.fees.meterprofilemgt.entity.DaMeter;
 import com.tofly.fees.meterprofilemgt.service.DaMeterService;
 import com.tofly.fees.meterreadingmgt.entity.BwMeterReadPlan;
@@ -28,14 +31,20 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
+import org.apache.ibatis.mapping.ParameterMode;
 import org.springframework.beans.BeanUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
+import java.sql.JDBCType;
+import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 /**
  * 抄表计划_抄表录入
@@ -269,4 +278,124 @@ public class BwMeterReadPlanController extends BaseController {
         IPage<Map<String, Object>> pageList = bwMeterReadPlanMapper.getUserList(page, companyBranch, mrBooks, searchText);
         return ResultRespone.success(pageList);
     }
+
+    /**
+     * 抄表算费-按选中用户算费
+     *
+     * @param meterCardIds 抄表卡ID集(多个英文逗号隔开)
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/doCalcFeeForUser")
+    @ApiOperation(value = "抄表算费-按选中用户算费")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "meterCardIds", value = "抄表卡ID集(多个英文逗号隔开)", dataType = "String")
+    })
+    public ResultRespone doCalcFeeForUser(String meterCardIds) throws Exception {
+        if (StringUtils.isBlank(meterCardIds)) {
+            return ResultRespone.failed("算费失败:请选择需要算费的用户!");
+        }
+        String[] arrCardIds = meterCardIds.split(",");
+        return getResultResponse(arrCardIds);
+    }
+
+    /**
+     * 抄表算费-按选中抄表册
+     *
+     * @param mrBooks 抄表册编码集(多个英文逗号隔开)
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/doCalcFeeForMrBook")
+    @ApiOperation(value = "抄表算费-按选中抄表册")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mrBooks", value = "抄表册编码集(多个英文逗号隔开)", dataType = "String")
+    })
+    public ResultRespone doCalcFeeForMrBook(String mrBooks) throws Exception {
+        if (StringUtils.isBlank(mrBooks)) {
+            return ResultRespone.failed("算费失败:抄表册参数为空!");
+        }
+        ArrayList arrayList = bwMeterReadPlanMapper.getMeterCardIds(mrBooks);
+        if (arrayList.size() == 0) {
+            return ResultRespone.failed("算费失败:当前所选的抄表册不存在需算费的用户!");
+        }
+        String[] arrList = (String[]) arrayList.toArray();
+        return getResultResponse(arrList);
+    }
+
+    /**
+     * 算费相关处理
+     *
+     * @param arrCardIds 抄表卡ID集数组
+     * @return
+     * @throws Exception
+     */
+    private ResultRespone<Object> getResultResponse(String[] arrCardIds) throws Exception {
+        int maxCalcNum = Integer.parseInt(SysConfigUtils.getConfigValue("CBJSMaxCount"));
+        if (arrCardIds.length > maxCalcNum) {
+            return ResultRespone.failed(MessageFormat.format("算费失败:选择的【{0}】条抄表记录过多,每次算费最多不超过【{1}】条记录,请分批计算费用!", arrCardIds.length, maxCalcNum));
+        }
+        DbHelper db = DbHelper.getDbHelper();
+        //先进行总表水量计算
+        List<ProcParamModel> listZB = new ArrayList<>();
+        listZB.add(new ProcParamModel("P_CBKID", ParameterMode.IN, JDBCType.INTEGER, null));
+        listZB.add(new ProcParamModel("P_SFCG", ParameterMode.OUT, JDBCType.INTEGER, 0));
+        listZB.add(new ProcParamModel("P_MSG", ParameterMode.OUT, JDBCType.VARCHAR, ""));
+        Map mapZB = db.excuteProcedure("PROC_SLJS_ZB", listZB);
+
+        //存储过程返回的参数
+        if (!(mapZB != null && mapZB.get("P_SFCG").equals(1))) {
+            return ResultRespone.failed(MessageFormat.format("算费失败:总表水量计算异常【异常消息:{0}】,已终止!", mapZB.get("P_MSG")));
+        }
+        //声明队列
+        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
+        for (String meterCardId : arrCardIds) {
+            queue.add(meterCardId);
+        }
+        //开始时间
+        Date dtBegin = new Date();
+        //运行队列
+        int intSuccessNum = doRunDataQueue(db, queue);
+        //结束时间
+        Date dtEnd = new Date();
+        //获取时间运行的秒数
+        long secNum = DateUtils.getSecond(dtBegin, dtEnd);
+
+        String strMsg = "";
+        if (intSuccessNum == 0) {
+            strMsg = MessageFormat.format("算费失败:已算费0条抄表记录!共耗时{0}秒!", secNum);
+        } else {
+            strMsg = MessageFormat.format("算费成功:成功算费{0}个用户,共耗时{1}秒!", intSuccessNum, secNum);
+        }
+        LogHelper.excuteCustom(BwMeterReadPlan.class, "抄表算费:按选中抄表册", strMsg);
+        return (intSuccessNum == 0) ? ResultRespone.failed(strMsg) : ResultRespone.success(strMsg);
+    }
+
+    /**
+     * 运行数据队列
+     *
+     * @param db    数据处理对象
+     * @param queue 队列对象
+     * @return 运行的成功数
+     */
+    private int doRunDataQueue(DbHelper db, ConcurrentLinkedQueue<String> queue) {
+        //成功数量
+        int intReturnNum = 0;
+        while (!queue.isEmpty()) {
+            String meterCId = queue.poll();
+            //调用水量算费存储过程
+            List<ProcParamModel> listSLSF = new ArrayList<>();
+            listSLSF.add(new ProcParamModel("P_CBKID", ParameterMode.IN, JDBCType.INTEGER, meterCId));
+            listSLSF.add(new ProcParamModel("P_SFCG", ParameterMode.OUT, JDBCType.INTEGER, 0));
+            listSLSF.add(new ProcParamModel("P_MSG", ParameterMode.OUT, JDBCType.VARCHAR, ""));
+            Map mapSLSF = db.excuteProcedure("PROC_SLSFJS", listSLSF);
+            //判断返回结果
+            if (mapSLSF != null && mapSLSF.get("P_SFCG").equals(1)) {
+                intReturnNum++;
+            }
+            //移除已处理的子项
+            queue.remove(meterCId);
+        }
+        return intReturnNum;
+    }
 }

+ 1 - 1
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/meterreadingmgt/entity/BwMeterReadPlan.java

@@ -182,7 +182,7 @@ public class BwMeterReadPlan extends Model<BwMeterReadPlan> {
     /**
      * 旧表止读
      */
-    @ApiModelProperty(value = "旧表止")
+    @ApiModelProperty(value = "旧表止")
     private BigDecimal oldMeterEreading;
     /**
      * 新表起度

+ 10 - 1
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/meterreadingmgt/mapper/BwMeterReadPlanMapper.java

@@ -10,6 +10,7 @@ import com.tofly.fees.meterreadingmgt.entity.BwMeterReadPlan;
 import org.apache.ibatis.annotations.MapKey;
 import org.springframework.stereotype.Repository;
 
+import java.util.ArrayList;
 import java.util.Map;
 
 /**
@@ -49,8 +50,16 @@ public interface BwMeterReadPlanMapper extends BaseMapper<BwMeterReadPlan> {
      * @return
      */
     @MapKey("meter_card_id")
-    Page<Map<String, Object>> getUserList(Page page, String companyBranch, String mrBooks,String searchText);
+    Page<Map<String, Object>> getUserList(Page page, String companyBranch, String mrBooks, String searchText);
 
+    /**
+     * 通过抄表本集合查询已抄表待算费的抄表卡ID集
+     *
+     * @param mrBooks 抄表本集合
+     * @return
+     */
+    @MapKey("meter_card_id")
+    ArrayList getMeterCardIds(String mrBooks);
 
     int delByNo(String no);
 

+ 0 - 1
collect-fees/collect-fees-service/src/main/resources/mapper/common/CommonMapper.xml

@@ -38,7 +38,6 @@
                 pzid = #{pzid}
             </if>
         </where>
-        )
     </select>
 
     <!--获取当前的财务日期-->

+ 10 - 2
collect-fees/collect-fees-service/src/main/resources/mapper/meterreadingmgt/BwMeterReadPlanMapper.xml

@@ -51,7 +51,7 @@
     <select id="getMrBookList" resultType="java.util.Map">
         select a.mr_book cbbbm,b.name cbbmc,count(0) yhsl
         from tf_ywys_bw_meter_read_plan a,tf_ywys_bm_mr_book b
-        where a.mr_book = b.code and a.mr_flag = '1' and a.cal_flag = '0' and a.cal_state='1'
+        where a.mr_book = b.code and a.mr_flag = '1' and a.audit_flag='1' and a.cal_flag = '0' and a.cal_state='1'
         <!--所属公司-->
         <if test="companyBranch!=null and companyBranch!=''">
             and a.company_branch=#{companyBranch}
@@ -66,7 +66,7 @@
     <select id="getUserList" resultType="java.util.Map">
         select a.meter_card_id,a.customer_no,b.customer_name,b.customer_address,a.quantity
         from tf_ywys_bw_meter_read_plan a inner join tf_ywys_da_customer b on a.customer_no=b.customer_no
-        where a.mr_flag = '1' and a.cal_flag = '0'
+        where a.mr_flag = '1' and a.audit_flag='1' and a.cal_flag = '0'
         <!--所属公司-->
         <if test="companyBranch!=null and companyBranch!=''">
             and a.company_branch=#{companyBranch}
@@ -80,6 +80,14 @@
             and a.mr_book in(${mrBooks})
         </if>
     </select>
+    <!--通过抄表本集合查询已抄表待算费的抄表卡ID集-->
+    <select id="getMeterCardIds" resultType="java.util.ArrayList">
+        select meter_card_id from tf_ywys_bw_meter_read_plan where mr_flag='1' and audit_flag='1' and cal_flag='0'
+        <!--抄表本集合-->
+        <if test="mrBooks!=null and mrBooks!=''">
+            and mr_book in(${mrBooks})
+        </if>
+    </select>
     <delete id="delByNo">
         delete
         from Tf_Ywys_Da_Customer