package com.vverp.controller.api; import com.vverp.dto.PaymentApplyQuery; import com.vverp.entity.Admin; import com.vverp.entity.Department; import com.vverp.entity.OrderBase; import com.vverp.entity.PaymentApply; import com.vverp.moli.util.Page; import com.vverp.moli.util.Pageable; import com.vverp.moli.util.RespData; import com.vverp.service.AdminService; import com.vverp.service.PaymentApplyService; import com.vverp.service.PurchaseOrderService; import com.vverp.util.DateUtil; import com.vverp.util.MapUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.*; /** * @author * @date 2020/9/15 4:41 下午 */ @RestController("apiPaymentApplyController") @RequestMapping("/api/paymentApply") public class PaymentApplyController extends BaseController { @Resource private PaymentApplyService paymentApplyService; @Resource private AdminService adminService; @Resource private PurchaseOrderService purchaseOrderService; @RequestMapping("/create") public RespData create(PaymentApply paymentApply) { Admin admin = adminService.getApp(); paymentApply.setAdminId(admin.getId()); return respDataWithHandle(() -> paymentApplyService.create(paymentApply)); } @RequestMapping("/createSeparate") public RespData createSeparate(PaymentApply paymentApply) { Admin admin = adminService.getApp(); paymentApply.setAdminId(admin.getId()); Department department = admin.getDepartment(); if (department == null) { return RespData.error("部门为空"); } paymentApply.setDepartmentId(department.getId()); return respDataWithHandle(() -> paymentApplyService.selfCreate(paymentApply)); } @RequestMapping("/list") public RespData list(PaymentApplyQuery query, Pageable pageable, Boolean separate) { query.setContractRequired(!separate); query.setApprovalFailed(false); Page page = paymentApplyService.findPage(pageable, query); List> list = getMapList(page.getContent()); return RespData.success(new Page<>(list, page.getTotal(), page.getPageable())); } @RequestMapping("/listAll") public RespData listAll(PaymentApplyQuery query) { List paymentApplyList = paymentApplyService.findList(query); List> list = getMapList(paymentApplyList); return RespData.success(list); } private List> getMapList(List paymentApplyList) { List> list = new ArrayList<>(); for (PaymentApply paymentApply : paymentApplyList) { Map map = MapUtils.beansToMap(paymentApply, Arrays.asList( "id", "companyName", "ownerName", "adminName", "amount", "status", "paymentType" )); map.put("applyDate", DateUtil.formatDate(paymentApply.getApplyDate())); list.add(map); } return list; } @RequestMapping("/view") public RespData separateList(Long id) { PaymentApply paymentApply = paymentApplyService.find(id); Map map = MapUtils.beansToMap(paymentApply, Arrays.asList( "id", "companyName", "ownerName", "adminName", "amount", "status", "paymentType", "type", "ownerId", "companyId", "departmentName", "bankName", "bankAccount", "remark", "amountCn", "receivePayment" )); map.put("applyDate", DateUtil.formatDate(paymentApply.getApplyDate())); return RespData.success(map); } @RequestMapping("/initInfo") public RespData initInfo(Long id, PaymentApply.Type type) { Map map = new HashMap<>(); OrderBase orderBase = new OrderBase(); if (type.equals(PaymentApply.Type.purchaseOrder)) { orderBase = purchaseOrderService.find(id); map.put("bankType", "supplier"); } map.put("ownerId", orderBase.getOwnerId()); map.put("ownerName", orderBase.getOwnerName()); map.put("departmentId", orderBase.getDepartmentId()); map.put("departmentName", orderBase.getDepartmentName()); map.put("companyId", orderBase.getCompanyId()); map.put("companyName", orderBase.getCompanyName()); return RespData.success(map); } }