Commit 2cf6e347 authored by liqin's avatar liqin 💬

bug fixed

parent bb5a9983
...@@ -7,8 +7,8 @@ public class MysqlGenerator { ...@@ -7,8 +7,8 @@ public class MysqlGenerator {
"asset_type", "asset_type",
"board_talking", "board_talking",
"copyright_owner", "copyright_owner",
"copytight_owner_asset_type", "copyright_owner_asset_type",
"copytight_owner_board_type", "copyright_owner_board_type",
"exhibition_board", "exhibition_board",
"exhibition_board_cat", "exhibition_board_cat",
"learning_content", "learning_content",
......
package cn.wisenergy.chnmuseum.party.common.validator;
import cn.wisenergy.chnmuseum.party.common.enums.RESPONSE_CODE_ENUM;
import cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException;
import com.google.common.base.Splitter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
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.RestControllerAdvice;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;
import java.util.stream.Collectors;
/**
* 全局异常处理
*
* @author Danny Lee
* @date 2019/8/1
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvisor {
/**
* 捕获全局异常,处理所有不可知的异常
*
* @param exception 异常对象
*/
@ExceptionHandler(Exception.class)
public Object handleException(Exception exception) {
log.error("\r\n ************** 操作出现异常:{}", ExceptionUtils.getStackTrace(exception));
Class<?> eClass = exception.getClass();
HttpResult httpResult = new HttpResult();
if (eClass.equals(HttpRequestMethodNotSupportedException.class)) {
addResCodeToMap(RESPONSE_CODE_ENUM.METHOD_NOT_SUPPORTED, httpResult);
} else if (eClass.equals(HttpMediaTypeNotAcceptableException.class)) {
addResCodeToMap(RESPONSE_CODE_ENUM.MEDIA_TYPE_NOT_ACCEPT, httpResult);
} else if (eClass.equals(HttpMediaTypeNotSupportedException.class)) {
addResCodeToMap(RESPONSE_CODE_ENUM.MEDIA_TYPE_NOT_SUPPORTED, httpResult);
} else if (eClass.equals(ConversionNotSupportedException.class)) {
addResCodeToMap(RESPONSE_CODE_ENUM.SERVER_ERROR, httpResult);
} else if (eClass.equals(HttpMessageNotWritableException.class)) {
addResCodeToMap(RESPONSE_CODE_ENUM.SERVER_ERROR, httpResult);
} else {
addResCodeToMap(RESPONSE_CODE_ENUM.SERVER_ERROR, httpResult);
}
return httpResult;
}
@ExceptionHandler(BindException.class)
@ResponseBody
public HttpResult handle(BindException ex) {
String message = ex.getBindingResult().getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(" \n "));
// BindingResult bindingResult = ex.getBindingResult();
// StringBuilder errMsg = new StringBuilder(bindingResult.getFieldErrors().size() * 16);
// errMsg.append("Invalid request:");
// for (int i = 0; i < bindingResult.getFieldErrors().size(); i++) {
// if (i > 0) {
// errMsg.append(",");
// }
// FieldError error = bindingResult.getFieldErrors().get(i);
// errMsg.append(error.getField()).append(":").append(error.getDefaultMessage());
// }
return new HttpResult(400, message);
//throw new InterfaceException(RESPONSE_CODE_ENUM.PARAM_NOT_VALID.getCode(), errMsg.toString());
}
//处理请求参数格式错误 @RequestParam上validate失败后抛出的异常是javax.validation.ConstraintViolationException
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
public String constraintViolationExceptionHandler(ConstraintViolationException e) {
return e.getConstraintViolations().stream().map(ConstraintViolation::getMessage).collect(Collectors.joining());
}
/**
* 处理请求参数格式错误 @RequestBody上validate失败后抛出的异常是MethodArgumentNotValidException异常。
*
* @param exception 错误信息集合
* @return 错误信息
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public HttpResult validationBodyException(MethodArgumentNotValidException exception) {
BindingResult result = exception.getBindingResult();
String msg = null;
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
for (ObjectError objectError : errors) {
FieldError fieldError = (FieldError) objectError;
if (fieldError.getDefaultMessage() != null) {
log.info("Data check failure : object{" + fieldError.getObjectName() + "},field{" + fieldError.getField() +
"},errorMessage{" + fieldError.getDefaultMessage() + "}");
msg = fieldError.getDefaultMessage();
}
}
}
return new HttpResult(400, msg);
}
@ExceptionHandler(DataAccessException.class)
public HttpResult dataAccessException(DataAccessException exception) {
return new HttpResult(400, exception.getLocalizedMessage());
}
@ExceptionHandler(DuplicateKeyException.class)
@ResponseBody
public HttpResult duplicateKeyException(DuplicateKeyException e) {
String localizedMessage = e.getLocalizedMessage();
String message = Splitter.on(System.lineSeparator()).trimResults().splitToList(localizedMessage).get(1);
String substring = message.substring(message.indexOf("Exception:"));
if (substring.toUpperCase().contains("NAME")) {
return new HttpResult(400, "名称已存在");
} else if (substring.toUpperCase().contains("CODE")) {
return new HttpResult(400, "编码已存在");
}
return new HttpResult(400, message);
}
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
@ResponseBody
public HttpResult sqlIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException e) {
String localizedMessage = e.getLocalizedMessage();
String message = Splitter.on(System.lineSeparator()).trimResults().splitToList(localizedMessage).get(1);
String substring = message.substring(message.indexOf("Exception:"));
if (substring.toUpperCase().contains("NAME")) {
return new HttpResult(400, "名称已存在");
} else if (substring.toUpperCase().contains("CODE")) {
return new HttpResult(400, "编码已存在");
}
return new HttpResult(400, message);
}
/**
* 参数类型转换错误
*
* @param exception 错误
* @return 错误信息
*/
@ExceptionHandler(HttpMessageConversionException.class)
public HttpResult httpMessageConversionException(HttpMessageConversionException exception) {
log.error(exception.getCause().getLocalizedMessage());
return new HttpResult(400, exception.getCause().getLocalizedMessage());
}
/**
* 捕获业务异常
*
* @param exception 自定义接口异常类
* @return 返回的异常信息map
*/
@ExceptionHandler(InterfaceException.class)
public HttpResult handleInterfaceException(InterfaceException exception) {
HttpResult httpResult = new HttpResult();
httpResult.setCode(Integer.parseInt(exception.getErrorCode()));
httpResult.setMsg(exception.getErrorMsg());
return httpResult;
}
/**
* 捕获Shiro无权限异常 未授权异常
*
* @param exception 无权限异常
* @return 返回的异常信息map
*/
@ExceptionHandler(UnauthorizedException.class)
public Object handleUnauthorizedException(UnauthorizedException exception) {
HttpResult httpResult = new HttpResult();
// 无权限
addResCodeToMap(RESPONSE_CODE_ENUM.UNAUTHORIZED, httpResult);
return httpResult;
}
/**
* 捕获Shiro无权限异常 未认证异常
*
* @param exception 无权限异常
* @return 返回的异常信息map
*/
@ExceptionHandler(UnauthenticatedException.class)
public Object handleUnauthenticatedException(UnauthenticatedException exception) {
HttpResult httpResult = new HttpResult();
// 无权限
addResCodeToMap(RESPONSE_CODE_ENUM.UNAUTHORIZED, httpResult);
return httpResult;
}
/**
* 添加异常信息到map中
*
* @param responseCodeEnum 错误响应编码枚举类对象
* @param httpResult 响应对象
*/
private void addResCodeToMap(RESPONSE_CODE_ENUM responseCodeEnum, HttpResult httpResult) {
httpResult.setCode(Integer.parseInt(responseCodeEnum.getCode()));
httpResult.setMsg(responseCodeEnum.getMsg());
}
}
package cn.wisenergy.chnmuseum.party.common.validator;
public class HttpResult {
// 响应的状态码
private int code;
// 响应的响应信息
private String msg;
// 响应的响应体
private Object body;
public HttpResult() {
}
public HttpResult(int code, String msg) {
this.code = code;
this.msg = msg;
}
public HttpResult(int code, Object body) {
this.code = code;
this.body = body;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getBody() {
return body;
}
public void setBody(Object body) {
this.body = body;
}
@Override
public String toString() {
return "{" +
"\"code\":" + code +
", \"msg\":" + "\"" + msg + "\"" +
", \"body\":" + body +
'}';
}
}
...@@ -38,18 +38,20 @@ public class FastJsonHttpMessageConvertersConfig { ...@@ -38,18 +38,20 @@ public class FastJsonHttpMessageConvertersConfig {
SerializerFeature.WriteMapNullValue, SerializerFeature.WriteMapNullValue,
SerializerFeature.DisableCircularReferenceDetect SerializerFeature.DisableCircularReferenceDetect
); );
// 处理ie浏览器保存数据时出现下载json数据问题 // 全局时间配置
fastJsonConfig.setDateFormat("yyyy-MM-dd");
// 处理中文乱码问题
List<MediaType> mediaTypes = new ArrayList<>(); List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON); mediaTypes.add(MediaType.APPLICATION_JSON);
mediaTypes.add(MediaType.TEXT_PLAIN); mediaTypes.add(MediaType.TEXT_PLAIN);
//mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8"))); //mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8")));
converter.setSupportedMediaTypes(mediaTypes); converter.setSupportedMediaTypes(mediaTypes);
// o 是class,s 是key值,o1 是value值 // o 是class,s 是key值,o1 是value值
ValueFilter valueFilter = (o, s, o1) -> { ValueFilter valueFilter = (o1, s, o2) -> {
if (null == o1) { if (null == o2) {
o1 = ""; o2 = "";
} }
return o1; return o2;
}; };
fastJsonConfig.setSerializeFilters(valueFilter); fastJsonConfig.setSerializeFilters(valueFilter);
converter.setFastJsonConfig(fastJsonConfig); converter.setFastJsonConfig(fastJsonConfig);
......
...@@ -18,9 +18,7 @@ import org.slf4j.LoggerFactory; ...@@ -18,9 +18,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import org.springframework.core.annotation.Order;
import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPoolConfig;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -29,8 +27,8 @@ import java.util.LinkedHashMap; ...@@ -29,8 +27,8 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Configuration //@Configuration
@Order(1) //@Order(1)
public class ShiroConfig { public class ShiroConfig {
private static final Logger logger = LoggerFactory.getLogger(ShiroConfig.class); private static final Logger logger = LoggerFactory.getLogger(ShiroConfig.class);
......
package cn.wisenergy.chnmuseum.party.mapper; package cn.wisenergy.chnmuseum.party.mapper;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerAssetType; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerAssetType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/** /**
* <p> * <pre>
* 版权方视频分类 Mapper 接口 * 版权方视频分类 Mapper 接口
* </p> * </pre>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
public interface CopytightOwnerAssetTypeMapper extends BaseMapper<CopytightOwnerAssetType> { @Repository
public interface CopyrightOwnerAssetTypeMapper extends BaseMapper<CopyrightOwnerAssetType> {
} }
package cn.wisenergy.chnmuseum.party.mapper; package cn.wisenergy.chnmuseum.party.mapper;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerBoardType; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerBoardType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/** /**
* <p> * <pre>
* 版权方展板分类 Mapper 接口 * 版权方展板分类 Mapper 接口
* </p> * </pre>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
public interface CopytightOwnerBoardTypeMapper extends BaseMapper<CopytightOwnerBoardType> { @Repository
public interface CopyrightOwnerBoardTypeMapper extends BaseMapper<CopyrightOwnerBoardType> {
} }
...@@ -59,4 +59,8 @@ public class AssetType implements Serializable { ...@@ -59,4 +59,8 @@ public class AssetType implements Serializable {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime; private LocalDateTime updateTime;
@ApiModelProperty("版权方")
@TableField(exist = false)
private String copyrightOwnerName;
} }
...@@ -12,6 +12,7 @@ import javax.validation.constraints.NotBlank; ...@@ -12,6 +12,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* <p> * <p>
...@@ -69,4 +70,16 @@ public class CopyrightOwner implements Serializable { ...@@ -69,4 +70,16 @@ public class CopyrightOwner implements Serializable {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime; private LocalDateTime updateTime;
@ApiModelProperty("视频分类ID集合(详情使用)")
@TableField(exist = false)
private List<String> assetTypeIdList;
@ApiModelProperty("视频分类名称集合(详情使用)")
@TableField(exist = false)
private List<String> assetTypeNameList;
@ApiModelProperty("视频分类名称(列表使用)")
@TableField(exist = false)
private String assetTypeNames;
} }
package cn.wisenergy.chnmuseum.party.model; package cn.wisenergy.chnmuseum.party.model;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add; import com.baomidou.mybatisplus.annotation.TableName;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import com.baomidou.mybatisplus.annotations.Version;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import com.baomidou.mybatisplus.annotation.TableField;
/** /**
* <p> * <p>
...@@ -21,7 +28,7 @@ import java.io.Serializable; ...@@ -21,7 +28,7 @@ import java.io.Serializable;
* </p> * </p>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-17 * @since 2021-03-18
*/ */
@Data @Data
@Builder @Builder
...@@ -29,9 +36,9 @@ import java.io.Serializable; ...@@ -29,9 +36,9 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("copytight_owner_asset_type") @TableName("copyright_owner_asset_type")
@ApiModel(value = "版权方视频分类", description = "版权方视频分类") @ApiModel(value = "版权方视频分类", description = "版权方视频分类")
public class CopytightOwnerAssetType implements Serializable { public class CopyrightOwnerAssetType implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -49,4 +56,7 @@ public class CopytightOwnerAssetType implements Serializable { ...@@ -49,4 +56,7 @@ public class CopytightOwnerAssetType implements Serializable {
@NotBlank(message = "视频分类ID不能为空", groups = {Add.class, Update.class}) @NotBlank(message = "视频分类ID不能为空", groups = {Add.class, Update.class})
private String assetTypeId; private String assetTypeId;
} }
...@@ -21,7 +21,7 @@ import java.io.Serializable; ...@@ -21,7 +21,7 @@ import java.io.Serializable;
* </p> * </p>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-17 * @since 2021-03-18
*/ */
@Data @Data
@Builder @Builder
...@@ -29,9 +29,9 @@ import java.io.Serializable; ...@@ -29,9 +29,9 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("copytight_owner_board_type") @TableName("copyright_owner_board_type")
@ApiModel(value = "版权方展板分类", description = "版权方展板分类") @ApiModel(value = "版权方展板分类", description = "版权方展板分类")
public class CopytightOwnerBoardType implements Serializable { public class CopyrightOwnerBoardType implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
package cn.wisenergy.chnmuseum.party.model; package cn.wisenergy.chnmuseum.party.model;
import com.baomidou.mybatisplus.annotation.TableName; import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import com.baomidou.mybatisplus.annotation.IdType; import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import com.baomidou.mybatisplus.annotation.Version; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import com.baomidou.mybatisplus.annotations.Version;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import com.baomidou.mybatisplus.annotation.TableField; import java.io.Serializable;
import java.time.LocalDateTime;
/** /**
* <p> * <p>
......
package cn.wisenergy.chnmuseum.party.service; package cn.wisenergy.chnmuseum.party.service;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerAssetType; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerAssetType;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
/** /**
* <p> * <p>
* 版权方视频分类 服务 * 版权方视频分类 服务接口
* </p> * </p>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
public interface CopytightOwnerAssetTypeService extends IService<CopytightOwnerAssetType> { public interface CopyrightOwnerAssetTypeService extends IService<CopyrightOwnerAssetType> {
} }
package cn.wisenergy.chnmuseum.party.service; package cn.wisenergy.chnmuseum.party.service;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerBoardType; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerBoardType;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
/** /**
* <p> * <p>
* 版权方展板分类 服务 * 版权方展板分类 服务接口
* </p> * </p>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
public interface CopytightOwnerBoardTypeService extends IService<CopytightOwnerBoardType> { public interface CopyrightOwnerBoardTypeService extends IService<CopyrightOwnerBoardType> {
} }
package cn.wisenergy.chnmuseum.party.service.impl; package cn.wisenergy.chnmuseum.party.service.impl;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerAssetType; import cn.wisenergy.chnmuseum.party.mapper.CopyrightOwnerAssetTypeMapper;
import cn.wisenergy.chnmuseum.party.mapper.CopytightOwnerAssetTypeMapper; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerAssetType;
import cn.wisenergy.chnmuseum.party.service.CopytightOwnerAssetTypeService; import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerAssetTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* <p> * <pre>
* 版权方视频分类 服务实现类 * 版权方视频分类 服务实现类
* </p> * </pre>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
@Slf4j
@Service @Service
public class CopytightOwnerAssetTypeServiceImpl extends ServiceImpl<CopytightOwnerAssetTypeMapper, CopytightOwnerAssetType> implements CopytightOwnerAssetTypeService { public class CopyrightOwnerAssetTypeServiceImpl extends ServiceImpl<CopyrightOwnerAssetTypeMapper, CopyrightOwnerAssetType> implements CopyrightOwnerAssetTypeService {
} }
package cn.wisenergy.chnmuseum.party.service.impl; package cn.wisenergy.chnmuseum.party.service.impl;
import cn.wisenergy.chnmuseum.party.model.CopytightOwnerBoardType; import cn.wisenergy.chnmuseum.party.mapper.CopyrightOwnerBoardTypeMapper;
import cn.wisenergy.chnmuseum.party.mapper.CopytightOwnerBoardTypeMapper; import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerBoardType;
import cn.wisenergy.chnmuseum.party.service.CopytightOwnerBoardTypeService; import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerBoardTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* <p> * <pre>
* 版权方展板分类 服务实现类 * 版权方展板分类 服务实现类
* </p> * </pre>
* *
* @author Danny Lee * @author Danny Lee
* @since 2021-03-16 * @since 2021-03-18
*/ */
@Slf4j
@Service @Service
public class CopytightOwnerBoardTypeServiceImpl extends ServiceImpl<CopytightOwnerBoardTypeMapper, CopytightOwnerBoardType> implements CopytightOwnerBoardTypeService { public class CopyrightOwnerBoardTypeServiceImpl extends ServiceImpl<CopyrightOwnerBoardTypeMapper, CopyrightOwnerBoardType> implements CopyrightOwnerBoardTypeService {
} }
...@@ -4,12 +4,8 @@ import cn.wisenergy.chnmuseum.party.common.enums.CopyrightOwnerTypeEnum; ...@@ -4,12 +4,8 @@ import cn.wisenergy.chnmuseum.party.common.enums.CopyrightOwnerTypeEnum;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add; import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update; import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam; import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
import cn.wisenergy.chnmuseum.party.model.Asset; import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.model.CopyrightOwner; import cn.wisenergy.chnmuseum.party.service.*;
import cn.wisenergy.chnmuseum.party.model.ExhibitionBoard;
import cn.wisenergy.chnmuseum.party.service.AssetService;
import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerService;
import cn.wisenergy.chnmuseum.party.service.ExhibitionBoardService;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController; import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
...@@ -26,8 +22,10 @@ import org.springframework.validation.annotation.Validated; ...@@ -26,8 +22,10 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* <pre> * <pre>
...@@ -49,6 +47,12 @@ public class CopyrightOwnerController extends BaseController { ...@@ -49,6 +47,12 @@ public class CopyrightOwnerController extends BaseController {
@Resource @Resource
private AssetService assetService; private AssetService assetService;
@Resource
private AssetTypeService assetTypeService;
@Resource
private CopyrightOwnerAssetTypeService copyrightOwnerAssetTypeService;
@Resource @Resource
private ExhibitionBoardService exhibitionBoardService; private ExhibitionBoardService exhibitionBoardService;
...@@ -59,6 +63,19 @@ public class CopyrightOwnerController extends BaseController { ...@@ -59,6 +63,19 @@ public class CopyrightOwnerController extends BaseController {
copyrightOwner.setOwnerType(copyrightOwnerTypeEnum.name()); copyrightOwner.setOwnerType(copyrightOwnerTypeEnum.name());
// 保存业务节点信息 // 保存业务节点信息
boolean result = copyrightOwnerService.save(copyrightOwner); boolean result = copyrightOwnerService.save(copyrightOwner);
List<String> assetTypeIdList = copyrightOwner.getAssetTypeIdList();
if (assetTypeIdList != null && !assetTypeIdList.isEmpty()) {
List<CopyrightOwnerAssetType> copyrightOwnerAssetTypeList = new ArrayList<>();
for (String assetTypeId : assetTypeIdList) {
copyrightOwnerAssetTypeList.add(CopyrightOwnerAssetType.builder()
.assetTypeId(assetTypeId)
.copyrightOwnerId(copyrightOwner.getId())
.build());
}
this.copyrightOwnerAssetTypeService.saveBatch(copyrightOwnerAssetTypeList);
}
// 返回操作结果 // 返回操作结果
if (result) { if (result) {
return getSuccessResult(); return getSuccessResult();
...@@ -74,6 +91,21 @@ public class CopyrightOwnerController extends BaseController { ...@@ -74,6 +91,21 @@ public class CopyrightOwnerController extends BaseController {
public Map<String, Object> updateCopyrightOwner(@Validated(value = {Update.class}) CopyrightOwner copyrightOwner, @RequestParam("copyrightOwnerType") CopyrightOwnerTypeEnum copyrightOwnerTypeEnum) { public Map<String, Object> updateCopyrightOwner(@Validated(value = {Update.class}) CopyrightOwner copyrightOwner, @RequestParam("copyrightOwnerType") CopyrightOwnerTypeEnum copyrightOwnerTypeEnum) {
copyrightOwner.setOwnerType(copyrightOwnerTypeEnum.name()); copyrightOwner.setOwnerType(copyrightOwnerTypeEnum.name());
boolean flag = copyrightOwnerService.updateById(copyrightOwner); boolean flag = copyrightOwnerService.updateById(copyrightOwner);
List<String> assetTypeIdList = copyrightOwner.getAssetTypeIdList();
if (assetTypeIdList != null && !assetTypeIdList.isEmpty()) {
LambdaUpdateWrapper<CopyrightOwnerAssetType> updateWrapper = Wrappers.<CopyrightOwnerAssetType>lambdaUpdate().eq(CopyrightOwnerAssetType::getCopyrightOwnerId, copyrightOwner.getId());
this.copyrightOwnerAssetTypeService.remove(updateWrapper);
List<CopyrightOwnerAssetType> copyrightOwnerAssetTypeList = new ArrayList<>();
for (String assetTypeId : assetTypeIdList) {
copyrightOwnerAssetTypeList.add(CopyrightOwnerAssetType.builder()
.assetTypeId(assetTypeId)
.copyrightOwnerId(copyrightOwner.getId())
.build());
}
this.copyrightOwnerAssetTypeService.saveBatch(copyrightOwnerAssetTypeList);
}
if (flag) { if (flag) {
return getSuccessResult(); return getSuccessResult();
} }
...@@ -87,17 +119,19 @@ public class CopyrightOwnerController extends BaseController { ...@@ -87,17 +119,19 @@ public class CopyrightOwnerController extends BaseController {
@ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String") @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String")
}) })
public Map<String, Object> deleteCopyrightOwner(@PathVariable("id") String id) { public Map<String, Object> deleteCopyrightOwner(@PathVariable("id") String id) {
boolean result = copyrightOwnerService.removeById(id); LambdaUpdateWrapper<Asset> updateWrapper = Wrappers.<Asset>lambdaUpdate().eq(Asset::getAssetCopyrightOwnerId, id);
updateWrapper.set(Asset::getAssetCopyrightOwnerId, null);
boolean result1 = this.assetService.update(updateWrapper);
LambdaUpdateWrapper<Asset> updateWrapper1 = Wrappers.<Asset>lambdaUpdate().eq(Asset::getAssetCopyrightOwnerId, id); LambdaUpdateWrapper<ExhibitionBoard> updateWrapper1 = Wrappers.<ExhibitionBoard>lambdaUpdate().eq(ExhibitionBoard::getCopyrightOwnerId, id);
updateWrapper1.set(Asset::getAssetCopyrightOwnerId, null); updateWrapper1.set(ExhibitionBoard::getCopyrightOwnerId, null);
boolean result1 = this.assetService.update(updateWrapper1); boolean result2 = this.exhibitionBoardService.update(updateWrapper1);
LambdaUpdateWrapper<ExhibitionBoard> updateWrapper = Wrappers.<ExhibitionBoard>lambdaUpdate().eq(ExhibitionBoard::getCopyrightOwnerId, id); LambdaUpdateWrapper<CopyrightOwnerAssetType> updateWrapper2 = Wrappers.<CopyrightOwnerAssetType>lambdaUpdate().eq(CopyrightOwnerAssetType::getCopyrightOwnerId, id);
updateWrapper.set(ExhibitionBoard::getCopyrightOwnerId, null); boolean result3 = this.copyrightOwnerAssetTypeService.remove(updateWrapper2);
boolean result2 = this.exhibitionBoardService.update(updateWrapper);
if (result && result1 && result2) { boolean result = this.copyrightOwnerService.removeById(id);
if (result && result1 && result2 && result3) {
return getSuccessResult(); return getSuccessResult();
} }
return getFailResult(); return getFailResult();
...@@ -142,7 +176,11 @@ public class CopyrightOwnerController extends BaseController { ...@@ -142,7 +176,11 @@ public class CopyrightOwnerController extends BaseController {
CopyrightOwner::getUpdateTime); CopyrightOwner::getUpdateTime);
Page<CopyrightOwner> page = this.copyrightOwnerService.page(getPage(), queryWrapper); Page<CopyrightOwner> page = this.copyrightOwnerService.page(getPage(), queryWrapper);
for (CopyrightOwner copyrightOwner : page.getRecords()) { for (CopyrightOwner copyrightOwner : page.getRecords()) {
final List<CopyrightOwnerAssetType> CopyrightOwnerAssetTypeList = this.copyrightOwnerAssetTypeService.list(Wrappers.<CopyrightOwnerAssetType>lambdaQuery().eq(CopyrightOwnerAssetType::getCopyrightOwnerId, copyrightOwner.getId()));
final List<String> idList = CopyrightOwnerAssetTypeList.stream().map(CopyrightOwnerAssetType::getAssetTypeId).collect(Collectors.toList());
List<AssetType> assetTypeList = this.assetTypeService.listByIds(idList);
final String assetTypeNameList = assetTypeList.stream().map(AssetType::getName).collect(Collectors.joining("、"));
copyrightOwner.setAssetTypeNames(assetTypeNameList);
} }
return getResult(page); return getResult(page);
} }
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.chnmuseum.party.mapper.CopytightOwnerAssetTypeMapper"> <mapper namespace="cn.wisenergy.chnmuseum.party.mapper.CopyrightOwnerAssetTypeMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.wisenergy.chnmuseum.party.model.CopytightOwnerAssetType"> <resultMap id="BaseResultMap" type="cn.wisenergy.chnmuseum.party.model.CopyrightOwnerAssetType">
<id column="id" property="id" /> <id column="id" property="id"/>
<result column="copyright_owner_id" property="copyrightOwnerId" /> <result column="copyright_owner_id" property="copyrightOwnerId"/>
<result column="asset_type_id" property="assetTypeId" /> <result column="asset_type_id" property="assetTypeId"/>
</resultMap> </resultMap>
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.chnmuseum.party.mapper.CopytightOwnerBoardTypeMapper"> <mapper namespace="cn.wisenergy.chnmuseum.party.mapper.CopyrightOwnerBoardTypeMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.wisenergy.chnmuseum.party.model.CopytightOwnerBoardType"> <resultMap id="BaseResultMap" type="cn.wisenergy.chnmuseum.party.model.CopyrightOwnerBoardType">
<id column="id" property="id" /> <id column="id" property="id"/>
<result column="copyright_owner_id" property="copyrightOwnerId" /> <result column="copyright_owner_id" property="copyrightOwnerId"/>
<result column="board_type_id" property="boardTypeId" /> <result column="board_type_id" property="boardTypeId"/>
</resultMap> </resultMap>
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
......
package ${package.Mapper}; package ${package.Mapper};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${superMapperClassPackage}; import ${superMapperClassPackage};
import ${package.Entity}.${entity}; import ${package.Entity}.${entity};
import ${cfg.paging};
import ${cfg.pageParamPath};
import ${cfg.queryVoPath};
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
/** /**
* <pre> * <pre>
...@@ -23,27 +14,7 @@ import java.io.Serializable; ...@@ -23,27 +14,7 @@ import java.io.Serializable;
#if(${kotlin}) #if(${kotlin})
interface ${table.mapperName} : ${superMapperClass}<${entity}> interface ${table.mapperName} : ${superMapperClass}<${entity}>
#else #else
@Repository
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
#if(${cfg.generatorStrategy})
/*
* 根据ID获取查询对象
*
* @param id
* @return
*/
${entity}QueryVo get${entity}ById(Serializable id);
/*
* 获取分页对象
*
* @param page
* @param ${cfg.entityObjectName}PageParam
* @return
*/
IPage<${entity}QueryVo> get${entity}PageList(@Param("page") Page page, @Param("param") ${entity}PageParam ${cfg.entityObjectName}PageParam);
#end
} }
#end #end
package ${package.Service} package ${package.Service};
import ${package.Entity}.${entity}; import ${package.Entity}.${entity};
import ${superServiceClassPackage}; import ${superServiceClassPackage};
import ${cfg.paging};
import ${cfg.pageParamPath};
import ${cfg.queryVoPath};
/** /**
* <p> * <p>
...@@ -49,23 +46,6 @@ public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { ...@@ -49,23 +46,6 @@ public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
boolean delete${entity}(Long id) throws Exception; boolean delete${entity}(Long id) throws Exception;
#end #end
/**
* 根据ID获取查询对象
*
* @param id
* @return
* @throws Exception
*/
${entity}QueryVo get${entity}ById(Serializable id) throws Exception;
/**
* 获取分页对象
*
* @param ${cfg.entityObjectName}PageParam
* @return
* @throws Exception
*/
Paging<${entity}QueryVo> get${entity}PageList(${entity}PageParam ${cfg.entityObjectName}PageParam) throws Exception;
#end #end
} }
#end #end
...@@ -3,10 +3,6 @@ package ${package.ServiceImpl}; ...@@ -3,10 +3,6 @@ package ${package.ServiceImpl};
import ${package.Entity}.${entity}; import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName}; import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName}; import ${package.Service}.${table.serviceName};
import ${cfg.paging};
import ${cfg.pageParamPath};
import ${cfg.commonPageUtilPath};
import ${cfg.queryVoPath};
import ${superServiceImplClassPackage}; import ${superServiceImplClassPackage};
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -14,12 +10,6 @@ import org.springframework.stereotype.Service; ...@@ -14,12 +10,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
/** /**
* <pre> * <pre>
* $!{table.comment} 服务实现类 * $!{table.comment} 服务实现类
...@@ -35,7 +25,7 @@ open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperNam ...@@ -35,7 +25,7 @@ open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperNam
} }
#else #else
public class ${table.serviceImplName} extends BaseServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} { public class ${table.serviceImplName} extends ServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} {
@Autowired @Autowired
private ${table.mapperName} ${cfg.mapperObjectName}; private ${table.mapperName} ${cfg.mapperObjectName};
...@@ -60,18 +50,6 @@ public class ${table.serviceImplName} extends BaseServiceImpl<${table.mapperName ...@@ -60,18 +50,6 @@ public class ${table.serviceImplName} extends BaseServiceImpl<${table.mapperName
return super.removeById(id); return super.removeById(id);
} }
#end #end
@Override
public ${entity}QueryVo get${entity}ById(Serializable id) throws Exception {
return ${cfg.mapperObjectName}.get${entity}ById(id);
}
@Override
public Paging<${entity}QueryVo> get${entity}PageList(${entity}PageParam ${cfg.entityObjectName}PageParam) throws Exception {
Page page = PageUtil.getPage(${cfg.entityObjectName}PageParam, OrderItem.desc(getLambdaColumn(${entity}::getCreateTime)));
IPage<${entity}QueryVo> iPage = ${cfg.mapperObjectName}.get${entity}PageList(page, ${cfg.entityObjectName}PageParam);
return new Paging(iPage);
}
#end #end
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment