xiongzhu 3 лет назад
Родитель
Сommit
f7c184f4e5

+ 2 - 0
src/main/java/com/izouma/awesomeAdmin/domain/Order.java

@@ -103,4 +103,6 @@ public class Order extends BaseEntity {
     private boolean locked;
 
     private boolean del;
+
+    private Long batchId;
 }

+ 2 - 0
src/main/java/com/izouma/awesomeAdmin/domain/Product.java

@@ -88,4 +88,6 @@ public class Product extends BaseEntity {
     private User user;
 
     private boolean locked;
+
+    private Long batchId;
 }

+ 8 - 0
src/main/java/com/izouma/awesomeAdmin/domain/SaleBatch.java

@@ -6,6 +6,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import javax.persistence.Entity;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
 
 @Data
 @Entity
@@ -18,5 +20,11 @@ public class SaleBatch extends BaseEntity {
 
     private Boolean enabled;
 
+    private LocalTime sellStart;
 
+    private LocalTime sellEnd;
+
+    private LocalTime delegateStart;
+
+    private LocalTime delegateEnd;
 }

+ 16 - 0
src/main/java/com/izouma/awesomeAdmin/repo/SaleBatchRepo.java

@@ -0,0 +1,16 @@
+package com.izouma.awesomeAdmin.repo;
+
+import com.izouma.awesomeAdmin.domain.SaleBatch;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.transaction.Transactional;
+
+public interface SaleBatchRepo extends JpaRepository<SaleBatch, Long>, JpaSpecificationExecutor<SaleBatch> {
+    @Query("update SaleBatch t set t.enabled = false where t.id = ?1")
+    @Modifying
+    @Transactional
+    void deleteById(Long id);
+}

+ 21 - 7
src/main/java/com/izouma/awesomeAdmin/service/DelegationService.java

@@ -60,8 +60,20 @@ public class DelegationService {
     private TaskScheduler        taskScheduler;
     private ScheduledFuture<?>   future;
     private UserMoneyRecordRepo  userMoneyRecordRepo;
+    private SaleBatchRepo        saleBatchRepo;
 
-    public DelegationService(DelegationRepo delegationRepo, OrderRepo orderRepo, SysConfigService sysConfigService, ProductRepo productRepo, CommissionRecordRepo commissionRecordRepo, UserRepo userRepo, AlipayClient alipayClient, WxPayService wxPayService, Environment env, TaskScheduler taskScheduler, UserMoneyRecordRepo userMoneyRecordRepo) {
+    public DelegationService(DelegationRepo delegationRepo,
+                             OrderRepo orderRepo,
+                             SysConfigService sysConfigService,
+                             ProductRepo productRepo,
+                             CommissionRecordRepo commissionRecordRepo,
+                             UserRepo userRepo,
+                             AlipayClient alipayClient,
+                             WxPayService wxPayService,
+                             Environment env,
+                             TaskScheduler taskScheduler,
+                             UserMoneyRecordRepo userMoneyRecordRepo,
+                             SaleBatchRepo saleBatchRepo) {
         this.delegationRepo = delegationRepo;
         this.orderRepo = orderRepo;
         this.sysConfigService = sysConfigService;
@@ -73,6 +85,7 @@ public class DelegationService {
         this.env = env;
         this.taskScheduler = taskScheduler;
         this.userMoneyRecordRepo = userMoneyRecordRepo;
+        this.saleBatchRepo = saleBatchRepo;
     }
 
     public void payDelegationAlipay(Long userId, Long orderId, BigDecimal riseRate, String returnUrl, Model model) {
@@ -205,8 +218,13 @@ public class DelegationService {
     }
 
     private BigDecimal checkPayDelegation(Long userId, Long orderId, BigDecimal riseRate) {
-        LocalTime delegationTime = sysConfigService.getTime(Constants.DELEGATION_TIME);
-        LocalTime sellTime = sysConfigService.getTime(Constants.SELL_TIME);
+        Order sellerOrder = orderRepo.findById(orderId).orElseThrow(new BusinessException("无记录"));
+        if (!userId.equals(sellerOrder.getUserId())) {
+            throw new BusinessException("无权限");
+        }
+        SaleBatch saleBatch = saleBatchRepo.findById(sellerOrder.getBatchId()).orElseThrow(new BusinessException("无记录"));
+        LocalTime delegationTime = saleBatch.getDelegateStart();
+        LocalTime sellTime = saleBatch.getSellStart();
         if (LocalTime.now().isBefore(delegationTime) && LocalTime.now().isAfter(sellTime)) {
             throw new BusinessException("委托未开始,请" + delegationTime
                     .format(DateTimeFormatter.ofPattern("HH:mm")) + "后再来");
@@ -215,10 +233,6 @@ public class DelegationService {
         if (max.compareTo(riseRate) < 0) {
             throw new BusinessException("最大上涨比例不超过" + max.toString());
         }
-        Order sellerOrder = orderRepo.findById(orderId).orElseThrow(new BusinessException("无记录"));
-        if (!userId.equals(sellerOrder.getUserId())) {
-            throw new BusinessException("无权限");
-        }
         return sellerOrder.getTotalPrice()
                 .multiply(sysConfigService.getBigDecimal(Constants.PLATFORM_COMMISSION))
                 .setScale(2, RoundingMode.HALF_UP);

+ 14 - 0
src/main/java/com/izouma/awesomeAdmin/service/SaleBatchService.java

@@ -0,0 +1,14 @@
+package com.izouma.awesomeAdmin.service;
+
+import com.izouma.awesomeAdmin.domain.SaleBatch;
+import com.izouma.awesomeAdmin.repo.SaleBatchRepo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SaleBatchService {
+
+    @Autowired
+    private SaleBatchRepo saleBatchRepo;
+
+}

+ 66 - 0
src/main/java/com/izouma/awesomeAdmin/web/SaleBatchController.java

@@ -0,0 +1,66 @@
+package com.izouma.awesomeAdmin.web;
+import com.izouma.awesomeAdmin.domain.SaleBatch;
+import com.izouma.awesomeAdmin.service.SaleBatchService;
+import com.izouma.awesomeAdmin.dto.PageQuery;
+import com.izouma.awesomeAdmin.exception.BusinessException;
+import com.izouma.awesomeAdmin.repo.SaleBatchRepo;
+import com.izouma.awesomeAdmin.utils.ObjUtils;
+import com.izouma.awesomeAdmin.utils.excel.ExcelUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@RestController
+@RequestMapping("/saleBatch")
+public class SaleBatchController extends BaseController {
+    /*generatedStart*/
+    @Autowired
+    private SaleBatchService saleBatchService;
+
+    @Autowired
+    private SaleBatchRepo saleBatchRepo;
+    /*generatedEnd*/
+
+    /*generatedStart*/
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public SaleBatch save(@RequestBody SaleBatch record) {
+        if (record.getId() != null) {
+            SaleBatch orig = saleBatchRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return saleBatchRepo.save(orig);
+        }
+        return saleBatchRepo.save(record);
+    }
+
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @GetMapping("/all")
+    public Page<SaleBatch> all(PageQuery pageQuery) {
+        return saleBatchRepo.findAll(toSpecification(pageQuery,SaleBatch.class), toPageRequest(pageQuery));
+    }
+
+    @GetMapping("/get/{id}")
+    public SaleBatch get(@PathVariable Long id) {
+        return saleBatchRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        saleBatchRepo.deleteById(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<SaleBatch> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+    /*generatedEnd*/
+}
+

+ 1 - 0
src/main/resources/genjson/SaleBatch.json

@@ -0,0 +1 @@
+{"tableName":"SaleBatch","className":"SaleBatch","remark":"销售批次","genTable":true,"genClass":true,"genList":true,"genForm":true,"genRouter":true,"javaPath":"/Users/drew/Projects/Java/art-trade/src/main/java/com/izouma/awesomeAdmin","viewPath":"/Users/drew/Projects/Java/art-trade/src/main/vue/src/views","routerPath":"/Users/drew/Projects/Java/art-trade/src/main/vue/src","resourcesPath":"/Users/drew/Projects/Java/art-trade/src/main/resources","dataBaseType":"Mysql","fields":[{"name":"name","modelName":"name","remark":"名称","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"enabled","modelName":"enabled","remark":"启用","showInList":true,"showInForm":true,"formType":"switch","required":true},{"name":"sellStart","modelName":"sellStart","remark":"开始销售时间","showInList":true,"showInForm":true,"formType":"datetime","required":true},{"name":"sellEnd","modelName":"sellEnd","remark":"结束销售时间","showInList":true,"showInForm":true,"formType":"datetime","required":true},{"name":"delegateStart","modelName":"delegateStart","remark":"开始上架时间","showInList":true,"showInForm":true,"formType":"datetime","required":true},{"name":"delegateEnd","modelName":"delegateEnd","remark":"结束上架时间","showInList":true,"showInForm":true,"formType":"datetime","required":true}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.awesomeAdmin","tablePackage":"com.izouma.awesomeAdmin.domain.SaleBatch"}

+ 16 - 0
src/main/vue/src/router.js

@@ -289,6 +289,22 @@ const router = new Router({
                     meta: {
                         title: '子平台管理'
                     }
+                },
+                {
+                    path: '/saleBatchEdit',
+                    name: 'SaleBatchEdit',
+                    component: () => import(/* webpackChunkName: "saleBatchEdit" */ '@/views/SaleBatchEdit.vue'),
+                    meta: {
+                        title: '销售批次编辑'
+                    }
+                },
+                {
+                    path: '/saleBatchList',
+                    name: 'SaleBatchList',
+                    component: () => import(/* webpackChunkName: "saleBatchList" */ '@/views/SaleBatchList.vue'),
+                    meta: {
+                        title: '销售批次'
+                    }
                 }
                 /**INSERT_LOCATION**/
             ]

+ 27 - 1
src/main/vue/src/views/ProductEdit.vue

@@ -69,6 +69,16 @@
                     </el-option>
                 </el-select>
             </el-form-item>
+            <el-form-item label="批次" prop="batchId">
+                <el-select v-model="formData.batchId" placeholder="选择批次">
+                    <el-option
+                        v-for="item in batchOptions"
+                        :key="item.value"
+                        :value="item.value"
+                        :label="item.label"
+                    ></el-option>
+                </el-select>
+            </el-form-item>
             <el-form-item prop="reserve" label="暂存商品池">
                 <el-checkbox v-model="formData.reserve" disabled></el-checkbox>
             </el-form-item>
@@ -146,6 +156,14 @@ export default {
                 console.log(e);
                 this.$message.error(e.error);
             });
+        this.$http.get('/saleBatch/all').then(res => {
+            this.batchOptions = res.content.map(i => {
+                return {
+                    label: i.name,
+                    value: i.id
+                };
+            });
+        });
     },
     data() {
         return {
@@ -192,6 +210,13 @@ export default {
                         message: '请选择分类',
                         trigger: 'blur'
                     }
+                ],
+                batchId: [
+                    {
+                        required: true,
+                        message: '请选择批次',
+                        trigger: 'blur'
+                    }
                 ]
             },
             userOptions: [],
@@ -199,7 +224,8 @@ export default {
                 { label: '上架', value: 'IN_STOCK' },
                 { label: '下架', value: 'SOLD_OUT' }
             ],
-            categoryIdOptions: []
+            categoryIdOptions: [],
+            batchOptions: []
         };
     },
     methods: {

+ 180 - 0
src/main/vue/src/views/SaleBatchEdit.vue

@@ -0,0 +1,180 @@
+<template>
+    <div class="edit-view">
+        <el-form
+            :model="formData"
+            :rules="rules"
+            ref="form"
+            label-width="108px"
+            label-position="right"
+            size="small"
+            style="max-width: 500px;"
+        >
+            <el-form-item prop="name" label="名称">
+                <el-input v-model="formData.name"></el-input>
+            </el-form-item>
+            <el-form-item prop="enabled" label="启用">
+                <el-switch v-model="formData.enabled"></el-switch>
+            </el-form-item>
+            <el-form-item label="销售时间" prop="sell">
+                <el-time-picker
+                    is-range
+                    v-model="formData.sell"
+                    range-separator="至"
+                    start-placeholder="开始时间"
+                    end-placeholder="结束时间"
+                    placeholder="选择时间范围"
+                    value-format="HH:mm:ss"
+                >
+                </el-time-picker>
+            </el-form-item>
+            <el-form-item label="上架时间" prop="delegate">
+                <el-time-picker
+                    is-range
+                    v-model="formData.delegate"
+                    range-separator="至"
+                    start-placeholder="开始时间"
+                    end-placeholder="结束时间"
+                    placeholder="选择时间范围"
+                    value-format="HH:mm:ss"
+                >
+                </el-time-picker>
+            </el-form-item>
+            <el-form-item>
+                <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
+                <el-button @click="onDelete" :loading="saving" type="danger" v-if="formData.id">删除 </el-button>
+                <el-button @click="$router.go(-1)">取消</el-button>
+            </el-form-item>
+        </el-form>
+    </div>
+</template>
+<script>
+export default {
+    name: 'SaleBatchEdit',
+    created() {
+        if (this.$route.query.id) {
+            this.$http
+                .get('saleBatch/get/' + this.$route.query.id)
+                .then(res => {
+                    if (res.sellStart && res.sellEnd) {
+                        res.sell = [res.sellStart, res.sellEnd];
+                    }
+                    if (res.delegateStart && res.delegateEnd) {
+                        res.delegate = [res.delegateStart, res.delegateEnd];
+                    }
+                    this.formData = res;
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.$message.error(e.error);
+                });
+        }
+    },
+    data() {
+        return {
+            saving: false,
+            formData: {
+                enabled: false,
+                sell: null,
+                delegate: null
+            },
+            rules: {
+                name: [
+                    {
+                        required: true,
+                        message: '请输入名称',
+                        trigger: 'blur'
+                    }
+                ],
+                enabled: [
+                    {
+                        required: true,
+                        message: '请输入启用',
+                        trigger: 'blur'
+                    }
+                ],
+                sellStart: [
+                    {
+                        required: true,
+                        message: '请输入开始销售时间',
+                        trigger: 'blur'
+                    }
+                ],
+                sellEnd: [
+                    {
+                        required: true,
+                        message: '请输入结束销售时间',
+                        trigger: 'blur'
+                    }
+                ],
+                delegateStart: [
+                    {
+                        required: true,
+                        message: '请输入开始上架时间',
+                        trigger: 'blur'
+                    }
+                ],
+                delegateEnd: [
+                    {
+                        required: true,
+                        message: '请输入结束上架时间',
+                        trigger: 'blur'
+                    }
+                ],
+                sell: [{ required: true, message: '请选择销售时间', trigger: 'blur' }],
+                delegate: [{ required: true, message: '请选择上架时间', trigger: 'change' }]
+            }
+        };
+    },
+    methods: {
+        onSave() {
+            this.$refs.form.validate(valid => {
+                if (valid) {
+                    this.submit();
+                } else {
+                    return false;
+                }
+            });
+        },
+        submit() {
+            let data = {
+                ...this.formData,
+                sellStart: this.formData.sell[0],
+                sellEnd: this.formData.sell[1],
+                delegateStart: this.formData.delegate[0],
+                delegateEnd: this.formData.delegate[1]
+            };
+
+            this.saving = true;
+            this.$http
+                .post('/saleBatch/save', data, { body: 'json' })
+                .then(res => {
+                    this.saving = false;
+                    this.$message.success('成功');
+                    this.$router.go(-1);
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.saving = false;
+                    this.$message.error(e.error);
+                });
+        },
+        onDelete() {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/saleBatch/del/${this.formData.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.$router.go(-1);
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        console.log(e);
+                        this.$message.error(e.error);
+                    }
+                });
+        }
+    }
+};
+</script>
+<style lang="less" scoped></style>

+ 172 - 0
src/main/vue/src/views/SaleBatchList.vue

@@ -0,0 +1,172 @@
+<template>
+    <div class="list-view">
+        <div class="filters-container">
+            <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
+            <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索 </el-button>
+            <el-button @click="addRow" type="primary" icon="el-icon-plus" class="filter-item">添加 </el-button>
+            <el-button
+                @click="download"
+                type="primary"
+                icon="el-icon-download"
+                :loading="downloading"
+                class="filter-item"
+                >导出EXCEL
+            </el-button>
+        </div>
+        <el-table
+            :data="tableData"
+            row-key="id"
+            ref="table"
+            header-row-class-name="table-header-row"
+            header-cell-class-name="table-header-cell"
+            row-class-name="table-row"
+            cell-class-name="table-cell"
+            :height="tableHeight"
+        >
+            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
+            <el-table-column prop="id" label="ID" width="100"> </el-table-column>
+            <el-table-column prop="name" label="名称"> </el-table-column>
+            <el-table-column prop="enabled" label="启用" align="center">
+                <template slot-scope="{ row }">
+                    <el-tag :type="row.enabled ? '' : 'info'">{{ row.enabled ? '是' : '否' }}</el-tag>
+                </template>
+            </el-table-column>
+            <el-table-column prop="sellStart" label="开始销售时间"> </el-table-column>
+            <el-table-column prop="sellEnd" label="结束销售时间"> </el-table-column>
+            <el-table-column prop="delegateStart" label="开始上架时间"> </el-table-column>
+            <el-table-column prop="delegateEnd" label="结束上架时间"> </el-table-column>
+            <el-table-column label="操作" align="center" fixed="right" min-width="150">
+                <template slot-scope="{ row }">
+                    <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
+                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
+                </template>
+            </el-table-column>
+        </el-table>
+        <div class="pagination-wrapper">
+            <div class="multiple-mode-wrapper">
+                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
+                <el-button-group v-else>
+                    <el-button @click="operation1">批量操作1</el-button>
+                    <el-button @click="operation2">批量操作2</el-button>
+                    <el-button @click="toggleMultipleMode(false)">取消</el-button>
+                </el-button-group>
+            </div>
+            <el-pagination
+                background
+                @size-change="onSizeChange"
+                @current-change="onCurrentChange"
+                :current-page="page"
+                :page-sizes="[10, 20, 30, 40, 50]"
+                :page-size="pageSize"
+                layout="total, sizes, prev, pager, next, jumper"
+                :total="totalElements"
+            >
+            </el-pagination>
+        </div>
+    </div>
+</template>
+<script>
+import { mapState } from 'vuex';
+import pageableTable from '@/mixins/pageableTable';
+
+export default {
+    name: 'SaleBatchList',
+    mixins: [pageableTable],
+    created() {
+        this.getData();
+    },
+    data() {
+        return {
+            multipleMode: false,
+            search: '',
+            url: '/saleBatch/all',
+            downloading: false
+        };
+    },
+    computed: {
+        selection() {
+            return this.$refs.table.selection.map(i => i.id);
+        }
+    },
+    methods: {
+        beforeGetData() {
+            if (this.search) {
+                return { search: this.search };
+            }
+        },
+        toggleMultipleMode(multipleMode) {
+            this.multipleMode = multipleMode;
+            if (!multipleMode) {
+                this.$refs.table.clearSelection();
+            }
+        },
+        addRow() {
+            this.$router.push({
+                path: '/saleBatchEdit',
+                query: {
+                    ...this.$route.query
+                }
+            });
+        },
+        editRow(row) {
+            this.$router.push({
+                path: '/saleBatchEdit',
+                query: {
+                    id: row.id
+                }
+            });
+        },
+        download() {
+            this.downloading = true;
+            this.$axios
+                .get('/saleBatch/excel', {
+                    responseType: 'blob',
+                    params: { size: 10000 }
+                })
+                .then(res => {
+                    console.log(res);
+                    this.downloading = false;
+                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+                    const link = document.createElement('a');
+                    link.href = downloadUrl;
+                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    document.body.appendChild(link);
+                    link.click();
+                    link.remove();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    this.$message.error(e.error);
+                });
+        },
+        operation1() {
+            this.$notify({
+                title: '提示',
+                message: this.selection
+            });
+        },
+        operation2() {
+            this.$message('操作2');
+        },
+        deleteRow(row) {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/saleBatch/del/${row.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.getData();
+                })
+                .catch(action => {
+                    if (action === 'cancel') {
+                        this.$message.info('删除取消');
+                    } else {
+                        this.$message.error('删除失败');
+                    }
+                });
+        }
+    }
+};
+</script>
+<style lang="less" scoped></style>