Bladeren bron

[chg]业务模块增加启动项,初始化电梯品牌列表

别傲 5 jaren geleden
bovenliggende
commit
b98b89d0c7

+ 49 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/runner/BusinessServiceRunner.java

@@ -0,0 +1,49 @@
+package cn.com.ty.lift.business.framework.runner;
+
+import cn.com.ty.lift.business.library.dao.entity.LiftBrand;
+import cn.com.ty.lift.business.library.dao.mapper.LiftBrandMapper;
+import cn.com.ty.lift.common.constants.RedisConstants;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author bieao
+ * @date 2019/12/10
+ * @description 业务模块启动项
+ */
+@Component
+@Slf4j
+public class BusinessServiceRunner implements ApplicationRunner {
+
+    @Resource
+    private RedisTemplate redisTemplate;
+
+    @Resource
+    private LiftBrandMapper liftBrandMapper;
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        //初始化电梯品牌列表
+        initLiftBrandList();
+    }
+
+    /**
+     * @description 初始化电梯品牌列表
+     * @date 2019/12/10 10:12 AM
+     */
+    public void initLiftBrandList() {
+        //查询品牌列表
+        List<LiftBrand> liftBrandList = liftBrandMapper.selectList(new QueryWrapper<>());
+        //设置品牌列表缓存到redis
+        redisTemplate.opsForValue().set(RedisConstants.RK_LIFT_BRAND_LIST, liftBrandList);
+        log.info("初始化品牌列表{}", JSONUtil.parse(liftBrandList));
+    }
+}

+ 20 - 10
lift-business-service/src/main/java/cn/com/ty/lift/business/library/controller/LibraryController.java

@@ -6,7 +6,7 @@ import cn.com.ty.lift.business.library.dao.entity.model.BatchUpdateLiftRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.SelectBatchPlatformCompanyRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.LiftRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.UpdateBatchPlatformCompanyRequest;
-import cn.com.ty.lift.business.library.service.LibraryService;
+import cn.com.ty.lift.business.library.service.LiftService;
 import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
 import cn.com.ty.lift.business.library.service.ProjectLiftRelevanceService;
 import cn.com.ty.lift.common.base.ExportRequest;
@@ -18,14 +18,14 @@ import javax.annotation.Resource;
 /**
  * @author bieao
  * @date 2019/11/27
- * @description 电梯档案控制层
+ * @description 电梯控制层
  */
 @RestController
-@RequestMapping("library")
-public class LibraryController {
+@RequestMapping("lift")
+public class LiftController {
 
     @Resource
-    private LibraryService libraryService;
+    private LiftService liftService;
 
     @Resource
     private ProjectLiftRelevanceService projectRelevanceService;
@@ -41,7 +41,17 @@ public class LibraryController {
      */
     @PostMapping("list")
     public RestResponse list(@RequestBody LiftRequest request) {
-        return libraryService.list(request);
+        return liftService.list(request);
+    }
+
+    /**
+     * @return RestResponse 电梯品牌列表
+     * @description 查询电梯品牌列表
+     * @date 2019/12/10 10:23 AM
+     */
+    @PostMapping("brand/list")
+    public RestResponse list(){
+        return liftService.list();
     }
 
     /**
@@ -52,7 +62,7 @@ public class LibraryController {
      */
     @PostMapping("detail/{id}")
     public RestResponse detail(@PathVariable(name = "id") Long id) {
-        return libraryService.detail(id);
+        return liftService.detail(id);
     }
 
     /**
@@ -63,7 +73,7 @@ public class LibraryController {
      */
     @PostMapping("add")
     public RestResponse add(@RequestBody Lift lift) {
-        return libraryService.add(lift);
+        return liftService.add(lift);
     }
 
     /**
@@ -74,7 +84,7 @@ public class LibraryController {
      */
     @PostMapping("modify")
     public RestResponse modify(@RequestBody Lift lift) {
-        return libraryService.modify(lift);
+        return liftService.modify(lift);
     }
 
     /**
@@ -129,6 +139,6 @@ public class LibraryController {
      */
     @PostMapping("export")
     public void export(@RequestBody ExportRequest request) {
-        libraryService.export(request);
+        liftService.export(request);
     }
 }

+ 26 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/entity/LiftBrand.java

@@ -0,0 +1,26 @@
+package cn.com.ty.lift.business.library.dao.entity;
+
+import lombok.Data;
+
+/**
+ * 实体类 - 表:lift_brand
+ * @author bieao
+ * @since 2019-12-10 10:15:08
+ */
+@Data
+public class LiftBrand {
+	/**
+	 * 序号
+	 */
+	private Integer sort;
+
+	/**
+	 * 品牌名
+	 */
+	private String name;
+
+	/**
+	 * 编码
+	 */
+	private String code;
+}

+ 13 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/mapper/LiftBrandMapper.java

@@ -0,0 +1,13 @@
+package cn.com.ty.lift.business.library.dao.mapper;
+
+import cn.com.ty.lift.business.library.dao.entity.LiftBrand;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * MyBatis Mapper 接口 - 表:lift_brand
+ * @author bieao
+ * @since 2019-12-10 10:15:08
+ */
+public interface LiftBrandMapper extends BaseMapper<LiftBrand> {
+
+}

+ 18 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LibraryService.java

@@ -2,6 +2,7 @@ package cn.com.ty.lift.business.library.service;
 
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.library.dao.entity.Lift;
+import cn.com.ty.lift.business.library.dao.entity.LiftBrand;
 import cn.com.ty.lift.business.library.dao.entity.LiftExtension;
 import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
 import cn.com.ty.lift.business.library.dao.entity.model.LiftRequest;
@@ -10,10 +11,12 @@ import cn.com.ty.lift.business.library.dao.mapper.LiftExtensionMapper;
 import cn.com.ty.lift.business.library.dao.mapper.LiftMapper;
 import cn.com.ty.lift.common.base.ExportRequest;
 import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.common.constants.RedisConstants;
 import cn.com.ty.lift.common.export.ExportUtils;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -26,10 +29,10 @@ import java.util.Map;
 /**
  * @author bieao
  * @date 2019/11/27
- * @description 电梯档案业务层
+ * @description 电梯业务层
  */
 @Service
-public class LibraryService {
+public class LiftService {
 
     @Resource
     private LiftMapper liftMapper;
@@ -43,6 +46,9 @@ public class LibraryService {
     @Resource
     private ProjectLiftRelevanceService projectRelevanceService;
 
+    @Resource
+    private RedisTemplate redisTemplate;
+
     private Map<String, String> paramMap = new HashMap<String, String>() {{
         put("liftCode", "电梯号");
         put("registrationCode", "注册代码");
@@ -68,6 +74,16 @@ public class LibraryService {
         return RestResponse.ok(page, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.query.success"));
     }
 
+    /**
+     * @return RestResponse 电梯品牌列表
+     * @description 查询电梯品牌列表
+     * @date 2019/12/10 10:23 AM
+     */
+    public RestResponse list() {
+        List<LiftBrand> liftBrandList = (List<LiftBrand>) redisTemplate.opsForValue().get(RedisConstants.RK_LIFT_BRAND_LIST);
+        return RestResponse.ok(liftBrandList, ApiConstants.RESULT_SUCCESS, MessageUtils.get("msg.query.success"));
+    }
+
     /**
      * @param id 电梯id
      * @return RestResponse 电梯详情

+ 9 - 0
lift-business-service/src/main/resources/mapper/lift/LiftBrandMapper.xml

@@ -0,0 +1,9 @@
+<?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="cn.com.ty.lift.business.library.dao.mapper.LiftBrandMapper" >
+	<resultMap id="BaseResultMap" type="cn.com.ty.lift.business.library.dao.entity.LiftBrand" >
+		<id column="sort" property="sort" jdbcType="INTEGER" />
+		<result column="name" property="name" jdbcType="VARCHAR" />
+		<result column="code" property="code" jdbcType="VARCHAR" />
+	</resultMap>
+</mapper>

+ 5 - 0
lift-common/src/main/java/cn.com.ty.lift.common/constants/RedisConstants.java

@@ -11,4 +11,9 @@ public class RedisConstants {
      */
     public static final String RK_AREA_LIST = "system::area::list";
 
+    /**
+     * 电梯品牌列表 key
+     */
+    public static final String RK_LIFT_BRAND_LIST = "business::liftBrand::list";
+
 }

+ 1 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/framework/runner/SystemServiceRunner.java

@@ -42,6 +42,6 @@ public class SystemServiceRunner implements ApplicationRunner {
         //组装省、市、区树形结构列表
         List<AreaCode> areaCodeList = iAreaCodeService.areaTree();
         redisTemplate.opsForValue().set(RedisConstants.RK_AREA_LIST, areaCodeList);
-        log.info("初始化区域信息列表", JSONUtil.parse(areaCodeList));
+        log.info("初始化区域信息列表{}", JSONUtil.parse(areaCodeList));
     }
 }