diff --git a/collect-sdry/src/main/java/com/docus/server/AppRunBootstrap.java b/collect-sdry/src/main/java/com/docus/server/AppRunBootstrap.java index 6cd683b..4a4ed0e 100644 --- a/collect-sdry/src/main/java/com/docus/server/AppRunBootstrap.java +++ b/collect-sdry/src/main/java/com/docus/server/AppRunBootstrap.java @@ -12,7 +12,7 @@ import org.springframework.retry.annotation.EnableRetry; @Slf4j @EnableFeignClients(basePackages = ("com.docus.core.excel.feign")) //@EnableHystrix -//@MapperScan("com.docus.server.**.mapper") +//@MapperScan("com.docus.server.**.baseMapper") @SpringBootApplication(scanBasePackages = {"com.docus"}) @EnableRetry @EnableTrackGroup diff --git a/collect-sdry/src/main/resources/bootstrap.yml b/collect-sdry/src/main/resources/bootstrap.yml index 6fc1285..985f0b6 100644 --- a/collect-sdry/src/main/resources/bootstrap.yml +++ b/collect-sdry/src/main/resources/bootstrap.yml @@ -124,7 +124,7 @@ mybatis-plus: update-strategy: ignored field-strategy: NOT_EMPTY 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 xxl: diff --git a/common-collect/src/main/java/com/docus/server/collect/user/view/UserViewCollectJob.java b/common-collect/src/main/java/com/docus/server/collect/user/view/UserViewCollectJob.java index de3a2fd..e747e74 100644 --- a/common-collect/src/main/java/com/docus/server/collect/user/view/UserViewCollectJob.java +++ b/common-collect/src/main/java/com/docus/server/collect/user/view/UserViewCollectJob.java @@ -1,10 +1,14 @@ 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.server.collect.ICollector; import com.docus.server.collect.web.job.AbstractCollectJob; import com.docus.server.his.service.IHisService; 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 org.springframework.stereotype.Component; @@ -42,7 +46,31 @@ public class UserViewCollectJob extends AbstractCollectJob { @Override public void batchInsertOrUpdate(List t) { + int insertcount = 0; + int updatecount = 0; List userNames = ListUtils.distinctSelect(t, UserDTO::getUserName); + LambdaQueryWrapper query = Wrappers.lambdaQuery(); + if (Func.isNotEmpty(userNames)) { + query.in(PowerUser::getUserName, userNames); + } + List powerUsers = userService.getBaseMapper().selectList(query); + List 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); } diff --git a/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java b/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java index a920395..24b947c 100644 --- a/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java +++ b/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java @@ -8,6 +8,7 @@ import com.docus.server.collect.web.service.ITaskConfigService; import com.docus.server.collect.web.utils.PeriodTime; import com.docus.server.record.service.ITBasicService; import com.docus.server.sys.service.IPowerDeptService; +import com.docus.server.sys.service.IPowerThirdLoginService; import com.docus.server.sys.service.IPowerUserService; import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; @@ -22,6 +23,8 @@ public abstract class AbstractCollectJob implements IJob { @Resource protected IPowerUserService userService; @Resource + protected IPowerThirdLoginService powerThirdLoginService; + @Resource protected IPowerDeptService deptService; @Autowired protected ITBasicService basicService; diff --git a/docus-sys/src/main/java/com/docus/server/sys/common/BaseService.java b/docus-sys/src/main/java/com/docus/server/sys/common/BaseService.java new file mode 100644 index 0000000..77c4ac4 --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/common/BaseService.java @@ -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, T> extends ServiceImpl implements IBaseService { + + 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 findByIds(Collection ids) { + if (ids == null || ids.size() == 0) { + return new ArrayList<>(); + } + return baseMapper.selectBatchIds(ids); + } + + /** + * 按字段查询,返回所有匹配的记录 + */ + public List findBy(String propertyName, Object propertyValue) { + String columnName = getColumnName(propertyName); + return baseMapper.selectList(new QueryWrapper().eq(columnName, propertyValue)); + } + + public List findActiveBy(String propertyName, Object propertyValue) { + String columnName = getColumnName(propertyName); + QueryWrapper queryWrapper = new QueryWrapper().eq(columnName, propertyValue); + queryWrapper.ne("state", 1); + return baseMapper.selectList(queryWrapper); + } + + //返回所有匹配的记录并排序 + public List findBy(String propertyName, Object propertyValue, Sort sort) { + String columnName = getColumnName(propertyName); + QueryWrapper query = new QueryWrapper().eq(columnName, propertyValue); + buildSort(sort, query); + return baseMapper.selectList(query); + } + + /** + * 返回所有匹配的Active记录并排序 + */ + public List findActiveBy(String propertyName, Object propertyValue, Sort sort) { + String columnName = getColumnName(propertyName); + QueryWrapper query = new QueryWrapper().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().eq(columnName, propertyValue)); + } + + //按字段查询,返回第一条Active 记录 + public T findActiveOneBy(String propertyName, Object propertyValue) { + String columnName = getColumnName(propertyName); + QueryWrapper queryWrapper = new QueryWrapper().eq(columnName, propertyValue); + queryWrapper.ne("state", 1); + return baseMapper.selectOne(queryWrapper); + } + + //* L ambda方式自由组合查询条件 + public List find(LambdaQueryWrapper queryWrapper) { + return baseMapper.selectList(queryWrapper); + } + + //L ambda方式自由组合查询条件,返回第一条记录 + public T findone(LambdaQueryWrapper queryWrapper) { + return baseMapper.selectOne(queryWrapper); + } + + //返回表所有记录 + public List findAll() { + return baseMapper.selectList(null); + } + + //返回表所有Active的记录 + public List findA1lActive() { + return baseMapper.selectList(Wrappers.query().ne("state", 1)); + } + + //返回表所有记录并排序 + public List findA1l(Sort sort) { + QueryWrapper query = new QueryWrapper(); + buildSort(sort, query); + return baseMapper.selectList(query); + } + + //返回表所有Active记录并排序 + public List findAllActive(Sort sort) { + QueryWrapper query = new QueryWrapper(); + query.ne("state", 1); + buildSort(sort, query); + return baseMapper.selectList(query); + } + + //组装排序语句 + private void buildSort(Sort sort, QueryWrapper query) { + if (sort != null) { + List 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 idList) { + if (idList == null || idList.size() == 0) { + return 0; + } + return baseMapper.deleteBatchIds(idList); + } + + + //通过实体属性获取对应的数据库字段名 + public String getColumnName(String propertyName) { + Map 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 + "的列名"); + } +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/common/IBaseService.java b/docus-sys/src/main/java/com/docus/server/sys/common/IBaseService.java new file mode 100644 index 0000000..75e8c10 --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/common/IBaseService.java @@ -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 extends IService { + + public T findById(String id); + + public List findByIds(Collection ids); + + public List findBy(String propertyName, Object propertyValue); + + public List findActiveBy(String propertyName, Object propertyValue); + + public List findBy(String propertyName, Object propertyValue, Sort sort); + + public List findActiveBy(String propertyName, Object propertyValue, Sort sort); + +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/common/Sort.java b/docus-sys/src/main/java/com/docus/server/sys/common/Sort.java new file mode 100644 index 0000000..5e2a6fd --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/common/Sort.java @@ -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 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 getSortList() { + //复制、只读 + List 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; + } +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/common/pojo/dto/UserDTO.java b/docus-sys/src/main/java/com/docus/server/sys/common/pojo/dto/UserDTO.java index 6f2c9ce..f4be868 100644 --- a/docus-sys/src/main/java/com/docus/server/sys/common/pojo/dto/UserDTO.java +++ b/docus-sys/src/main/java/com/docus/server/sys/common/pojo/dto/UserDTO.java @@ -15,6 +15,10 @@ public class UserDTO { * 用户工号 */ private String userName; + /** + * 第三方用户密码 + */ + private String pwd; /** * 用户姓名 */ diff --git a/docus-sys/src/main/java/com/docus/server/sys/common/pojo/entity/PowerThirdLogin.java b/docus-sys/src/main/java/com/docus/server/sys/common/pojo/entity/PowerThirdLogin.java new file mode 100644 index 0000000..1925f1b --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/common/pojo/entity/PowerThirdLogin.java @@ -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; + +/** + *

+ * 第三方登陆 + *

+ * + * @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; + + +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/mapper/PowerThirdLoginMapper.java b/docus-sys/src/main/java/com/docus/server/sys/mapper/PowerThirdLoginMapper.java new file mode 100644 index 0000000..f3f8ea4 --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/mapper/PowerThirdLoginMapper.java @@ -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; + +/** + *

+ * 第三方登陆 Mapper 接口 + *

+ * + * @author jiashi + * @since 2021-04-26 + */ +public interface PowerThirdLoginMapper extends BaseMapper { + +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java b/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java new file mode 100644 index 0000000..a5ab043 --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java @@ -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; + +/** + *

+ * 第三方登陆 服务类 + *

+ * + * @author jiashi + * @since 2021-04-26 + */ +public interface IPowerThirdLoginService extends IService { + +} diff --git a/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java b/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java new file mode 100644 index 0000000..7b5b608 --- /dev/null +++ b/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java @@ -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; + +/** + *

+ * 第三方登陆 服务实现类 + *

+ * + * @author jiashi + * @since 2021-04-26 + */ +@Service +public class PowerThirdLoginServiceImpl extends BaseService implements IPowerThirdLoginService { + + +} +