parent
d99b538fd0
commit
a10a934b40
|
|
@ -19,7 +19,15 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-tools</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.czg.config;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsFilter implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) resp;
|
||||
HttpServletRequest reqs = (HttpServletRequest) req;
|
||||
String curOrigin = reqs.getHeader("Origin");
|
||||
response.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
|
||||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("Access-Control-Allow-Headers", "token");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
chain.doFilter(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.czg.exception;
|
||||
|
||||
import com.czg.resp.CzgRespCode;
|
||||
import com.czg.resp.CzgResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class CzgControllerAdvice {
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> errorHandler(Exception ex) {
|
||||
setErrorLog(ex);
|
||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public CzgResult<Object> requestParamException(MethodArgumentNotValidException ex) {
|
||||
setErrorLog(ex);
|
||||
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
|
||||
String message = allErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(";"));
|
||||
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), message);
|
||||
}
|
||||
|
||||
private void setErrorLog(Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -41,5 +41,11 @@
|
|||
<artifactId>tomcat-embed-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>api-config</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.group.InsertGroup;
|
||||
import com.czg.group.UpdateGroup;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.system.dto.SysParamsDTO;
|
||||
import com.czg.service.system.service.SysParamsService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@RequestMapping("/admin/sysParams")
|
||||
@RestController
|
||||
public class SysParamController {
|
||||
|
||||
@Resource
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
/**
|
||||
* 新增参数
|
||||
*
|
||||
* @param paramsDTO 参数
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public CzgResult<Long> insertParams(@RequestBody @Validated({InsertGroup.class}) SysParamsDTO paramsDTO) {
|
||||
return sysParamsService.insertParams(paramsDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数
|
||||
* @param paramsDTO 参数
|
||||
* @return 修改结果
|
||||
*/
|
||||
@PutMapping
|
||||
public CzgResult<Long> updateParams(@RequestBody @Validated({UpdateGroup.class}) SysParamsDTO paramsDTO) {
|
||||
return sysParamsService.updateParams(paramsDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
package com.czg.service.system.dto;
|
||||
|
||||
import com.czg.group.InsertGroup;
|
||||
import com.czg.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -7,9 +11,16 @@ import lombok.Data;
|
|||
*/
|
||||
@Data
|
||||
public class SysParamsDTO {
|
||||
@NotNull(message = "id不能为空", groups = {UpdateGroup.class})
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "参数编码不能为空", groups = {UpdateGroup.class, InsertGroup.class})
|
||||
private String paramCode;
|
||||
|
||||
@NotBlank(message = "参数值不能为空", groups = {UpdateGroup.class, InsertGroup.class})
|
||||
private String paramValue;
|
||||
|
||||
@NotNull(message = "参数类型不能为空", groups = {UpdateGroup.class, InsertGroup.class})
|
||||
private Integer paramType;
|
||||
private String remark;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
package com.czg.service.system.service.impl;
|
||||
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.system.dto.SysParamsDTO;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.service.system.entity.SysParams;
|
||||
import com.czg.service.system.mapper.SysParamsMapper;
|
||||
import com.czg.service.system.service.SysParamsService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +60,8 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
|
|||
.setParamType(paramsDTO.getParamType())
|
||||
.setUpdateUserId(userId);
|
||||
|
||||
updateById(sysParams);
|
||||
|
||||
return CzgResult.success(sysParams.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue