340 lines
13 KiB
Java
340 lines
13 KiB
Java
package com.vverp.controller.admin;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
import com.vverp.base.Setting;
|
|
import com.vverp.dto.CompanyQuery;
|
|
import com.vverp.dto.OrderInfo;
|
|
import com.vverp.dto.OrderQuery;
|
|
import com.vverp.entity.*;
|
|
import com.vverp.enums.OrderStatus;
|
|
import com.vverp.moli.util.*;
|
|
import com.vverp.service.*;
|
|
import com.vverp.util.ZipUtil;
|
|
import org.bouncycastle.math.raw.Mod;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.File;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
|
|
@Controller("adminSupplierController")
|
|
@RequestMapping("/admin/supplier")
|
|
public class SupplierController extends BaseController {
|
|
|
|
@Resource
|
|
private SupplierService supplierService;
|
|
|
|
@Resource
|
|
private PurchaseStockService purchaseStockService;
|
|
|
|
@Resource
|
|
private PaymentAccountService paymentAccountService;
|
|
|
|
@Resource
|
|
private PurchaseOrderService purchaseOrderService;
|
|
|
|
@Resource
|
|
private PurchaseStockItemService purchaseStockItemService;
|
|
|
|
@Resource
|
|
private PaymentApplyService paymentApplyService;
|
|
|
|
@Resource
|
|
private ProgressService progressService;
|
|
|
|
@Resource
|
|
private AdminService adminService;
|
|
|
|
@Resource
|
|
private AreaService areaService;
|
|
|
|
@RequestMapping("/list")
|
|
public String list(Pageable pageable, CompanyQuery companyQuery, ModelMap modelMap) {
|
|
Admin admin = adminService.getCurrent();
|
|
modelMap.addAttribute("progressId",companyQuery.getProgressId());
|
|
modelMap.addAttribute("progressList",progressService.findAll());
|
|
if (companyQuery.getProgressId() == null) {
|
|
companyQuery.setProgressId(admin.getNowProgress());
|
|
}
|
|
if (admin.getNowProgress() == null) {
|
|
modelMap.addAttribute("company",true);
|
|
}else {
|
|
modelMap.addAttribute("company",false);
|
|
}
|
|
Page<Supplier> page = supplierService.findPageView(pageable, companyQuery);
|
|
modelMap.addAttribute("page", page);
|
|
modelMap.addAttribute("createDateStart", companyQuery.getCreateDateStart());
|
|
modelMap.addAttribute("createDateEnd", companyQuery.getCreateDateEnd());
|
|
modelMap.addAttribute("sn", companyQuery.getSn());
|
|
modelMap.addAttribute("name", companyQuery.getName());
|
|
modelMap.addAttribute("address", companyQuery.getAddress());
|
|
modelMap.addAttribute("contact", companyQuery.getContact());
|
|
modelMap.addAttribute("phone", companyQuery.getPhone());
|
|
modelMap.addAttribute("landLinePhone", companyQuery.getLandLinePhone());
|
|
modelMap.addAttribute("memo", companyQuery.getMemo());
|
|
modelMap.addAttribute("email", companyQuery.getEmail());
|
|
modelMap.addAttribute("deliveryWay", companyQuery.getDeliveryWay());
|
|
modelMap.addAttribute("totalBalance", supplierService.sumBalance(companyQuery));
|
|
return "/supplier/list";
|
|
}
|
|
|
|
@RequestMapping("/statistics")
|
|
public String statistics(Pageable pageable, String name, Date startDate, Date endDate, ModelMap modelMap) {
|
|
CompanyQuery companyQuery = new CompanyQuery();
|
|
companyQuery.setName(name);
|
|
Page<Supplier> page = supplierService.findPageView(pageable, companyQuery);
|
|
|
|
OrderQuery orderQuery = new OrderQuery();
|
|
orderQuery.setCreateDateStart(startDate);
|
|
orderQuery.setCreateDateEnd(endDate);
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
for (Supplier supplier : page.getContent()) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("id", supplier.getId());
|
|
map.put("name", supplier.getName());
|
|
orderQuery.setOwnerId(supplier.getId());
|
|
// 单数
|
|
OrderInfo orderInfo = purchaseStockService.orderInfo(orderQuery);
|
|
map.put("orderCount", orderInfo.getCount());
|
|
// 金额
|
|
map.put("amount", orderInfo.getAmount());
|
|
// 总量
|
|
orderInfo = purchaseStockItemService.orderInfo(orderQuery);
|
|
map.put("count", orderInfo.getNumber());
|
|
list.add(map);
|
|
}
|
|
|
|
orderQuery.setOwnerId(null);
|
|
OrderInfo orderInfo = purchaseStockService.orderInfo(orderQuery);
|
|
modelMap.addAttribute("orderCount", orderInfo.getCount());
|
|
modelMap.addAttribute("amount", orderInfo.getAmount());
|
|
orderInfo = purchaseStockItemService.orderInfo(orderQuery);
|
|
modelMap.addAttribute("count", orderInfo.getAmount());
|
|
|
|
modelMap.addAttribute("page", new Page<>(list, page.getTotal(), page.getPageable()));
|
|
modelMap.addAttribute("name", companyQuery.getName());
|
|
modelMap.addAttribute("startDate", startDate);
|
|
modelMap.addAttribute("endDate", endDate);
|
|
return "/supplier/statistics";
|
|
}
|
|
|
|
@RequestMapping("/add")
|
|
public String add(ModelMap modelMap) {
|
|
Admin admin = adminService.getCurrent();
|
|
modelMap.addAttribute("progressList",progressService.findAll());
|
|
modelMap.addAttribute("progressId",admin.getNowProgress());
|
|
modelMap.addAttribute("provinceList", areaService.findProvinceList());
|
|
return "/supplier/add";
|
|
}
|
|
|
|
@RequestMapping(value = "/edit")
|
|
public String edit(Long id, ModelMap modelMap) {
|
|
Supplier supplier = supplierService.find(id);
|
|
modelMap.addAttribute("provinceList", areaService.findProvinceList());
|
|
modelMap.addAttribute("supplier", supplier);
|
|
modelMap.addAttribute("progressList",progressService.findAll());
|
|
modelMap.addAttribute("areaService", areaService);
|
|
return "/supplier/edit";
|
|
}
|
|
|
|
@RequestMapping(value = "/view")
|
|
public String view(Long id, ModelMap modelMap) {
|
|
Supplier supplier = supplierService.find(id);
|
|
modelMap.addAttribute("provinceList", areaService.findProvinceList());
|
|
modelMap.addAttribute("supplier", supplier);
|
|
modelMap.addAttribute("areaService", areaService);
|
|
return "/supplier/view";
|
|
}
|
|
|
|
@RequestMapping("/save")
|
|
@ResponseBody
|
|
public Message save(Supplier supplier,String username) {
|
|
// if (!isValid(supplier, BaseEntity.Save.class)) {
|
|
// return ERROR;
|
|
// }
|
|
try {
|
|
supplierService.saveSupplier(supplier,username);
|
|
return SUCCESS;
|
|
} catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
return Message.error(e.getMessage());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ERROR;
|
|
}
|
|
}
|
|
|
|
@RequestMapping("/update")
|
|
@ResponseBody
|
|
public Message update(Supplier supplier,String username) {
|
|
// if (!isValid(supplier, BaseEntity.Update.class)) {
|
|
// return ERROR;
|
|
// }
|
|
try {
|
|
supplierService.updateSupplier(supplier,username);
|
|
return SUCCESS;
|
|
} catch (RuntimeException e) {
|
|
return Message.error(e.getMessage());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ERROR;
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public Message delete(Long[] ids) {
|
|
supplierService.webDelete(ids);
|
|
return SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* 供应商付款
|
|
*/
|
|
@RequestMapping("/dialog/payment")
|
|
public String dialogPayment(ModelMap modelMap, Long id) {
|
|
Supplier supplier = supplierService.find(id);
|
|
modelMap.addAttribute("provinceList", areaService.findProvinceList());
|
|
modelMap.addAttribute("supplier", supplier);
|
|
OrderQuery orderQuery = new OrderQuery();
|
|
orderQuery.setStatus(OrderStatus.approved);
|
|
orderQuery.setOwnerId(id);
|
|
|
|
if (Setting.getData().getReceiptPoint().equals(SystemSetting.ReceiptPoint.order)) {
|
|
modelMap.addAttribute("list", purchaseOrderService.findList(orderQuery));
|
|
} else {
|
|
modelMap.addAttribute("list", purchaseStockService.findList(orderQuery));
|
|
}
|
|
|
|
modelMap.addAttribute("receiptPoint", Setting.getData().getReceiptPoint());
|
|
modelMap.addAttribute("paymentAccounts", paymentAccountService.findAll());
|
|
return "/supplier/dialog/payment";
|
|
}
|
|
|
|
/**
|
|
* 客户收款
|
|
*/
|
|
@RequestMapping("/payment")
|
|
@ResponseBody
|
|
public RespData payment(@RequestBody JSONObject jsonObject) {
|
|
try {
|
|
Supplier supplier = supplierService.find(jsonObject.getLong("supplierId"));
|
|
BigDecimal totalAmount = jsonObject.getBigDecimal("totalAmount");
|
|
Long accountId = jsonObject.getLong("account");
|
|
PaymentAccount paymentAccount = paymentAccountService.find(accountId);
|
|
for (Object o : jsonObject.getJSONArray("list")) {
|
|
JSONObject item = (JSONObject) o;
|
|
Long id = item.getLong("id");
|
|
BigDecimal amount = item.getBigDecimal("amount");
|
|
if (Setting.getData().getReceiptPoint().equals(SystemSetting.ReceiptPoint.order)) {
|
|
PurchaseOrder purchaseOrder = purchaseOrderService.find(id);
|
|
purchaseOrder.setPayedAmount(purchaseOrder.getPayedAmount().add(amount));
|
|
purchaseOrderService.update(purchaseOrder);
|
|
} else {
|
|
PurchaseStock purchaseStock = purchaseStockService.find(id);
|
|
purchaseStock.setPayedAmount(purchaseStock.getPayedAmount().add(amount));
|
|
purchaseStockService.update(purchaseStock);
|
|
}
|
|
}
|
|
supplierService.payment(supplier, totalAmount, null, paymentAccount);
|
|
return RespData.success();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return RespData.error("操作失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 采购应付
|
|
*/
|
|
@RequestMapping("/purchasePayment")
|
|
public String purchasePayment(ModelMap modelMap, Pageable pageable) {
|
|
pageable.setFilters(Collections.singletonList(Filter.gt("balance", 0)));
|
|
Page<Supplier> page = supplierService.findPage(pageable);
|
|
modelMap.addAttribute("page", page);
|
|
return "/supplier/purchasePayment";
|
|
}
|
|
|
|
/**
|
|
* 导出
|
|
*/
|
|
@RequestMapping("/export")
|
|
public void export(HttpServletResponse response, CompanyQuery companyQuery) {
|
|
Admin admin = adminService.getCurrent();
|
|
companyQuery.setProgressId(admin.getNowProgress());
|
|
supplierService.export(response, companyQuery);
|
|
}
|
|
|
|
/**
|
|
* 导入模板
|
|
*/
|
|
@RequestMapping("/exportTemplate")
|
|
public void exportTemplate(HttpServletResponse response) {
|
|
supplierService.exportTemplate(response);
|
|
}
|
|
|
|
@RequestMapping("dialog/addFile")
|
|
public String addFile(ModelMap modelMap){
|
|
modelMap.addAttribute("progressId",adminService.getCurrent().getNowProgress());
|
|
return "supplier/dialog/addFile";
|
|
}
|
|
@RequestMapping("/import")
|
|
@ResponseBody
|
|
public RespData importExcel(MultipartFile file,Long progressId) {
|
|
try {
|
|
supplierService.importExcel(file,progressId);
|
|
return RespData.success();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return RespData.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@RequestMapping("/dialog/detail")
|
|
public String dialogDetail(ModelMap modelMap, Long id) {
|
|
Supplier supplier = supplierService.find(id);
|
|
modelMap.addAttribute("supplier", supplier);
|
|
|
|
List<PurchaseOrder> contractList = purchaseOrderService.findList(null, Collections.singletonList(
|
|
Filter.eq("ownerId", supplier.getId())
|
|
), null);
|
|
|
|
List<PaymentApply> paymentApplyList = paymentApplyService.findList(null, Arrays.asList(
|
|
Filter.eq("type", PaymentApply.Type.purchaseOrder),
|
|
Filter.eq("ownerId", supplier.getId()),
|
|
Filter.eq("receivePayment", PaymentApply.ReceivePayment.payment)
|
|
), null);
|
|
|
|
List<PaymentApply> refundApplyList = paymentApplyService.findList(null, Arrays.asList(
|
|
Filter.eq("type", PaymentApply.Type.purchaseOrder),
|
|
Filter.eq("ownerId", supplier.getId()),
|
|
Filter.eq("receivePayment", PaymentApply.ReceivePayment.receive)
|
|
), null);
|
|
|
|
modelMap.addAttribute("contractList", contractList);
|
|
modelMap.addAttribute("paymentApplyList", paymentApplyList);
|
|
modelMap.addAttribute("refundApplyList", refundApplyList);
|
|
return "/supplier/dialog/detail";
|
|
}
|
|
|
|
@RequestMapping("dialog/loadZip")
|
|
public String dialogLoadZip(ModelMap modelMap){
|
|
modelMap.addAttribute("progressId",adminService.getCurrent().getNowProgress());
|
|
return "supplier/dialog/loadZip";
|
|
}
|
|
|
|
@RequestMapping(value = "/loadZip",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public RespData loadZip(@RequestParam("file") MultipartFile file,Long progressId){
|
|
supplierService.loadZip(file,progressId);
|
|
return RespData.success();
|
|
}
|
|
}
|