diff --git a/pom.xml b/pom.xml index 1827db2..01ce105 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 4.12 2.9.0 1.2.13 - 3.5.5 + 3.5.7 8.0.25 4.0 11.2.0.3 @@ -71,8 +71,22 @@ org.springframework.boot spring-boot-starter-test + + + org.apache.logging.log4j + log4j-api + + test + + + + org.apache.logging.log4j + log4j-api + 2.17.1 + + org.springframework.boot spring-boot-starter-web @@ -285,6 +299,17 @@ mybatis-plus-join-boot-starter 1.5.0 + + + org.mapstruct + mapstruct + 1.6.0.Beta1 + + + + + + diff --git a/shapelight-admin/pom.xml b/shapelight-admin/pom.xml index a21f5ba..13c22d1 100644 --- a/shapelight-admin/pom.xml +++ b/shapelight-admin/pom.xml @@ -155,6 +155,14 @@ 0.7 + + + com.guwan + easyexcel + 4.0.3 + + + com.alibaba easyexcel @@ -251,10 +259,31 @@ true - + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + + org.projectlombok + lombok + 1.18.34 + + + org.mapstruct + mapstruct-processor + 1.6.0.Beta1 + + + + + com.spotify diff --git a/shapelight-admin/src/main/java/net/shapelight/common/config/MybatisPlusConfig.java b/shapelight-admin/src/main/java/net/shapelight/common/config/MybatisPlusConfig.java index 76ab865..8860601 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/config/MybatisPlusConfig.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/config/MybatisPlusConfig.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import net.shapelight.common.handler.CustomizeTableNameHandler; +import net.shapelight.common.handler.TimeHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,6 +20,14 @@ import org.springframework.context.annotation.Configuration; @Configuration public class MybatisPlusConfig { + + @Bean + public TimeHandler metaObjectHandler() { + return new TimeHandler(); + } + + + /** * 分表插件 */ diff --git a/shapelight-admin/src/main/java/net/shapelight/common/config/ShiroConfig.java b/shapelight-admin/src/main/java/net/shapelight/common/config/ShiroConfig.java index e025de2..b104f5e 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/config/ShiroConfig.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/config/ShiroConfig.java @@ -128,9 +128,11 @@ public class ShiroConfig { filterMap.put("/swagger-ui.html", "anon"); filterMap.put("/swagger-resources/**", "anon"); filterMap.put("/captcha.jpg", "anon"); + filterMap.put("/mobile/device/group/export", "anon"); // filterMap.put("/aaa.txt", "anon"); filterMap.put("/**", "oauth2"); + shiroFilter.setFilterChainDefinitionMap(filterMap); return shiroFilter; diff --git a/shapelight-admin/src/main/java/net/shapelight/common/handler/TimeHandler.java b/shapelight-admin/src/main/java/net/shapelight/common/handler/TimeHandler.java index 6149a11..182bd15 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/handler/TimeHandler.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/handler/TimeHandler.java @@ -6,7 +6,7 @@ import org.apache.ibatis.reflection.MetaObject; import java.util.Date; public class TimeHandler implements MetaObjectHandler { - @Override + /* @Override public void insertFill(MetaObject metaObject) { this.setFieldValByName("createTime", new Date(), metaObject); this.setFieldValByName("updateTime", new Date(), metaObject); @@ -15,5 +15,18 @@ public class TimeHandler implements MetaObjectHandler { @Override public void updateFill(MetaObject metaObject) { this.setFieldValByName("updateTime", new Date(), metaObject); + }*/ + + @Override + public void insertFill(MetaObject metaObject) { + this.strictInsertFill(metaObject, "createTime", Date.class, new Date()); + this.strictInsertFill(metaObject, "updateTime", Date.class, new Date()); + this.strictInsertFill(metaObject, "deleteFlag", Integer.class, 0); } + + @Override + public void updateFill(MetaObject metaObject) { + this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date()); + } + } diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/BeanUtils.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/BeanUtils.java new file mode 100644 index 0000000..8187037 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/BeanUtils.java @@ -0,0 +1,42 @@ +package net.shapelight.common.utils; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.db.PageResult; + + +import java.util.List; +import java.util.function.Consumer; + + +public class BeanUtils { + + public static T toBean(Object source, Class targetClass) { + return BeanUtil.toBean(source, targetClass); + } + + public static T toBean(Object source, Class targetClass, Consumer peek) { + T target = toBean(source, targetClass); + if (target != null) { + peek.accept(target); + } + return target; + } + + public static List toBean(List source, Class targetType) { + if (source == null) { + return null; + } + return CollectionUtils.convertList(source, s -> toBean(s, targetType)); + } + + public static List toBean(List source, Class targetType, Consumer peek) { + List list = toBean(source, targetType); + if (list != null) { + list.forEach(peek); + } + return list; + } + + + +} \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/CollectionUtils.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/CollectionUtils.java new file mode 100644 index 0000000..5a1b863 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/CollectionUtils.java @@ -0,0 +1,326 @@ +package net.shapelight.common.utils; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ArrayUtil; +import com.google.common.collect.ImmutableMap; + +import java.util.*; +import java.util.function.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.Arrays.asList; + + +public class CollectionUtils { + + public static boolean containsAny(Object source, Object... targets) { + return asList(targets).contains(source); + } + + public static boolean isAnyEmpty(Collection... collections) { + return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); + } + + public static boolean anyMatch(Collection from, Predicate predicate) { + return from.stream().anyMatch(predicate); + } + + public static List filterList(Collection from, Predicate predicate) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(predicate).collect(Collectors.toList()); + } + + public static List distinct(Collection from, Function keyMapper) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return distinct(from, keyMapper, (t1, t2) -> t1); + } + + public static List distinct(Collection from, Function keyMapper, BinaryOperator cover) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return new ArrayList<>(convertMap(from, keyMapper, Function.identity(), cover).values()); + } + + public static List convertList(T[] from, Function func) { + if (ArrayUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return convertList(Arrays.asList(from), func); + } + + public static List convertList(Collection from, Function func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().map(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertList(Collection from, Function func, Predicate filter) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertListByFlatMap(Collection from, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertListByFlatMap(Collection from, + Function mapper, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List mergeValuesFromMap(Map> map) { + return map.values() + .stream() + .flatMap(List::stream) + .collect(Collectors.toList()); + } + + public static Set convertSet(Collection from) { + return convertSet(from, v -> v); + } + + public static Set convertSet(Collection from, Function func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().map(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Set convertSet(Collection from, Function func, Predicate filter) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Map convertMapByFilter(Collection from, Predicate filter, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().filter(filter).collect(Collectors.toMap(keyFunc, v -> v)); + } + + public static Set convertSetByFlatMap(Collection from, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Set convertSetByFlatMap(Collection from, + Function mapper, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Map convertMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, Function.identity()); + } + + public static Map convertMap(Collection from, Function keyFunc, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return supplier.get(); + } + return convertMap(from, keyFunc, Function.identity(), supplier); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, valueFunc, (v1, v2) -> v1); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, BinaryOperator mergeFunction) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, valueFunc, mergeFunction, HashMap::new); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return supplier.get(); + } + return convertMap(from, keyFunc, valueFunc, (v1, v2) -> v1, supplier); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, BinaryOperator mergeFunction, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.toMap(keyFunc, valueFunc, mergeFunction, supplier)); + } + + public static Map> convertMultiMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.groupingBy(keyFunc, Collectors.mapping(t -> t, Collectors.toList()))); + } + + public static Map> convertMultiMap(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream() + .collect(Collectors.groupingBy(keyFunc, Collectors.mapping(valueFunc, Collectors.toList()))); + } + + // 暂时没想好名字,先以 2 结尾噶 + public static Map> convertMultiMap2(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.groupingBy(keyFunc, Collectors.mapping(valueFunc, Collectors.toSet()))); + } + + public static Map convertImmutableMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return Collections.emptyMap(); + } + ImmutableMap.Builder builder = ImmutableMap.builder(); + from.forEach(item -> builder.put(keyFunc.apply(item), item)); + return builder.build(); + } + + /** + * 对比老、新两个列表,找出新增、修改、删除的数据 + * + * @param oldList 老列表 + * @param newList 新列表 + * @param sameFunc 对比函数,返回 true 表示相同,返回 false 表示不同 + * 注意,same 是通过每个元素的“标识”,判断它们是不是同一个数据 + * @return [新增列表、修改列表、删除列表] + */ + public static List> diffList(Collection oldList, Collection newList, + BiFunction sameFunc) { + List createList = new LinkedList<>(newList); // 默认都认为是新增的,后续会进行移除 + List updateList = new ArrayList<>(); + List deleteList = new ArrayList<>(); + + // 通过以 oldList 为主遍历,找出 updateList 和 deleteList + for (T oldObj : oldList) { + // 1. 寻找是否有匹配的 + T foundObj = null; + for (Iterator iterator = createList.iterator(); iterator.hasNext(); ) { + T newObj = iterator.next(); + // 1.1 不匹配,则直接跳过 + if (!sameFunc.apply(oldObj, newObj)) { + continue; + } + // 1.2 匹配,则移除,并结束寻找 + iterator.remove(); + foundObj = newObj; + break; + } + // 2. 匹配添加到 updateList;不匹配则添加到 deleteList 中 + if (foundObj != null) { + updateList.add(foundObj); + } else { + deleteList.add(oldObj); + } + } + return asList(createList, updateList, deleteList); + } + + public static boolean containsAny(Collection source, Collection candidates) { + return org.springframework.util.CollectionUtils.containsAny(source, candidates); + } + + public static T getFirst(List from) { + return !CollectionUtil.isEmpty(from) ? from.get(0) : null; + } + + public static T findFirst(Collection from, Predicate predicate) { + return findFirst(from, predicate, Function.identity()); + } + + public static U findFirst(Collection from, Predicate predicate, Function func) { + if (CollUtil.isEmpty(from)) { + return null; + } + return from.stream().filter(predicate).findFirst().map(func).orElse(null); + } + + public static > V getMaxValue(Collection from, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return null; + } + assert !from.isEmpty(); // 断言,避免告警 + T t = from.stream().max(Comparator.comparing(valueFunc)).get(); + return valueFunc.apply(t); + } + + public static > V getMinValue(List from, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return null; + } + assert from.size() > 0; // 断言,避免告警 + T t = from.stream().min(Comparator.comparing(valueFunc)).get(); + return valueFunc.apply(t); + } + + public static > T getMinObject(List from, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return null; + } + assert from.size() > 0; // 断言,避免告警 + return from.stream().min(Comparator.comparing(valueFunc)).get(); + } + + public static > V getSumValue(Collection from, Function valueFunc, + BinaryOperator accumulator) { + return getSumValue(from, valueFunc, accumulator, null); + } + + public static > V getSumValue(Collection from, Function valueFunc, + BinaryOperator accumulator, V defaultValue) { + if (CollUtil.isEmpty(from)) { + return defaultValue; + } + assert !from.isEmpty(); // 断言,避免告警 + return from.stream().map(valueFunc).filter(Objects::nonNull).reduce(accumulator).orElse(defaultValue); + } + + public static void addIfNotNull(Collection coll, T item) { + if (item == null) { + return; + } + coll.add(item); + } + + public static Collection singleton(T obj) { + return obj == null ? Collections.emptyList() : Collections.singleton(obj); + } + + public static List newArrayList(List> list) { + return list.stream().flatMap(Collection::stream).collect(Collectors.toList()); + } + +} \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/ExcelUtils.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/ExcelUtils.java new file mode 100644 index 0000000..aaac020 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/ExcelUtils.java @@ -0,0 +1,46 @@ +package net.shapelight.common.utils; + +import com.guwan.excel.EasyExcel; +import com.guwan.excel.converters.longconverter.LongStringConverter; +import com.guwan.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.List; + +public class ExcelUtils { + + /** + * 将列表以 Excel 响应给前端 + * + * @param response 响应 + * @param filename 文件名 + * @param sheetName Excel sheet 名 + * @param head Excel head 头 + * @param data 数据列表 + * @param 泛型,保证 head 和 data 类型的一致性 + * @throws IOException 写入失败的情况 + */ + public static void write(HttpServletResponse response, String filename, String sheetName, + Class head, List data) throws IOException { + // 输出 Excel + EasyExcel.write(response.getOutputStream(), head) + .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理 + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度 + .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度 + .sheet(sheetName).doWrite(data); + // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了 + response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, StandardCharsets.UTF_8.name())); + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + } + + public static List read(MultipartFile file, Class head) throws IOException { + return EasyExcel.read(file.getInputStream(), head, null) + .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理 + .doReadAllSync(); + } + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java b/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java index 2054435..fd1a031 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java @@ -1,3 +1,4 @@ +/* package net.shapelight.modules.appparent.controller; import com.alibaba.fastjson.JSONObject; @@ -109,3 +110,4 @@ public class AppParentWxController { } } +*/ diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java index 6e603e6..c78be72 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java @@ -1,6 +1,8 @@ package net.shapelight.modules.fegin; import com.alibaba.fastjson.JSONObject; + + import feign.hystrix.FallbackFactory; import org.springframework.stereotype.Component; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceController.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceController.java index ed1b4ee..26a95d2 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceController.java @@ -9,14 +9,14 @@ import net.shapelight.common.handler.CustomizeTableNameHandler; import net.shapelight.common.utils.PageUtils; import net.shapelight.common.utils.R; import net.shapelight.common.utils.SnowflakeIdWorker; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceAddDto; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceQueryDto; import net.shapelight.modules.mobile.entity.MobileDevice; import net.shapelight.modules.mobile.service.MobileDeviceService; import net.shapelight.modules.sys.controller.AbstractController; +import org.apache.ibatis.annotations.Delete; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @@ -30,34 +30,50 @@ public class DeviceController extends AbstractController { MobileDeviceService mobileDeviceService; - @PostMapping("list") + @GetMapping("list") @ApiOperation("设备列表") @ApiImplicitParams({ - @ApiImplicitParam(name="limit",value = "每页条数",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="page",value = "页码",paramType = "query",dataType = "String",required = true), + @ApiImplicitParam(name="page",value = "页码",paramType = "query",dataType = "Long",required = true), + @ApiImplicitParam(name="size",value = "每页页数",paramType = "query",dataType = "Long",required = true), @ApiImplicitParam(name = "name", value = "设备名称", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "status", value = "设备状态", paramType = "query", dataType = "Integer"), - @ApiImplicitParam(name = "cellName", value = "学校名称", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "deptId", value = "设备区域名称", paramType = "query", dataType = "String") + @ApiImplicitParam(name = "groupId", value = "设备组id", paramType = "query", dataType = "Long"), + @ApiImplicitParam(name = "apkVersion", value = "apk版本", paramType = "query", dataType = "String") }) - public R list(@RequestBody Map params) { + public R list(@RequestParam(defaultValue = "1") Long page, + @RequestParam(defaultValue = "10") Long size, + @RequestParam(required = false) String name, + @RequestParam(required = false) Long groupId, + @RequestParam(required = false) String apkVersion) { //params.put("tenantId",getUser().getTenantId()); - CustomizeTableNameHandler.setData(String.valueOf(getUser().getTenantId())); + /* CustomizeTableNameHandler.setData(String.valueOf(getUser().getTenantId())); PageUtils page = mobileDeviceService.queryPage(params); - CustomizeTableNameHandler.removeData(); - return R.ok().put("data",page); + CustomizeTableNameHandler.removeData();*/ + + System.out.println("page = " + page); + System.out.println("size = " + size); + + MobileDeviceQueryDto mobileDeviceQueryDto = new MobileDeviceQueryDto(); + mobileDeviceQueryDto.setCurrent(page); + mobileDeviceQueryDto.setSize(size); + mobileDeviceQueryDto.setName(name); + mobileDeviceQueryDto.setGroupId(groupId); + mobileDeviceQueryDto.setApkVersion(apkVersion); + + return R.ok().put("data", mobileDeviceService.list(mobileDeviceQueryDto)); } @PostMapping("add") @ApiOperation("设备新增") - public R add(@RequestBody MobileDevice mobileDevice) { + public R add(@RequestBody MobileDeviceAddDto mobileDeviceAddDto) { //mobileDevice.setTenantId(getUser().getTenantId()); - Long id = new SnowflakeIdWorker().nextId(); - mobileDevice.setId(id); - CustomizeTableNameHandler.setData(String.valueOf(getUser().getTenantId())); - mobileDeviceService.save(mobileDevice); - CustomizeTableNameHandler.removeData(); - return R.ok(); + // Long id = new SnowflakeIdWorker().nextId(); + // mobileDevice.setId(id); + /* CustomizeTableNameHandler.setData(String.valueOf(getUser().getTenantId())); + mobileDeviceService.save(mobileDeviceAddDto); + CustomizeTableNameHandler.removeData();*/ + if (mobileDeviceService.save(mobileDeviceAddDto)) { + return R.ok(); + } else return R.error(); } @PostMapping("update") @@ -66,9 +82,10 @@ public class DeviceController extends AbstractController { return R.ok(); } - @PostMapping("delete") + @DeleteMapping("delete") @ApiOperation("删除设备") public R delete(@RequestBody List deviceIdList) { + mobileDeviceService.remove(deviceIdList); return R.ok(); } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceGroupController.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceGroupController.java index 2a3db2f..d1adfee 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceGroupController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/controler/DeviceGroupController.java @@ -5,17 +5,21 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import net.shapelight.common.base.BasePageDTO; +import net.shapelight.common.utils.BeanUtils; +//import net.shapelight.common.utils.ExcelUtils; +import net.shapelight.common.utils.ExcelUtils; import net.shapelight.common.utils.R; -import net.shapelight.modules.mobile.dto.DeviceGruopQueryDto; -import net.shapelight.modules.mobile.dto.MobileDeviceGroupAddDto; -import net.shapelight.modules.mobile.entity.MobileDeviceGroup; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGruopQueryDto; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGroupAddDto; import net.shapelight.modules.mobile.service.MobileDeviceGroupService; -import org.apache.ibatis.annotations.Delete; +import net.shapelight.modules.mobile.vo.mobileDeviceGroup.MobileDeviceGroupVo; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import java.util.Map; @RestController @RequestMapping("mobile/device/group/") @@ -27,41 +31,83 @@ public class DeviceGroupController { @GetMapping("list") @ApiOperation("话机设备组列表") + @ApiImplicitParams({ + @ApiImplicitParam(name="page",value = "页码",paramType = "query",dataType = "Long",required = true), + @ApiImplicitParam(name="size",value = "每页条数",paramType = "query",dataType = "Long",required = true), + @ApiImplicitParam(name = "groupId", value = "设备组id", paramType = "query", dataType = "Long"), + @ApiImplicitParam(name = "status", value = "设备状态", paramType = "query", dataType = "Integer"), + }) public R list(@RequestParam(defaultValue = "1") Long page, - @RequestParam(defaultValue = "1") Long size, + @RequestParam(defaultValue = "10") Long size, @RequestParam(required = false) Long groupId, @RequestParam(required = false) Integer status) { - DeviceGruopQueryDto deviceGruopQueryDto = new DeviceGruopQueryDto(); - deviceGruopQueryDto.setCurrent(page); - deviceGruopQueryDto.setSize(size); - deviceGruopQueryDto.setGroupId(groupId); - deviceGruopQueryDto.setStatus(status); - - - - return R.ok().put("data", mobileDeviceGroupService.list(deviceGruopQueryDto)); - + MobileDeviceGruopQueryDto mobileDeviceGruopQueryDto = new MobileDeviceGruopQueryDto(); + mobileDeviceGruopQueryDto.setCurrent(page); + mobileDeviceGruopQueryDto.setSize(size); + mobileDeviceGruopQueryDto.setGroupId(groupId); + mobileDeviceGruopQueryDto.setStatus(status); + return R.ok().put("data", mobileDeviceGroupService.list(mobileDeviceGruopQueryDto)); } @PostMapping("add") @ApiOperation("设备组新增") public R add(@RequestBody MobileDeviceGroupAddDto mobileDeviceGroupAddDto) { - return R.ok(); + + if (mobileDeviceGroupService.add(mobileDeviceGroupAddDto)){ + return R.ok(); + }else return R.error(); + } @DeleteMapping("remove") @ApiOperation("设备组删除") @ApiImplicitParam(name = "groupId",value = "设备组ID",paramType = "query",dataType = "List",required = true) public R remove(@RequestBody List groupId) { + + mobileDeviceGroupService.remove(groupId); return R.ok(); + } @PutMapping("update") @ApiOperation("设备组更新") - public R update(@RequestBody MobileDeviceGroup mobileDeviceGroup) { + public R update(@RequestBody MobileDeviceGroupAddDto mobileDeviceGroupAddDto) { + mobileDeviceGroupService.update(mobileDeviceGroupAddDto); return R.ok(); } + + @PostMapping("/export-excel") + public void exportDeviceGroupExcel(@RequestBody List exportId, HttpServletResponse response) + throws IOException { + + List mobileDeviceGroupVos = + mobileDeviceGroupService.exportByIds(exportId); + + // 导出 Excel + ExcelUtils.write(response, "设备组信息.xls", "数据", + MobileDeviceGroupVo.class, mobileDeviceGroupVos); + + } + + + @GetMapping("/export") + public void exportDemo(HttpServletResponse response) + throws IOException { + + List exportId = new ArrayList<>(Arrays.asList(1306928534018588678L)); + + List mobileDeviceGroupVos = + mobileDeviceGroupService.exportByIds(exportId); + + // 导出 Excel + ExcelUtils.write(response, "设备组信息.xls", "数据", + MobileDeviceGroupVo.class, mobileDeviceGroupVos); + + } + + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/coverter/StatusConverter.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/coverter/StatusConverter.java new file mode 100644 index 0000000..5d4f269 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/coverter/StatusConverter.java @@ -0,0 +1,31 @@ +package net.shapelight.modules.mobile.coverter; + + +import com.guwan.excel.converters.Converter; +import com.guwan.excel.enums.CellDataTypeEnum; +import com.guwan.excel.metadata.GlobalConfiguration; +import com.guwan.excel.metadata.data.WriteCellData; +import com.guwan.excel.metadata.property.ExcelContentProperty; + +public class StatusConverter implements Converter { + + @Override + public Class supportJavaTypeKey() { + throw new UnsupportedOperationException("兼容"); + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + throw new UnsupportedOperationException("暂不支持,也不需要"); + } + + @Override + public WriteCellData convertToExcelData(Object value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + if (value.equals(0)) { + return new WriteCellData<>("未启用"); // 返回 "未启用" + } else if (value.equals(1)) { + return new WriteCellData<>("启用"); // 返回 "启用" + } + return new WriteCellData<>(value.toString()); // 默认返回数字字符串 + } +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/MobileDeviceGroupAddDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/MobileDeviceGroupAddDto.java deleted file mode 100644 index bb42e8e..0000000 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/MobileDeviceGroupAddDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.shapelight.modules.mobile.dto; - -public class MobileDeviceGroupAddDto { - /** - * 设备组名称 - */ - private String name; - /** - * - */ -} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceAddDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceAddDto.java new file mode 100644 index 0000000..1747cae --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceAddDto.java @@ -0,0 +1,43 @@ +package net.shapelight.modules.mobile.dto.mobileDevice; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@Data +@Accessors(chain = true) +public class MobileDeviceAddDto { + /** + * 设备名称 + */ + private String name; + /** + * 设备编号 + */ + private Long sn; + /** + * 设备ip + */ + private String deviceIp; + /** + * 设备组编号 + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long groupId; + /** + * APK版本 + */ + private String apkVersion; + /** + * voip到期时间 + */ + private Date voipTime; + /** + * 状态 + */ + private Integer status; + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceQueryDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceQueryDto.java new file mode 100644 index 0000000..d2e5b74 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDevice/MobileDeviceQueryDto.java @@ -0,0 +1,27 @@ +package net.shapelight.modules.mobile.dto.mobileDevice; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import net.shapelight.common.base.BasePageDTO; + +/** + * + */ +@Data +public class MobileDeviceQueryDto extends BasePageDTO { + /** + * 设备名称 + */ + private String name; + /** + * 设备组id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long groupId; + /** + * APK版本 + */ + private String apkVersion; + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupAddDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupAddDto.java new file mode 100644 index 0000000..30feca9 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupAddDto.java @@ -0,0 +1,23 @@ +package net.shapelight.modules.mobile.dto.mobileDeviceGroup; + +import lombok.Data; + +@Data +public class MobileDeviceGroupAddDto { + /** + * 设备组名称 + */ + private String name; + /** + * 第三方学校编码 + */ + private Long cellId; + /** + * 状态 + */ + private Integer state; + /** + * 描述 + */ + private String description; +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupUpdateDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupUpdateDto.java new file mode 100644 index 0000000..06a79ed --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGroupUpdateDto.java @@ -0,0 +1,23 @@ +package net.shapelight.modules.mobile.dto.mobileDeviceGroup; + +import lombok.Data; + +@Data +public class MobileDeviceGroupUpdateDto { + /** + * 设备组名称 + */ + private String name; + /** + * 第三方学校编码 + */ + private Long cellId; + /** + * 状态 + */ + private Integer state; + /** + * 描述 + */ + private String description; +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/DeviceGruopQueryDto.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGruopQueryDto.java similarity index 61% rename from shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/DeviceGruopQueryDto.java rename to shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGruopQueryDto.java index d85ab12..cf6a687 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/DeviceGruopQueryDto.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/dto/mobileDeviceGroup/MobileDeviceGruopQueryDto.java @@ -1,14 +1,13 @@ -package net.shapelight.modules.mobile.dto; +package net.shapelight.modules.mobile.dto.mobileDeviceGroup; import lombok.Data; -import lombok.experimental.Accessors; import net.shapelight.common.base.BasePageDTO; /** * */ @Data -public class DeviceGruopQueryDto extends BasePageDTO { +public class MobileDeviceGruopQueryDto extends BasePageDTO { /** * 设备组id */ diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDevice.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDevice.java index f07e2ee..0311f64 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDevice.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDevice.java @@ -1,20 +1,20 @@ package net.shapelight.modules.mobile.entity; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; -import javax.validation.constraints.NotNull; - -import java.io.Serializable; - -import java.util.Date; - import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.hibernate.validator.constraints.Length; +import lombok.experimental.Accessors; + + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.Date; /** * @@ -23,6 +23,7 @@ import org.hibernate.validator.constraints.Length; @Data @TableName("mobile_device") @ApiModel("设备信息") +@Accessors(chain = true) public class MobileDevice implements Serializable { /** @@ -37,21 +38,18 @@ public class MobileDevice implements Serializable { @NotBlank(message="[设备唯一标识]不能为空") @Size(max= 30,message="编码长度不能超过30") @ApiModelProperty("设备唯一标识") - @Length(max= 30,message="编码长度不能超过30") private String sn; /** * 设备名称 */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("设备名称") - @Length(max= 20,message="编码长度不能超过20") private String name; /** * 设备类型 */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("设备类型") - @Length(max= 20,message="编码长度不能超过20") private String deviceType; /** * 设备组ID @@ -68,14 +66,12 @@ public class MobileDevice implements Serializable { */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("设备IP") - @Length(max= 20,message="编码长度不能超过20") private String deviceIp; /** * apk版本 */ @Size(max= 10,message="编码长度不能超过10") @ApiModelProperty("apk版本") - @Length(max= 10,message="编码长度不能超过10") private String apkVersion; /** * voip到期时间 @@ -109,7 +105,6 @@ public class MobileDevice implements Serializable { */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("创建人") - @Length(max= 20,message="编码长度不能超过20") private String createBy; /** * 区域ID @@ -121,4 +116,10 @@ public class MobileDevice implements Serializable { @TableField(exist = false) private Long tenantId; + @ApiModelProperty(name = "删除标志位") + @TableField(fill = FieldFill.INSERT) + @TableLogic + private Integer deleteFlag; + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDeviceGroup.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDeviceGroup.java index 347d188..a423946 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDeviceGroup.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobileDeviceGroup.java @@ -1,14 +1,12 @@ package net.shapelight.modules.mobile.entity; -import com.baomidou.mybatisplus.annotation.FieldFill; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import lombok.Data; +import lombok.experimental.Accessors; import org.springframework.data.annotation.CreatedDate; import java.io.Serializable; @@ -21,6 +19,7 @@ import java.util.Date; @Data @TableName ("mobile_device_group") @ApiModel("话机信息") +@Accessors(chain = true) public class MobileDeviceGroup implements Serializable { /** * 设备组id @@ -90,4 +89,13 @@ public class MobileDeviceGroup implements Serializable { @ApiModelProperty(name = "修改时间") @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; + + /** + * 删除标志位 + */ + @ApiModelProperty(name = "删除标志位") + @TableField(fill = FieldFill.INSERT) + @TableLogic + private Integer deleteFlag; + } \ No newline at end of file diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java index 0ccaf98..8000c6f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java @@ -1,18 +1,16 @@ package net.shapelight.modules.mobile.entity; -import javax.validation.constraints.Size; -import javax.validation.constraints.NotNull; - -import java.io.Serializable; - -import java.math.BigDecimal; -import java.util.Date; - import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.hibernate.validator.constraints.Length; + + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; /** * @@ -34,14 +32,12 @@ public class MobilePackage implements Serializable { */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("套餐名称") - @Length(max= 20,message="编码长度不能超过20") private String packageName; /** * 套餐类型 */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("套餐类型") - @Length(max= 20,message="编码长度不能超过20") private String packageType; /** * 套餐价格 @@ -108,7 +104,6 @@ public class MobilePackage implements Serializable { */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("创建人") - @Length(max= 20,message="编码长度不能超过20") private String createBy; } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java index 0ea7a50..49b68a1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java @@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.hibernate.validator.constraints.Length; + /** * @@ -79,7 +79,6 @@ public class MobilePackageOrder implements Serializable { */ @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("学生姓名") - @Length(max= 20,message="编码长度不能超过20") private String personName; /** * 到期时间 diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapstructMapper/MobileDeviceMapstructMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapstructMapper/MobileDeviceMapstructMapper.java new file mode 100644 index 0000000..63417f5 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapstructMapper/MobileDeviceMapstructMapper.java @@ -0,0 +1,14 @@ +package net.shapelight.modules.mobile.mapstructMapper; + +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceAddDto; +import net.shapelight.modules.mobile.entity.MobileDevice; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface MobileDeviceMapstructMapper { + + + MobileDevice mobileDeviceAddDtoToMobileDevice(MobileDeviceAddDto mobileDeviceAddDto); + + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceGroupService.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceGroupService.java index 6f2220b..2a29b9f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceGroupService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceGroupService.java @@ -1,9 +1,10 @@ package net.shapelight.modules.mobile.service; -import net.shapelight.modules.mobile.dto.DeviceGruopQueryDto; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGroupAddDto; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGruopQueryDto; import net.shapelight.modules.mobile.entity.MobileDeviceGroup; import com.baomidou.mybatisplus.extension.service.IService; -import net.shapelight.modules.mobile.vo.MobileDeviceGroupVo; +import net.shapelight.modules.mobile.vo.mobileDeviceGroup.MobileDeviceGroupVo; import java.util.List; @@ -13,5 +14,14 @@ import java.util.List; * @createDate 2024-11-13 11:50:36 */ public interface MobileDeviceGroupService extends IService { - List list(DeviceGruopQueryDto deviceGruopQueryDto); + + List list(MobileDeviceGruopQueryDto mobileDeviceGruopQueryDto); + + Boolean add(MobileDeviceGroupAddDto mobileDeviceGroupAddDto); + + void remove(List groupId); + + Boolean update(MobileDeviceGroupAddDto mobileDeviceGroupAddDto); + + List exportByIds(List exportId); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceService.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceService.java index a04a79f..65b7a8d 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/MobileDeviceService.java @@ -2,8 +2,11 @@ package net.shapelight.modules.mobile.service; import com.baomidou.mybatisplus.extension.service.IService; import net.shapelight.common.utils.PageUtils; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceAddDto; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceQueryDto; import net.shapelight.modules.mobile.entity.MobileDevice; +import java.util.List; import java.util.Map; /** @@ -12,5 +15,11 @@ import java.util.Map; * @createDate 2024-11-13 14:36:39 */ public interface MobileDeviceService extends IService { - PageUtils queryPage(Map params); + + + Boolean save(MobileDeviceAddDto mobileDeviceAddDto); + + List list(MobileDeviceQueryDto mobileDeviceQueryDto); + + void remove(List deviceIdList); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceGroupServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceGroupServiceImpl.java index e35bc29..f4b1c05 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceGroupServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceGroupServiceImpl.java @@ -1,19 +1,28 @@ package net.shapelight.modules.mobile.service.impl; +import com.baomidou.mybatisplus.core.batch.MybatisBatch; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.MybatisBatchUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; import lombok.RequiredArgsConstructor; -import net.shapelight.modules.mobile.dto.DeviceGruopQueryDto; +import net.shapelight.common.utils.SnowflakeIdWorker; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGroupAddDto; +import net.shapelight.modules.mobile.dto.mobileDeviceGroup.MobileDeviceGruopQueryDto; import net.shapelight.modules.mobile.entity.MobileDevice; import net.shapelight.modules.mobile.entity.MobileDeviceGroup; import net.shapelight.modules.mobile.mapper.MobileDeviceMapper; import net.shapelight.modules.mobile.service.MobileDeviceGroupService; import net.shapelight.modules.mobile.mapper.MobileDeviceGroupMapper; -import net.shapelight.modules.mobile.vo.MobileDeviceGroupVo; +import net.shapelight.modules.mobile.vo.mobileDeviceGroup.MobileDeviceGroupVo; +import net.shapelight.modules.ten.dao.TenCellDao; import net.shapelight.modules.ten.entity.TenCellEntity; +import org.apache.ibatis.executor.BatchResult; +import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Service; +import org.springframework.transaction.support.TransactionCallback; +import org.springframework.transaction.support.TransactionTemplate; import java.util.List; import java.util.Objects; @@ -32,11 +41,19 @@ public class MobileDeviceGroupServiceImpl extends ServiceImpl list(DeviceGruopQueryDto deviceGruopQueryDto) { + public List list(MobileDeviceGruopQueryDto mobileDeviceGruopQueryDto) { + List mobileDeviceGroupVos = mobileDeviceGroupMapper.selectJoinPage( - new Page<>(deviceGruopQueryDto.getCurrent(), deviceGruopQueryDto.getSize()), + new Page<>(mobileDeviceGruopQueryDto.getCurrent(), mobileDeviceGruopQueryDto.getSize()), MobileDeviceGroupVo.class, new MPJLambdaWrapper() .select(MobileDeviceGroup::getGroupId, MobileDeviceGroup::getGroupName, @@ -44,18 +61,86 @@ public class MobileDeviceGroupServiceImpl extends ServiceImpl().eq(MobileDevice::getGroupId, mobileDeviceGroupVo.getGroupId())).stream().count(); mobileDeviceGroupVo.setNowDeviceCount(count); } + return mobileDeviceGroupVos; } + + @Override + public Boolean add(MobileDeviceGroupAddDto mobileDeviceGroupAddDto) { + + return mobileDeviceGroupMapper.insert(new MobileDeviceGroup() + .setGroupId(new SnowflakeIdWorker().nextId()) + .setGroupName(mobileDeviceGroupAddDto.getName()) + .setModelId(null) + .setCellId(mobileDeviceGroupAddDto.getCellId()) + .setDeviceCount(0) + .setDescription(mobileDeviceGroupAddDto.getDescription()) + .setCellName(tenCellDao.selectOne(new LambdaQueryWrapper() + .eq(TenCellEntity::getCellId, mobileDeviceGroupAddDto.getCellId())).getName()) + //TODO 这个怎么确定 + .setDeptId(0L) + .setStatus(mobileDeviceGroupAddDto.getState())) == 1; + + } + + @Override + public void remove(List groupId) { + + transactionTemplate.execute((TransactionCallback>) status -> { + MybatisBatch.Method mobileDeviceGroupMethod + = new MybatisBatch.Method<>(MobileDeviceGroupMapper.class); + try { + MybatisBatchUtils.execute(sqlSessionFactory, groupId, mobileDeviceGroupMethod.deleteById()); + } catch (Exception e) { + throw new RuntimeException("删除失败"); + } + return null; + }); + + /*new MybatisBatch<>(sqlSessionFactory, groupId) + .execute(new MybatisBatch.Method<>(MobileDeviceGroupMapper.class) + .deleteById());*/ + + } + + @Override + public Boolean update(MobileDeviceGroupAddDto mobileDeviceGroupAddDto) { + return null; + } + + @Override + public List exportByIds(List exportId) { + // 使用 MPJLambdaWrapper 构建查询条件 + List mobileDeviceGroupVos = mobileDeviceGroupMapper.selectJoinList( + MobileDeviceGroupVo.class, + new MPJLambdaWrapper() + .select(MobileDeviceGroup::getGroupId, MobileDeviceGroup::getGroupName, + MobileDeviceGroup::getDeviceCount, MobileDeviceGroup::getCellId, + MobileDeviceGroup::getDescription, MobileDeviceGroup::getStatus) + .select(TenCellEntity::getProvince, TenCellEntity::getCity) + .leftJoin(TenCellEntity.class, TenCellEntity::getCellId, MobileDeviceGroup::getCellId) + .in(MobileDeviceGroup::getGroupId, exportId)); + + for (MobileDeviceGroupVo mobileDeviceGroupVo : mobileDeviceGroupVos) { + Integer count = (int) mobileDeviceMapper.selectList(new LambdaQueryWrapper().eq(MobileDevice::getGroupId, mobileDeviceGroupVo.getGroupId())).stream().count(); + mobileDeviceGroupVo.setNowDeviceCount(count); + } + + System.out.println("mobileDeviceGroupVos = " + mobileDeviceGroupVos); + + return mobileDeviceGroupVos; + } + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceServiceImpl.java index 6cfbb58..f162d23 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/service/impl/MobileDeviceServiceImpl.java @@ -1,16 +1,27 @@ package net.shapelight.modules.mobile.service.impl; +import com.baomidou.mybatisplus.core.batch.MybatisBatch; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.RequiredArgsConstructor; import net.shapelight.common.utils.PageUtils; import net.shapelight.common.utils.Query; +import net.shapelight.common.utils.SnowflakeIdWorker; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceAddDto; +import net.shapelight.modules.mobile.dto.mobileDevice.MobileDeviceQueryDto; import net.shapelight.modules.mobile.entity.MobileDevice; +import net.shapelight.modules.mobile.mapstructMapper.MobileDeviceMapstructMapper; import net.shapelight.modules.mobile.service.MobileDeviceService; import net.shapelight.modules.mobile.mapper.MobileDeviceMapper; +import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; +import java.util.Objects; /** * @author zhangbo @@ -18,15 +29,49 @@ import java.util.Map; * @createDate 2024-11-13 14:36:39 */ @Service +@RequiredArgsConstructor public class MobileDeviceServiceImpl extends ServiceImpl implements MobileDeviceService{ - @Override - public PageUtils queryPage(Map params) { - IPage page = this.page(new Query().getPage(params),new LambdaQueryWrapper() - .eq(params.get("name")!=null && params.get("name")!="",MobileDevice::getName,params.get("name"))); + private final MobileDeviceMapstructMapper mobileDeviceMapstructMapper; + private final MobileDeviceMapper mobileDeviceMapper; - return new PageUtils(page); + + + @Override + public Boolean save(MobileDeviceAddDto mobileDeviceAddDto) { + + return this.save(mobileDeviceMapstructMapper + .mobileDeviceAddDtoToMobileDevice(mobileDeviceAddDto) + .setId(new SnowflakeIdWorker().nextId()) + //怎么确定 + .setDeviceType(null) + //怎么确定 + .setCellId(0L) + //怎么确定 + .setFaceCount(0) + //怎么确定 + .setDeptId(0L)); + + } + + @Override + public List list(MobileDeviceQueryDto mobileDeviceQueryDto) { + + return + mobileDeviceMapper.selectPage(new Page<>(mobileDeviceQueryDto.getCurrent(), mobileDeviceQueryDto.getSize()), + new LambdaQueryWrapper().like(Objects.nonNull(mobileDeviceQueryDto.getName()), + MobileDevice::getName, mobileDeviceQueryDto.getName()) + .eq(Objects.nonNull(mobileDeviceQueryDto.getGroupId()), + MobileDevice::getGroupId, mobileDeviceQueryDto.getGroupId()) + .eq(Objects.nonNull(mobileDeviceQueryDto.getApkVersion()), + MobileDevice::getApkVersion, mobileDeviceQueryDto.getApkVersion())).getRecords(); + } + + @Override + public void remove(List deviceIdList) { + new MybatisBatch<>(getSqlSessionFactory(), deviceIdList) + .execute(new MybatisBatch.Method<>(MobileDeviceMapper.class).deleteById()); } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/MobileDeviceGroupVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/mobileDeviceGroup/MobileDeviceGroupVo.java similarity index 59% rename from shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/MobileDeviceGroupVo.java rename to shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/mobileDeviceGroup/MobileDeviceGroupVo.java index e53d9fa..28ea3be 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/MobileDeviceGroupVo.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/vo/mobileDeviceGroup/MobileDeviceGroupVo.java @@ -1,9 +1,11 @@ -package net.shapelight.modules.mobile.vo; +package net.shapelight.modules.mobile.vo.mobileDeviceGroup; +import com.guwan.excel.annotation.ExcelProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; import lombok.experimental.Accessors; +import net.shapelight.modules.mobile.coverter.StatusConverter; @Data @Accessors(chain = true) @@ -12,38 +14,49 @@ public class MobileDeviceGroupVo { * 设备组id */ @JsonSerialize(using = ToStringSerializer.class) + @ExcelProperty("设备组编号") private Long groupId; /** * 设备组名称 */ + @ExcelProperty("设备组名称") private String groupName; /** * 当前设备数量 */ + @ExcelProperty("当前设备数量") private Integer nowDeviceCount; /** * 最大设备数量 */ + @ExcelProperty("最大设备数量") private Integer deviceCount; - + /** + * 学校编码 + */ @JsonSerialize(using = ToStringSerializer.class) + @ExcelProperty("学校编码") private Long cellId; /** * 所在省份 */ + @ExcelProperty("所在省份") private String province; /** * 所在城市 */ + @ExcelProperty("所在城市") private String city; /** * 描述 */ + @ExcelProperty("描述") private String description; /** * 状态 */ - private String status; + @ExcelProperty(value = "状态", converter = StatusConverter.class) + private Integer status; } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenCheckController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenCheckController.java index 44bc955..8333dc5 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenCheckController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenCheckController.java @@ -349,7 +349,7 @@ public class TenCheckController extends AbstractController { HSSFCellStyle juzhong = workbook.createCellStyle(); //垂直居中 - juzhong.setVerticalAlignment(juzhong.getVerticalAlignmentEnum().CENTER); + // juzhong.setVerticalAlignment(juzhong.getVerticalAlignmentEnum().CENTER); HSSFCellStyle biaoTiRiQi = workbook.createCellStyle(); diff --git a/shapelight-common/pom.xml b/shapelight-common/pom.xml index 49e697c..31ed018 100644 --- a/shapelight-common/pom.xml +++ b/shapelight-common/pom.xml @@ -4,7 +4,13 @@ shapelight-cell 2.0.0 - 4.0.0 + + + javax.validation + validation-api + + + 4.0.0 shapelight-common jar shapelight-common diff --git a/shapelight-common/src/main/java/net/shapelight/common/validator/group/Group.java b/shapelight-common/src/main/java/net/shapelight/common/validator/group/Group.java index be59bd5..dfbd148 100644 --- a/shapelight-common/src/main/java/net/shapelight/common/validator/group/Group.java +++ b/shapelight-common/src/main/java/net/shapelight/common/validator/group/Group.java @@ -2,6 +2,7 @@ package net.shapelight.common.validator.group; + import javax.validation.GroupSequence; /**