Explorar o código

Merge remote-tracking branch 'origin/20200908' into 20200908

pengdi@zoniot.com %!s(int64=4) %!d(string=hai) anos
pai
achega
01e4b9e53e

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java

@@ -126,7 +126,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                 .and().authorizeRequests()
                 .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
-                .anyRequest().authenticated()
+                //.anyRequest().authenticated()
                 .and()
                 .formLogin()
                 .successHandler(authenticationSuccessHandler)//登陆成功处理

+ 46 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/PlatformApiController.java

@@ -0,0 +1,46 @@
+package com.bz.smart_city.controller;
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.dto.TodayDynamicDto;
+import com.bz.smart_city.service.PlatformAapiService;
+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.web.bind.annotation.*;
+
+@RestController
+@ResponseBody
+@RequestMapping("/platform")
+@Api(tags = "计费接口")
+public class PlatformApiController {
+    @Autowired
+    private PlatformAapiService platformAapiService;
+    @PostMapping ("/updateMeterNo")
+    @ApiOperation(value = "同步档案号")
+    public AjaxMessage updateMeterNo(
+            @ApiParam(value = "客户id", required = true) @RequestParam String customerNo,
+            @RequestParam String meterNo, @RequestParam String meterCode) {
+        platformAapiService.updateMeterNo(meterNo,meterCode,customerNo);
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
+    @PostMapping ("/sendCommond ")
+    @ApiOperation(value = "阀门操作")
+    public AjaxMessage sendCommond (
+            @ApiParam(value = "客户id", required = true)  @RequestParam String customerNo,
+            @RequestParam String meterNo,Integer type) {
+        platformAapiService.sendCommond(meterNo,type,customerNo);
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
+    @GetMapping  ("/getWaterMeterNo")
+    @ApiOperation(value = "获取电子号")
+    public AjaxMessage getWaterMeterNo (@ApiParam(value = "客户id", required = true)  @RequestParam String customerNo,
+                                        @RequestParam  String meterNo) {
+        String waterMeterElectronicNumber=platformAapiService.getWaterMeterNo(meterNo,customerNo);
+        System.out.println(waterMeterElectronicNumber);
+        return new AjaxMessage<>(ResultStatus.OK,waterMeterElectronicNumber);
+    }
+}

+ 3 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceMapper.java

@@ -175,5 +175,8 @@ public interface DeviceMapper {
                               @Param("customerNo") String customerNo);
 
     List<MeterSyncDto> meterSync(@Param("createDate") String createDate, @Param("customerId") Integer customerId, @Param("fileNo") List<String> fileNo);
+
+    void updateMeterNo(@Param("meterNo") String meterNo, @Param("meterCode") String meterCode,
+                       @Param("customerId")int customerId);
 }
 

+ 82 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/OperatingValveRecordMapper.java

@@ -0,0 +1,82 @@
+package com.bz.smart_city.dao;
+
+import com.bz.smart_city.entity.OperatingValveRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * (OperatingValveRecord)表数据库访问层
+ *
+ * @author hym
+ * @since 2021-01-14 16:04:56
+ */
+@Mapper
+public interface OperatingValveRecordMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    OperatingValveRecord selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<OperatingValveRecord> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param operatingValveRecord 实例对象
+     * @return 对象列表
+     */
+    List<OperatingValveRecord> selectList(OperatingValveRecord operatingValveRecord);
+
+    /**
+     * 新增数据
+     *
+     * @param operatingValveRecord 实例对象
+     * @return 影响行数
+     */
+    int insert(OperatingValveRecord operatingValveRecord);
+
+    /**
+     * 批量新增
+     *
+     * @param operatingValveRecords 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("operatingValveRecords") List<OperatingValveRecord> operatingValveRecords);
+
+    /**
+     * 修改数据
+     *
+     * @param operatingValveRecord 实例对象
+     * @return 影响行数
+     */
+    int update(OperatingValveRecord operatingValveRecord);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+    void updateStatus(OperatingValveRecord operatingValveRecordMessage);
+}

+ 5 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/ValveControlDataDto.java

@@ -11,4 +11,9 @@ public class ValveControlDataDto {
 
     @ApiModelProperty("阀门操作,0 关,1 开 2 无阀")
     private String valve;
+    @ApiModelProperty(value = "active")
+    private String active;
+    @ApiModelProperty(value = "客户id")
+    private Integer customerId;
+
 }

+ 52 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/OperatingValveRecord.java

@@ -0,0 +1,52 @@
+package com.bz.smart_city.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * (OperatingValveRecord)实体类
+ *
+ * @author hym
+ * @since 2021-01-14 16:41:13
+ */
+@Data
+@ApiModel
+public class OperatingValveRecord implements Serializable {
+    private static final long serialVersionUID = -76860967376729669L;
+    @ApiModelProperty(value = "")
+    private Integer id;
+    /**
+     * 档案号
+     */
+    @ApiModelProperty(value = "档案号")
+    private String waterFileNo;
+    /**
+     * 电子号
+     */
+    @ApiModelProperty(value = "电子号")
+    private String waterNo;
+    @ApiModelProperty(value = "")
+    private Date createDate;
+    @ApiModelProperty(value = "")
+    private Date updateDate;
+    @ApiModelProperty(value = "")
+    private String createBy;
+    @ApiModelProperty(value = "")
+    private String updateBy;
+    @ApiModelProperty(value = "")
+    private Integer status;
+    /**
+     * 客户id
+     */
+    @ApiModelProperty(value = "客户id")
+    private Integer customerId;
+    /**
+     * 阀门操作
+     */
+    @ApiModelProperty(value = "阀门操作")
+    private Integer operation;
+}

+ 55 - 0
smart-city-platform/src/main/java/com/bz/smart_city/kafka/consumer/ValveStatusReceiver.java

@@ -0,0 +1,55 @@
+package com.bz.smart_city.kafka.consumer;
+
+import com.bz.smart_city.commom.util.MessageSend.JSONUtils;
+import com.bz.smart_city.dao.OperatingValveRecordMapper;
+import com.bz.smart_city.dto.ValveControlDataDto;
+import com.bz.smart_city.entity.OperatingValveRecord;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class ValveStatusReceiver {
+    @Autowired
+    private OperatingValveRecordMapper operatingValveRecordMapper;
+    @Value("${billing.valveStatus.receiving}")
+    private String billingValveStatusReceiving;
+    @Autowired
+    KafkaTemplate<String, Object> kafkaTemplate;
+    @KafkaListener(topics = {"${com.zcxk.kafka.card.topic}"})
+    public void pushValveStatusMessage(String message) {
+        OperatingValveRecord operatingValveRecord=new OperatingValveRecord();
+        operatingValveRecord.setStatus(1);
+        List<OperatingValveRecord> operatingValveRecords = operatingValveRecordMapper.selectList(operatingValveRecord);
+        OperatingValveRecord operatingValveRecordMessage=null;
+        if(operatingValveRecords.size()>0){
+            ValveControlDataDto valveControlDataDto = JSONUtils.json2pojo(message, ValveControlDataDto.class);
+            boolean flag=false;
+            for (OperatingValveRecord valveRecord : operatingValveRecords) {
+                if(valveRecord.getWaterNo().equals(valveControlDataDto.getMeterNo())
+                        &&valveRecord.getCustomerId().equals(valveControlDataDto.getCustomerId())){
+                    flag=true;
+                    operatingValveRecordMessage=valveRecord;
+                    valveRecord.setOperation(Integer.parseInt(valveControlDataDto.getValve()));
+                    break;
+                }
+            }
+            if(flag){
+                Map<String,Object>valveMessage=new HashMap<>();
+                valveMessage.put("meterNo",operatingValveRecordMessage.getWaterFileNo());
+                valveMessage.put("meterStatus",operatingValveRecordMessage.getOperation());
+                kafkaTemplate.send(billingValveStatusReceiving, JSONUtils.obj2json(valveMessage));
+                operatingValveRecordMapper.updateStatus(operatingValveRecordMessage);
+            }
+        }
+    }
+}

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/PlatformAapiService.java

@@ -0,0 +1,9 @@
+package com.bz.smart_city.service;
+
+public interface PlatformAapiService {
+    void updateMeterNo(String meterNo, String meterCode, String customerNo);
+
+    void sendCommond(String meterNo, Integer type, String customerNo);
+
+    String getWaterMeterNo(String meterNo, String customerNo);
+}

+ 83 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/sync/PlatformAapiServiceImpl.java

@@ -0,0 +1,83 @@
+package com.bz.smart_city.service.sync;
+
+import com.bz.smart_city.dao.CustomerMapper;
+import com.bz.smart_city.dao.DeviceMapper;
+import com.bz.smart_city.dao.OperatingValveRecordMapper;
+import com.bz.smart_city.entity.Customer;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.OperatingValveRecord;
+import com.bz.smart_city.service.DeviceService;
+import com.bz.smart_city.service.PlatformAapiService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class PlatformAapiServiceImpl implements PlatformAapiService {
+    @Autowired
+    private DeviceMapper deviceMapper;
+    @Autowired
+    private CustomerMapper customerMapper;
+    @Autowired
+    private DeviceService deviceService;
+    @Autowired
+    private OperatingValveRecordMapper operatingValveRecordMapper;
+    @Override
+    public void updateMeterNo(String meterNo, String meterCode, String customerNo) {
+        Customer customer = customerMapper.findBySiteIdAndCustomerNo(null, customerNo);
+        if(customer!=null){
+           deviceMapper.updateMeterNo(meterNo,meterCode,customer.getId());
+        }
+
+    }
+
+    @Override
+    public void sendCommond(String meterNo, Integer type, String customerNo) {
+
+
+            Device device = getDevice(meterNo, customerNo);
+            if(device!=null){
+                deviceService.setValveV2(device.getId(),type+"");
+                OperatingValveRecord operatingValveRecord=new OperatingValveRecord();
+                operatingValveRecord.setCreateBy("system");
+                operatingValveRecord.setCreateDate(new Date());
+                operatingValveRecord.setCustomerId(device.getCustomerId());
+                operatingValveRecord.setStatus(1);
+                operatingValveRecord.setWaterFileNo(device.getWaterMeterFileNo());
+                operatingValveRecord.setWaterNo(device.getWaterMeterNo());
+                operatingValveRecord.setOperation(type);
+                operatingValveRecordMapper.insert(operatingValveRecord);
+
+            }
+
+
+
+    }
+
+
+
+    @Override
+    public String getWaterMeterNo(String meterNo, String customerNo) {
+        Device device = getDevice(meterNo, customerNo);
+        if(device!=null){
+            return device.getWaterMeterNo();
+        }
+        return null;
+    }
+    private Device getDevice(String meterNo, String customerNo){
+        Device device=null;
+        List<String>fileNo=new ArrayList<>();
+        fileNo.add(meterNo);
+        List<Device> devices = deviceMapper.findByFileNo(fileNo, customerNo);
+        if(devices.size()>0){
+           device=devices.get(0);
+        }
+        return device;
+    }
+
+
+}

+ 2 - 0
smart-city-platform/src/main/resources/application-dev.properties

@@ -131,6 +131,8 @@ com.zcxk.kafka.alarm.topic=sc_alarm_topic_dev
 com.zcxk.kafka.card.topic=sc_card_topic_dev
 com.zcxk.kafka.accept_add_account.topic=sc_accept_add_account_topic_dev
 com.zcxk.kafka.accept_meter_replace.topic=sc_accept_meter_replace_topic_dev
+com.zcxk.kafka.valve.status.topic=sc_valve_status_billing
+billing.valveStatus.receiving=billing_valveStatus_receiving
 #\u9AD8\u5FB7\u5730\u56FE
 geomap.apikey=bb218fd3700b37dd1e02872365cab4d5
 geomap.api.url=https://restapi.amap.com/v3/geocode/geo

+ 2 - 0
smart-city-platform/src/main/resources/application-sit.properties

@@ -128,6 +128,8 @@ com.zcxk.kafka.alarm.topic=sc_alarm_topic_sit
 com.zcxk.kafka.card.topic=sc_card_topic_sit
 com.zcxk.kafka.accept_add_account.topic=sc_accept_add_account_topic_sit
 com.zcxk.kafka.accept_meter_replace.topic=sc_accept_meter_replace_topic_sit
+com.zcxk.kafka.valve.status.topic=sc_valve_status_billing
+billing.valveStatus.receiving=billing_valveStatus_receiving
 #kafka producer config
 spring.kafka.producer.retries=0
 spring.kafka.producer.batch-size=4096

+ 5 - 1
smart-city-platform/src/main/resources/mapper/DeviceMapper.xml

@@ -1181,7 +1181,7 @@
         </if>
     </select>
     <select id="findByFileNo"  resultType="com.bz.smart_city.entity.Device">
-        select b.water_meter_file_no ,b.id from sc_customer a left join  sc_device b on a.id=b.customer_id
+        select b.water_meter_file_no ,b.water_meter_no,b.id ,b.customer_id from sc_customer a left join  sc_device b on a.id=b.customer_id
         where
         a.customer_no=#{customerNo}
         and b.water_meter_file_no in
@@ -1211,5 +1211,9 @@
         <if test="createDate != null and createDate != ''"> and DATE_FORMAT(sd.date_create, '%Y%m%d' ) = #{createDate}</if>
         and sd.water_meter_file_no in <foreach collection="fileNo" item="item" open="(" separator="," close=")">#{item}</foreach>
     </select>
+    <update id="updateMeterNo">
+        update sc_device set water_meter_file_no=#{meterCode}
+        where water_meter_file_no=#{meterNo} and customer_id=#{customerId}
+    </update>
 </mapper>
 

+ 149 - 0
smart-city-platform/src/main/resources/mapper/OperatingValveRecordMapper.xml

@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.OperatingValveRecordMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.bz.smart_city.entity.OperatingValveRecord" id="OperatingValveRecordMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="waterFileNo" column="water_file_no" jdbcType="VARCHAR"/>
+        <result property="waterNo" column="water_no" jdbcType="VARCHAR"/>
+        <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
+        <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
+        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="customerId" column="customer_id" jdbcType="INTEGER"/>
+        <result property="operation" column="operation" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, water_file_no, water_no, create_date, update_date, create_by, update_by, status, customer_id, operation    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="OperatingValveRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_operating_valve_record
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="OperatingValveRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_operating_valve_record
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="OperatingValveRecordMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_operating_valve_record
+        <where>
+             status=1
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="waterFileNo != null and waterFileNo != ''">
+                and water_file_no = #{waterFileNo}
+            </if>
+            <if test="waterNo != null and waterNo != ''">
+                and water_no = #{waterNo}
+            </if>
+            <if test="createDate != null">
+                and create_date = #{createDate}
+            </if>
+            <if test="updateDate != null">
+                and update_date = #{updateDate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and create_by = #{createBy}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and update_by = #{updateBy}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="customerId != null">
+                and customer_id = #{customerId}
+            </if>
+            <if test="operation != null">
+                and operation = #{operation}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into sc_operating_valve_record(id, water_file_no, water_no, create_date, update_date, create_by,
+                                              update_by, status, customer_id, operation)
+        values (#{id}, #{waterFileNo}, #{waterNo}, #{createDate}, #{updateDate}, #{createBy}, #{updateBy}, #{status},
+                #{customerId}, #{operation})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into sc_operating_valve_record(id, water_file_no, water_no, create_date, update_date, create_by,
+        update_by, status, customer_id, operation)
+        values
+        <foreach collection="operatingValveRecords" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.waterFileNo}, #{item.waterNo}, #{item.createDate}, #{item.updateDate}, #{item.createBy},
+            #{item.updateBy}, #{item.status}, #{item.customerId}, #{item.operation} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update sc_operating_valve_record
+        <set>
+            <if test="waterFileNo != null and waterFileNo != ''">
+                water_file_no = #{waterFileNo},
+            </if>
+            <if test="waterNo != null and waterNo != ''">
+                water_no = #{waterNo},
+            </if>
+            <if test="createDate != null">
+                create_date = #{createDate},
+            </if>
+            <if test="updateDate != null">
+                update_date = #{updateDate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                create_by = #{createBy},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                update_by = #{updateBy},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="customerId != null">
+                customer_id = #{customerId},
+            </if>
+            <if test="operation != null">
+                operation = #{operation},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from sc_operating_valve_record
+        where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from sc_operating_valve_record
+    </select>
+    <update id="updateStatus">
+        update sc_operating_valve_record set status=0,update_date=now() where water_file_no=#{waterFileNo}
+        and customer_id=#{customerId}
+    </update>
+</mapper>