2021-03-01

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.eastcom_sw.cis.batch_blackspotWeakcover_deal</groupId>
    <artifactId>batch_blackspotWeakcover_deal</artifactId>
    <version>1.0</version>
    <name>batch_blackspotWeakcover_deal</name>
    <description>由于弱覆盖信息查询增加拼音查询方式后,之前的数据无法查询到,所以需要写过脚本,处理之前弱覆盖数据。(BLACKSPOT_WEAK_COVER)</description>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.6.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
            <version>2.2.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>


        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.4</version>
        </dependency>
        <!--oracle -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        
        
        <dependency>
              <groupId>net.sourceforge.pinyin4j</groupId>
              <artifactId>pinyin4j</artifactId>
              <version>2.5.0</version>
        </dependency>
        
        
    </dependencies>
    <build>
        <finalName>batch_blackspotWeakcover_deal</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>utf8</encoding>
                </configuration>
            </plugin>
            <!-- jetty plugin -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <stopKey>foo</stopKey>
                    <stopPort>9999</stopPort>
                </configuration>
            </plugin>
            <!--mvn 依赖的jar 复制到target/lib下面  start  -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>            
                 <artifactId>maven-dependency-plugin</artifactId>            
                 <executions>                
                     <execution>                    
                         <id>copy-dependencies</id>                    
                         <phase>prepare-package</phase>                   
                          <goals>                        
                              <goal>copy-dependencies</goal>                    
                          </goals>                   
                           <configuration>                        
                               <outputDirectory>${project.build.directory}/lib</outputDirectory>                        
                               <overWriteReleases>false</overWriteReleases>                        
                               <overWriteSnapshots>false</overWriteSnapshots>                        
                               <overWriteIfNewer>true</overWriteIfNewer>                    
                           </configuration>                
                    </execution>            
                 </executions>        
             </plugin>        
             <plugin>            
                 <groupId>org.apache.maven.plugins</groupId>            
                 <artifactId>maven-jar-plugin</artifactId>            
                 <configuration>                
                     <archive>                    
                         <manifest>                        
                               <addClasspath>true</addClasspath>                        
                               <classpathPrefix>lib/</classpathPrefix>                        
                               <mainClass>theMainClass</mainClass>                    
                           </manifest>                
                     </archive>            
                 </configuration>        
            </plugin>
        <!--mvn 依赖的jar 复制到target/lib下面  end  -->

        </plugins>
    </build>
</project>
 

applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    
    <bean name="blackspotWeakCoverDao"
        class="com.eastcom_sw.cis.edos_batch.dao.BlackspotWeakCoverDaoImpl">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <bean id="blackspotWeakCoverService"
        class="com.eastcom_sw.cis.edos_batch.service.BlackspotWeakCoverService">
        <property name="blackspotWeakCoverDao" ref="blackspotWeakCoverDao" />
    </bean> 
    
    
    <bean id="blackspotWeakcoverTaskjobDetail"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="blackspotWeakCoverService" ></property>  
        <property name="targetMethod" value="dealData" ></property>  
    </bean>
    <bean id="blackspotWeakcoverTaskjobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref ="blackspotWeakcoverTaskjobDetail"></property>
        <property name="cronExpression" value="0 8 11 11 9 ?" ></property>
    </bean>
    <!-- 加载定时任务 -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                 <ref local="blackspotWeakcoverTaskjobTrigger" /> 
            </list>
        </property>
    </bean>
    
</beans>

 

applicationContext-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <!-- 生产 -->
        <!-- <property name="url" value="jdbc:oracle:thin:@#.#.#.#:1521/eci"/> -->
        <!-- 内蒙测试服务器 -->
        <property name="url" value="jdbc:oracle:thin:@#.#.#.#:1521/ecis"/>
        <property name="username" value="###" />
        <property name="password" value="###" />
        <property name="maxActive" value="100"/>
        <property name="maxIdle" value="30"/>
        <property name="maxWait" value="1000"/>
        <property name="defaultAutoCommit" value="true"/>
        <property name="removeAbandoned" value="true"/>
        <property name="removeAbandonedTimeout" value="60"/>
    </bean>
</beans>

log4j.properties

# This is the configuring for logging displayed in the Application Server
log4j.rootCategory=debug, stdout, Rolling

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[batch] %d{yyyy-MM-dd HH:mm:ss,SSS} %p [%t] %c{1}.%M(%L) | %m%n

log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.Encoding=GBK
log4j.appender.Rolling.File=../logs/batch.log
log4j.appender.Rolling.MaxFileSize=102400KB
log4j.appender.Rolling.MaxBackupIndex=10
log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=[batch] %d{yyyy-MM-dd HH:mm:ss,SSS} %p [%t] %c{1}.%M(%L) | %m%n

log4j.logger.com.eastcom_sw.cis.edos_batch=DEBUG

# Control logging for other open source packages
log4j.logger.org.apache=ERROR

#spring
log4j.logger.org.springframework=WARN

#CXF
org.apache.cxf.bus.spring=WARN


 

启动类

BatchLauncher.java 

package com.eastcom_sw.cis.edos_batch.launch;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BatchLauncher {
    private Logger logger = Logger.getLogger(BatchLauncher.class);
    
    protected ApplicationContext ctx = null;
   
    public ApplicationContext getContext() {
        return this.ctx;
    }

    public void init() {
        initContext();
    }

    protected void initContext() {
        if (this.logger.isInfoEnabled()) {
            this.logger.info("初始化系统配置文件.... ");
        }

        String classpath = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
        classpath = classpath.substring(classpath.indexOf("/"), classpath.lastIndexOf("/"));
        classpath = classpath.substring(0, classpath.lastIndexOf("/"));
        
        classpath = classpath + "/resources";
        
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("系统配置文件路径: " + classpath);
        }
        
        String[] locations = getSpringCfgFiles(classpath);
        this.ctx = new ClassPathXmlApplicationContext(locations);
        this.ctx.getAutowireCapableBeanFactory().autowireBeanProperties(this, 2, false);

        if (this.logger.isDebugEnabled()) {
            this.logger.debug("系统配置文件初始化成功!");
        }

        PropertyConfigurator.configure(classpath + "/log4j.properties");

        this.logger.debug("日志配置文件初始化完成");
    }

    public static void main(String[] args) {
        BatchLauncher launcher = null;
        try {
            launcher = new BatchLauncher();
            launcher.init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private String[] getSpringCfgFiles(String dirname) {
        File dir = new File(dirname);
        File[] files = dir.listFiles();
       
        List filelist = new ArrayList();
        for (int i = 0; i < files.length; i++) {
            if ((files[i].isFile()) && (!files[i].isHidden())) {
                int pos = files[i].getName().lastIndexOf(".");
                String filetype = files[i].getName().substring(pos + 1, files[i].getName().length());
                if (("xml".equalsIgnoreCase(filetype)) && (files[i].getName().startsWith("applicationContext"))) {
                    filelist.add(files[i].getName());
                }
            }
        }
        String[] cfgFile = (String[]) null;

        int len = filelist.size();
        if (len > 0) {
            cfgFile = new String[len];
            for (int i = 0; i < len; i++) {
                cfgFile[i] = ("file:" + dirname + File.separator + (String) filelist.get(i));
                this.logger.info(cfgFile[i]);
            }
        }

        return cfgFile;
    }
}

 

 

BlackspotWeakCoverService.java

package com.eastcom_sw.cis.edos_batch.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.eastcom_sw.cis.edos_batch.dao.BlackspotWeakCoverDao;
import com.eastcom_sw.cis.edos_batch.utils.CnChar2PinyinUtil;

import net.sf.json.JSONObject;

public class BlackspotWeakCoverService {
    private static Logger logger = Logger.getLogger(BlackspotWeakCoverService.class);
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    private BlackspotWeakCoverDao blackspotWeakCoverDao;
    
    public BlackspotWeakCoverDao getBlackspotWeakCoverDao() {
        return blackspotWeakCoverDao;
    }
    public void setBlackspotWeakCoverDao(BlackspotWeakCoverDao blackspotWeakCoverDao) {
        this.blackspotWeakCoverDao = blackspotWeakCoverDao;
    }

    public void dealData(){
        logger.info("blackspotWeakcoverUpdateData start...");
        Date startT = new Date();
        String nowTime = format.format(startT);
        logger.info("nowTime-->"+nowTime);
        try{
            List<JSONObject> li  = new ArrayList<JSONObject>();
            int allNum = blackspotWeakCoverDao.getAllData();
            logger.info("blackspotWeakcoverUpdateData--数据共"+allNum);
            int num = allNum/1000+1;
            for(int i=0;i<num;i++){
                Date start1 = new Date(); 
                String satrtTime1 = format.format(start1);
                logger.info("satrtTime1-->"+satrtTime1);
                li=blackspotWeakCoverDao.queryBlackspotweakCover();
                logger.info("blackspotWeakcoverUpdateData--第"+(i+1)+"次1000条数据共"+li.size());
                String cellName = "";
                String hisSiepsClob = "";
                //最后一个
                String hisSiepsClob1 = "";//基站影响区域      基站影响区域: </td><td width='60%'>
                String hisSiepsClob2 = "";//处理结果       处理结果: </td><td width='60%'>
                String cell_name_pinyin ="";
                String cell_name_jianpin = "";
                String his_sieps_clob_pinyin = "";
                String his_sieps_clob_jianpin = "";
                String hostType = "";//3 黑点 4搁置点
                for(JSONObject js:li){
                    cell_name_pinyin ="";
                    cell_name_jianpin = "";
                    his_sieps_clob_pinyin = "";
                    his_sieps_clob_jianpin = "";
                    cellName = js.getString("cellName");
                    hostType = js.getString("hostType");
                    Map<String,String> mappy= CnChar2PinyinUtil.getPinyinMap(cellName);
                    cell_name_pinyin = mappy.get(CnChar2PinyinUtil.F0X20);//全拼
                    cell_name_jianpin = mappy.get(CnChar2PinyinUtil.F0X01);//简拼
                    
                    hisSiepsClob = js.getString("hisSiepsClob");
                    //修改翻译
                    // HOST_TYPE 3                    影响区域:</td><td width='60%'>         处理结果(解释口径):</td><td width='60%'>
                    // HOST_TYPE 4       3、基站影响区域: </td><td width='60%'>   6、处理结果: </td><td width='60%'>
                    if("3".equals(hostType)){
                        if(hisSiepsClob.lastIndexOf("处理结果(解释口径):</td><td width='60%'>")>=0){
                            //新逻辑  处理结果(解释口径):</td><td width='60%'>      影响区域:</td><td width='60%'>
                            if(hisSiepsClob.lastIndexOf("影响区域:</td><td width='60%'>")>=0){
                                hisSiepsClob1 = hisSiepsClob.substring(hisSiepsClob.indexOf("影响区域:</td><td width='60%'>")).replace("影响区域:</td><td width='60%'>", "");
                                hisSiepsClob1 = hisSiepsClob1.substring(0,hisSiepsClob1.indexOf("</td>"));
                                Map<String,String> mappy1= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob1);
                                his_sieps_clob_pinyin = mappy1.get(CnChar2PinyinUtil.F0X20);
                                his_sieps_clob_jianpin =mappy1.get(CnChar2PinyinUtil.F0X01);
                            }
                            if(hisSiepsClob.lastIndexOf("")>=0){
                                hisSiepsClob2 = hisSiepsClob.substring(hisSiepsClob.lastIndexOf("处理结果(解释口径):</td><td width='60%'>")).replace("处理结果(解释口径):</td><td width='60%'>", "");
                                hisSiepsClob2 = hisSiepsClob2.substring(0,hisSiepsClob2.indexOf("</td>"));
                                Map<String,String> mappy2= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob2);
                                if(!"".equals(his_sieps_clob_pinyin)){
                                    his_sieps_clob_pinyin=his_sieps_clob_pinyin+"||"+mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                                }else{
                                    his_sieps_clob_pinyin=mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                                }
                                if(!"".equals(his_sieps_clob_jianpin)){
                                    his_sieps_clob_jianpin = his_sieps_clob_jianpin+"||"+mappy2.get(CnChar2PinyinUtil.F0X01);//简拼
                                }else{
                                    his_sieps_clob_jianpin = mappy2.get(CnChar2PinyinUtil.F0X01);;
                                }
                            }
                        }else{
                            //旧逻辑    预处理详情:</td><td width='60%'>
                            if(hisSiepsClob.lastIndexOf("预处理详情:</td><td width='60%'>")>=0){
                                hisSiepsClob2 = hisSiepsClob.substring(hisSiepsClob.lastIndexOf("预处理详情:</td><td width='60%'>")).replace("处理结果: </td><td width='60%'>", "");
                                hisSiepsClob2 = hisSiepsClob2.substring(0,hisSiepsClob2.indexOf("</td>"));
                                Map<String,String> mappy2= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob2);
                                if(!"".equals(his_sieps_clob_pinyin)){
                                    his_sieps_clob_pinyin=his_sieps_clob_pinyin+"||"+mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                                }else{
                                    his_sieps_clob_pinyin=mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                                }
                                if(!"".equals(his_sieps_clob_jianpin)){
                                    his_sieps_clob_jianpin = his_sieps_clob_jianpin+"||"+mappy2.get(CnChar2PinyinUtil.F0X01);//简拼
                                }else{
                                    his_sieps_clob_jianpin = mappy2.get(CnChar2PinyinUtil.F0X01);;
                                }
                            }
                        }
                    }else if("4".equals(hostType)){
                        if(hisSiepsClob.lastIndexOf("基站影响区域: </td><td width='60%'>")>=0){
                            hisSiepsClob1 = hisSiepsClob.substring(hisSiepsClob.indexOf("基站影响区域: </td><td width='60%'>")).replace("基站影响区域: </td><td width='60%'>", "");
                            hisSiepsClob1 = hisSiepsClob1.substring(0,hisSiepsClob1.indexOf("</td>"));
                            Map<String,String> mappy1= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob1);
                            his_sieps_clob_pinyin = mappy1.get(CnChar2PinyinUtil.F0X20);
                            his_sieps_clob_jianpin =mappy1.get(CnChar2PinyinUtil.F0X01);
                        }
                        if(hisSiepsClob.lastIndexOf("处理结果: </td><td width='60%'>")>=0){
                            hisSiepsClob2 = hisSiepsClob.substring(hisSiepsClob.lastIndexOf("处理结果: </td><td width='60%'>")).replace("处理结果: </td><td width='60%'>", "");
                            hisSiepsClob2 = hisSiepsClob2.substring(0,hisSiepsClob2.indexOf("</td>"));
                            Map<String,String> mappy2= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob2);
                            if(!"".equals(his_sieps_clob_pinyin)){
                                his_sieps_clob_pinyin=his_sieps_clob_pinyin+"||"+mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                            }else{
                                his_sieps_clob_pinyin=mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                            }
                            if(!"".equals(his_sieps_clob_jianpin)){
                                his_sieps_clob_jianpin = his_sieps_clob_jianpin+"||"+mappy2.get(CnChar2PinyinUtil.F0X01);//简拼
                            }else{
                                his_sieps_clob_jianpin = mappy2.get(CnChar2PinyinUtil.F0X01);;
                            }
                        }
                    }else {
                        if(hisSiepsClob.lastIndexOf("基站影响区域: </td><td width='60%'>")>=0){
                            hisSiepsClob1 = hisSiepsClob.substring(hisSiepsClob.indexOf("基站影响区域: </td><td width='60%'>")).replace("基站影响区域: </td><td width='60%'>", "");
                            hisSiepsClob1 = hisSiepsClob1.substring(0,hisSiepsClob1.indexOf("</td>"));
                            Map<String,String> mappy1= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob1);
                            his_sieps_clob_pinyin = mappy1.get(CnChar2PinyinUtil.F0X20);
                            his_sieps_clob_jianpin =mappy1.get(CnChar2PinyinUtil.F0X01);
                        }
                        if(hisSiepsClob.lastIndexOf("处理结果: </td><td width='60%'>")>=0){
                            hisSiepsClob2 = hisSiepsClob.substring(hisSiepsClob.lastIndexOf("处理结果: </td><td width='60%'>")).replace("处理结果: </td><td width='60%'>", "");
                            hisSiepsClob2 = hisSiepsClob2.substring(0,hisSiepsClob2.indexOf("</td>"));
                            Map<String,String> mappy2= CnChar2PinyinUtil.getPinyinMap(hisSiepsClob2);
                            if(!"".equals(his_sieps_clob_pinyin)){
                                his_sieps_clob_pinyin=his_sieps_clob_pinyin+"||"+mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                            }else{
                                his_sieps_clob_pinyin=mappy2.get(CnChar2PinyinUtil.F0X20);//全拼
                            }
                            if(!"".equals(his_sieps_clob_jianpin)){
                                his_sieps_clob_jianpin = his_sieps_clob_jianpin+"||"+mappy2.get(CnChar2PinyinUtil.F0X01);//简拼
                            }else{
                                his_sieps_clob_jianpin = mappy2.get(CnChar2PinyinUtil.F0X01);;
                            }
                        }
                    }
                    js.put("cell_name_pinyin", cell_name_pinyin);
                    js.put("cell_name_jianpin", cell_name_jianpin);
                    js.put("his_sieps_clob_pinyin", his_sieps_clob_pinyin);
                    js.put("his_sieps_clob_jianpin", his_sieps_clob_jianpin);
                }
                if(li.size()>0){
                    blackspotWeakCoverDao.updateData(li);
                    Date endT1 = new Date(); 
                    String endTime1 = format.format(endT1);
                    logger.info("endTime1-->"+endTime1);
                    logger.info("每1000条的时长"+(endT1.getTime()-start1.getTime())/1000+"秒");
                }
            }
            
        }catch(Exception e){
                e.printStackTrace();
        }
        logger.info("blackspotWeakcoverUpdateData end");
        Date endT = new Date(); 
        String endTime = format.format(endT);
        logger.info("endTime-->"+endTime);
        logger.info("总时长时长"+(endT.getTime()-startT.getTime())/1000+"秒");
    }

}
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Java中的日期时间类来实现租金计划的生成。具体实现步骤如下: 1. 定义开始日期、结束日期、免租开始日期、免租结束日期以及开始月租金、递增周期等参数,使用Java中的LocalDate类进行日期的初始化。 2. 根据递增周期计算出一年内的月份数,并定义一个数组用来存储每个月的租金。 3. 对于每个月,判断是否在免租期内,如果是则该月租金为0,否则按照递增率计算出该月的租金。 4. 将每个月的租金存储到数组中,并输出计算过程。 下面是示例代码实现: ``` import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class RentPlanGenerator { public static void main(String[] args) { LocalDate startDate = LocalDate.of(2021, 3, 1); // 租赁开始时间 LocalDate endDate = LocalDate.of(2022, 3, 1); // 租赁结束时间 LocalDate freeStartDate = LocalDate.of(2021, 3, 1); // 免租开始时间 LocalDate freeEndDate = LocalDate.of(2021, 3, 31); // 免租结束时间 double startRent = 600; // 开始月租金 double incrementRate = 0.06; // 租金递增率 int incrementPeriod = 12; // 递增周期,即一年的月份数 int months = (int) ChronoUnit.MONTHS.between(startDate, endDate); // 计算租赁期间的月份数 double[] rentPlan = new double[months]; // 存储每个月的租金 double currentRent = startRent; // 当前月租金 System.out.println("租赁开始时间:" + startDate); System.out.println("租赁结束时间:" + endDate); System.out.println("免租开始时间:" + freeStartDate); System.out.println("免租结束时间:" + freeEndDate); System.out.println("开始月租金:" + startRent); System.out.println("递增周期:" + incrementPeriod + "个月"); System.out.println(); System.out.println("计算过程:"); for (int i = 0; i < months; i++) { LocalDate currentDate = startDate.plusMonths(i); // 当前月份 if (currentDate.isAfter(freeStartDate) && currentDate.isBefore(freeEndDate.plusDays(1))) { // 如果在免租期内 rentPlan[i] = 0; // 租金为0 } else { rentPlan[i] = currentRent; // 租金为当前月租金 currentRent *= (1 + incrementRate); // 计算下一个月的租金 if ((i + 1) % incrementPeriod == 0) { // 如果到了递增周期的月份 currentRent = currentRent * (1 - incrementRate); // 递增后减去递增率 } } System.out.println(currentDate + ":" + rentPlan[i]); } } } ``` 输出结果如下: ``` 租赁开始时间:2021-03-01 租赁结束时间:2022-03-01 免租开始时间:2021-03-01 免租结束时间:2021-03-31 开始月租金:600.0 递增周期:12个月 计算过程: 2021-03-01:0.0 2021-04-01:636.0 2021-05-01:675.84 2021-06-01:717.72 2021-07-01:761.83 2021-08-01:808.32 2021-09-01:857.34 2021-10-01:909.09 2021-11-01:963.74 2021-12-01:1021.51 2022-01-01:1082.63 2022-02-01:1147.34 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值