Create service master jumlah diskon dokter
This commit is contained in:
parent
ea623cafa1
commit
574b96ae06
@ -0,0 +1,12 @@
|
||||
package com.jasamedika.medifirst2000.dao;
|
||||
|
||||
import com.jasamedika.medifirst2000.entities.JumlahDiskonDokter;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
public interface JumlahDiskonDokterDao extends JpaRepository<JumlahDiskonDokter, Long> {
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.jasamedika.medifirst2000.service;
|
||||
|
||||
import com.jasamedika.medifirst2000.dto.JumlahDiskonDokterDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
public interface JumlahDiskonDokterService {
|
||||
|
||||
void save(List<JumlahDiskonDokterDto> dtos);
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.jasamedika.medifirst2000.service.impl;
|
||||
|
||||
import com.jasamedika.medifirst2000.dao.JumlahDiskonDokterDao;
|
||||
import com.jasamedika.medifirst2000.dto.JumlahDiskonDokterDto;
|
||||
import com.jasamedika.medifirst2000.entities.JumlahDiskonDokter;
|
||||
import com.jasamedika.medifirst2000.service.JumlahDiskonDokterService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class JumlahDiskonDokterServiceImpl implements JumlahDiskonDokterService {
|
||||
|
||||
@Autowired
|
||||
private JumlahDiskonDokterDao jumlahDiskonDokterDao;
|
||||
|
||||
@Override
|
||||
public void save(List<JumlahDiskonDokterDto> dtos) {
|
||||
List<JumlahDiskonDokter> entities = new ArrayList<>();
|
||||
dtos.forEach(
|
||||
dto -> entities.add(JumlahDiskonDokter.builder().persenDiskon(new BigDecimal(dto.getPersenDiskon()))
|
||||
.statusEnabled(dto.getStatusEnabled()).kdProfile((short) 0).build()));
|
||||
jumlahDiskonDokterDao.save(entities);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.jasamedika.medifirst2000.dto;
|
||||
|
||||
import com.jasamedika.medifirst2000.helper.Caption;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class JumlahDiskonDokterDto {
|
||||
protected Long id;
|
||||
|
||||
private Boolean statusEnabled;
|
||||
|
||||
private Short kdProfile;
|
||||
|
||||
@NotBlank
|
||||
@Caption("Persen Diskon")
|
||||
private String persenDiskon;
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.jasamedika.medifirst2000.entities;
|
||||
|
||||
import com.jasamedika.medifirst2000.helper.Caption;
|
||||
import lombok.*;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static javax.persistence.GenerationType.SEQUENCE;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "jumlah_diskon_dokter_m")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class JumlahDiskonDokter implements Serializable {
|
||||
private static final long serialVersionUID = 7600189956745393785L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = SEQUENCE, generator = "sg_jumlah_diskon_dokter_m")
|
||||
@SequenceGenerator(name = "sg_jumlah_diskon_dokter_m", sequenceName = "jumlah_diskon_dokter_m_seq", allocationSize = 1)
|
||||
@Column(name = "id")
|
||||
protected Long id;
|
||||
|
||||
private Boolean statusEnabled;
|
||||
|
||||
private Short kdProfile;
|
||||
|
||||
@Column(nullable = false, unique = true, columnDefinition = "numeric(6,2)")
|
||||
@NotBlank
|
||||
@Caption("Persen Diskon")
|
||||
private BigDecimal persenDiskon;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.jasamedika.medifirst2000.controller;
|
||||
|
||||
import com.jasamedika.medifirst2000.dto.JumlahDiskonDokterDto;
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
import com.jasamedika.medifirst2000.service.JumlahDiskonDokterService;
|
||||
import com.jasamedika.medifirst2000.util.rest.RestUtil;
|
||||
import org.apache.commons.collections4.map.SingletonMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||
|
||||
/**
|
||||
* @author salmanoe
|
||||
* @version 1.0.0
|
||||
* @since 07/02/2024
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/master/dokter/jumlah-diskon")
|
||||
public class JumlahDiskonDokterController {
|
||||
private static final Logger LOGGER = getLogger(JumlahDiskonDokterController.class);
|
||||
|
||||
@Autowired
|
||||
private JumlahDiskonDokterService jumlahDiskonDokterService;
|
||||
|
||||
@RequestMapping(method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<List<JumlahDiskonDokterDto>> save(HttpServletRequest request,
|
||||
@Valid @RequestBody List<JumlahDiskonDokterDto> dtos) {
|
||||
try {
|
||||
jumlahDiskonDokterService.save(dtos);
|
||||
return RestUtil.getJsonResponse(dtos, CREATED, new SingletonMap<>("status", CREATED.getReasonPhrase()));
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got exception {} when add jumlah diskon dokter", e.getMessage());
|
||||
return RestUtil.getJsonHttptatus(INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user