异步任务相关的类和删除一些没用的生成代码

master
土豆兄弟 4 years ago
parent 0cc653eed2
commit 1ebfa27940

@ -0,0 +1,33 @@
package me.zhengjie.utils;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.beans.factory.annotation.Value;
/**
*
* @see cn.hutool.http.HttpUtil
* Http,Http
*/
public class HttpUtil extends cn.hutool.http.HttpUtil {
@Value(value = "req.db.url")
private String reqDBUrl;
private HttpUtil(){}
/**
* HTTPPost
*
* @param json body
* @return
*/
private HttpResponse sendPostReq(String url, String json){
HttpResponse httpResponse = HttpRequest
.post(url)
.body(json)
.execute();
return httpResponse;
}
}

@ -56,6 +56,7 @@ public class TaskRecord implements Serializable {
@Column(name = "task_name")
@ApiModelProperty(value = "任务名称")
@NotBlank
private String taskName;
@Column(name = "time_period",nullable = false)
@ -78,7 +79,6 @@ public class TaskRecord implements Serializable {
private String oprationName;
@Column(name = "desc",nullable = false)
@NotBlank
@ApiModelProperty(value = "自定义内容补充")
private String desc;

@ -16,19 +16,25 @@
package me.zhengjie.modules.taskrecord.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.common.CommonResponse;
import me.zhengjie.common.ResponseCode;
import me.zhengjie.modules.abmessage.rest.vo.AbMessageVO;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordQueryCriteria;
import me.zhengjie.task.SendRecordTask;
import org.springframework.beans.factory.annotation.Autowired;
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.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
/**
@ -44,6 +50,10 @@ public class TaskRecordController {
private final TaskRecordService taskRecordService;
@Autowired
private SendRecordTask sendRecordTask;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@ -87,12 +97,21 @@ public class TaskRecordController {
}
// ================ 自定义功能实现 start ================
/**
* ,,
* @param idList
* @return
*/
@Log("发送课包任务")
@ApiOperation("ABMessage发送任务")
@ApiOperation("发送课包任务")
@PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/sendTask")
public ResponseEntity<Object> sendTask(@Validated @RequestBody TaskRecord resources){
// TODO: 2020/9/8 0008 发送任务在相关逻辑类中实现
public ResponseEntity<Object> sendTask(@RequestParam(value = "ids") List<Integer> idList){
if (CollectionUtils.isEmpty(idList)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
sendRecordTask.doRunTask(idList);
return new ResponseEntity<>(HttpStatus.OK);
}
@ -100,7 +119,7 @@ public class TaskRecordController {
@ApiOperation("任务课包任务合并")
@PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/mergeRecord")
public ResponseEntity<Object> mergeRecord(@RequestBody Integer[] ids){
public ResponseEntity<Object> mergeRecord(@RequestBody Integer[] ids, @RequestBody TaskRecord taskRecord){
// TODO: 2020/9/8 0008 发送任务在相关逻辑类中实现
return new ResponseEntity<>(HttpStatus.OK);
}

@ -1,12 +1,20 @@
package me.zhengjie.task;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
import me.zhengjie.utils.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
/**
@ -14,7 +22,15 @@ import java.util.List;
*/
@Component
@Slf4j
public class SendRecordTask {
public class SendRecordTask <T> {
/**
*
*/
private static final int BUILD_STATUS = 1;
@Autowired
private TaskRecordService taskRecordService;
/**
@ -32,6 +48,40 @@ public class SendRecordTask {
}
private void runTask(List<T> list) {
// 准备所有需要发送任务
List<TaskRecordDto> readySendTasks = new ArrayList<>();
list.forEach(
id->{
TaskRecordDto taskRecordDto = taskRecordService.findById((Integer) id);
if (BUILD_STATUS == taskRecordDto.getIsBuild() && StringUtils.isNotBlank(taskRecordDto.getLocalFilePath())){
readySendTasks.add(taskRecordDto);
}
}
);
// 遍历所有的待发送路径进行发送
readySendTasks.forEach(
task->{
try {
// 先查数据库从上次该课包的指定行数开始继续读取指定的行,默认每次发送指定发送条数的数据
checkReadySendTotal();
List<String> lines = Files.readAllLines(Paths.get(task));
} catch (IOException e) {
log.error("read ready send file fail, send class is {}, ready send file path is {}", this.getClass().getName(), path, e);
}
}
);
//
}
/**
*
*/
private void checkReadySendTotal(){
}
}

@ -111,3 +111,7 @@ file:
# 文件大小 /M
maxSize: 100
avatarMaxSize: 5
# 配置请求发送路径
req:
db:
url: # 设置给大坝回传号码的地址

@ -1,112 +0,0 @@
/*
* 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 eladmin-system.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 javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2020-09-07
**/
@Entity
@Data
@Table(name="t_form_message")
public class FormMessage implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ApiModelProperty(value = "id")
private Long id;
@Column(name = "gmt_create")
@CreationTimestamp
@ApiModelProperty(value = "gmtCreate")
private Timestamp gmtCreate;
@Column(name = "gmt_modified")
@UpdateTimestamp
@ApiModelProperty(value = "gmtModified")
private Timestamp gmtModified;
@Column(name = "rec_id")
@ApiModelProperty(value = "记录id")
private Long recId;
@Column(name = "uid")
@ApiModelProperty(value = "uid")
private String uid;
@Column(name = "act_name")
@ApiModelProperty(value = "业务名")
private String actName;
@Column(name = "stu_name")
@ApiModelProperty(value = "报课学生名")
private String stuName;
@Column(name = "stu_grade")
@ApiModelProperty(value = "报课年级")
private Integer stuGrade;
@Column(name = "stu_sub")
@ApiModelProperty(value = "报课学科")
private Integer stuSub;
@Column(name = "province_code")
@ApiModelProperty(value = "所在省份编码")
private Integer provinceCode;
@Column(name = "city")
@ApiModelProperty(value = "所在城市")
private String city;
@Column(name = "city_code")
@ApiModelProperty(value = "所在城市编码")
private Integer cityCode;
@Column(name = "device")
@ApiModelProperty(value = "听课设备(0.没有以上设备 1.平板电脑 2.笔记本电脑 3.台式设备+耳麦)")
private Integer device;
@Column(name = "appointment_time")
@ApiModelProperty(value = "预约听课时间(0.近期没有学习安排 1.三天内 2.一周内 3.一周以后)")
private Integer appointmentTime;
@Column(name = "start_time")
@ApiModelProperty(value = "业务开始时间")
private Timestamp startTime;
@Column(name = "push_time")
@ApiModelProperty(value = "最新推送时间")
private Timestamp pushTime;
public void copy(FormMessage source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

@ -1,28 +0,0 @@
/*
* 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 eladmin-system.repository;
import eladmin-system.domain.FormMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-07
**/
public interface FormMessageRepository extends JpaRepository<FormMessage, Long>, JpaSpecificationExecutor<FormMessage> {
}

@ -1,87 +0,0 @@
/*
* 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 eladmin-system.rest;
import me.zhengjie.annotation.Log;
import eladmin-system.domain.FormMessage;
import eladmin-system.service.FormMessageService;
import eladmin-system.service.dto.FormMessageQueryCriteria;
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 x
* @date 2020-09-07
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "form管理")
@RequestMapping("/api/formMessage")
public class FormMessageController {
private final FormMessageService formMessageService;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('formMessage:list')")
public void download(HttpServletResponse response, FormMessageQueryCriteria criteria) throws IOException {
formMessageService.download(formMessageService.queryAll(criteria), response);
}
@GetMapping
@Log("查询form")
@ApiOperation("查询form")
@PreAuthorize("@el.check('formMessage:list')")
public ResponseEntity<Object> query(FormMessageQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(formMessageService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增form")
@ApiOperation("新增form")
@PreAuthorize("@el.check('formMessage:add')")
public ResponseEntity<Object> create(@Validated @RequestBody FormMessage resources){
return new ResponseEntity<>(formMessageService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改form")
@ApiOperation("修改form")
@PreAuthorize("@el.check('formMessage:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody FormMessage resources){
formMessageService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除form")
@ApiOperation("删除form")
@PreAuthorize("@el.check('formMessage:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
formMessageService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

@ -1,83 +0,0 @@
/*
* 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 eladmin-system.service;
import eladmin-system.domain.FormMessage;
import eladmin-system.service.dto.FormMessageDto;
import eladmin-system.service.dto.FormMessageQueryCriteria;
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 x
* @date 2020-09-07
**/
public interface FormMessageService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(FormMessageQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<FormMessageDto>
*/
List<FormMessageDto> queryAll(FormMessageQueryCriteria criteria);
/**
* ID
* @param id ID
* @return FormMessageDto
*/
FormMessageDto findById(Long id);
/**
*
* @param resources /
* @return FormMessageDto
*/
FormMessageDto create(FormMessage resources);
/**
*
* @param resources /
*/
void update(FormMessage resources);
/**
*
* @param ids /
*/
void deleteAll(Long[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<FormMessageDto> all, HttpServletResponse response) throws IOException;
}

@ -1,75 +0,0 @@
/*
* 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 eladmin-system.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2020-09-07
**/
@Data
public class FormMessageDto implements Serializable {
private Long id;
private Timestamp gmtCreate;
private Timestamp gmtModified;
/** 记录id */
private Long recId;
/** uid */
private String uid;
/** 业务名 */
private String actName;
/** 报课学生名 */
private String stuName;
/** 报课年级 */
private Integer stuGrade;
/** 报课学科 */
private Integer stuSub;
/** 所在省份编码 */
private Integer provinceCode;
/** 所在城市 */
private String city;
/** 所在城市编码 */
private Integer cityCode;
/** 听课设备(0.没有以上设备 1.平板电脑 2.笔记本电脑 3.台式设备+耳麦) */
private Integer device;
/** 预约听课时间(0.近期没有学习安排 1.三天内 2.一周内 3.一周以后) */
private Integer appointmentTime;
/** 业务开始时间 */
private Timestamp startTime;
/** 最新推送时间 */
private Timestamp pushTime;
}

@ -1,54 +0,0 @@
/*
* 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 eladmin-system.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-07
**/
@Data
public class FormMessageQueryCriteria{
/** 精确 */
@Query
private String uid;
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String actName;
/** 精确 */
@Query
private Integer device;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Integer> createTime;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<String> createTime;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
}

@ -1,118 +0,0 @@
/*
* 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 eladmin-system.service.impl;
import eladmin-system.domain.FormMessage;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import eladmin-system.repository.FormMessageRepository;
import eladmin-system.service.FormMessageService;
import eladmin-system.service.dto.FormMessageDto;
import eladmin-system.service.dto.FormMessageQueryCriteria;
import eladmin-system.service.mapstruct.FormMessageMapper;
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 x
* @date 2020-09-07
**/
@Service
@RequiredArgsConstructor
public class FormMessageServiceImpl implements FormMessageService {
private final FormMessageRepository formMessageRepository;
private final FormMessageMapper formMessageMapper;
@Override
public Map<String,Object> queryAll(FormMessageQueryCriteria criteria, Pageable pageable){
Page<FormMessage> page = formMessageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(formMessageMapper::toDto));
}
@Override
public List<FormMessageDto> queryAll(FormMessageQueryCriteria criteria){
return formMessageMapper.toDto(formMessageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Transactional
public FormMessageDto findById(Long id) {
FormMessage formMessage = formMessageRepository.findById(id).orElseGet(FormMessage::new);
ValidationUtil.isNull(formMessage.getId(),"FormMessage","id",id);
return formMessageMapper.toDto(formMessage);
}
@Override
@Transactional(rollbackFor = Exception.class)
public FormMessageDto create(FormMessage resources) {
return formMessageMapper.toDto(formMessageRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(FormMessage resources) {
FormMessage formMessage = formMessageRepository.findById(resources.getId()).orElseGet(FormMessage::new);
ValidationUtil.isNull( formMessage.getId(),"FormMessage","id",resources.getId());
formMessage.copy(resources);
formMessageRepository.save(formMessage);
}
@Override
public void deleteAll(Long[] ids) {
for (Long id : ids) {
formMessageRepository.deleteById(id);
}
}
@Override
public void download(List<FormMessageDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (FormMessageDto formMessage : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put(" gmtCreate", formMessage.getGmtCreate());
map.put(" gmtModified", formMessage.getGmtModified());
map.put("记录id", formMessage.getRecId());
map.put("uid", formMessage.getUid());
map.put("业务名", formMessage.getActName());
map.put("报课学生名", formMessage.getStuName());
map.put("报课年级", formMessage.getStuGrade());
map.put("报课学科", formMessage.getStuSub());
map.put("所在省份编码", formMessage.getProvinceCode());
map.put("所在城市", formMessage.getCity());
map.put("所在城市编码", formMessage.getCityCode());
map.put("听课设备(0.没有以上设备 1.平板电脑 2.笔记本电脑 3.台式设备+耳麦)", formMessage.getDevice());
map.put("预约听课时间(0.近期没有学习安排 1.三天内 2.一周内 3.一周以后)", formMessage.getAppointmentTime());
map.put("业务开始时间", formMessage.getStartTime());
map.put("最新推送时间", formMessage.getPushTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

@ -1,32 +0,0 @@
/*
* 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 eladmin-system.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import eladmin-system.domain.FormMessage;
import eladmin-system.service.dto.FormMessageDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-07
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface FormMessageMapper extends BaseMapper<FormMessageDto, FormMessage> {
}

@ -1,108 +0,0 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<label class="el-form-item-label">id</label>
<el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<label class="el-form-item-label">姓名</label>
<el-input v-model="query.name" clearable placeholder="姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<label class="el-form-item-label">年龄</label>
<el-input v-model="query.age" clearable placeholder="年龄" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<rrOperation :crud="crud" />
</div>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission" />
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<el-form-item label="id" prop="id">
<el-input v-model="form.id" style="width: 370px;" />
</el-form-item>
<el-form-item label="姓名" prop="name">
<el-input v-model="form.name" :rows="3" type="textarea" style="width: 370px;" />
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU"></el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU"></el-button>
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="id" />
<el-table-column prop="name" label="姓名" />
<el-table-column prop="age" label="年龄" />
<el-table-column v-permission="['admin','student:edit','student:del']" label="操作" width="150px" align="center">
<template slot-scope="scope">
<udOperation
:data="scope.row"
:permission="permission"
/>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
</div>
</div>
</template>
<script>
import crudStudent from '@/api/student'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { id: null, name: null, age: null }
export default {
name: 'Student',
components: { pagination, crudOperation, rrOperation, udOperation },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({ title: 'student', url: 'api/student', sort: 'id,desc', crudMethod: { ...crudStudent }})
},
data() {
return {
permission: {
add: ['admin', 'student:add'],
edit: ['admin', 'student:edit'],
del: ['admin', 'student:del']
},
rules: {
id: [
{ required: true, message: 'id不能为空', trigger: 'blur' }
],
name: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
age: [
{ required: true, message: '年龄不能为空', trigger: 'blur' }
]
},
queryTypeOptions: [
{ key: 'id', display_name: 'id' },
{ key: 'name', display_name: '姓名' },
{ key: 'age', display_name: '年龄' }
]
}
},
methods: {
// false
[CRUD.HOOK.beforeRefresh]() {
return true
}
}
}
</script>
<style scoped>
</style>

@ -1,108 +0,0 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<label class="el-form-item-label">id</label>
<el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<label class="el-form-item-label">姓名</label>
<el-input v-model="query.name" clearable placeholder="姓名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<label class="el-form-item-label">年龄</label>
<el-input v-model="query.age" clearable placeholder="年龄" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<rrOperation :crud="crud" />
</div>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission" />
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<el-form-item label="id" prop="id">
<el-input v-model="form.id" style="width: 370px;" />
</el-form-item>
<el-form-item label="姓名" prop="name">
<el-input v-model="form.name" :rows="3" type="textarea" style="width: 370px;" />
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU"></el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU"></el-button>
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="id" label="id" />
<el-table-column prop="name" label="姓名" />
<el-table-column prop="age" label="年龄" />
<el-table-column v-permission="['admin','student:edit','student:del']" label="操作" width="150px" align="center">
<template slot-scope="scope">
<udOperation
:data="scope.row"
:permission="permission"
/>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
</div>
</div>
</template>
<script>
import crudStudent from '@/api/student'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { id: null, name: null, age: null }
export default {
name: 'Student',
components: { pagination, crudOperation, rrOperation, udOperation },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({ title: 'student', url: 'api/student', sort: 'id,desc', crudMethod: { ...crudStudent }})
},
data() {
return {
permission: {
add: ['admin', 'student:add'],
edit: ['admin', 'student:edit'],
del: ['admin', 'student:del']
},
rules: {
id: [
{ required: true, message: 'id不能为空', trigger: 'blur' }
],
name: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
age: [
{ required: true, message: '年龄不能为空', trigger: 'blur' }
]
},
queryTypeOptions: [
{ key: 'id', display_name: 'id' },
{ key: 'name', display_name: '姓名' },
{ key: 'age', display_name: '年龄' }
]
}
},
methods: {
// false
[CRUD.HOOK.beforeRefresh]() {
return true
}
}
}
</script>
<style scoped>
</style>

@ -1,27 +0,0 @@
import request from '@/utils/request'
export function add(data) {
return request({
url: 'api/student',
method: 'post',
data
})
}
export function del(ids) {
return request({
url: 'api/student/',
method: 'delete',
data: ids
})
}
export function edit(data) {
return request({
url: 'api/student',
method: 'put',
data
})
}
export default { add, edit, del }
Loading…
Cancel
Save