code-desc

1、SpringCloud-feign

@FeignClient(value = "book-auth-service", fallback = AuthFallBackService.class)
public interface AuthService {
    @GetMapping("/auth/authorities")
    ResJson> getAuthorities(@RequestParam("loginName") String loginName);

    @GetMapping("/auth/validateJwtToken")
    ResJson validateJwtToken(@RequestParam("token") String token);

    @GetMapping("/auth/getLoginName")
    ResJson getUserLoginNameByToken(@RequestParam("token") String token);

    @GetMapping("/auth/authuser")
    ResJson authUser(@RequestParam("token") String token);
}

@FeignClient(value = "book-auth-service", fallback = AuthFallBackService.class)
调用远程服务
value:为注册到Eureka中的服务名称
fallback:解决调用的服务不可用时(使用hytrix),返回自定义的值,避免出现服务熔断的情况。

AuthFallBackService.class:是当前接口的实现类,其中根据业务需要,在实现方法中定义返回值。
2、SpringBoot

@EnableTransactionManagement
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
@MapperScan("com.herokuCenter.mapper")
@EnableScheduling

public class HerokuCenterApplication {

    public static void main(String[] args) throws IOException {

        String env = StringUtils.isEmpty(System.getenv("ENV")) ? "uat" : System.getenv("ENV");
        env = "uat";
        System.out.println("==========当前环境是:" + env + ", 启动的配置文件是:application-" + env + ".properties");
        Properties properties = new Properties();
        InputStream in = HerokuCenterApplication.class.getClassLoader().getResourceAsStream("application-" + env + ".properties");
        properties.load(in);

        SpringApplication application = new SpringApplication(HerokuCenterApplication.class);
        application.setDefaultProperties(properties);
        application.run(args);
    }

}

@SpringBootApplication
使用该注解实现springboot项目的自动装配以及启动
3、代码

public String CreateCouponByDMP() {
//省略部分代码

        String tableName = isFirst.equals("0") ? batch : promCode;
        try {
            tempCouponMapper.createTableBatch("dmp." + "\"" + tableName + "\"");

            logger.info("dmp." + "\"" + tableName + "\"" + "创建表格成功");
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("dmp." + "\"" + tableName + "\"" + "表格创建失败");
        }
        logger.info("授权");
        tempCouponMapper.grantToDMP(dmpPGUserName);
        if (isFirst.equals("0")) {
            Map map = new HashMap();
            map.put("promCode", promCode);
            map.put("isfirst", isFirst);
            map.put("batch", batch);
            map.put("tablename", "dmp." + "\"" + batch + "\"");
            map.put("tablenamepro", "dmp." + "\"" + promCode + "\"");
            Integer selectCount = 0;
            String content = "处理成功";
            try {
                tempCouponMapper.insertTempCouponSec(map);
                selectCount = tempCouponMapper.selectCount("dmp." + "\"" + batch + "\"", batch);
            } catch (Exception e) {
                logger.info("isfirst=0;batch={};promCode={};处理异常", batch, promCode);
                content = "处理异常";
                e.printStackTrace();
            }
            Map map2 = new HashMap<>();
            map2.put("batchId", tempPromotionDefinition.getBatch());
            map2.put("endCouponTime", new Date());
            map2.put("couponCount", selectCount.toString());
            promotionTaskMapper.updateEndCoupon(map2);

            notifyDMP(content, tempPromotionDefinition.getBatch(), promCode, selectCount.toString(), busType, "DMP00", keyType);

            return "更新成功";
        }
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < threadAmount; i++) {
            logger.info("多线程操作");
            executorService.execute(new InsertThread(threadAmount, tempPromotionDefinition.getBatch(), i * btach, btach, promCode,
                    uuid, Count, total, busType, keyType, systemGuid, isFirst));
        }
        executorService.shutdown();

        while (true) {
            try {
                if (executorService.awaitTermination(5, TimeUnit.SECONDS)) {
                    logger.info("------dmp-------:开始通知");
                    Integer selectCount = tempCouponMapper.selectCount("dmp." + "\"" + promCode + "\"", batch);
                    logger.info("------dmp-------{}", selectCount);
                    Map map = new HashMap<>();
                    map.put("batchId", tempPromotionDefinition.getBatch());
                    map.put("endCouponTime", new Date());
                    map.put("couponCount", selectCount.toString());
                    promotionTaskMapper.updateEndCoupon(map);
                    //创建表
                    notifyDMP("处理成功", tempPromotionDefinition.getBatch(), promCode, selectCount.toString(), busType, "DMP00", keyType);
                    logger.info("------dmp-------:通知成功");
                    memberGroupMapper.createRepeatTable(tempPromotionDefinition.getBatch());
                    memberGroupMapper.delteRepeat(tempPromotionDefinition.getBatch());
                    memberGroupMapper.insertMemberGroupRepeat();
                    break;
                } else {
                    logger.info("线程池中还有线程线程,请等待。。。。");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        return "券生成成功";

    }

代码描述
代码在业务上的优点:根据状态以及批次动态的创建表格,避免大量的数据积累后出现更新操作数据被锁从而导致性能低下的情况,同时也避免第三方在进行拉数据的时候进行查询的操作(创建临时表格,根据批次数据全部拉取)。
性能上的优点:采用线程池避免线程的重复构建,同时使用shutdown()与awaitTermination(5, TimeUnit.SECONDS)的方法来判断线程执行情况,以及确定在全部执行完成后通知第三方系统进行数据的拉取,保证数据的完整性,同时保证性能。

你可能感兴趣的:(code-desc)