dto注释

segment2.0
beeajax 2 years ago
parent 0347e222a5
commit cfb75d8d04

@ -12,7 +12,7 @@ import org.springframework.retry.annotation.EnableRetry;
@Slf4j @Slf4j
@EnableFeignClients(basePackages = ("com.docus.core.excel.feign")) @EnableFeignClients(basePackages = ("com.docus.core.excel.feign"))
//@EnableHystrix //@EnableHystrix
//@MapperScan("com.docus.server.**.mapper") //@MapperScan("com.docus.server.**.baseMapper")
@SpringBootApplication(scanBasePackages = {"com.docus"}) @SpringBootApplication(scanBasePackages = {"com.docus"})
@EnableRetry @EnableRetry
@EnableTrackGroup @EnableTrackGroup

@ -124,7 +124,7 @@ mybatis-plus:
update-strategy: ignored update-strategy: ignored
field-strategy: NOT_EMPTY field-strategy: NOT_EMPTY
db-type: MYSQL db-type: MYSQL
mapper-locations: classpath*:/mapper/*Mapper.xml,file:mybatis.mapper/**/*Mapper.xml mapper-locations: classpath*:/baseMapper/*Mapper.xml,file:mybatis.baseMapper/**/*Mapper.xml
type-enums-package: com.docus.server.collect.web.enums type-enums-package: com.docus.server.collect.web.enums
xxl: xxl:

@ -1,10 +1,14 @@
package com.docus.server.collect.user.view; package com.docus.server.collect.user.view;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.docus.core.util.Func;
import com.docus.core.util.ListUtils; import com.docus.core.util.ListUtils;
import com.docus.server.collect.ICollector; import com.docus.server.collect.ICollector;
import com.docus.server.collect.web.job.AbstractCollectJob; import com.docus.server.collect.web.job.AbstractCollectJob;
import com.docus.server.his.service.IHisService; import com.docus.server.his.service.IHisService;
import com.docus.server.sys.common.pojo.dto.UserDTO; import com.docus.server.sys.common.pojo.dto.UserDTO;
import com.docus.server.sys.common.pojo.entity.PowerUser;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -42,7 +46,31 @@ public class UserViewCollectJob extends AbstractCollectJob<UserDTO> {
@Override @Override
public void batchInsertOrUpdate(List<UserDTO> t) { public void batchInsertOrUpdate(List<UserDTO> t) {
int insertcount = 0;
int updatecount = 0;
List<String> userNames = ListUtils.distinctSelect(t, UserDTO::getUserName); List<String> userNames = ListUtils.distinctSelect(t, UserDTO::getUserName);
LambdaQueryWrapper<PowerUser> query = Wrappers.lambdaQuery();
if (Func.isNotEmpty(userNames)) {
query.in(PowerUser::getUserName, userNames);
}
List<PowerUser> powerUsers = userService.getBaseMapper().selectList(query);
List<String> existUserNames = ListUtils.distinctSelect(powerUsers, PowerUser::getUserName);
t.forEach(p -> {
String userName = p.getUserName();
if (existUserNames.contains(userName)) {
powerThirdLoginService
} else {
long userid = 0;
insertcount += repositiory.SaveUser(o, userProperties.getDefpwd());
userid = repositiory.getUserId(userName);
long thirdid = SnowflakeIdWorker.generateId();
repositiory.SaveThirdLogin(thirdid, userid, userName, String.valueOf(o.get(PWDKey)));
}
});
log.info("本次" + businessName + "新增:" + insertcount + "笔;更新数据:" + updatecount + "笔");
userService.batchInsertOrUpdatePowerUser(t); userService.batchInsertOrUpdatePowerUser(t);
} }

@ -8,6 +8,7 @@ import com.docus.server.collect.web.service.ITaskConfigService;
import com.docus.server.collect.web.utils.PeriodTime; import com.docus.server.collect.web.utils.PeriodTime;
import com.docus.server.record.service.ITBasicService; import com.docus.server.record.service.ITBasicService;
import com.docus.server.sys.service.IPowerDeptService; import com.docus.server.sys.service.IPowerDeptService;
import com.docus.server.sys.service.IPowerThirdLoginService;
import com.docus.server.sys.service.IPowerUserService; import com.docus.server.sys.service.IPowerUserService;
import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.context.XxlJobHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,6 +23,8 @@ public abstract class AbstractCollectJob<T> implements IJob<T> {
@Resource @Resource
protected IPowerUserService userService; protected IPowerUserService userService;
@Resource @Resource
protected IPowerThirdLoginService powerThirdLoginService;
@Resource
protected IPowerDeptService deptService; protected IPowerDeptService deptService;
@Autowired @Autowired
protected ITBasicService basicService; protected ITBasicService basicService;

@ -0,0 +1,164 @@
package com.docus.server.sys.common;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public abstract class BaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseService<T> {
private static final Logger logger = LoggerFactory.getLogger(BaseService.class);
@Override
public T findById(String id) {
if (id == null) {
throw new RuntimeException("param id is required");
}
return baseMapper.selectById(id);
}
public List<T> findByIds(Collection<String> ids) {
if (ids == null || ids.size() == 0) {
return new ArrayList<>();
}
return baseMapper.selectBatchIds(ids);
}
/**
*
*/
public List<T> findBy(String propertyName, Object propertyValue) {
String columnName = getColumnName(propertyName);
return baseMapper.selectList(new QueryWrapper<T>().eq(columnName, propertyValue));
}
public List<T> findActiveBy(String propertyName, Object propertyValue) {
String columnName = getColumnName(propertyName);
QueryWrapper<T> queryWrapper = new QueryWrapper<T>().eq(columnName, propertyValue);
queryWrapper.ne("state", 1);
return baseMapper.selectList(queryWrapper);
}
//返回所有匹配的记录并排序
public List<T> findBy(String propertyName, Object propertyValue, Sort sort) {
String columnName = getColumnName(propertyName);
QueryWrapper<T> query = new QueryWrapper<T>().eq(columnName, propertyValue);
buildSort(sort, query);
return baseMapper.selectList(query);
}
/**
* Active
*/
public List<T> findActiveBy(String propertyName, Object propertyValue, Sort sort) {
String columnName = getColumnName(propertyName);
QueryWrapper<T> query = new QueryWrapper<T>().eq(columnName, propertyValue);
query.ne("state", 1);
buildSort(sort, query);
return baseMapper.selectList(query);
}
//按字段查询,返回第-条记录
public T findOneBy(String propertyName, Object propertyValue) {
String columnName = getColumnName(propertyName);
return baseMapper.selectOne(new QueryWrapper<T>().eq(columnName, propertyValue));
}
//按字段查询返回第一条Active 记录
public T findActiveOneBy(String propertyName, Object propertyValue) {
String columnName = getColumnName(propertyName);
QueryWrapper<T> queryWrapper = new QueryWrapper<T>().eq(columnName, propertyValue);
queryWrapper.ne("state", 1);
return baseMapper.selectOne(queryWrapper);
}
//* L ambda方式自由组合查询条件
public List<T> find(LambdaQueryWrapper<T> queryWrapper) {
return baseMapper.selectList(queryWrapper);
}
//L ambda方式自由组合查询条件返回第一条记录
public T findone(LambdaQueryWrapper<T> queryWrapper) {
return baseMapper.selectOne(queryWrapper);
}
//返回表所有记录
public List<T> findAll() {
return baseMapper.selectList(null);
}
//返回表所有Active的记录
public List<T> findA1lActive() {
return baseMapper.selectList(Wrappers.<T>query().ne("state", 1));
}
//返回表所有记录并排序
public List<T> findA1l(Sort sort) {
QueryWrapper<T> query = new QueryWrapper<T>();
buildSort(sort, query);
return baseMapper.selectList(query);
}
//返回表所有Active记录并排序
public List<T> findAllActive(Sort sort) {
QueryWrapper<T> query = new QueryWrapper<T>();
query.ne("state", 1);
buildSort(sort, query);
return baseMapper.selectList(query);
}
//组装排序语句
private void buildSort(Sort sort, QueryWrapper<T> query) {
if (sort != null) {
List<Sort.SortItem> sortList = sort.getSortList();
for (Sort.SortItem sortItem : sortList) {
if (sortItem.getDirection() == Sort.Direction.ASC) {
query.orderByAsc(getColumnName(sortItem.getProperty()));
} else {
query.orderByDesc(getColumnName(sortItem.getProperty()));
}
}
}
}
public int deleteByIdList(List<String> idList) {
if (idList == null || idList.size() == 0) {
return 0;
}
return baseMapper.deleteBatchIds(idList);
}
//通过实体属性获取对应的数据库字段名
public String getColumnName(String propertyName) {
Map<String, Field> fieldMap = ReflectionKit.getFieldMap(getEntityClass());
if (fieldMap != null) {
Field field = fieldMap.get(propertyName);
if (field != null) {
TableField annotation = field.getAnnotation(TableField.class);
if (annotation != null) {
return annotation.value();
}
TableId idAnnotation = field.getAnnotation(TableId.class);
if (idAnnotation != null) {
return idAnnotation.value();
}
}
}
throw new RuntimeException("获取不到属性" + propertyName + "的列名");
}
}

@ -0,0 +1,22 @@
package com.docus.server.sys.common;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Collection;
import java.util.List;
public interface IBaseService<T> extends IService<T> {
public T findById(String id);
public List<T> findByIds(Collection<String> ids);
public List<T> findBy(String propertyName, Object propertyValue);
public List<T> findActiveBy(String propertyName, Object propertyValue);
public List<T> findBy(String propertyName, Object propertyValue, Sort sort);
public List<T> findActiveBy(String propertyName, Object propertyValue, Sort sort);
}

@ -0,0 +1,62 @@
package com.docus.server.sys.common;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
//排序定义
public class Sort {
private List<SortItem> sortByProperties = new ArrayList<>();
// 隐藏构造函数
private Sort() {
}
public static Sort byAsc(String property) {
return new Sort().thenByAsc(property);
}
public static Sort byDesc(String property) {
return new Sort().thenByDesc(property);
}
public Sort thenByAsc(String property) {
sortByProperties.add(new SortItem(property, Direction.ASC));
return this;
}
public Sort thenByDesc(String property) {
sortByProperties.add(new SortItem(property, Direction.DESC));
return this;
}
public List<SortItem> getSortList() {
//复制、只读
List<SortItem> copyList = new ArrayList<>(sortByProperties);
return Collections.unmodifiableList(copyList);
}
public class SortItem {
private String property;
private Direction direction;
private SortItem(String property, Direction direction) {
this.property = property;
this.direction = direction;
}
public String getProperty() {
return property;
}
public Direction getDirection() {
return direction;
}
}
public enum Direction {
ASC, DESC;
}
}

@ -15,6 +15,10 @@ public class UserDTO {
* *
*/ */
private String userName; private String userName;
/**
*
*/
private String pwd;
/** /**
* *
*/ */

@ -0,0 +1,48 @@
package com.docus.server.sys.common.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author jiashi
* @since 2021-04-26
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="PowerThirdLogin对象", description="第三方登陆")
public class PowerThirdLogin implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@TableId(value = "id", type = IdType.ID_WORKER_STR)
private Long id;
@ApiModelProperty(value = "power_user表id")
private String powerUserId;
@ApiModelProperty(value = "用户")
private String user;
@ApiModelProperty(value = "密码")
private String pwd;
@ApiModelProperty(value = "来源")
private Integer source;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

@ -0,0 +1,16 @@
package com.docus.server.sys.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.docus.server.sys.common.pojo.entity.PowerThirdLogin;
/**
* <p>
* Mapper
* </p>
*
* @author jiashi
* @since 2021-04-26
*/
public interface PowerThirdLoginMapper extends BaseMapper<PowerThirdLogin> {
}

@ -0,0 +1,16 @@
package com.docus.server.sys.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.docus.server.sys.common.pojo.entity.PowerThirdLogin;
/**
* <p>
*
* </p>
*
* @author jiashi
* @since 2021-04-26
*/
public interface IPowerThirdLoginService extends IService<PowerThirdLogin> {
}

@ -0,0 +1,22 @@
package com.docus.server.sys.service.impl;
import com.docus.server.sys.common.BaseService;
import com.docus.server.sys.common.pojo.entity.PowerThirdLogin;
import com.docus.server.sys.mapper.PowerThirdLoginMapper;
import com.docus.server.sys.service.IPowerThirdLoginService;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author jiashi
* @since 2021-04-26
*/
@Service
public class PowerThirdLoginServiceImpl extends BaseService<PowerThirdLoginMapper, PowerThirdLogin> implements IPowerThirdLoginService {
}
Loading…
Cancel
Save