оказывается дата уже была в миллисекундах (╯°□°)╯

This commit is contained in:
Ino 2023-04-28 13:06:01 +04:00
parent 2b40c29f36
commit a9112f5e06
7 changed files with 34 additions and 23 deletions

View File

@ -4,7 +4,7 @@ import com.example.demo.supply.Product.Product;
import com.example.demo.supply.Supplier.Supplier; import com.example.demo.supply.Supplier.Supplier;
import java.sql.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class OrderDto { public class OrderDto {

View File

@ -6,7 +6,7 @@ import com.example.demo.supply.Supplier.SupplierService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.sql.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -28,7 +28,7 @@ public class OrderService {
@Transactional @Transactional
public _Order addOrder(Long supplierId){ public _Order addOrder(Long supplierId){
final _Order order = new _Order(new Date(System.currentTimeMillis())); final _Order order = new _Order(new Date());
order.setSupplier(supplierService.findSupplier(supplierId)); order.setSupplier(supplierService.findSupplier(supplierId));
return orderRepository.save(order); return orderRepository.save(order);
} }

View File

@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.sql.Date; import java.util.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;

View File

@ -24,7 +24,6 @@ export default class DataService {
static async readAll(url, transformer) { static async readAll(url, transformer) {
const response = await axios.get(this.mainUrl + url); const response = await axios.get(this.mainUrl + url);
//console.log(response)
return response.data.map(item => transformer(item)); return response.data.map(item => transformer(item));
} }
@ -42,7 +41,6 @@ export default class DataService {
static async create(url, data) { static async create(url, data) {
const response = await axios.post(getFullUrl(this.mainUrl + url, data)) const response = await axios.post(getFullUrl(this.mainUrl + url, data))
const res = response.data const res = response.data
//console.log(res)
return res return res
} }

View File

@ -12,6 +12,8 @@ export default function CreateOrderPage(props){
const supplierUrl = 'supplier/' const supplierUrl = 'supplier/'
const productUrl = 'product/' const productUrl = 'product/'
let selectedItems = [];
const headers = [ const headers = [
{ name: 'name', label: 'Продукт' }, { name: 'name', label: 'Продукт' },
{ name: 'cost', label: 'Цена' } { name: 'cost', label: 'Цена' }
@ -71,6 +73,23 @@ export default function CreateOrderPage(props){
}) })
} }
const removeProduct = () => {
if (selectedItems.length === 0) {
return;
}
if (window.confirm('Удалить выбранные элементы?')) {
const promises = [];
selectedItems.forEach(item => {
promises.push(DataService.delete(props.url + item));
});
Promise.all(promises).then((results) => {
selectedItems.length = 0;
loadItems();
});
}
}
const handleFormChange = (event) => { const handleFormChange = (event) => {
setOrder({ ...order, [event.target.id]: event.target.value }) setOrder({ ...order, [event.target.id]: event.target.value })
} }
@ -87,11 +106,10 @@ export default function CreateOrderPage(props){
} }
const hideModal = () => setModalVisible(false) const hideModal = () => setModalVisible(false)
const modalDone = () => {
}
const ds = () => console.log("") const ds = () => console.log("")
const handleTableClick = (tableSelectedItems) => selectedItems = tableSelectedItems;
return( return(
<div className="container"> <div className="container">
<div className="row"> <div className="row">
@ -123,14 +141,14 @@ export default function CreateOrderPage(props){
<p className="h4">Продукты</p> <p className="h4">Продукты</p>
<div className="btn-group" role="group" aria-label="Basic mixed styles example"> <div className="btn-group" role="group" aria-label="Basic mixed styles example">
<button type="button" className="btn btn-success" onClick={addProduct}>Добавить продукт</button> <button type="button" className="btn btn-success" onClick={addProduct}>Добавить продукт</button>
<button type="button" className="btn btn-danger" >Удалить продукт</button> <button type="button" className="btn btn-danger" onClick={removeProduct} >Удалить продукт</button>
</div> </div>
<Table <Table
headers={headers} headers={headers}
items={order.products} items={order.products}
selectable={true} selectable={true}
onClick={ds} onClick={handleTableClick}
onDblClick={ds}/> onDblClick={ds}/>
<Modal <Modal

View File

@ -24,15 +24,19 @@ export default function OrderPage(){
const loadItems = () => { const loadItems = () => {
DataService.getOrders(url).then(data => { DataService.getOrders(url).then(data => {
// console.log(data)
setOrders([]) setOrders([])
data.map(order => { data.map(order => {
const date = new Date(order.dateOfOrder)
order.dateOfOrder = `${date.getDate()}-${date.getMonth()}-${date.getFullYear()}`
setOrders(prevState => [...prevState, new Order(order)]) setOrders(prevState => [...prevState, new Order(order)])
}) })
}) })
} }
const add = () => loadItems() const add = () => {
console.log("add")
loadItems()
}
const edit = () =>{} const edit = () =>{}
const remove = () =>{ const remove = () =>{
@ -51,7 +55,6 @@ export default function OrderPage(){
} }
} }
const handleTableClick = (tableSelectedItems) => {selectedItems = tableSelectedItems;} const handleTableClick = (tableSelectedItems) => {selectedItems = tableSelectedItems;}
const handleTableDblClick = (tableSelectedItem) =>{} const handleTableDblClick = (tableSelectedItem) =>{}

View File

@ -28,18 +28,10 @@ function Catalog(props) {
} }
const saveItem = () => { const saveItem = () => {
if(isAddProd){
DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems())
}
if (!isEdit) { if (!isEdit) {
DataService.create(props.url, props.data).then(() => loadItems()) DataService.create(props.url, props.data).then(() => loadItems())
if(isAddProd) } else
DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems())
} else{
DataService.update(props.url + props.data.id, props.data).then(() => loadItems()) DataService.update(props.url + props.data.id, props.data).then(() => loadItems())
}
} }
const add = () => { const add = () => {