package com.dy.pipirrComCreator.p206V1; 
 | 
  
 | 
import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; 
 | 
import com.dy.common.util.ByteUtil; 
 | 
import com.dy.common.util.DateTime; 
 | 
import com.dy.common.util.NumUtil; 
 | 
  
 | 
/** 
 | 
 * @Author: liurunyu 
 | 
 * @Date: 2025/5/7 11:25 
 | 
 * @Description 
 | 
 */ 
 | 
public class P206V1CdA1 extends P206V1Cd { 
 | 
  
 | 
    public static final String ComCode = "A1" ; 
 | 
  
 | 
    public String checkParams(String ...params){ 
 | 
        if(params.length != 9){ 
 | 
            return "只有虚拟IC卡编号、剩余金额、水价、用水时长(分钟)、年、月、日、时、分九个参数" ; 
 | 
        } 
 | 
        //62090200300400001 
 | 
        if(!NumUtil.isPlusIntNumber(params[0])){ 
 | 
            return "虚拟IC卡编号必须是正整数" ; 
 | 
        } 
 | 
        if(params[0].length() != 17){ 
 | 
            return "虚拟IC卡编号必须是17位数字" ; 
 | 
        } 
 | 
        //2.10 
 | 
        if(!NumUtil.isPlusDoubleNumber(params[1])){ 
 | 
            return "剩余金额必须是正数" ; 
 | 
        } 
 | 
        Integer temp = (Double.valueOf(Double.parseDouble(params[1]) * 100.0D)).intValue() ; 
 | 
        if(temp <= 0){ 
 | 
            return "剩余金额必须是大于0的正数" ; 
 | 
        } 
 | 
        if(temp >= 99999999){ 
 | 
            return "剩余金额必须是小于999999.99的正数" ; 
 | 
        } 
 | 
        //1.23 
 | 
        if(!NumUtil.isPlusDoubleNumber(params[2])){ 
 | 
            return "水价必须是正数" ; 
 | 
        } 
 | 
        temp = (Double.valueOf(Double.parseDouble(params[2]) * 100.0D)).intValue() ; 
 | 
        if(temp <= 0){ 
 | 
            return "水价必须是大于0的正数" ; 
 | 
        } 
 | 
        if(temp >= 9999){ 
 | 
            return "水价必须是小于99.99的正数" ; 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[3])){ 
 | 
            return "用水时长必须是正整数" ; 
 | 
        } 
 | 
        temp = Integer.parseInt(params[3]) ; 
 | 
        if(temp <= 0){ 
 | 
            return "用水时长必须是大于0的正整数" ; 
 | 
        } 
 | 
        if(temp > 9999){ 
 | 
            return "用水时长必须是小于9999的正整数" ; 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[4])){ 
 | 
            return "年必须是正整数" ; 
 | 
        } 
 | 
        int year = Integer.parseInt(params[4]) ; 
 | 
        if(year < 2025){ 
 | 
            return "年必须是大于等于2025的正整数" ; 
 | 
        } 
 | 
        if(year > 9999){ 
 | 
            return "年必须是小于9999的正整数" ; 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[5])){ 
 | 
            return "月必须是正整数" ; 
 | 
        } 
 | 
        int month = Integer.parseInt(params[5]) ; 
 | 
        if(month <= 0){ 
 | 
            return "月必须是大于0的正整数" ; 
 | 
        } 
 | 
        if(month > 12){ 
 | 
            return "月必须是小于12的正整数" ; 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[6])){ 
 | 
            return "日必须是正整数" ; 
 | 
        } 
 | 
        temp = Integer.parseInt(params[6]) ; 
 | 
        if(temp <= 0){ 
 | 
            return "日必须是大于0的正整数" ; 
 | 
        } 
 | 
        if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ 
 | 
            if(temp > 31){ 
 | 
                return "日必须是小于31的正整数" ; 
 | 
            } 
 | 
        }else if(month == 4 || month == 6 || month == 9 || month == 11){ 
 | 
            if(temp > 30){ 
 | 
                return "日必须是小于30的正整数" ; 
 | 
            } 
 | 
        }else if(month == 2){ 
 | 
            if(DateTime.isLeapYear(year)){ 
 | 
                //润年 
 | 
                if(temp > 29){ 
 | 
                    return "日必须是小于29的正整数" ; 
 | 
                } 
 | 
            }else{ 
 | 
                if(temp > 28){ 
 | 
                    return "日必须是小于28的正整数" ; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[7])){ 
 | 
            return "时必须是正整数" ; 
 | 
        } 
 | 
        temp = Integer.parseInt(params[7]) ; 
 | 
        if(temp < 0){ 
 | 
            return "时必须是大于等于0的正整数" ; 
 | 
        } 
 | 
        if(temp >= 24){ 
 | 
            return "时必须是小于24的正整数" ; 
 | 
        } 
 | 
  
 | 
        if(!NumUtil.isPlusIntNumber(params[8])){ 
 | 
            return "分钟必须是正整数" ; 
 | 
        } 
 | 
        temp = Integer.parseInt(params[8]) ; 
 | 
        if(temp < 0){ 
 | 
            return "分钟必须是大于等于0的正整数" ; 
 | 
        } 
 | 
        if(temp > 59){ 
 | 
            return "分钟必须是小于等于59的正整数" ; 
 | 
        } 
 | 
        return null ; 
 | 
    } 
 | 
    public String helpInfo() { 
 | 
        return ComCode + " *...*(虚拟IC卡编号) *...*(剩余金额) *...*(水价) *...*(分钟时长) ****(年) **(月) **(日) **(时) **(分)[Enter](定时关阀式计划开阀)" ; 
 | 
    } 
 | 
    /** 
 | 
     * 构造命令数据(十六进制) 
 | 
     * @return 字符串 
 | 
     * @throws Exception 异常 
 | 
     */ 
 | 
    public String hex(String rtuAddr, String ...params) throws Exception { 
 | 
        byte[] bytes = bs(rtuAddr, params) ; 
 | 
        return ByteUtil.bytes2Hex(bytes, false) ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 构造命令数据(字节数组) 
 | 
     * @return 字节数组 
 | 
     * @throws Exception 异常 
 | 
     */ 
 | 
    public byte[] bs(String rtuAddr, String ...params) throws Exception { 
 | 
        byte[] bytes = createHead(rtuAddr, ComCode, P206V1Cd.CTRL); 
 | 
  
 | 
        byte[] bs = new byte[8] ; 
 | 
        GlCreate.createIcCardNo(params[0], bs, 0); 
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs) ; 
 | 
  
 | 
  
 | 
        bs = new byte[4] ; 
 | 
        byte index = 0 ; 
 | 
        Integer money = Double.valueOf(Double.parseDouble(params[1]) * 100.0D).intValue() ; 
 | 
        byte[] bTemp = ByteUtil.int2BCD_LE(money) ; 
 | 
        int bTempLen = bTemp.length ; 
 | 
        int count = 0 ; 
 | 
        for(int i = 0 ; i < bTempLen; i++){ 
 | 
            bs[index++] = bTemp[i] ; 
 | 
            count ++ ; 
 | 
            if(count >= 4){ 
 | 
                break ; 
 | 
            } 
 | 
        } 
 | 
        for(; count < 4; count++){ 
 | 
            bs[index++] = 0 ; 
 | 
        } 
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs) ; 
 | 
  
 | 
        bs = new byte[2] ; 
 | 
        index = 0 ; 
 | 
        Integer price = Double.valueOf(Double.parseDouble(params[2]) * 100.0D).intValue() ; 
 | 
        bTemp = ByteUtil.int2BCD_LE(price) ; 
 | 
        bTempLen = bTemp.length ; 
 | 
        count = 0 ; 
 | 
        for(int i = 0 ; i < bTempLen; i++){ 
 | 
            bs[index++] = bTemp[i] ; 
 | 
            count ++ ; 
 | 
            if(count >= 2){ 
 | 
                break ; 
 | 
            } 
 | 
        } 
 | 
        for(; count < 2; count++){ 
 | 
            bs[index++] = 0 ; 
 | 
        } 
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs) ; 
 | 
  
 | 
  
 | 
        bs = new byte[2] ; 
 | 
        index = 0 ; 
 | 
        Integer minutes = Integer.parseInt(params[3]) ; 
 | 
        bTemp = ByteUtil.int2BCD_LE(minutes) ; 
 | 
        bTempLen = bTemp.length ; 
 | 
        count = 0 ; 
 | 
        for(int i = 0 ; i < bTempLen; i++){ 
 | 
            bs[index++] = bTemp[i] ; 
 | 
            count ++ ; 
 | 
            if(count >= 2){ 
 | 
                break ; 
 | 
            } 
 | 
        } 
 | 
        for(; count < 2; count++){ 
 | 
            bs[index++] = 0 ; 
 | 
        } 
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs) ; 
 | 
  
 | 
        bs = new byte[5] ; 
 | 
        Integer year = Integer.parseInt(params[4]) ; 
 | 
        if(year >= 2024){ 
 | 
            year = year - 2000 ; 
 | 
        } 
 | 
        bs[0] = ByteUtil.int2BCD_LE(Integer.parseInt(params[8]))[0] ; 
 | 
        bs[1] = ByteUtil.int2BCD_LE(Integer.parseInt(params[7]))[0] ; 
 | 
        bs[2] = ByteUtil.int2BCD_LE(Integer.parseInt(params[6]))[0] ; 
 | 
        bs[3] = ByteUtil.int2BCD_LE(Integer.parseInt(params[5]))[0] ; 
 | 
        bs[4] = ByteUtil.int2BCD_LE(year)[0] ; 
 | 
  
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs) ;        GlCreate.createLen(bytes);//长度放字节数组中 
 | 
  
 | 
        byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 
 | 
  
 | 
        bytes = ByteUtil.bytesMerge(bytes, bsTail) ; 
 | 
  
 | 
        return bytes ; 
 | 
    } 
 | 
  
 | 
} 
 |