Browse Source

表册批量设置相关接口

shudong 1 year ago
parent
commit
d1d0759ca8

+ 219 - 0
collect-fees/collect-fees-service/src/main/java/com/tofly/fees/meterreadingmgt/controller/UserMrBookSetController.java

@@ -0,0 +1,219 @@
+package com.tofly.fees.meterreadingmgt.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.tofly.common.core.entity.ResultRespone;
+import com.tofly.fees.codemgt.mapper.BmMrAreaMapper;
+import com.tofly.fees.codemgt.service.BmMrAreaService;
+import com.tofly.fees.common.dbhelper.DbHelper;
+import com.tofly.fees.common.dbhelper.PageSortHelper;
+import com.tofly.fees.meterreadingmgt.mapper.BwMeterReadPlanMapper;
+import com.tofly.fees.meterreadingmgt.service.IBwMeterReadPlanService;
+import com.tofly.fees.userprofilemgt.mapper.DaCustomerMapper;
+import com.tofly.fees.userprofilemgt.service.DaCustomerService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 抄表管理-用户表册设置
+ *
+ * @author shudong
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/api/userMrBookSet")
+@Api(tags = "抄表管理-用户表册设置")
+public class UserMrBookSetController {
+    private final BwMeterReadPlanMapper bwMeterReadPlanMapper;
+
+    //region 表册列表
+
+    /**
+     * 用户表册设置:未分配抄表册的用户
+     */
+    @PostMapping("/unAllotList")
+    @ApiOperation(value = "未分配抄表册用户列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "companyBranch", value = "公司", dataType = "String"),
+            @ApiImplicitParam(name = "mrArea", value = "片区", dataType = "String"),
+            @ApiImplicitParam(name = "searchText", value = "模糊查询(用户编号、姓名)", dataType = "String")
+    })
+    public ResultRespone getUnAllotList(Page page, String companyBranch, String mrArea
+            , String searchText) {
+        PageSortHelper.setPageSort(page, null);
+        IPage<Map<String, Object>> pageList = bwMeterReadPlanMapper.getMrBookUserList(page, companyBranch, mrArea
+                , null, searchText, null);
+        return ResultRespone.success(pageList);
+    }
+
+    /**
+     * 用户表册设置:已分配抄表册的用户
+     */
+    @PostMapping("/allotList")
+    @ApiOperation(value = "已分配抄表册用户列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "companyBranch", value = "公司", dataType = "String"),
+            @ApiImplicitParam(name = "mrArea", value = "片区", dataType = "String"),
+            @ApiImplicitParam(name = "mrBook", value = "抄表本", dataType = "String"),
+            @ApiImplicitParam(name = "searchText", value = "模糊查询(用户编号、姓名)", dataType = "String")
+    })
+    public ResultRespone getAllotList(Page page, String companyBranch, String mrArea
+            , String mrBook, String searchText) {
+        PageSortHelper.setPageSort(page, null);
+        IPage<Map<String, Object>> pageList = bwMeterReadPlanMapper.getMrBookUserList(page, companyBranch, mrArea
+                , mrBook, searchText, "not");
+        return ResultRespone.success(pageList);
+    }
+    //endregion
+
+    //region 表册分配操作
+
+    /**
+     * 用户表册设置:选择分配
+     */
+    @PostMapping("/selectAllotment")
+    @ApiOperation(value = "用户表册设置:选择分配")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mrBook", value = "抄表本", dataType = "String"),
+            @ApiImplicitParam(name = "customerNos", value = "用户编号集", dataType = "String")
+    })
+    public ResultRespone selectAllotment(String mrBook, String customerNos) throws Exception {
+        if (StringUtils.isBlank(mrBook)) {
+            return ResultRespone.failed("抄表本编码不能为空!");
+        }
+        if (StringUtils.isBlank(customerNos)) {
+            return ResultRespone.failed("用户编号集不能为空!");
+        }
+        String strWhere = MessageFormat.format("and customer_no in ({0})", customerNos);
+        return getAllotmentResult(mrBook, strWhere, false);
+    }
+
+    /**
+     * 用户表册设置:全部分配
+     */
+    @PostMapping("/allAllotment")
+    @ApiOperation(value = "用户表册设置:全部分配")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mrArea", value = "抄表片区", dataType = "String"),
+            @ApiImplicitParam(name = "mrBook", value = "抄表本", dataType = "String")
+    })
+    public ResultRespone allAllotment(String mrArea, String mrBook) throws Exception {
+        if (StringUtils.isBlank(mrBook)) {
+            return ResultRespone.failed("抄表本编码不能为空!");
+        }
+        if (StringUtils.isBlank(mrArea)) {
+            mrArea = "";
+        } else {
+            mrArea = MessageFormat.format("and mr_area='{0}'", mrArea);
+        }
+        return getAllotmentResult(mrBook, mrArea, true);
+    }
+
+    /**
+     * 获取分配的处理过程返回
+     *
+     * @param mrBook   抄表本值
+     * @param strWhere 条件语句
+     * @param isAll    是否全部操作
+     * @return
+     * @throws Exception
+     */
+    private ResultRespone<Boolean> getAllotmentResult(String mrBook, String strWhere, Boolean isAll) throws Exception {
+        DbHelper dbHelper = DbHelper.getDbHelper();
+        String strMrArea = dbHelper.getValue("select mr_area from tf_ywys_bm_mr_book where code='" + mrBook + "'");
+        List<HashMap<String, Object>> listUser = dbHelper.getList("select customer_no from tf_ywys_da_customer where mr_book is null " + strWhere + " order by customer_no");
+
+        //自动选择分配序号
+        int intMaxSort = Integer.parseInt(dbHelper.getValue("select NVL(Max(a.mr_order_no),0) mxh from  tf_ywys_da_meter a  left join tf_ywys_da_customer b on a.customer_no=b.customer_no  where b.mr_book='" + mrBook + "'"));
+        for (int i = 0, len = listUser.size(); i < len; i++) {
+            intMaxSort += 1;
+            String strCusNo = listUser.get(i).get("customer_no").toString();
+            dbHelper.addTransactionSql(MessageFormat.format("update tf_ywys_da_meter set mr_order_no={0} where customer_no='{1}'", intMaxSort, strCusNo));
+            dbHelper.addTransactionSql(MessageFormat.format("update tf_ywys_bw_meter_read_plan set mr_order_no={0} where customer_no='{1}'", intMaxSort, strCusNo));
+        }
+
+        //更新抄表片区、抄表本值
+        String strSql = MessageFormat.format("update #table set mr_area='{0}', mr_book='{1}' where mr_book is null {2}", strMrArea, mrBook, strWhere);
+        dbHelper.addTransactionSql(strSql.replace("#table", "tf_ywys_da_customer"));
+        dbHelper.addTransactionSql(strSql.replace("#table", "tf_ywys_bw_meter_read_plan"));
+
+        String strTopMsg = isAll ? "全部" : "";
+        if (dbHelper.executeTransaction()) {
+            return ResultRespone.success(true, strTopMsg + "分配成功!");
+        } else {
+            return ResultRespone.failed(false, strTopMsg + "分配失败!");
+        }
+    }
+
+    //endregion
+
+    //region 表册撤销分配操作
+
+    /**
+     * 用户表册设置:选择撤销
+     */
+    @PostMapping("/selectCancel")
+    @ApiOperation(value = "用户表册设置:选择撤销")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mrArea", value = "抄表片区", dataType = "String"),
+            @ApiImplicitParam(name = "customerNos", value = "用户编号集", dataType = "String")
+    })
+    public ResultRespone selectCancel(String mrArea, String customerNos) throws Exception {
+        if (StringUtils.isBlank(customerNos)) {
+            return ResultRespone.failed("用户编号集不能为空!");
+        }
+        mrArea = StringUtils.isBlank(mrArea) ? "null" : "'" + mrArea + "'";
+        DbHelper dbHelper = DbHelper.getDbHelper();
+        dbHelper.addTransactionSql("update tf_ywys_da_meter set mr_order_no=0 where customer_no in(" + customerNos + ")");
+        dbHelper.addTransactionSql("update tf_ywys_da_customer set mr_area=" + mrArea + ", mr_book=null where customer_no in(" + customerNos + ")");
+        dbHelper.addTransactionSql("update tf_ywys_bw_meter_read_plan set mr_area=" + mrArea + ",mr_book=null,mr_order_no=0 where customer_no in(" + customerNos + ")");
+
+        if (dbHelper.executeTransaction()) {
+            return ResultRespone.success(true, "撤销成功!");
+        } else {
+            return ResultRespone.failed(false, "撤销失败!");
+        }
+    }
+
+    /**
+     * 用户表册设置:全部撤销
+     */
+    @PostMapping("/AllCancel")
+    @ApiOperation(value = "用户表册设置:全部撤销")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mrArea", value = "抄表片区", dataType = "String"),
+            @ApiImplicitParam(name = "mrBook", value = "抄表本", dataType = "String")
+    })
+    public ResultRespone allCancel(String mrArea, String mrBook) throws Exception {
+        if (StringUtils.isBlank(mrBook)) {
+            return ResultRespone.failed("抄表本不能为空!");
+        }
+        mrArea = StringUtils.isBlank(mrArea) ? "null" : "'" + mrArea + "'";
+
+        DbHelper dbHelper = DbHelper.getDbHelper();
+        dbHelper.addTransactionSql("update tf_ywys_da_meter set mr_order_no=0 where customer_no in(select customer_no from tf_ywys_da_customer where mr_book='" + mrBook + "')");
+        dbHelper.addTransactionSql("update tf_ywys_da_customer set mr_area=" + mrArea + ", mr_book=null where mr_book='" + mrBook + "'");
+        dbHelper.addTransactionSql("update tf_ywys_bw_meter_read_plan set mr_area=" + mrArea + ",mr_book=null,mr_order_no=0 where mr_book='" + mrBook + "'");
+
+        if (dbHelper.executeTransaction()) {
+            return ResultRespone.success(true, "全部撤销成功!");
+        } else {
+            return ResultRespone.failed(false, "全部撤销失败!");
+        }
+    }
+
+    //endregion
+
+}

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

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.tofly.fees.meterreadingmgt.entity.BwMeterReadPlan;
 import org.apache.ibatis.annotations.MapKey;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.ArrayList;
@@ -48,7 +49,7 @@ public interface BwMeterReadPlanMapper extends BaseMapper<BwMeterReadPlan> {
      * @param page          分页对象
      * @param companyBranch 公司编码值
      * @param mrBooks       抄表本集合
-     * @param searchText    关键字(用户姓名、地址、用户编号
+     * @param searchText    关键字(用户编号、用户姓名、地址)
      * @return
      */
     @MapKey("meter_card_id")
@@ -63,6 +64,20 @@ public interface BwMeterReadPlanMapper extends BaseMapper<BwMeterReadPlan> {
     @MapKey("meter_card_id")
     List<HashMap<String, Object>> getMeterCardIds(String mrBooks);
 
+    /**
+     * 抄表册批量设置:公用数据的用户列表
+     *
+     * @param page          分页对象
+     * @param companyBranch 公司编码值
+     * @param mrArea        抄表片区值
+     * @param mrBook       抄表本集合
+     * @param searchText    关键字(用户姓名、地址、用户编号)
+     * @param strType       操作类型
+     * @return
+     */
+    @MapKey("customer_no")
+    Page<Map<String, Object>> getMrBookUserList(Page page, String companyBranch, String mrArea, String mrBook, String searchText, String strType);
+
     int delByNo(String no);
 
     /**

+ 32 - 1
collect-fees/collect-fees-service/src/main/resources/mapper/meterreadingmgt/BwMeterReadPlanMapper.xml

@@ -82,12 +82,43 @@
     </select>
     <!--通过抄表本集合查询已抄表待算费的抄表卡ID集-->
     <select id="getMeterCardIds" resultType="java.util.HashMap">
-        select meter_card_id from tf_ywys_bw_meter_read_plan where cal_state='1' and mr_flag='1' and audit_flag='1' and cal_flag='0'
+        select meter_card_id from tf_ywys_bw_meter_read_plan where cal_state='1' and mr_flag='1' and audit_flag='1' and
+        cal_flag='0'
         <!--抄表本集合-->
         <if test="mrBooks!=null and mrBooks!=''">
             and mr_book in(${mrBooks})
         </if>
     </select>
+
+    <!--抄表册批量设置:公用数据的用户列表-->
+    <select id="getMrBookUserList" resultType="java.util.Map">
+        select customer_no,customer_name,customer_address from tf_ywys_da_customer
+        <where>
+            mr_book is
+            <if test="strType!=null and strType!=''">
+                ${strType}
+            </if>
+            null and customer_state in('0','1')
+        </where>
+        <!--所属公司-->
+        <if test="companyBranch!=null and companyBranch!=''">
+            and company_branch=#{companyBranch}
+        </if>
+        <!--所属片区-->
+        <if test="mrArea!=null and mrArea!=''">
+            and mr_area=#{mrArea}
+        </if>
+        <!--所属表册-->
+        <if test="mrBook!=null and mrBook!=''">
+            and mr_book=#{mrBook}
+        </if>
+        <!--关键字-->
+        <if test="searchText != null and searchText != ''">
+            AND (customer_no like '%${searchText}%' or customer_name like '%${searchText}%' or customer_address
+            like '%${searchText}%')
+        </if>
+    </select>
+
     <delete id="delByNo">
         delete
         from Tf_Ywys_Da_Customer