New World

[해외공구관리사이트] 캐쉬 - 적립 & 내역 조회 본문

Project/old

[해외공구관리사이트] 캐쉬 - 적립 & 내역 조회

hyeovi 2022. 9. 6. 22:14
728x90
반응형

캐쉬를 적립하는 페이지 기능

 

1. 캐쉬 적립할 내용을 작성

 

 

 

controller

ㄴCashController

    @RequestMapping("/cashOrder")
    public String cashOrder(HttpSession httpSession, Model model) {
        Long nowLoginMemberNo = memberService.nowLoginInfo(httpSession);
        model.addAttribute("nowLoginMember", memberService.myInfo(nowLoginMemberNo));
        return "sample/cash/cash-order";
    }

API

ㄴ CashApiController

입력했던 정보가 캐쉬 입력하기 위한 정보로 잘 들어가게 해준다.

    // 충전
    @GetMapping("/api/cash/add/{cashListNo}")
    public void mgtCash(@PathVariable("cashListNo") Long cashNo) {
        try {
            CashList cashList = cashService.findByCashListNo(cashNo);

            if (cashList.getStatus().equals(CashStatus.Loading)) {
                cashService.updateAdd(cashList.getCash().getNo(), cashList.getMoney(), cashList.getCash().getMember());
            }
        } catch (Exception e) {
            throw new IllegalStateException("주문서 발행 중 이상이 생겼습니다.");
        }
    }

Service

ㄴ CashService

ㄴ CashServiceImpl

기본적으로 업데이트할 것과 프로젝트 구매 방식에 따라 따로 업데이트 해야하는 것을 나눠 정보를 서버로 업데이트 시킨다.

 @Override
    @Transactional
    public Long saveList(int money, Cash cash, Order order) {
        CashList cashList = new CashList();

        cashList.setCash(cash);
        cashList.setDate(LocalDateTime.now());

        if (order == null) {
            cashList.setStatus(CashStatus.Loading);
        } else if (order.getOrderStatus().equals(OrderStatus.ORDER)) {
            cashList.setStatus(CashStatus.OUT);
        } else if (order.getOrderStatus().equals(OrderStatus.CANCEL)
                && order.getOrderStatus().equals(OrderStatus.UPDATE)) {
            cashList.setStatus(CashStatus.ADD);
        }
        cashList.setMoney(money);
        cashList.setOrder(order);

        return cashRepository.save(cashList);
    }

캐쉬를 내역 페이지 기능

 

1. 캐쉬와 관련된 내역이 노출

2. 연필은 프로젝트 화면으로 이동

 

controller

ㄴCashController

    @RequestMapping("/cashMyList")
    public String myList(HttpSession httpSession, Model model) {
        Long nowLoginMemberNo = memberService.nowLoginInfo(httpSession);
        model.addAttribute("nowLoginMember", memberService.myInfo(nowLoginMemberNo));
        return "sample/cash/my-list";
    }

API

ㄴ CashApiController

    // 내 프로젝트의 주문서
    @GetMapping("/api/cash/myList")
    public List<CashDto> cashMyList(@SessionAttribute("mSession") Long nowLoginMemberNo) {
        List<CashList> cashByMy = cashService.findByMemberList(memberService.myInfo(nowLoginMemberNo));
        List<CashDto> collect = cashByMy.stream()
                .map(cl -> new CashDto(cl.getNo(), cl.getDate(), cl.getStatus(), cl.getMoney(),
                        projectName(cl.getNo()), projectNo(cl.getNo())))
                .collect(Collectors.toList());
        return collect;
    }

Service

ㄴ CashService

ㄴ CashServiceImpl

    @Override
    public List<CashList> findByMemberList(Member member) {
        return cashRepository.findByMemberList(member);
    }
    
    @Override
    public List<CashList> findByLoading(Cash cash) {
        return cashRepository.findList();
    }

캐쉬를 내역 페이지 기능 (관리자)

 

1. 캐쉬와 관련된 내역이 노출

2. 연필1 => 프로젝트, 연필2 => 충전, 연필3 => 이체

 

controller

ㄴCashController

    @RequestMapping("/cashList")
    public String list(HttpSession httpSession, Model model) {
        Long nowLoginMemberNo = memberService.nowLoginInfo(httpSession);
        model.addAttribute("nowLoginMember", memberService.myInfo(nowLoginMemberNo));
        return "sample/cash/all-list";
    }

API

ㄴ CashApiController

    @GetMapping("/api/cash/list")
    public List<CashDto> cashList(Cash cash) {
        List<CashList> cashByLoading = cashService.findByLoading(cash);
        List<CashDto> collect = cashByLoading.stream()
                .map(cl -> new CashDto(cl.getNo(), cl.getDate(), cl.getStatus(), cl.getMoney(),
                        projectName(cl.getNo()), projectNo(cl.getNo())))
                .collect(Collectors.toList());
        return collect;
    }

Service

ㄴ CashService

ㄴ CashServiceImp

    @Override
    @Transactional
    public void updateAdd(Long no, int money, Member member) {
        update(no, money, member);

        CashList list = findByNo(no).getCashList();
        list.setDate(LocalDateTime.now());
        list.setStatus(CashStatus.ADD);
    }

    @Override
    @Transactional
    public void updateOut(Long no, int money, Member member) {
        update(no, money, member);

        CashList list = findByNo(no).getCashList();
        list.setDate(LocalDateTime.now());
        list.setStatus(CashStatus.OUT);
    }

    @Override
    @Transactional
    public void update(Long no, int money, Member member) {
        Cash cash = findByNo(no);

        cash.setDate(LocalDate.now());
        cash.setMoney(money);
        cash.setMember(member);
    }

    @Override
    public Cash findByNo(Long no) {
        return cashRepository.findByNo(no);
    }

l

반응형
Comments