فهرست منبع

修改定时任务

sss 3 سال پیش
والد
کامیت
5aa18691ae

+ 46 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/domain/DmCard.java

@@ -0,0 +1,46 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.domain;
+
+import lombok.Data;
+import cn.hutool.core.bean.BeanUtil;
+import io.swagger.annotations.ApiModelProperty;
+import cn.hutool.core.bean.copier.CopyOptions;
+import javax.persistence.*;
+import javax.validation.constraints.*;
+import java.io.Serializable;
+
+/**
+* @website https://el-admin.vip
+* @description /
+* @author Li Rui
+* @date 2021-12-31
+**/
+@Entity
+@Data
+@Table(name="dm_card")
+public class DmCard implements Serializable {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    @ApiModelProperty(value = "id")
+    private Integer id;
+
+    public void copy(DmCard source){
+        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
+    }
+}

+ 28 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/repository/DmCardRepository.java

@@ -0,0 +1,28 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.repository;
+
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+/**
+* @website https://el-admin.vip
+* @author Li Rui
+* @date 2021-12-31
+**/
+public interface DmCardRepository extends JpaRepository<DmCard, Integer>, JpaSpecificationExecutor<DmCard> {
+}

+ 87 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/rest/DmCardController.java

@@ -0,0 +1,87 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.rest;
+
+import me.zhengjie.annotation.Log;
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import me.zhengjie.modules.dm.card.service.DmCardService;
+import me.zhengjie.modules.dm.card.service.dto.DmCardQueryCriteria;
+import org.springframework.data.domain.Pageable;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import io.swagger.annotations.*;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+* @website https://el-admin.vip
+* @author Li Rui
+* @date 2021-12-31
+**/
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "卡号管理")
+@RequestMapping("/api/dmCard")
+public class DmCardController {
+
+    private final DmCardService dmCardService;
+
+    @Log("导出数据")
+    @ApiOperation("导出数据")
+    @GetMapping(value = "/download")
+    @PreAuthorize("@el.check('dmCard:list')")
+    public void download(HttpServletResponse response, DmCardQueryCriteria criteria) throws IOException {
+        dmCardService.download(dmCardService.queryAll(criteria), response);
+    }
+
+    @GetMapping
+    @Log("查询卡号")
+    @ApiOperation("查询卡号")
+    @PreAuthorize("@el.check('dmCard:list')")
+    public ResponseEntity<Object> query(DmCardQueryCriteria criteria, Pageable pageable){
+        return new ResponseEntity<>(dmCardService.queryAll(criteria,pageable),HttpStatus.OK);
+    }
+
+    @PostMapping
+    @Log("新增卡号")
+    @ApiOperation("新增卡号")
+    @PreAuthorize("@el.check('dmCard:add')")
+    public ResponseEntity<Object> create(@Validated @RequestBody DmCard resources){
+        return new ResponseEntity<>(dmCardService.create(resources),HttpStatus.CREATED);
+    }
+
+    @PutMapping
+    @Log("修改卡号")
+    @ApiOperation("修改卡号")
+    @PreAuthorize("@el.check('dmCard:edit')")
+    public ResponseEntity<Object> update(@Validated @RequestBody DmCard resources){
+        dmCardService.update(resources);
+        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+    }
+
+    @Log("删除卡号")
+    @ApiOperation("删除卡号")
+    @PreAuthorize("@el.check('dmCard:del')")
+    @DeleteMapping
+    public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
+        dmCardService.deleteAll(ids);
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
+}

+ 83 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/service/DmCardService.java

@@ -0,0 +1,83 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.service;
+
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import me.zhengjie.modules.dm.card.service.dto.DmCardDto;
+import me.zhengjie.modules.dm.card.service.dto.DmCardQueryCriteria;
+import org.springframework.data.domain.Pageable;
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+* @website https://el-admin.vip
+* @description 服务接口
+* @author Li Rui
+* @date 2021-12-31
+**/
+public interface DmCardService {
+
+    /**
+    * 查询数据分页
+    * @param criteria 条件
+    * @param pageable 分页参数
+    * @return Map<String,Object>
+    */
+    Map<String,Object> queryAll(DmCardQueryCriteria criteria, Pageable pageable);
+
+    /**
+    * 查询所有数据不分页
+    * @param criteria 条件参数
+    * @return List<DmCardDto>
+    */
+    List<DmCardDto> queryAll(DmCardQueryCriteria criteria);
+
+    /**
+     * 根据ID查询
+     * @param id ID
+     * @return DmCardDto
+     */
+    DmCardDto findById(Integer id);
+
+    /**
+    * 创建
+    * @param resources /
+    * @return DmCardDto
+    */
+    DmCardDto create(DmCard resources);
+
+    /**
+    * 编辑
+    * @param resources /
+    */
+    void update(DmCard resources);
+
+    /**
+    * 多选删除
+    * @param ids /
+    */
+    void deleteAll(Integer[] ids);
+
+    /**
+    * 导出数据
+    * @param all 待导出的数据
+    * @param response /
+    * @throws IOException /
+    */
+    void download(List<DmCardDto> all, HttpServletResponse response) throws IOException;
+}

+ 31 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/service/dto/DmCardDto.java

@@ -0,0 +1,31 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.service.dto;
+
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+* @website https://el-admin.vip
+* @description /
+* @author Li Rui
+* @date 2021-12-31
+**/
+@Data
+public class DmCardDto implements Serializable {
+
+    private Integer id;
+}

+ 29 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/service/dto/DmCardQueryCriteria.java

@@ -0,0 +1,29 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.service.dto;
+
+import lombok.Data;
+import java.util.List;
+import me.zhengjie.annotation.Query;
+
+/**
+* @website https://el-admin.vip
+* @author Li Rui
+* @date 2021-12-31
+**/
+@Data
+public class DmCardQueryCriteria{
+}

+ 103 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/service/impl/DmCardServiceImpl.java

@@ -0,0 +1,103 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.service.impl;
+
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import me.zhengjie.utils.ValidationUtil;
+import me.zhengjie.utils.FileUtil;
+import lombok.RequiredArgsConstructor;
+import me.zhengjie.modules.dm.card.repository.DmCardRepository;
+import me.zhengjie.modules.dm.card.service.DmCardService;
+import me.zhengjie.modules.dm.card.service.dto.DmCardDto;
+import me.zhengjie.modules.dm.card.service.dto.DmCardQueryCriteria;
+import me.zhengjie.modules.dm.card.service.mapstruct.DmCardMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import me.zhengjie.utils.PageUtil;
+import me.zhengjie.utils.QueryHelp;
+import java.util.List;
+import java.util.Map;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+
+/**
+* @website https://el-admin.vip
+* @description 服务实现
+* @author Li Rui
+* @date 2021-12-31
+**/
+@Service
+@RequiredArgsConstructor
+public class DmCardServiceImpl implements DmCardService {
+
+    private final DmCardRepository dmCardRepository;
+    private final DmCardMapper dmCardMapper;
+
+    @Override
+    public Map<String,Object> queryAll(DmCardQueryCriteria criteria, Pageable pageable){
+        Page<DmCard> page = dmCardRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
+        return PageUtil.toPage(page.map(dmCardMapper::toDto));
+    }
+
+    @Override
+    public List<DmCardDto> queryAll(DmCardQueryCriteria criteria){
+        return dmCardMapper.toDto(dmCardRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
+    }
+
+    @Override
+    @Transactional
+    public DmCardDto findById(Integer id) {
+        DmCard dmCard = dmCardRepository.findById(id).orElseGet(DmCard::new);
+        ValidationUtil.isNull(dmCard.getId(),"DmCard","id",id);
+        return dmCardMapper.toDto(dmCard);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public DmCardDto create(DmCard resources) {
+        return dmCardMapper.toDto(dmCardRepository.save(resources));
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void update(DmCard resources) {
+        DmCard dmCard = dmCardRepository.findById(resources.getId()).orElseGet(DmCard::new);
+        ValidationUtil.isNull( dmCard.getId(),"DmCard","id",resources.getId());
+        dmCard.copy(resources);
+        dmCardRepository.save(dmCard);
+    }
+
+    @Override
+    public void deleteAll(Integer[] ids) {
+        for (Integer id : ids) {
+            dmCardRepository.deleteById(id);
+        }
+    }
+
+    @Override
+    public void download(List<DmCardDto> all, HttpServletResponse response) throws IOException {
+        List<Map<String, Object>> list = new ArrayList<>();
+        for (DmCardDto dmCard : all) {
+            Map<String,Object> map = new LinkedHashMap<>();
+            list.add(map);
+        }
+        FileUtil.downloadExcel(list, response);
+    }
+}

+ 32 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/card/service/mapstruct/DmCardMapper.java

@@ -0,0 +1,32 @@
+/*
+*  Copyright 2019-2020 Zheng Jie
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+package me.zhengjie.modules.dm.card.service.mapstruct;
+
+import me.zhengjie.base.BaseMapper;
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import me.zhengjie.modules.dm.card.service.dto.DmCardDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+
+/**
+* @website https://el-admin.vip
+* @author Li Rui
+* @date 2021-12-31
+**/
+@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface DmCardMapper extends BaseMapper<DmCardDto, DmCard> {
+
+}

+ 7 - 2
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ZkDataSyncTask.java

@@ -22,6 +22,9 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.dm.card.domain.DmCard;
+import me.zhengjie.modules.dm.card.service.DmCardService;
+import me.zhengjie.modules.dm.card.service.dto.DmCardDto;
 import me.zhengjie.modules.dm.plateNumber.domain.DmPlateNumber;
 import me.zhengjie.modules.dm.plateNumber.repository.DmPlateNumberRepository;
 import me.zhengjie.modules.dm.roomDevice.domain.DmRoomDevice;
@@ -66,6 +69,7 @@ public class ZkDataSyncTask {
     private final PasswordEncoder passwordEncoder;
     private final DmPlateNumberRepository dmPlateNumberRepository;
     private final DmRoomDeviceRepository dmRoomDeviceRepository;
+    private final DmCardService dmCardService;
 
     public void run() {
         log.info("deptSync 执行开始");
@@ -247,8 +251,9 @@ public class ZkDataSyncTask {
                     if (dmUserDto != null) {
                         dmUserService.update(dmUser);
                     } else {
-                        Snowflake snowflake = IdUtil.createSnowflake(1, 1);
-                        dmUser.setCardid(String.valueOf(snowflake.nextId()));
+//                        Snowflake snowflake = IdUtil.createSnowflake(1, 1);
+                        DmCardDto dmCardDto = dmCardService.create(new DmCard());
+                        dmUser.setCardid(String.valueOf(dmCardDto.getId()));
                         dmUserService.create(dmUser);
                     }
                     user.setDmUser(dmUser);