Commit bf204e70 by levphon

新e盾公共服务

0 parents
Showing 50 changed files with 2186 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.glsx</groupId>
<artifactId>glsx-ne-shield</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>glsx-ne-shield-publiccenter</artifactId>
<dependencies>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-loggin</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-dfs</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-office</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>glsx-ne-shield-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>glsx-ne-shield-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>ne-shield-publiccenter-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>glsx-ne-shield-auth-client</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package cn.com.glsx;
import com.glsx.plat.context.EnableRestAdmin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct;
import java.util.TimeZone;
import static java.time.ZoneId.of;
import static java.util.TimeZone.getTimeZone;
/**
* @author payu
*/
@EnableRestAdmin
@EnableFeignClients(basePackages = {"cn.com.glsx.*.api"})
@EnableDiscoveryClient
@EnableTransactionManagement
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@SpringBootApplication(scanBasePackages = {"cn.com.glsx.*"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@PostConstruct
void started() {
TimeZone.setDefault(getTimeZone(of("Asia/Shanghai")));
}
}
package cn.com.glsx.base.common.exception;
import com.glsx.plat.exception.SystemMessage;
import lombok.Getter;
/**
* @author payu
*/
@Getter
public class PublicCenterException extends RuntimeException {
private int errorCode = SystemMessage.FAILURE.getCode();
public PublicCenterException(String message) {
super(message);
}
public PublicCenterException(int errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
public static PublicCenterException of(SystemMessage message) {
return new PublicCenterException(message.getCode(), message.getMsg());
}
public PublicCenterException(Throwable cause) {
super(cause);
}
public PublicCenterException(String message, Throwable cause) {
super(message, cause);
}
}
package cn.com.glsx.base.common.exception;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.glsx.plat.core.web.R;
import com.glsx.plat.exception.ExceptionLevel;
import com.glsx.plat.exception.GlobalExceptionHandler;
import com.glsx.plat.exception.SystemMessage;
import com.glsx.plat.loggin.LogginConstants;
import com.glsx.plat.loggin.LogginStrategyFactory;
import feign.FeignException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.BindingException;
import org.mybatis.spring.MyBatisSystemException;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局异常处理
*
* @author payu
*/
@Slf4j
@RestControllerAdvice
public class PublicCenterExceptionHandler extends GlobalExceptionHandler {
@Autowired
private LogginStrategyFactory logginStrategyFactory;
@ExceptionHandler(PublicCenterException.class)
public R handleAdminException(PublicCenterException e) {
this.saveException(e, ExceptionLevel.fatal);
return R.error(e.getErrorCode(), e.getMessage());
}
/**
* 引入Feign服务的话
*
* @param e
* @return
*/
@ExceptionHandler(FeignException.class)
public R handleFeignException(FeignException e) {
this.saveException(e, ExceptionLevel.fatal);
return R.error(e.status(), e.getMessage());
}
/**
* Mybatis BindingException
*
* @param e
* @return
*/
@ExceptionHandler(BindingException.class)
public R handleBindingException(BindingException e) {
this.saveException(e, ExceptionLevel.fatal);
return R.error(e.getMessage());
}
@ExceptionHandler(value = MyBatisSystemException.class)
public R myBatisSystemException(MyBatisSystemException e) {
log.error("数据存储出错", e);
this.saveException(e, ExceptionLevel.fatal);
return SystemMessage.DATA_HANDLE_ERROR.result();
}
@ExceptionHandler(value = UnrecognizedPropertyException.class)
public R unrecognizedPropertyException(UnrecognizedPropertyException e) {
log.error("不能识别的字段", e);
this.saveException(e, ExceptionLevel.fatal);
return SystemMessage.ARGS_ERROR.result();
}
@SneakyThrows
@Async
@Override
protected void saveException(Exception e, ExceptionLevel level) {
String logId = MDC.get(LogginConstants.MDC_LOG_DB_ID);
log.error("操作异常/失败ID:{},{}", MDC.get(LogginConstants.MDC_LOG_DB_ID), e.getMessage());
logginStrategyFactory.getStrategy().updateLogStatus(logId, "失败");
MDC.clear();
}
}
package cn.com.glsx.base.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author payu
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
// @Resource
// private AuthInterceptor authInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//1.加入的顺序就是拦截器执行的顺序,
//2.按顺序执行所有拦截器的preHandle
//3.所有的preHandle 执行完再执行全部postHandle 最后是postHandle
// registry.addInterceptor(authInterceptor).addPathPatterns("/**")
// .excludePathPatterns("/")
// .excludePathPatterns("/actuator/**")
// .excludePathPatterns("/api/**");
}
}
package cn.com.glsx.base.modules;
import cn.com.glsx.auth.model.SyntheticUser;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import com.glsx.plat.core.web.R;
import com.glsx.plat.web.controller.AbstractController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author liuyf
* @Title BaseController.java
* @Package com.glsx.vasp.controller
* @Description
* @date 2019年10月24日 下午2:24:00
*/
@RestController
public class BaseController extends AbstractController {
/**
* 这个给Spring Boot Admin探测用
*
* @return
*/
@GetMapping(value = "/")
public R index() {
return R.ok("You get it!");
}
/**
* 从session中获取当前用户
*
* @return
*/
@Override
public SyntheticUser getSessionUser() {
return ShieldContextHolder.getUser();
}
@Override
public Long getUserId() {
return ShieldContextHolder.getUserId();
}
@Override
public String getAccount() {
return ShieldContextHolder.getAccount();
}
}
package cn.com.glsx.base.modules.api;
import cn.com.glsx.base.modules.converter.DictDataConverter;
import cn.com.glsx.base.modules.entity.SysDictData;
import cn.com.glsx.base.modules.service.DictDataService;
import cn.com.glsx.publiccenter.api.dto.request.FindDictDataRequest;
import cn.com.glsx.publiccenter.api.dto.response.SysDictDataResponse;
import cn.com.glsx.publiccenter.api.feign.SysDictDataService;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Desc:字典api
* @Author huangxc
* @Date 2021/5/29
*/
@Slf4j
@RestController
@RequestMapping(value = "/sysdict")
public class SysDictController implements SysDictDataService {
@Autowired
private DictDataService dictDataService;
@Override
@GetMapping(value = "/getDictDataById")
public R<SysDictDataResponse> getDictDataById(@RequestParam("id") Long id) {
SysDictData sysDictData = dictDataService.getDictDataById(id);
SysDictDataResponse response = null;
if (sysDictData != null) {
response = DictDataConverter.INSTANCE.do2foo(sysDictData);
}
return R.ok().data(response);
}
@Override
@GetMapping(value = "/findByDict")
public R<List<SysDictDataResponse>> findByDict(@RequestBody FindDictDataRequest request) {
SysDictData sysDictData = new SysDictData();
sysDictData.setDictLabel(request.getDictLabel());
sysDictData.setDictType(request.getDictType());
sysDictData.setDictValue(request.getDictValue());
List<SysDictData> sysDictDataList = dictDataService.findByDict(sysDictData);
List<SysDictDataResponse> responseList = Lists.newArrayList();
sysDictDataList.forEach(u -> {
responseList.add(DictDataConverter.INSTANCE.do2foo(u));
});
return R.ok().data(responseList);
}
}
package cn.com.glsx.base.modules.controller;
import cn.com.glsx.base.modules.entity.BaseCity;
import cn.com.glsx.base.modules.service.BaseCityService;
import com.glsx.plat.core.web.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;
import java.util.List;
/**
* 市区
*
* @author Mark
* @date 2019-03-28 13:49:24
*/
@RestController
@RequestMapping("basic/city")
@Validated
public class BaseCityController {
@Autowired
private BaseCityService baseCityService;
/**
* 根据条件查询
*/
@RequestMapping("/list")
public R list(@NotBlank(message = "省份编码不能为空") String provCode) {
List<BaseCity> list = baseCityService.list(provCode);
return R.ok().data(list);
}
}
package cn.com.glsx.base.modules.controller;
import cn.com.glsx.base.modules.entity.BaseProvince;
import cn.com.glsx.base.modules.service.BaseProvinceService;
import com.glsx.plat.core.web.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 省份
*
* @author Mark
* @date 2019-03-28 10:17:01
*/
@RestController
@RequestMapping("basic/province")
public class BaseProvinceController {
@Autowired
private BaseProvinceService baseProvinceService;
/**
* 列表
*/
@RequestMapping("/list")
public R list() {
List<BaseProvince> list = baseProvinceService.list();
return R.ok().data(list);
}
}
package cn.com.glsx.base.modules.controller;
import cn.com.glsx.base.modules.entity.BaseZone;
import cn.com.glsx.base.modules.service.BaseZoneService;
import com.glsx.plat.core.web.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;
import java.util.List;
/**
* @author liuyf
* @date 2019-04-03 11:33:49
*/
@RestController
@RequestMapping("basic/zone")
public class BaseZoneController {
@Autowired
private BaseZoneService baseZoneService;
@RequestMapping("/list")
public R list(@NotBlank(message = "城市编码不能为空") String cityCode) {
List<BaseZone> list = baseZoneService.searchByCityCode(cityCode);
return R.ok().data(list);
}
}
package cn.com.glsx.base.modules.controller;
import cn.com.glsx.base.modules.converter.DictDataConverter;
import cn.com.glsx.base.modules.entity.SysDictData;
import cn.com.glsx.base.modules.model.DictDataBO;
import cn.com.glsx.base.modules.model.DictDataDTO;
import cn.com.glsx.base.modules.model.DictDataSearch;
import cn.com.glsx.base.modules.model.export.DictDataExport;
import cn.com.glsx.base.modules.service.DictDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.context.utils.validator.AssertUtils;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
/**
* @author payu
*/
@RestController
@RequestMapping("dict/data")
public class DictDataController {
private final static String MODULE = "字典管理";
@Autowired
private DictDataService dictDataService;
@GetMapping("/search")
public R search(DictDataSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize());
PageInfo<DictDataDTO> pageInfo = dictDataService.searchData(search);
return R.ok().putPageData(pageInfo);
}
@GetMapping(value = "/export")
public void export(HttpServletResponse response, DictDataSearch search) throws Exception {
List<DictDataExport> list = dictDataService.exportData(search);
EasyExcelUtils.writeExcel(response, list, "字典数据_" + DateUtils.formatSerial(new Date()), "Sheet1", DictDataExport.class);
}
/**
* 根据字典类型查询字典数据信息
*/
@GetMapping(value = "/type/{dictType}")
public R dictType(@PathVariable("dictType") String dictType) {
List<DictDataDTO> list = dictDataService.getDictDataByTypeWithCached(dictType);
return R.ok().data(list);
}
/**
* 根据字典类型和字典label查询字典数据信息
*/
@GetMapping(value = "/type/{dictType}/{dataLabel}")
public R dictType(@PathVariable("dictType") String dictType, @PathVariable("dataLabel") String dataLabel) {
DictDataDTO dataDTO = dictDataService.getDictDataByTypeAndLabelWithCached(dictType, dataLabel);
return R.ok().data(dataDTO);
}
@SysLog(module = MODULE, action = OperateType.ADD)
@PostMapping("/add")
public R add(@RequestBody @Valid DictDataBO dataBO) {
SysDictData data = DictDataConverter.INSTANCE.bo2do(dataBO);
if (StringUtils.isNullOrEmpty(data.getIsDefault())) data.setIsDefault("N");
dictDataService.addData(data);
return R.ok();
}
@SysLog(module = MODULE, action = OperateType.EDIT)
@PostMapping("/edit")
public R edit(@RequestBody @Valid DictDataBO dataBO) {
AssertUtils.isNull(dataBO.getId(), "ID不能为空");
SysDictData data = DictDataConverter.INSTANCE.bo2do(dataBO);
dictDataService.editData(data);
return R.ok();
}
@GetMapping("/info")
public R info(@RequestParam("dataId") Long id) {
SysDictData data = dictDataService.getDictDataById(id);
DictDataDTO dataDTO = DictDataConverter.INSTANCE.do2dto(data);
return R.ok().data(dataDTO);
}
@GetMapping("/delete")
public R delete(@RequestParam("dataId") Long id) {
dictDataService.logicDeleteDataById(id);
return R.ok();
}
}
package cn.com.glsx.base.modules.controller;
import cn.com.glsx.base.modules.converter.DictTypeConverter;
import cn.com.glsx.base.modules.entity.SysDictType;
import cn.com.glsx.base.modules.model.DictDataSearch;
import cn.com.glsx.base.modules.model.DictTypeBO;
import cn.com.glsx.base.modules.model.DictTypeDTO;
import cn.com.glsx.base.modules.model.export.DictTypeExport;
import cn.com.glsx.base.modules.service.DictDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.context.utils.validator.AssertUtils;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
/**
* @author payu
*/
@RestController
@RequestMapping("dict/type")
public class DictTypeController {
private final static String MODULE = "字典管理";
@Autowired
private DictDataService dictDataService;
@GetMapping("/search")
public R search(DictDataSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize());
PageInfo<DictTypeDTO> pageInfo = dictDataService.searchType(search);
return R.ok().putPageData(pageInfo);
}
@GetMapping(value = "/export")
public void export(HttpServletResponse response, DictDataSearch search) throws Exception {
List<DictTypeExport> list = dictDataService.exportType(search);
EasyExcelUtils.writeExcel(response, list, "字典类型_" + DateUtils.formatSerial(new Date()), "Sheet1", DictTypeExport.class);
}
@SysLog(module = MODULE, action = OperateType.ADD)
@PostMapping("/add")
public R add(@RequestBody @Valid DictTypeBO typeBO) {
SysDictType type = DictTypeConverter.INSTANCE.bo2do(typeBO);
dictDataService.addType(type);
return R.ok();
}
@SysLog(module = MODULE, action = OperateType.EDIT)
@PostMapping("/edit")
public R edit(@RequestBody @Valid DictTypeBO typeBO) {
AssertUtils.isNull(typeBO.getId(), "ID不能为空");
SysDictType type = DictTypeConverter.INSTANCE.bo2do(typeBO);
dictDataService.editType(type);
return R.ok();
}
@GetMapping("/info")
public R info(@RequestParam("typeId") Long id) {
SysDictType type = dictDataService.getDictTypeById(id);
DictTypeDTO typeDTO = DictTypeConverter.INSTANCE.do2dto(type);
return R.ok().data(typeDTO);
}
@GetMapping("/delete")
public R delete(@RequestParam("typeId") Long id) {
dictDataService.logicDeleteTypeById(id);
return R.ok();
}
@GetMapping("/options")
public R options() {
List<DictTypeDTO> list = dictDataService.getAllDictType2();
return R.ok().data(list);
}
}
package cn.com.glsx.base.modules.controller;
import com.glsx.plat.common.utils.SnowFlake;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.context.properties.UploadProperties;
import com.glsx.plat.core.web.R;
import com.glsx.plat.dfs.fastdfs.FastDfsUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
/**
* @author payu
*/
@Slf4j
@RestController
@RequestMapping(value = "basic/file")
public class FileController {
@Resource
private FastDfsUtils fastDfsUtils;
@Resource
private UploadProperties uploadProperties;
/**
* 文件上传到本地服务器
*/
@PostMapping(value = "/upload2local", headers = "content-type=multipart/form-data")
public R upload2local(@RequestParam("file") MultipartFile file) throws Exception {
String result;
//获取文件存放路径
String path = uploadProperties.getBasePath();
File targetDir = new File(path);
if (!targetDir.exists()) {
targetDir.mkdirs();
}
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.indexOf("."));
String newFilename = SnowFlake.nextId() + suffix;
String tempPath = targetDir + File.separator + newFilename;
// 转存文件
File desc = new File(tempPath);
FileUtils.copyInputStreamToFile(file.getInputStream(), desc);
path = tempPath;
if (StringUtils.isNotEmpty(path)) {
result = uploadProperties.getFilepath() + newFilename;
return R.ok().data(result);
} else {
result = "上传失败";
return R.error(result);
}
}
/**
* 文件上传分布式文件服务器
*/
@PostMapping(value = "/upload2dfs", headers = "content-type=multipart/form-data")
public R upload2dfs(@RequestParam("file") MultipartFile file) {
String result;
try {
String path = fastDfsUtils.upload(file);
if (StringUtils.isNotEmpty(path)) {
result = path;
} else {
result = "上传失败";
}
return R.ok().data(result);
} catch (Exception e) {
e.printStackTrace();
result = "文件服务异常";
return R.error(result);
}
}
/**
* 文件删除
*
* @param url
* @return
*/
@GetMapping(value = "/deleteByUrl")
public R deleteByUrl(@RequestParam("url") String url) {
fastDfsUtils.delete(url);
return R.ok();
}
}
package cn.com.glsx.base.modules.converter;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface DictDataConverter {
DictDataConverter INSTANCE = Mappers.getMapper(DictDataConverter.class);
cn.com.glsx.base.modules.model.DictDataDTO do2dto(cn.com.glsx.base.modules.entity.SysDictData data);
cn.com.glsx.base.modules.entity.SysDictData bo2do(cn.com.glsx.base.modules.model.DictDataBO dataBO);
cn.com.glsx.publiccenter.api.dto.response.SysDictDataResponse do2foo(cn.com.glsx.base.modules.entity.SysDictData data);
}
package cn.com.glsx.base.modules.converter;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface DictTypeConverter {
DictTypeConverter INSTANCE = Mappers.getMapper(DictTypeConverter.class);
cn.com.glsx.base.modules.model.DictTypeDTO do2dto(cn.com.glsx.base.modules.entity.SysDictType type);
cn.com.glsx.base.modules.entity.SysDictType bo2do(cn.com.glsx.base.modules.model.DictTypeBO typeBO);
}
package cn.com.glsx.base.modules.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Data
@Entity
@Table(name = "base_cities")
public class BaseCity implements Serializable {
@Id
private Long id;
private String code;
private String name;
@Column(name = "prov_code")
private String provCode;
}
\ No newline at end of file
package cn.com.glsx.base.modules.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Data
@Entity
@Table(name = "base_provinces")
public class BaseProvince implements Serializable {
@Id
private Long id;
private String code;
private String name;
@Column(name = "region_code")
private String regionCode;
@Column(name = "region_name")
private String regionName;
}
\ No newline at end of file
package cn.com.glsx.base.modules.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Data
@Entity
@Table(name = "base_zone")
public class BaseZone implements Serializable {
@Id
private Long id;
@Column(name = "city_code")
private String cityCode;
private String code;
private String name;
@Column(name = "prov_code")
private String provCode;
}
\ No newline at end of file
package cn.com.glsx.base.modules.entity;
import com.glsx.plat.mybatis.base.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.Column;
import javax.persistence.Table;
@Data
@Accessors(chain = true)
@Table(name = "t_dict_data")
public class SysDictData extends BaseEntity {
/**
* 字典类型
*/
@Column(name = "dict_type")
private String dictType;
/**
* 字典标签
*/
@Column(name = "dict_label")
private String dictLabel;
/**
* 字典键值
*/
@Column(name = "dict_value")
private String dictValue;
/**
* 字典排序
*/
@Column(name = "dict_sort")
private Integer dictSort;
/**
* 是否默认(Y是 N否)
*/
@Column(name = "is_default")
private String isDefault;
@Column(name = "enable_status")
private Integer enableStatus;
/**
* 备注
*/
private String remark;
}
\ No newline at end of file
package cn.com.glsx.base.modules.entity;
import com.glsx.plat.mybatis.base.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.Column;
import javax.persistence.Table;
@Data
@Accessors(chain = true)
@Table(name = "t_dict_type")
public class SysDictType extends BaseEntity {
/**
* 字典名称
*/
@Column(name = "dict_name")
private String dictName;
/**
* 字典类型
*/
@Column(name = "dict_type")
private String dictType;
/**
* 备注
*/
private String remark;
@Column(name = "enable_status")
private Integer enableStatus;
}
\ No newline at end of file
package cn.com.glsx.base.modules.mapper;
import cn.com.glsx.base.modules.entity.BaseCity;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface BaseCityMapper extends CommonBaseMapper<BaseCity> {
List<BaseCity> selectByProvCode(@Param("provCode") String provCode);
BaseCity selectByCode(@Param("cityCode") String cityCode);
}
\ No newline at end of file
package cn.com.glsx.base.modules.mapper;
import cn.com.glsx.base.modules.entity.BaseProvince;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface BaseProvinceMapper extends CommonBaseMapper<BaseProvince> {
BaseProvince selectByCode(@Param("provCode") String provCode);
}
\ No newline at end of file
package cn.com.glsx.base.modules.mapper;
import cn.com.glsx.base.modules.entity.BaseZone;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface BaseZoneMapper extends CommonBaseMapper<BaseZone> {
List<BaseZone> selectByCityCode(@Param("cityCode") String cityCode);
BaseZone selectByCode(@Param("code") String zoneCode);
}
\ No newline at end of file
package cn.com.glsx.base.modules.mapper;
import cn.com.glsx.base.modules.entity.SysDictData;
import cn.com.glsx.base.modules.model.DictDataDTO;
import cn.com.glsx.base.modules.model.DictDataSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysDictDataMapper extends CommonBaseMapper<SysDictData> {
List<DictDataDTO> selectList(DictDataSearch search);
List<SysDictData> selectByType(@Param("type") String type);
List<DictDataDTO> selectByType2(@Param("type") String type);
List<DictDataDTO> selectByTypeWithDeleted(@Param("type") String type);
DictDataDTO selectByTypeAndLabelWithDeleted(@Param("type") String type, @Param("label") String label);
SysDictData selectById(@Param("id") Long id);
int logicDeleteById(@Param("id") Long id);
List<SysDictData> findByDict(@Param("sysDictData") SysDictData sysDictData);
}
\ No newline at end of file
package cn.com.glsx.base.modules.mapper;
import cn.com.glsx.base.modules.entity.SysDictType;
import cn.com.glsx.base.modules.model.DictDataSearch;
import cn.com.glsx.base.modules.model.DictTypeDTO;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysDictTypeMapper extends CommonBaseMapper<SysDictType> {
List<DictTypeDTO> selectList(DictDataSearch search);
List<SysDictType> selectAllDictType();
List<DictTypeDTO> selectAllDictType2();
SysDictType selectById(@Param("id") Long id);
SysDictType selectByType(@Param("type") String dictType);
SysDictType selectByNameWithDeleted(@Param("name") String dictName);
SysDictType selectByTypeWithDeleted(@Param("type") String dictType);
int logicDeleteById(@Param("id") Long id);
}
\ No newline at end of file
package cn.com.glsx.base.modules.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class DictDataBO implements Serializable {
private Long id;
private String dictType;
private String dictLabel;
private String dictValue;
private Integer dictSort;
private String isDefault;
private Integer enableStatus;
private String remark;
}
package cn.com.glsx.base.modules.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class DictDataDTO implements Serializable {
private Long id;
private String dictLabel;
private String dictValue;
private String dictType;
private Integer dictSort;
private String isDefault;
private Integer enableStatus;
@JsonIgnore
private Integer delFlag;
private String remark;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createdDate;
private boolean typeDisabled;
private boolean disabled;
private boolean typeDeleted;
private boolean deleted;
}
package cn.com.glsx.base.modules.model;
import cn.hutool.db.Page;
import lombok.Data;
@Data
public class DictDataSearch extends Page {
private String name;
private String type;
private String tag;
private Integer status;
private String sDate;
private String eDate;
}
package cn.com.glsx.base.modules.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class DictTypeBO implements Serializable {
private Long id;
private String dictName;
private String dictType;
private String remark;
private Integer enableStatus;
}
package cn.com.glsx.base.modules.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class DictTypeDTO implements Serializable {
private Long id;
private String dictName;
private String dictType;
private String remark;
private Integer enableStatus;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createdDate;
@JsonIgnore
private Integer delFlag;
}
package cn.com.glsx.base.modules.model.export;
public class DictDataExport {
}
package cn.com.glsx.base.modules.model.export;
public class DictTypeExport {
}
package cn.com.glsx.base.modules.service;
import cn.com.glsx.base.modules.entity.BaseCity;
import cn.com.glsx.base.modules.mapper.BaseCityMapper;
import com.glsx.plat.redis.utils.RedisUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseCityService {
@Resource
private BaseCityMapper cityMapper;
@Autowired
private RedisUtils redisUtils;
public List<BaseCity> list(String provCode) {
List<BaseCity> list = null;//redisUtils.getListByPrex(ConstantCacheKeys.REDIS_CITY_KEY + provinceCode);
// Collections.sort(list, Comparator.comparing(BaseCity::getCode));
if (CollectionUtils.isEmpty(list)) list = cityMapper.selectByProvCode(provCode);
return list;
}
}
package cn.com.glsx.base.modules.service;
import cn.com.glsx.base.modules.entity.BaseProvince;
import cn.com.glsx.base.modules.mapper.BaseProvinceMapper;
import com.glsx.plat.redis.utils.RedisUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseProvinceService {
@Resource
private BaseProvinceMapper provinceMapper;
@Autowired
private RedisUtils redisUtils;
public List<BaseProvince> list() {
List<BaseProvince> list = null;//redisUtils.getListByPrex(ConstantCacheKeys.REDIS_PROVINCES_KEY);
//排序
// Collections.sort(list, Comparator.comparing(BaseProvince::getCode));
if (CollectionUtils.isEmpty(list)) list = provinceMapper.selectAll();
return list;
}
}
package cn.com.glsx.base.modules.service;
import cn.com.glsx.base.modules.entity.BaseZone;
import cn.com.glsx.base.modules.mapper.BaseZoneMapper;
import com.glsx.plat.redis.utils.RedisUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseZoneService {
@Resource
private BaseZoneMapper areaMapper;
@Autowired
private RedisUtils redisUtils;
public List<BaseZone> searchByCityCode(String cityCode) {
List<BaseZone> list = null;//redisUtils.getListByPrex(ConstantCacheKeys.REDIS_AREA_KEY + cityCode);
// Collections.sort(list, Comparator.comparing(BaseArea::getCode));
if (CollectionUtils.isEmpty(list)) list = areaMapper.selectByCityCode(cityCode);
return list;
}
}
package cn.com.glsx.base.modules.utils;
import cn.com.glsx.base.modules.model.DictDataDTO;
import com.glsx.plat.redis.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
* 字典工具类
*/
@Component
public class DictUtils {
@Autowired
private RedisUtils redisUtils;
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 设置字典缓存
*
* @param key 参数键
* @param dictDatas 字典数据列表
*/
public void setDictCache(String key, List<DictDataDTO> dictDatas) {
String fullKey = getCacheKey(key);
redisUtils.set(fullKey, dictDatas);
}
/**
* 获取字典缓存
*
* @param key 参数键
* @return dictDatas 字典数据列表
*/
public List<DictDataDTO> getDictCache(String key) {
Object cacheObj = redisUtils.get(getCacheKey(key));
if (Objects.isNull(cacheObj)) {
return null;
}
return cast(cacheObj);
}
/**
* 清空字典缓存
*/
public void clearDictCache() {
Collection<String> keys = redisUtils.keys(SYS_DICT_KEY + "*");
redisUtils.del(keys);
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
public static String getCacheKey(String configKey) {
return SYS_DICT_KEY + configKey;
}
@SuppressWarnings("unchecked")
public static <T> T cast(Object obj) {
return (T) obj;
}
}
#项目名称
spring.application.name=glsx-ne-shield-publiccenter
#日志路径(logback-spring.xml读取,不要加入配置中心)
logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
#nacos配置中心
spring.cloud.nacos.config.server-addr=192.168.3.206:8848
#nacos配置id,完整dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension(由新增配置时选的文件类型决定)}
#示例:http://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP
spring.cloud.nacos.config.group=NESHIELD_DEV_GROUP
#配置prefix,默认值同${spring.application.name}
spring.cloud.nacos.config.prefix=${spring.application.name}
#配置开发环境
spring.profiles.active=dev
#配置格式
spring.cloud.nacos.config.file-extension=properties
#微服务sentinel、zipkin、actuator等公共配置
spring.cloud.nacos.config.shared-configs[0].data-id=glsx-rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0].group=DEV_GROUP
spring.cloud.nacos.config.shared-configs[0].refresh=true
#数据库、redis等公共配置
spring.cloud.nacos.config.shared-configs[1].group=NESHIELD_DEV_GROUP
spring.cloud.nacos.config.shared-configs[1].data-id=glsx-ne-shield-share-dev.properties
spring.cloud.nacos.config.shared-configs[1].refresh=true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!--
说明:
1. 文件的命名和加载顺序有关
logback.xml早于application.yml加载,logback-spring.xml晚于application.yml加载
如果logback配置需要使用application.yml中的属性,需要命名为logback-spring.xml
2. logback使用application.yml中的属性
使用springProperty才可使用application.yml中的值 可以设置默认值
如果非要用yaml文件,那么只能使用绝对路径,例如:
logback-spring.xml引入文件:
<property file="${HOME}/configuration/application.yaml"/>
-->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property resource="bootstrap.properties"/>
<property name="APP_NAME" value="${spring.application.name}"/>
<!-- 生成日志文件目录 -->
<property name="LOG_FILE" value="${logging.path}"/>
<contextName>${APP_NAME}</contextName>
<turboFilter class="com.glsx.plat.common.loggin.BootTurboFilter">
<Marker>${APP_NAME}</Marker>
</turboFilter>
<!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 -->
<!-- <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />-->
<!-- <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />-->
<!-- <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />-->
<!-- 配置日志输出参数,彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<!-- 控制台打印日志 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<!-- Minimum logging level to be presented in the console logs-->
<level>INFO</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- 日志定时生成压缩文件 -->​
<appender name="flatfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- 日志进行格式化 -->
<!-- <appender name="logstash" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!-- <file>${LOG_FILE}.json</file>-->
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!-- <fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern>-->
<!-- <maxHistory>7</maxHistory>-->
<!-- </rollingPolicy>-->
<!-- <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">-->
<!-- <providers>-->
<!-- <timestamp>-->
<!-- <timeZone>UTC</timeZone>-->
<!-- </timestamp>-->
<!-- <pattern>-->
<!-- <pattern>-->
<!-- {-->
<!-- "severity": "%level",-->
<!-- "service": "${APP_NAME:-}",-->
<!-- "trace": "%X{X-B3-TraceId:-}",-->
<!-- "span": "%X{X-B3-SpanId:-}",-->
<!-- "parent": "%X{X-B3-ParentSpanId:-}",-->
<!-- "exportable": "%X{X-Span-Export:-}",-->
<!-- "pid": "${PID:-}",-->
<!-- "thread": "%thread",-->
<!-- "class": "%logger{40}",-->
<!-- "rest": "%message"-->
<!-- }-->
<!-- </pattern>-->
<!-- </pattern>-->
<!-- </providers>-->
<!-- </encoder>-->
<!-- </appender>-->
​
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="flatfile"/>
<!-- uncomment this to have also JSON logs -->
<!-- <appender-ref ref="logstash"/>-->
</root>
</configuration>
\ No newline at end of file
<?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.glsx.base.modules.mapper.BaseCityMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.base.modules.entity.BaseCity">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="prov_code" jdbcType="VARCHAR" property="provCode"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, code, `name`, prov_code
</sql>
<select id="selectByProvCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from base_cities
where prov_code =#{provCode}
order by code
</select>
<select id="selectByCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from base_cities
where code =#{cityCode}
</select>
</mapper>
\ No newline at end of file
<?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.glsx.base.modules.mapper.BaseProvinceMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.base.modules.entity.BaseProvince">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="region_code" jdbcType="VARCHAR" property="regionCode"/>
<result column="region_name" jdbcType="VARCHAR" property="regionName"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, code, `name`, region_code, region_name
</sql>
<select id="selectByCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from base_provinces
where code =#{provCode}
</select>
</mapper>
\ No newline at end of file
<?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.glsx.base.modules.mapper.BaseZoneMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.base.modules.entity.BaseZone">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="city_code" jdbcType="VARCHAR" property="cityCode"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="prov_code" jdbcType="VARCHAR" property="provCode"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, city_code, code, `name`, prov_code
</sql>
<select id="selectByCityCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from base_areas
where city_code =#{cityCode}
order by code
</select>
<select id="selectByCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from base_zone
where code =#{code}
</select>
</mapper>
\ No newline at end of file
<?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.glsx.base.modules.mapper.SysDictDataMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.base.modules.entity.SysDictData">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="dict_sort" jdbcType="INTEGER" property="dictSort"/>
<result column="dict_label" jdbcType="VARCHAR" property="dictLabel"/>
<result column="dict_value" jdbcType="VARCHAR" property="dictValue"/>
<result column="dict_type" jdbcType="VARCHAR" property="dictType"/>
<result column="is_default" jdbcType="CHAR" property="isDefault"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
</resultMap>
<resultMap id="DTOResultMap" type="cn.com.glsx.base.modules.model.DictDataDTO">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="dict_sort" jdbcType="INTEGER" property="dictSort"/>
<result column="dict_label" jdbcType="VARCHAR" property="dictLabel"/>
<result column="dict_value" jdbcType="VARCHAR" property="dictValue"/>
<result column="dict_type" jdbcType="VARCHAR" property="dictType"/>
<result column="is_default" jdbcType="CHAR" property="isDefault"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, dict_sort, dict_label, dict_value, dict_type, is_default, enable_status, del_flag,
created_by, created_date, updated_by, updated_date, remark
</sql>
<select id="selectByType" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where dict_type = #{type}
and del_flag = 0
</select>
<select id="selectByType2" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where dict_type = #{type}
and del_flag = 0
</select>
<select id="selectByTypeWithDeleted" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where dict_type = #{type}
</select>
<select id="selectByTypeAndLabelWithDeleted" resultType="cn.com.glsx.base.modules.model.DictDataDTO">
select
<include refid="Base_Column_List"/>
from t_dict_data
where dict_type = #{type}
and dict_label = #{label}
</select>
<select id="selectList" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where del_flag = 0
and dict_type = #{type}
<if test="tag != null and tag != ''">
and dict_label LIKE CONCAT('%',#{tag},'%')
</if>
<if test="status != null">
and enable_status = #{status}
</if>
<if test="sDate != null and sDate != '' and eDate != null and eDate != ''">
and DATE_FORMAT(created_date, '%Y-%m-%d') &gt;= #{sDate}
and DATE_FORMAT(created_date, '%Y-%m-%d') &lt;= #{eDate}
</if>
order by id desc
</select>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where id = #{id}
and del_flag = 0
</select>
<update id="logicDeleteById">
update t_dict_data
set del_flag = -1
where id = #{id}
</update>
<select id="findByDict" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_data
where del_flag = 0
<if test="sysDictData != null">
<if test="sysDictData.dictLabel != null and sysDictData.dictLabel != ''">
and dict_label = #{sysDictData.dictLabel}
</if>
<if test="sysDictData.dictType != null and sysDictData.dictType != ''">
and dict_type = #{sysDictData.dictType}
</if>
<if test="sysDictData.dictValue != null and sysDictData.dictValue != ''">
and dict_value #{sysDictData.dictValue}
</if>
</if>
</select>
</mapper>
\ No newline at end of file
<?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.glsx.base.modules.mapper.SysDictTypeMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.base.modules.entity.SysDictType">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="dict_name" jdbcType="VARCHAR" property="dictName"/>
<result column="dict_type" jdbcType="VARCHAR" property="dictType"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
</resultMap>
<resultMap id="DTOResultMap" type="cn.com.glsx.base.modules.model.DictTypeDTO">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="dict_name" jdbcType="VARCHAR" property="dictName"/>
<result column="dict_type" jdbcType="VARCHAR" property="dictType"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, dict_name, dict_type, remark, enable_status, del_flag, created_by, created_date, updated_by,
updated_date
</sql>
<select id="selectList" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where del_flag = 0
<if test="name != null and name != ''">
and dict_name LIKE CONCAT('%',#{name},'%')
</if>
<if test="type != null and type != ''">
and dict_type LIKE CONCAT('%',#{type},'%')
</if>
<if test="status != null">
and enable_status = #{status}
</if>
<if test="sDate != null and sDate != '' and eDate != null and eDate != ''">
and DATE_FORMAT(created_date, '%Y-%m-%d') &gt;= #{sDate}
and DATE_FORMAT(created_date, '%Y-%m-%d') &lt;= #{eDate}
</if>
order by id desc
</select>
<select id="selectAllDictType" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where del_flag = 0
</select>
<select id="selectAllDictType2" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where del_flag = 0
</select>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where del_flag = 0
and id = #{id}
</select>
<select id="selectByType" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where del_flag = 0
and dict_type = #{type}
</select>
<select id="selectByNameWithDeleted" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where dict_name = #{name}
</select>
<select id="selectByTypeWithDeleted" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_dict_type
where dict_type = #{type}
</select>
<update id="logicDeleteById">
update t_dict_type set del_flag = -1 where id = #{id}
</update>
</mapper>
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
./stop.sh
if [ ! $? -eq 2 ];then
./start.sh
fi
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
if [ "$1" = "start" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV
else
if [ "$1" = "stop" ]; then
./stop.sh
else
if [ "$1" = "debug" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV debug
else
if [ "$1" = "restart" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./restart.sh $ENV
else
if [ "$1" = "dump" ]; then
./dump.sh
else
echo "ERROR: Please input argument: start or stop or debug or restart or dump"
exit 1
fi
fi
fi
fi
fi
#!/bin/bash
####################################
# #
# General shell v1.0.0.1 #
# #
# #
####################################
###########init variable#############
JAVA_HOME="/app/soft/jdk1.8.0_144"
SERVER_PORT="8881"
DUBBO_PORT=""
JMX_ARG="-Xmx1024m -Xms512m -Xmn256m"
MAIN="cn.com.glsx.Application"
SERVER_NAME="glsx-ne-shield-publiccenter"
###########end#######################
PID_DIR="/app/soft/java_project/pids"
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
if [ -d "classes" ];then
CONF_DIR="$(pwd)/classes"
LIB_DIR="$(pwd)/lib"
elif [ -d "conf" ];then
CONF_DIR="$(pwd)/conf"
LIB_DIR="$(pwd)/lib"
fi
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
export CLASSPATH=$CONF_DIR:$LIB_JARS
if [ -z "$CONF_DIR" ];then
echo "Configure dir not found"
exit 1
fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The app is already started!"
echo "PID: $PIDS"
exit 1
fi
if [ ! -d "$PID_DIR" ];then
mkdir -p $PID_DIR
fi
CHECK_PORT=$2
if [ -n "$SERVER_PORT" ];then
SERVER_PORT_COUNT=`netstat -tln | grep -w $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The port $SERVER_PORT is already used!"
exit 1
fi
fi
if [ -n "$DUBBO_PORT" ];then
DUBBO_PORT_COUNT=`netstat -tln | grep -w $DUBBO_PORT | wc -l`
if [ $DUBBO_PORT_COUNT -gt 0 ]; then
echo "ERROR: The port $DUBBO_PORT already used!"
exit 1
fi
fi
if [[ -z "$SERVER_PORT" && -z "$DUBBO_PORT" ]];then
CHECK_PORT="skip"
fi
LOG_FILE="/data/java_log/jetty/${SERVER_NAME}/${SERVER_NAME}.log"
LOG_DIR=`dirname $LOG_FILE`
if [ ! -d $LOG_DIR ];then
mkdir -p $LOG_DIR
fi
############java args #######
#JAVA_OPTS="$PINPOINT -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Ddubbo.registry.file=/home/jdkapp/.dubbo/${SERVER_NAME}.cache"
JAVA_OPTS="$PINPOINT -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
#JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
JAVA_DEBUG_OPTS=""
if [ "$2" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$2" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
BITS=`file $JAVA_HOME/bin/java | grep 64-bit`
if [ -n "$BITS" ]; then
if [ -n "$JMX_ARG" ];then
JAVA_MEM_OPTS="-server $JMX_ARG -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70"
else
JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
fi
else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi
echo -e "Starting $SERVER_NAME \c"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -DCLASS_DIR=$CONF_DIR:$LIB_DIR $MAIN > /dev/null 2>&1 &
PIDS=$!
if [ "$CHECK_PORT" != "skip" ];then
COUNT=0
ERROR=0
TIME_OUT=60
ctime=`date +"%s"`
while [ $COUNT -lt 1 ]; do
ctime2=`date +"%s"`
echo -e ".\c"
sleep 1
#PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" | awk '{print $2}'`
RESULT=`ps --no-heading -p $PIDS`
if [ -n "$RESULT" ];then
if [ -n "$DUBBO_PORT" ]; then
#COUNT=`echo status | nc 127.0.0.1 $DUBBO_PORT -i 1 | grep -c OK`
COUNT=`/usr/sbin/ss -lpn | grep "${DUBBO_PORT}.*$PIDS" | wc -l`
else
if [ -n "$SERVER_PORT" ]; then
#COUNT=`netstat -ntl | grep -w $SERVER_PORT | wc -l`
COUNT=`/usr/sbin/ss -lpn | grep "${SERVER_PORT}.*$PIDS" | wc -l`
fi
fi
if [ $COUNT -gt 0 ]; then
echo $PIDS > $PID_DIR/${SERVER_NAME}.pid
break
fi
dtime=$((ctime2 - ctime))
if [ "$dtime" -ge "$TIME_OUT" ];then
echo $PIDS > $PID_DIR/${SERVER_NAME}.pid
echo -e "\ncheck port status timeout"
exit 1
fi
else
ERROR=$((ERROR + 1))
if [ "$ERROR" -gt 3 ];then
echo -e "\nProgram startup failed"
exit 2
fi
fi
done
fi
#服务检测与注册
if [[ "x$SERVER_PORT" != "x" && -f ./bin/check.sh ]]
then
./bin/check.sh $SERVER_NAME $SERVER_PORT $PIDS &
fi
echo "PID: $PIDS"
echo "LOGFILE: $LOG_FILE"
\ No newline at end of file
#!/bin/bash
####################################
# #
# General shell v1.0.0.1 #
# #
# #
####################################
SERVER_NAME="glsx-ne-shield-publiccenter"
PID_DIR="/app/soft/java_project/pids"
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
if [ -d "classes" ];then
CONF_DIR="$(pwd)/classes"
elif [ -d "conf" ];then
CONF_DIR="$(pwd)/conf"
fi
#if [ -f "$PID_DIR/${SERVER_NAME}.pid" ];then
# PID=`cat $PID_DIR/${SERVER_NAME}.pid`
#else
PID=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
#fi
if [ -z "$PID" ];then
echo "The program is not running"
exit 1
fi
pcount=`ps --no-heading -p $PID | wc -l`
if [ "$pcount" -ne 1 ];then
echo "ERROR: $SERVER_NAME does not started!"
exit 1
fi
echo -e "Stopping $SERVER_NAME ...\c"
kill $PID > /dev/null 2>&1
COUNT=0
ctime=`date +"%s"`
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
PID_EXIST=`ps --no-heading -p $PID`
if [ -n "$PID_EXIST" ]; then
ctime2=`date +"%s"`
dtime=$((ctime2 - ctime))
if [ "$dtime" -ge 10 ];then
echo -e "\nstop program timeout, use kill -9 $PID"
kill -9 $PID >/dev/null 2>&1
if [ ! $? -eq 0 ];then
echo "No permissions"
exit 2
else
rm -rf $PID_DIR/${SERVER_NAME}.pid
fi
fi
COUNT=0
continue
fi
done
echo "OK!"
rm -rf $PID_DIR/${SERVER_NAME}.pid
\ No newline at end of file
package cn.com.glsx.test;
import cn.com.glsx.Application;
import cn.com.glsx.base.modules.entity.BaseCity;
import com.glsx.plat.redis.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PublicApplicationTests {
@Autowired
private RedisUtils redisUtils;
@Test
public void testRedisSet() {
BaseCity baseCity = new BaseCity();
baseCity.setId(111L);
baseCity.setProvCode("6565");
baseCity.setCode("6596556");
baseCity.setName("大唐");
redisUtils.set("baseCity", baseCity);
}
@Test
public void testRedisGet() {
BaseCity baseCity = (BaseCity) redisUtils.get("baseCity");
System.out.println(baseCity);
}
}
\ No newline at end of file
package cn.com.glsx.test;
import cn.com.glsx.Application;
import cn.com.glsx.base.modules.converter.DictDataConverter;
import cn.com.glsx.base.modules.entity.SysDictData;
import cn.com.glsx.base.modules.service.DictDataService;
import cn.com.glsx.publiccenter.api.dto.response.SysDictDataResponse;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
/**
* @Desc:
* @Author huangxc
* @Date 2021/5/31
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SysDictDataTest {
@Autowired
private DictDataService dictDataService;
@Test
public void findByDictTest() {
SysDictData sysDictData = new SysDictData();
sysDictData.setDictLabel("混动雅阁");
sysDictData.setDictType("");
sysDictData.setDictValue("");
List<SysDictData> sysDictDataList = dictDataService.findByDict(sysDictData);
List<SysDictDataResponse> responseList = Lists.newArrayList();
sysDictDataList.forEach(u -> {
responseList.add(DictDataConverter.INSTANCE.do2foo(u));
});
System.out.println(JSONObject.toJSONString(responseList));
}
@Test
public void getDictDataByIdTest() {
SysDictData sysDictData = dictDataService.getDictDataById(90L);
SysDictDataResponse response = null;
if (sysDictData != null) {
response = DictDataConverter.INSTANCE.do2foo(sysDictData);
}
System.out.println(JSONObject.toJSONString(response));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!