终端商户池派单
This commit is contained in:
parent
d528e0fe89
commit
ccb787514f
|
|
@ -1,60 +0,0 @@
|
|||
package com.chushang.inspection.terminal.query;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DispatchQuery implements Serializable {
|
||||
|
||||
/** 终端id */
|
||||
private List<Long> ids;
|
||||
|
||||
/** 任务id */
|
||||
@NotNull(message = "必须指定任务")
|
||||
private Long taskId;
|
||||
|
||||
/** 业务员id */
|
||||
private Long userId;
|
||||
|
||||
/** 工单类型 */
|
||||
@NotNull(message = "必须指定工单类型")
|
||||
@Range(min = 1, max = 50, message = "工单类型非法")
|
||||
private Integer workType;
|
||||
|
||||
/** 截至时间 */
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN)
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/** 工单优先级 */
|
||||
private Integer workSort ;
|
||||
|
||||
/** 备注 */
|
||||
@Size(max = 100, message = "备注不能超过100个字符")
|
||||
private String remark;
|
||||
|
||||
/** 工单来源 */
|
||||
@Range(min = 1, max = 4, message = "工单来源非法")
|
||||
private Integer workSource;
|
||||
|
||||
/** 商户号 */
|
||||
private List<String> nos ;
|
||||
|
||||
/** 终端号 */
|
||||
private List<String> terminalNos ;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -64,6 +64,10 @@ public class DispatchQuery implements Serializable {
|
|||
@Builder.Default
|
||||
private List<String> terminalNos = ListUtil.toList();
|
||||
|
||||
/** 是否被占用*/
|
||||
private Integer occupy;
|
||||
|
||||
|
||||
public DispatchQuery dispatchOrder(WrkIcbcJs entity, Long userId) {
|
||||
this.terminalIds = ListUtil.toList(entity.getTerminalId());
|
||||
this.taskId = 1701151817643495425L;
|
||||
|
|
|
|||
|
|
@ -66,9 +66,6 @@ public class InsDetailController {
|
|||
detail.setDetailId(null);
|
||||
Long configId = detail.getConfigId();
|
||||
AssertUtil.invalidate(null == configId, "巡检单配置id 不能为空");
|
||||
|
||||
detail.setDeptId(SecurityUtils.getDeptId());
|
||||
|
||||
String configKey = detail.getConfigKey();
|
||||
AssertUtil.invalidate(null == configKey, "巡检单配置key 不能为空");
|
||||
|
||||
|
|
|
|||
|
|
@ -85,18 +85,5 @@ public class TerminalController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 派单-批量派单
|
||||
* @param query 条件
|
||||
*/
|
||||
@SysLog(value = "派单-批量派单", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/dispatch/app")
|
||||
@RequiresPermissions("ins:terminal:dispatch")
|
||||
public AjaxResult dispatch(@RequestBody @Validated TerminalQuery query) {
|
||||
Terminal terminal = BeanUtil.copyProperties(query, Terminal.class);
|
||||
// terminalService.dispatch(terminal)
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import com.chushang.inspection.terminal.po.Terminal;
|
|||
import com.chushang.inspection.terminal.query.TerminalAppQuery;
|
||||
import com.chushang.inspection.terminal.query.TerminalQuery;
|
||||
import com.chushang.inspection.terminal.vo.TerminalVO;
|
||||
import com.chushang.inspection.work.dto.DispatchDTO;
|
||||
import com.chushang.inspection.work.query.DispatchQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -24,10 +26,7 @@ public interface TerminalMapper extends BaseMapper<Terminal> {
|
|||
@DataScope(deptAlias = "t")
|
||||
List<TerminalAppVO> selectPageApp(@Param("query") TerminalAppQuery query, Page<TerminalAppVO> page);
|
||||
|
||||
@DataScope(deptAlias = "t")
|
||||
List<DispatchDTO> getStoreByTasKIdOrIds(@Param("query") DispatchQuery query);
|
||||
|
||||
List<TerminalVO> getStoreByTasKIdOrIds(@Param("taskId")Long taskId,
|
||||
@Param("ids")List<Long> ids,
|
||||
@Param("nos")List<String> nos,
|
||||
@Param("terminalNos")List<String> terminalNos,
|
||||
@Param("i")int i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.chushang.common.mybatis.utils.PageResult;
|
||||
import com.chushang.inspection.project.vo.TerminalApp;
|
||||
import com.chushang.inspection.terminal.po.Terminal;
|
||||
import com.chushang.inspection.terminal.query.DispatchQuery;
|
||||
import com.chushang.inspection.terminal.query.TerminalAppQuery;
|
||||
import com.chushang.inspection.terminal.query.TerminalQuery;
|
||||
import com.chushang.inspection.terminal.vo.TerminalVO;
|
||||
import com.chushang.inspection.work.po.WrkInfo;
|
||||
import com.chushang.inspection.work.dto.DispatchDTO;
|
||||
import com.chushang.inspection.work.query.DispatchQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -38,12 +36,17 @@ public interface TerminalService extends IService<Terminal>{
|
|||
TerminalApp getAppById(Long terminalId, Long taskId);
|
||||
|
||||
/**
|
||||
* 派单 id
|
||||
* @param query
|
||||
* 修改终端占用状态
|
||||
* @param terminalIds
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
List<WrkInfo> dispatch(DispatchQuery query, int i);
|
||||
void updateOccupy(List<Long> terminalIds, int i);
|
||||
|
||||
List<DispatchDTO> getStoreByTasKIdOrIds(Long taskId, List<Long> termintalIds, List<String> nos, List<String> terminalNos, int i);
|
||||
/**
|
||||
* 查询终端商户巡检信息
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
List<DispatchDTO> getStoreByTasKIdOrIds(DispatchQuery query);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,10 @@ import com.chushang.common.dict.utils.DictUtils;
|
|||
import com.chushang.common.mybatis.enums.Operator;
|
||||
import com.chushang.common.mybatis.page.CommonParam;
|
||||
import com.chushang.common.mybatis.utils.PageResult;
|
||||
import com.chushang.common.mybatis.utils.WrapperUtils;
|
||||
import com.chushang.datascope.annotation.DataScope;
|
||||
import com.chushang.inspection.project.vo.TerminalApp;
|
||||
import com.chushang.inspection.project.vo.TerminalAppVO;
|
||||
import com.chushang.inspection.terminal.po.Store;
|
||||
import com.chushang.inspection.terminal.po.Terminal;
|
||||
import com.chushang.inspection.terminal.query.DispatchQuery;
|
||||
import com.chushang.inspection.terminal.query.TerminalAppQuery;
|
||||
import com.chushang.inspection.terminal.query.TerminalQuery;
|
||||
import com.chushang.inspection.terminal.service.StoreService;
|
||||
|
|
@ -23,7 +20,7 @@ import com.chushang.inspection.terminal.vo.TerminalVO;
|
|||
import com.chushang.inspection.utils.TaskConfigUtils;
|
||||
import com.chushang.inspection.work.dto.DispatchDTO;
|
||||
import com.chushang.inspection.work.po.WrkInfo;
|
||||
import com.sun.xml.bind.v2.TODO;
|
||||
import com.chushang.inspection.work.query.DispatchQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chushang.inspection.terminal.mapper.TerminalMapper;
|
||||
|
|
@ -79,15 +76,17 @@ public class TerminalServiceImpl extends ServiceImpl<TerminalMapper, Terminal> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DispatchDTO> getStoreByTasKIdOrIds(Long taskId, List<Long> ids, List<String> nos, List<String> terminalNos, int i) {
|
||||
return List.of();
|
||||
public void updateOccupy(List<Long> terminalIds, int i) {
|
||||
for (Long terminalId : terminalIds) {
|
||||
Terminal terminal = getById(terminalId);
|
||||
terminal.setOccupy(i);
|
||||
baseMapper.updateById(terminal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WrkInfo> dispatch(DispatchQuery query, int i) {
|
||||
// TODO 先关联终端和商户查询出来要派单的终端信息 然后通过派单方式走不同的策略拼接wrk_entity实体
|
||||
// 落入wrk_info表 然后修改终端占用 终端进度表没啥用
|
||||
public List<DispatchDTO> getStoreByTasKIdOrIds(DispatchQuery query) {
|
||||
return baseMapper.getStoreByTasKIdOrIds(query);
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,207 @@
|
|||
package com.chushang.inspection.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.SimpleCache;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.cglib.beans.BeanCopier;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
import org.springframework.cglib.core.Converter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>bean深拷贝工具(基于 cglib 性能优异)</h1>
|
||||
*
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BeanCopyUtils {
|
||||
|
||||
/**
|
||||
* <h2>单对象基于class创建拷贝</h2>
|
||||
*
|
||||
* @param source 数据来源实体
|
||||
* @param desc 描述对象 转换后的对象
|
||||
* @return desc
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public static <T, V> V copy(T source, Class<V> desc) {
|
||||
if (ObjectUtil.isNull(source)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(desc)) {
|
||||
return null;
|
||||
}
|
||||
final V target = ReflectUtil.newInstanceIfPossible(desc);
|
||||
return copy(source, target);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>单对象基于对象创建拷贝</h2>
|
||||
*
|
||||
* @param source 数据来源实体
|
||||
* @param desc 转换后的对象
|
||||
* @return desc
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public static <T, V> V copy(T source, V desc) {
|
||||
if (ObjectUtil.isNull(source)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(desc)) {
|
||||
return null;
|
||||
}
|
||||
BeanCopier beanCopier = BeanCopierCache.INSTANCE.get(source.getClass(), desc.getClass(), null);
|
||||
beanCopier.copy(source, desc, null);
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>列表对象基于class创建拷贝</h2>
|
||||
*
|
||||
* @param sourceList 数据来源实体列表
|
||||
* @param desc 描述对象 转换后的对象
|
||||
* @return desc
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public static <T, V> List<V> copyList(List<T> sourceList, Class<V> desc) {
|
||||
if (ObjectUtil.isNull(sourceList)) {
|
||||
return null;
|
||||
}
|
||||
if (CollUtil.isEmpty(sourceList)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return StreamUtils.toList(sourceList, source -> {
|
||||
V target = ReflectUtil.newInstanceIfPossible(desc);
|
||||
copy(source, target);
|
||||
return target;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>bean拷贝到map</h2>
|
||||
*
|
||||
* @param bean 数据来源实体
|
||||
* @return map对象
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Map<String, Object> copyToMap(T bean) {
|
||||
if (ObjectUtil.isNull(bean)) {
|
||||
return null;
|
||||
}
|
||||
return BeanMap.create(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>map拷贝到bean</h2>
|
||||
*
|
||||
* @param map 数据来源
|
||||
* @param beanClass bean类
|
||||
* @return bean对象
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public static <T> T mapToBean(Map<String, Object> map, Class<T> beanClass) {
|
||||
if (MapUtil.isEmpty(map)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(beanClass)) {
|
||||
return null;
|
||||
}
|
||||
T bean = ReflectUtil.newInstanceIfPossible(beanClass);
|
||||
return mapToBean(map, bean);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>map拷贝到bean</h2>
|
||||
*
|
||||
* @param map 数据来源
|
||||
* @param bean bean对象
|
||||
* @return bean对象
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public static <T> T mapToBean(Map<String, Object> map, T bean) {
|
||||
if (MapUtil.isEmpty(map)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(bean)) {
|
||||
return null;
|
||||
}
|
||||
BeanMap.create(bean).putAll(map);
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h1>BeanCopier属性缓存</h1>
|
||||
*
|
||||
* <p>
|
||||
* 缓存用于防止多次反射造成的性能问题
|
||||
* </p>
|
||||
*
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public enum BeanCopierCache {
|
||||
/**
|
||||
* BeanCopier属性缓存单例
|
||||
*/
|
||||
INSTANCE;
|
||||
|
||||
private final SimpleCache<String, BeanCopier> cache = new SimpleCache<>();
|
||||
|
||||
|
||||
/**
|
||||
* <h2>获得类与转换器生成的key在{@link BeanCopier}的Map中对应的元素</h2>
|
||||
*
|
||||
* @param srcClass 源Bean的类
|
||||
* @param targetClass 目标Bean的类
|
||||
* @param converter 转换器
|
||||
* @return Map中对应的BeanCopier
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
public BeanCopier get(Class<?> srcClass, Class<?> targetClass, Converter converter) {
|
||||
final String key = genKey(srcClass, targetClass, converter);
|
||||
return cache.get(key, () -> BeanCopier.create(srcClass, targetClass, converter != null));
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获得类与转换器生成的key</h2>
|
||||
*
|
||||
* @param srcClass 源Bean的类
|
||||
* @param targetClass 目标Bean的类
|
||||
* @param converter 转换器
|
||||
* @return 属性名和Map映射的key
|
||||
* @author 单傲
|
||||
* @date 2023/1/10 11:15
|
||||
*/
|
||||
private String genKey(Class<?> srcClass, Class<?> targetClass, Converter converter) {
|
||||
final StringBuilder key = StrUtil.builder()
|
||||
.append(srcClass.getName()).append('#').append(targetClass.getName());
|
||||
if (null != converter) {
|
||||
key.append('#').append(converter.getClass().getName());
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
package com.chushang.inspection.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h2>stream 流工具类</h2>
|
||||
*
|
||||
* @author 单傲
|
||||
* @date 2023/1/17 15:20
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class StreamUtils {
|
||||
|
||||
/**
|
||||
* <h2>将collection过滤</h2>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param function 过滤方法
|
||||
* @author 单傲
|
||||
* @date 2023/1/17 15:20
|
||||
*/
|
||||
public static <E> List<E> filter(Collection<E> collection, Predicate<E> function) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return collection.stream().filter(function).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>将collection拼接</h2>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param function 拼接方法
|
||||
* @author 单傲
|
||||
* @date 2023/1/17 15:20
|
||||
*/
|
||||
public static <E> String join(Collection<E> collection, Function<E, String> function) {
|
||||
return join(collection, function, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>将collection拼接</h2>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param function 拼接方法
|
||||
* @param delimiter 拼接符
|
||||
* @return 拼接后的list
|
||||
* @author 单傲
|
||||
* @date 2023/1/17 15:20
|
||||
*/
|
||||
public static <E> String join(Collection<E> collection, Function<E, String> function, CharSequence delimiter) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
return collection.stream().map(function).filter(Objects::nonNull).collect(Collectors.joining(delimiter));
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>将collection拼接</h2>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param comparing 排序方法
|
||||
* @return 拼接后的list
|
||||
* @author 单傲
|
||||
* @date 2023/1/17 15:20
|
||||
*/
|
||||
public static <E> List<E> sorted(Collection<E> collection, Comparator<E> comparing) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return collection.stream().sorted(comparing).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将collection转化为类型不变的map<br>
|
||||
* <B>{@code Collection<V> ----> Map<K,V>}</B>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param key V类型转化为K类型的lambda方法
|
||||
* @param <V> collection中的泛型
|
||||
* @param <K> map中的key类型
|
||||
* @return 转化后的map
|
||||
*/
|
||||
public static <V, K> Map<K, V> toIdentityMap(Collection<V> collection, Function<V, K> key) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return MapUtil.newHashMap();
|
||||
}
|
||||
return collection.stream().collect(Collectors.toMap(key, Function.identity(), (l, r) -> l));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Collection转化为map(value类型与collection的泛型不同)<br>
|
||||
* <B>{@code Collection<E> -----> Map<K,V> }</B>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param key E类型转化为K类型的lambda方法
|
||||
* @param value E类型转化为V类型的lambda方法
|
||||
* @param <E> collection中的泛型
|
||||
* @param <K> map中的key类型
|
||||
* @param <V> map中的value类型
|
||||
* @return 转化后的map
|
||||
*/
|
||||
public static <E, K, V> Map<K, V> toMap(Collection<E> collection, Function<E, K> key, Function<E, V> value) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return MapUtil.newHashMap();
|
||||
}
|
||||
return collection.stream().collect(Collectors.toMap(key, value, (l, r) -> l));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将collection按照规则(比如有相同的班级id)分类成map<br>
|
||||
* <B>{@code Collection<E> -------> Map<K,List<E>> } </B>
|
||||
*
|
||||
* @param collection 需要分类的集合
|
||||
* @param key 分类的规则
|
||||
* @param <E> collection中的泛型
|
||||
* @param <K> map中的key类型
|
||||
* @return 分类后的map
|
||||
*/
|
||||
public static <E, K> Map<K, List<E>> groupByKey(Collection<E> collection, Function<E, K> key) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return MapUtil.newHashMap();
|
||||
}
|
||||
return collection
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(key, LinkedHashMap::new, Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map<br>
|
||||
* <B>{@code Collection<E> ---> Map<T,Map<U,List<E>>> } </B>
|
||||
*
|
||||
* @param collection 需要分类的集合
|
||||
* @param key1 第一个分类的规则
|
||||
* @param key2 第二个分类的规则
|
||||
* @param <E> 集合元素类型
|
||||
* @param <K> 第一个map中的key类型
|
||||
* @param <U> 第二个map中的key类型
|
||||
* @return 分类后的map
|
||||
*/
|
||||
public static <E, K, U> Map<K, Map<U, List<E>>> groupBy2Key(Collection<E> collection, Function<E, K> key1, Function<E, U> key2) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return MapUtil.newHashMap();
|
||||
}
|
||||
return collection
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.groupingBy(key2, LinkedHashMap::new, Collectors.toList())));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map<br>
|
||||
* <B>{@code Collection<E> ---> Map<T,Map<U,E>> } </B>
|
||||
*
|
||||
* @param collection 需要分类的集合
|
||||
* @param key1 第一个分类的规则
|
||||
* @param key2 第二个分类的规则
|
||||
* @param <T> 第一个map中的key类型
|
||||
* @param <U> 第二个map中的key类型
|
||||
* @param <E> collection中的泛型
|
||||
* @return 分类后的map
|
||||
*/
|
||||
public static <E, T, U> Map<T, Map<U, E>> group2Map(Collection<E> collection, Function<E, T> key1, Function<E, U> key2) {
|
||||
if (CollUtil.isEmpty(collection) || key1 == null || key2 == null) {
|
||||
return MapUtil.newHashMap();
|
||||
}
|
||||
return collection
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.toMap(key2, Function.identity(), (l, r) -> l)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将collection转化为List集合,但是两者的泛型不同<br>
|
||||
* <B>{@code Collection<E> ------> List<T> } </B>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param function collection中的泛型转化为list泛型的lambda表达式
|
||||
* @param <E> collection中的泛型
|
||||
* @param <T> List中的泛型
|
||||
* @return 转化后的list
|
||||
*/
|
||||
public static <E, T> List<T> toList(Collection<E> collection, Function<E, T> function) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return collection
|
||||
.stream()
|
||||
.map(function)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将collection转化为Set集合,但是两者的泛型不同<br>
|
||||
* <B>{@code Collection<E> ------> Set<T> } </B>
|
||||
*
|
||||
* @param collection 需要转化的集合
|
||||
* @param function collection中的泛型转化为set泛型的lambda表达式
|
||||
* @param <E> collection中的泛型
|
||||
* @param <T> Set中的泛型
|
||||
* @return 转化后的Set
|
||||
*/
|
||||
public static <E, T> Set<T> toSet(Collection<E> collection, Function<E, T> function) {
|
||||
if (CollUtil.isEmpty(collection) || function == null) {
|
||||
return CollUtil.newHashSet();
|
||||
}
|
||||
return collection
|
||||
.stream()
|
||||
.map(function)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 合并两个相同key类型的map
|
||||
*
|
||||
* @param map1 第一个需要合并的 map
|
||||
* @param map2 第二个需要合并的 map
|
||||
* @param merge 合并的lambda,将key value1 value2合并成最终的类型,注意value可能为空的情况
|
||||
* @param <K> map中的key类型
|
||||
* @param <X> 第一个 map的value类型
|
||||
* @param <Y> 第二个 map的value类型
|
||||
* @param <V> 最终map的value类型
|
||||
* @return 合并后的map
|
||||
*/
|
||||
public static <K, X, Y, V> Map<K, V> merge(Map<K, X> map1, Map<K, Y> map2, BiFunction<X, Y, V> merge) {
|
||||
if (MapUtil.isEmpty(map1) && MapUtil.isEmpty(map2)) {
|
||||
return MapUtil.newHashMap();
|
||||
} else if (MapUtil.isEmpty(map1)) {
|
||||
map1 = MapUtil.newHashMap();
|
||||
} else if (MapUtil.isEmpty(map2)) {
|
||||
map2 = MapUtil.newHashMap();
|
||||
}
|
||||
Set<K> key = new HashSet<>();
|
||||
key.addAll(map1.keySet());
|
||||
key.addAll(map2.keySet());
|
||||
Map<K, V> map = new HashMap<>();
|
||||
for (K t : key) {
|
||||
X x = map1.get(t);
|
||||
Y y = map2.get(t);
|
||||
V z = merge.apply(x, y);
|
||||
if (z != null) {
|
||||
map.put(t, z);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -116,6 +116,16 @@ public class WrkInfoController {
|
|||
return AjaxResult.success(wrkInfoService.queryWorkOrderDetails(wrkId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量派单/领取
|
||||
*/
|
||||
@PostMapping("/dispatch/app")
|
||||
@RequiresPermissions("wrk:dispatch")
|
||||
@SysLog(value = "批量派单/领取", businessType = BusinessType.IMPORT)
|
||||
public void dispatchApp(@RequestBody @Validated DispatchQuery query) {
|
||||
wrkInfoService.dispatch(query, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量派单/领取
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ import java.util.List;
|
|||
* @auther: zhao
|
||||
* @date: 2024/6/28 17:16
|
||||
*/
|
||||
public class WrkInfoDispatchImpl implements WrkInfoDispatch {
|
||||
@Override
|
||||
public List<WrkInfo> dispatch(DispatchQuery query, List<DispatchDTO> dispatch) {
|
||||
return List.of();
|
||||
}
|
||||
public class WrkInfoDispatchImpl {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@ package com.chushang.inspection.work.service.impl;
|
|||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.chushang.common.core.constant.SecurityConstants;
|
||||
import com.chushang.common.core.exception.utils.AssertUtil;
|
||||
import com.chushang.common.core.util.IPUtils;
|
||||
import com.chushang.common.core.web.Result;
|
||||
import com.chushang.common.mybatis.enums.Operator;
|
||||
import com.chushang.common.mybatis.page.CommonParam;
|
||||
import com.chushang.common.mybatis.utils.PageResult;
|
||||
|
|
@ -15,10 +18,12 @@ import com.chushang.common.mybatis.utils.WrapperUtils;
|
|||
import com.chushang.datascope.annotation.DataScope;
|
||||
import com.chushang.inspection.project.service.InspectionDataService;
|
||||
import com.chushang.inspection.terminal.po.FiveStore;
|
||||
import com.chushang.inspection.terminal.po.Terminal;
|
||||
import com.chushang.inspection.terminal.service.FiveStoreService;
|
||||
import com.chushang.inspection.terminal.service.StoreService;
|
||||
import com.chushang.inspection.terminal.service.TerminalService;
|
||||
import com.chushang.inspection.terminal.vo.FiveStoreVO;
|
||||
import com.chushang.inspection.utils.StreamUtils;
|
||||
import com.chushang.inspection.utils.TaskConfigUtils;
|
||||
import com.chushang.inspection.work.dto.DispatchDTO;
|
||||
import com.chushang.inspection.work.po.*;
|
||||
|
|
@ -28,19 +33,28 @@ import com.chushang.inspection.work.query.WrkAppQuery;
|
|||
import com.chushang.inspection.work.query.WrkInfoQuery;
|
||||
import com.chushang.inspection.work.service.*;
|
||||
import com.chushang.inspection.work.vo.*;
|
||||
import com.chushang.security.entity.po.SysUser;
|
||||
import com.chushang.system.feign.RemoteUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chushang.inspection.work.mapper.WrkInfoMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @auther: zhao
|
||||
* @date: 2024/6/26 17:13
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WrkInfoServiceImpl extends ServiceImpl<WrkInfoMapper, WrkInfo> implements WrkInfoService {
|
||||
|
||||
@Resource
|
||||
|
|
@ -53,6 +67,17 @@ public class WrkInfoServiceImpl extends ServiceImpl<WrkInfoMapper, WrkInfo> impl
|
|||
InspectionDataService inspectionDataService;
|
||||
@Resource
|
||||
WrkImgService wrkImgService;
|
||||
|
||||
@Resource
|
||||
WrkInfoService wrkInfoService;
|
||||
|
||||
@Resource
|
||||
WrkInfoStoreRecordService wrkInfoStoreRecordService;
|
||||
|
||||
|
||||
@Resource
|
||||
WrkInfoTerminalRecordService wrkInfoTerminalRecordService;
|
||||
|
||||
@Resource
|
||||
FiveStoreService fiveStoreService;
|
||||
@Resource
|
||||
|
|
@ -60,6 +85,9 @@ public class WrkInfoServiceImpl extends ServiceImpl<WrkInfoMapper, WrkInfo> impl
|
|||
@Resource
|
||||
StoreService service;
|
||||
|
||||
@Resource
|
||||
RemoteUserService userFeignService;
|
||||
|
||||
@Value("${push.icbc-js.enable:false}")
|
||||
private boolean enable;
|
||||
|
||||
|
|
@ -134,20 +162,86 @@ public class WrkInfoServiceImpl extends ServiceImpl<WrkInfoMapper, WrkInfo> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<WrkInfo> dispatch(DispatchQuery query, int i) {
|
||||
List<DispatchDTO> dispatch = terminalService.getStoreByTasKIdOrIds(query.getTaskId(), query.getTerminalIds(), query.getNos(), query.getTerminalNos(), i);
|
||||
query.setOccupy(i);
|
||||
List<DispatchDTO> dispatch = terminalService.getStoreByTasKIdOrIds(query);
|
||||
AssertUtil.invalidate(CollectionUtil.isEmpty(dispatch), "您指定派单/领取的终端不存在");
|
||||
|
||||
Integer method = TaskConfigUtils.dispatchMethod(query.getTaskId());
|
||||
// WrkInfoDispatch infoDispatch = Assert.notNull(dispatchMap.get("dispatch" + method), "派单方式不支持");
|
||||
// List<WrkInfo> infoEntities = infoDispatch.dispatch(query, dispatch);
|
||||
// Db.tx(() -> {
|
||||
// Assert.isTrue(mapper.insertBatch(infoEntities) == infoEntities.size(), "派单失败");
|
||||
// if (!TaskConfigUtils.isRepeat(query.getTaskId())) {
|
||||
// terminalService.updateOccupy(infoEntities.stream().map(WrkInfoEntity::getTerminalId).collect(Collectors.toList()), 1);
|
||||
// }
|
||||
// scheduleService.updateWorkOrderProgress(6, StreamUtils.toList(infoEntities, WrkInfoEntity::getId), null);
|
||||
// return true;
|
||||
// });
|
||||
|
||||
this.saveData(dispatch,query,method);
|
||||
|
||||
if (!TaskConfigUtils.isRepeat(query.getTaskId())) {
|
||||
terminalService.updateOccupy(dispatch.stream().map(DispatchDTO::getTerminalId).collect(Collectors.toList()), 1);
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private WrkInfo makeWrkInfoEntity(DispatchDTO dispatch,DispatchQuery query,Long userId,String userName,Integer workMethod){
|
||||
WrkInfo wrkInfo = new WrkInfo();
|
||||
wrkInfo.setTaskId(query.getTaskId());
|
||||
wrkInfo.setUserId(userId);
|
||||
wrkInfo.setAccountPhone(dispatch.getAccountPhone());
|
||||
wrkInfo.setUserName(userName);
|
||||
wrkInfo.setWorkNo(IdUtil.getSnowflake().nextId());
|
||||
wrkInfo.setWorkType(query.getWorkType());
|
||||
wrkInfo.setWorkMethod(workMethod);
|
||||
wrkInfo.setWorkSort(query.getWorkSort());
|
||||
wrkInfo.setWrkStatus(1);
|
||||
wrkInfo.setWorkSource(query.getWorkSource());
|
||||
// 处理时间
|
||||
//wrkInfo.setDisposeTime(query.getEndTime());
|
||||
// 业务员名字和客户经理?
|
||||
// wrkInfo.setAccountManager(dispatch.getAccountManager());
|
||||
return wrkInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void saveData(List<DispatchDTO> dispatch,DispatchQuery query,Integer method){
|
||||
// (0 业务员领取 1 只能派给负责项目的业务员 2 只能派给商户对应的客户经理 )
|
||||
if(method.equals(0)){
|
||||
Set<String> nickNames = StreamUtils.toSet(dispatch, DispatchDTO::getAccountManager);
|
||||
Result<Map<String, Long>> result = userFeignService.getIdByNicknames(nickNames, SecurityConstants.INNER);
|
||||
if(result.isSuccess()){
|
||||
Map<String, Long> userIds =result .getData();
|
||||
for (DispatchDTO dispatchDTO : dispatch){
|
||||
Long userId = userIds.get(dispatchDTO.getAccountManager());
|
||||
Assert.notNull(userId, "【{}】未设置商户", dispatchDTO.getAccountManager());
|
||||
// 组装wrkinfo实体
|
||||
WrkInfo wrkInfo = makeWrkInfoEntity(dispatchDTO, query, userId,dispatchDTO.getAccountManager(),0);
|
||||
wrkInfoService.save(wrkInfo);
|
||||
//组装wrkterminal 实体
|
||||
WrkInfoTerminalRecord wrkInfoTerminalRecord = BeanUtil.copyProperties(dispatchDTO, WrkInfoTerminalRecord.class);
|
||||
wrkInfoTerminalRecord.setWrkId(wrkInfo.getWrkId());
|
||||
wrkInfoTerminalRecordService.save(wrkInfoTerminalRecord);
|
||||
WrkInfoStoreRecord wrkInfoStoreRecord = BeanUtil.copyProperties(dispatchDTO, WrkInfoStoreRecord.class);
|
||||
wrkInfoStoreRecord.setWrkId(wrkInfo.getWrkId());
|
||||
wrkInfoStoreRecordService.save(wrkInfoStoreRecord);
|
||||
}
|
||||
}
|
||||
}else if(method.equals(1) || method.equals(2)){
|
||||
Assert.notNull(query.getUserId(), "需要指定业务员");
|
||||
Result<SysUser> result = userFeignService.getInfoById(query.getUserId(), SecurityConstants.INNER);
|
||||
if(result.isSuccess()){
|
||||
String nickName = result.getData().getNickName();
|
||||
for (DispatchDTO dispatchDTO : dispatch){
|
||||
Assert.notNull(nickName, "【{}】未设置商户", dispatchDTO.getAccountManager());
|
||||
WrkInfo wrkInfo = makeWrkInfoEntity(dispatchDTO, query, query.getUserId(), dispatchDTO.getAccountManager(), method);
|
||||
// 组装wrkinfo实体
|
||||
wrkInfoService.save(wrkInfo);
|
||||
//组装wrkterminal 实体
|
||||
WrkInfoTerminalRecord wrkInfoTerminalRecord = BeanUtil.copyProperties(dispatchDTO, WrkInfoTerminalRecord.class);
|
||||
wrkInfoTerminalRecord.setWrkId(wrkInfo.getWrkId());
|
||||
wrkInfoTerminalRecordService.save(wrkInfoTerminalRecord);
|
||||
WrkInfoStoreRecord wrkInfoStoreRecord = BeanUtil.copyProperties(dispatchDTO, WrkInfoStoreRecord.class);
|
||||
wrkInfoStoreRecord.setWrkId(wrkInfo.getWrkId());
|
||||
wrkInfoStoreRecordService.save(wrkInfoStoreRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,85 +233,50 @@
|
|||
</select>
|
||||
|
||||
|
||||
<select id="getStoreByTasKIdOrIds" resultType="com.chushang.inspection.work.dto.DispatchDTO">
|
||||
select t1.terminal_id,
|
||||
t1.terminal_sn,
|
||||
t1.terminal_no,
|
||||
t1.terminal_type,
|
||||
t1.terminal_model,
|
||||
t1.terminal_version,
|
||||
t1.terminal_address,
|
||||
t1.terminal_source,
|
||||
t1.terminal_source,
|
||||
t1.terminal_property,
|
||||
t2.store_no,
|
||||
t2.store_name,
|
||||
t2.store_contact,
|
||||
t2.store_phone,
|
||||
t2.store_address,
|
||||
t2.special_num,
|
||||
t2.shop_name,
|
||||
t2.store_type,
|
||||
t2.products,
|
||||
t2.tip_tool,
|
||||
t2.ins_fre,
|
||||
t2.register_address,
|
||||
t2.legal_name,
|
||||
t2.legal_name,
|
||||
t2.legal_name,
|
||||
t2.legal_name,
|
||||
t2.legal_name,
|
||||
t3.management_code,
|
||||
t3.geographic_location,
|
||||
t3.geographic_address
|
||||
from st_terminal t1
|
||||
left join st_store t2 on t1.store_id = t2.store_id
|
||||
left join st_terminal_ins t3 on t3.terminal_id = t1.terminal_id
|
||||
|
||||
<select id="getStoreByTasKIdOrIds" resultType="com.chushang.inspection.terminal.vo.TerminalVO">
|
||||
SELECT
|
||||
s.state AS storeState,
|
||||
s.store_name AS storeName,
|
||||
t.store_id AS storeId,
|
||||
t.store_no AS storeNo,
|
||||
t.terminal_id AS terminalId,
|
||||
t.terminal_no AS terminalNo,
|
||||
t.terminal_sn AS terminalSn,
|
||||
t.terminal_type As terminalType,
|
||||
t.terminal_model AS terminalModel,
|
||||
t.terminal_version AS terminalVersion,
|
||||
t.terminal_address AS terminalAddress,
|
||||
t.occupy,
|
||||
t.create_time AS createTime,
|
||||
t.terminal_status AS terminalStatus,
|
||||
t.lower_task_id AS lowerTaskId,
|
||||
t.dept_id AS deptId
|
||||
FROM st_terminal t
|
||||
LEFT JOIN st_store s ON t.store_id = s.store_id
|
||||
<where>
|
||||
<if test="taskId != null">
|
||||
AND t.task_id = #{taskId}
|
||||
</if>
|
||||
<if test="nos != null AND nos.size() > 0 ">
|
||||
AND t.terminal_no IN
|
||||
<foreach collection="nos" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="nos != null AND nos.size() > 0 ">
|
||||
AND t.terminal_no IN
|
||||
<foreach collection="nos" item="item" index="index" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="query.terminalNo != null">
|
||||
AND t.terminal_no = #{query.terminalNo}
|
||||
</if>
|
||||
<if test="query.terminalSn != null">
|
||||
AND t.terminal_sn = #{query.terminalSn}
|
||||
</if>
|
||||
<if test="query.terminalType != null">
|
||||
AND t.terminal_type = #{query.terminalType}
|
||||
</if>
|
||||
<if test="query.terminalSource != null">
|
||||
AND t.terminal_source = #{query.terminalSource}
|
||||
</if>
|
||||
<if test="query.terminalVersion != null">
|
||||
AND t.terminal_version = #{query.terminalVersion}
|
||||
</if>
|
||||
<if test="query.terminalAddress != null and query.terminalAddress != ''">
|
||||
AND t.terminal_address like concat('%', #{query.terminalAddress}, '%')
|
||||
</if>
|
||||
<if test="query.terminalModel != null and query.terminalModel != ''">
|
||||
AND t.terminal_model like concat('%', #{query.terminalModel}, '%')
|
||||
</if>
|
||||
<if test="query.lowerTaskIds != null and query.lowerTaskIds.size() > 0">
|
||||
AND t.lower_task_id IN
|
||||
<foreach collection="query.lowerTaskIds" item="lowerTaskId" open="(" close=")" separator=",">
|
||||
#{lowerTaskId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="query.storeName != null and query.storeName != ''">
|
||||
AND s.store_name like concat('%', #{query.storeName}, '%')
|
||||
</if>
|
||||
<if test="query.storeState != null ">
|
||||
AND s.state = #{query.storeState}
|
||||
</if>
|
||||
|
||||
<if test="query.createTimes != null and query.createTimes.size() > 0">
|
||||
AND t.create_time BETWEEN #{query.createTimes[0]} AND #{query.createTimes[1]}
|
||||
<if test="query.taskId != null">
|
||||
AND t.task_id = #{query.taskId}
|
||||
</if>
|
||||
<if test="1 == 1">
|
||||
${query.sqlParam.get('dataScope')}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY #{query.orderBy} #{query.isAsc}
|
||||
ORDER BY t.create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue