4 / 4 / 1
Регистрация: 15.04.2017
Сообщений: 346
|
|
|
|
Когда получаю данные из БД MS Sql GET запросом, то вычисляемые столбцы отображают
28.02.2024, 21:40. Показов 869. Ответов 0
Добрый вечер.
Когда получаю данные из БД MS Sql GET запросом, то вычисляемые столбцы(считаются на стороне MS SQL функциями) отображаются в виде NULL, как мне это исправить?
Моя сущность:
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "IncomeDetails", schema = "dbo", catalog = "AVBusiness")
public class IncomeDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer numParty;
@ManyToOne
@JoinColumn(name="incId")
private Incomes incId;
@ManyToOne
@JoinColumn(name="branchId")
private Branch branchId;
@ManyToOne
@JoinColumn(name="productId")
private Products productId;
private Double qty;
@ManyToOne
@JoinColumn(name="Measure")
private Measure measure;
private Double priceC;
private Double priceCallowance;
@Transient
private Double sumPriceCr;
private Double wholeSaleSurcharge;
@Transient
private Double sumWprice;
@Transient
private Double taxSumR;
@Transient
private Double taxSumW;
@Transient
private Double totalPriceR;
@Transient
private Double totalPriceCurR;
@Transient
private Double totalPriceW;
@Transient
private Double totalPriceCurW;
private Boolean prod;
@ManyToOne
@JoinColumn(name="Tax")
private Tax tax;
} |
|
DTO
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| package com.dto;
import lombok.Data;
@Data
public class IncomeDetailsDto {
private int Incomes;
private Integer BranchId;
private int ProductId;
private Double Qty;
private Integer Measure;
private Double PriceC;
private Double PriceCallowance;
private Double SumPriceCr;
private Double WholeSaleSurcharge;
private Double SumWprice;
private Double TaxSumR;
private Double TaxSumW;
private Double TotalPriceR;
private Double TotalPriceCurR;
private Double TotalPriceW;
private Double TotalPriceCurW;
private Boolean Prod;
private Integer idTax;
} |
|
Repository
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| package com.repository;
import com.entity.Currency;
import com.entity.Customers;
import com.entity.Incomes;
import com.entity.Status;
import com.entity.Stock;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IncomesRepository extends JpaRepository<Incomes, Integer> {
List<Incomes> findByStatus(Status status);
List<Incomes> findByStock(Stock stock);
List<Incomes> findByCurrency(Currency currency);
List<Incomes> findByCustomers(Customers customers);
} |
|
Service
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| package com.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.dto.IncomeDetailsDto;
import com.entity.Branch;
import com.entity.IncomeDetails;
import com.entity.Incomes;
import com.entity.Measure;
import com.entity.Tax;
import com.repository.IncomeDetailsRepository;
import lombok.*;
@Service
@AllArgsConstructor
public class IncomeDetailsService {
private final IncomeDetailsRepository incomeDetailsRepository;
private final TaxService taxService;
private final MeasureService measureService;
private final IncomesService incomeService;
private final BranchService branchService;
private final ProductService productService;
public IncomeDetails create(IncomeDetailsDto dto) {
// Tax tax = taxService.getById(dto.getTax());
return incomeDetailsRepository.save(IncomeDetails.builder()
.branchId(branchService.readById(dto.getBranchId()))
.productId(productService.readById(dto.getProductId()))
.qty(dto.getQty())
.measure(measureService.readById(dto.getMeasure()))
.priceC(dto.getPriceC())
.priceCallowance(dto.getPriceCallowance())
.sumPriceCr(dto.getSumPriceCr())
.wholeSaleSurcharge(dto.getWholeSaleSurcharge())
.sumWprice(dto.getSumWprice())
.tax(taxService.readById(dto.getIdTax()))
.taxSumR(dto.getTaxSumR())
.taxSumW(dto.getTaxSumW())
.totalPriceR(dto.getTotalPriceR())
.totalPriceCurR(dto.getTotalPriceCurR())
.totalPriceW(dto.getTotalPriceR())
.totalPriceCurW(dto.getTotalPriceCurW())
.prod(dto.getProd())
.build());
}
public List<IncomeDetails> readAll() {
return incomeDetailsRepository.findAllIncd();
}
public List<IncomeDetails> readByBranch (Integer idBranch) {
Branch branch = branchService.readById(idBranch);
return incomeDetailsRepository.findByBranchId(branch);
}
public List<IncomeDetails> readByTaxId (Integer idTax) {
Tax tax = taxService.readById(idTax);
return incomeDetailsRepository.findByTax(tax);
}
public List<IncomeDetails> readByIncId (Integer incId) {
Incomes incomes = incomeService.readById(incId);
return incomeDetailsRepository.findByIncId(incomes);
}
public List<IncomeDetails> readByMeasure (Integer idMeasure) {
Measure measure = measureService.readById(idMeasure);
return incomeDetailsRepository.findByMeasure(measure);
}
public IncomeDetails readById(Integer idNumParty)
{
return incomeDetailsRepository.findById(idNumParty).orElseThrow(()->
new RuntimeException("Номер партии не найден!"));
}
public IncomeDetails update(IncomeDetails incomeDetails)
{
return incomeDetailsRepository.save(incomeDetails);
}
public void delete(Integer id)
{
incomeDetailsRepository.deleteById(id);
}
} |
|
controller
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| package com.controller;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dto.IncomeDetailsDto;
import com.entity.IncomeDetails;
import com.service.IncomeDetailsService;
@RestController
@AllArgsConstructor
@RequestMapping("/incomeDt")
public class IncomeDetailsController {
private final IncomeDetailsService incomeDetailsService;
@PostMapping
public ResponseEntity<IncomeDetails> create(@RequestBody IncomeDetailsDto incomeDetailsDto){
return mappingResponseIncomeDetails(incomeDetailsService.create(incomeDetailsDto));
}
@GetMapping
public ResponseEntity<List<IncomeDetails>> readAll(){
return mappingResponseListIncomeDetails(incomeDetailsService.readAll());
}
@GetMapping("/branch/{IdBranch}")
public ResponseEntity<List<IncomeDetails>> readByBranchId(@PathVariable("IdBranch") Integer IdBranch){
return new ResponseEntity<>(incomeDetailsService.readByBranch(IdBranch), HttpStatus.OK);
}
@GetMapping("/{numParty}")
public ResponseEntity<IncomeDetails> read(@PathVariable("numParty") Integer numParty){
return new ResponseEntity<>(incomeDetailsService.readById(numParty), HttpStatus.OK);
}
@GetMapping("/tax/{IdTax}")
public ResponseEntity<List<IncomeDetails>> readByTaxId(@PathVariable("IdTax") Integer IdTax){
return new ResponseEntity<>(incomeDetailsService.readByTaxId(IdTax), HttpStatus.OK);
}
@GetMapping("/incomes/{IncId}")
public ResponseEntity<List<IncomeDetails>> readByIncId(@PathVariable("IncId") Integer IncId){
return new ResponseEntity<>(incomeDetailsService.readByIncId(IncId), HttpStatus.OK);
}
@GetMapping("/measure/{Measure}")
public ResponseEntity<List<IncomeDetails>> readByMeasure(@PathVariable("Measure") Integer Measure){
return new ResponseEntity<>(incomeDetailsService.readByMeasure(Measure), HttpStatus.OK);
}
@PutMapping
public ResponseEntity<IncomeDetails> update(@RequestBody IncomeDetails incomeDetails)
{
return new ResponseEntity<>(incomeDetailsService.update(incomeDetails), HttpStatus.OK);
}
@DeleteMapping("/{numParty}")
public HttpStatus delete(@PathVariable("numParty") Integer numParty) {
incomeDetailsService.delete(numParty);
return HttpStatus.OK;
}
private ResponseEntity<IncomeDetails> mappingResponseIncomeDetails(IncomeDetails incomeDetails)
{
return new ResponseEntity<>(incomeDetails, HttpStatus.OK);
}
private ResponseEntity<List<IncomeDetails>> mappingResponseListIncomeDetails(List<IncomeDetails> incomeDetails)
{
return new ResponseEntity<>(incomeDetails, HttpStatus.OK);
}
} |
|
0
|