feature : VipInvoicingJob + (WIP) client category

pull/6221/head
Gauthier LO 2023-10-30 15:26:36 +01:00
parent cd924ce2d1
commit 1efb88c7a1
41 changed files with 823 additions and 101 deletions

View File

@ -2,17 +2,12 @@ package org.jeecg.modules.business.controller.admin;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.business.entity.Credit;
import org.jeecg.modules.business.service.IBalanceService;
import org.jeecg.modules.business.service.ICreditService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -20,22 +15,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
/**
* @Description: credit
@ -50,6 +37,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class CreditController extends JeecgController<Credit, ICreditService> {
@Autowired
private ICreditService creditService;
@Autowired
private IBalanceService balanceService;
/**
*
@ -60,7 +49,6 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
* @param req
* @return
*/
//@AutoLog(value = "credit-分页列表查询")
@ApiOperation(value="credit-分页列表查询", notes="credit-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<Credit>> queryPageList(Credit credit,
@ -81,9 +69,11 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
*/
@AutoLog(value = "credit-添加")
@ApiOperation(value="credit-添加", notes="credit-添加")
@Transactional
@PostMapping(value = "/add")
public Result<String> add(@RequestBody Credit credit) {
creditService.save(credit);
balanceService.updateBalance(credit.getClientId(), credit.getId(), credit.getAmount(), credit.getCurrencyId());
return Result.OK("添加成功!");
}
@ -95,9 +85,11 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
*/
@AutoLog(value = "credit-编辑")
@ApiOperation(value="credit-编辑", notes="credit-编辑")
@Transactional
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> edit(@RequestBody Credit credit) {
creditService.updateById(credit);
balanceService.editBalance(credit.getId(), "Credit", credit.getClientId() ,credit.getAmount(), credit.getCurrencyId());
return Result.OK("编辑成功!");
}
@ -109,9 +101,11 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
*/
@AutoLog(value = "credit-通过id删除")
@ApiOperation(value="credit-通过id删除", notes="credit-通过id删除")
@Transactional
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
public Result<String> delete(@RequestParam(name="id") String id) {
creditService.removeById(id);
balanceService.deleteBalance(id, "Credit");
return Result.OK("删除成功!");
}
@ -123,9 +117,12 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
*/
@AutoLog(value = "credit-批量删除")
@ApiOperation(value="credit-批量删除", notes="credit-批量删除")
@Transactional
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.creditService.removeByIds(Arrays.asList(ids.split(",")));
public Result<String> deleteBatch(@RequestParam(name="ids") String ids) {
List<String> idList = Arrays.asList(ids.split(","));
creditService.removeByIds(idList);
balanceService.deleteBatchBalance(idList, "Credit");
return Result.OK("批量删除成功!");
}
@ -135,10 +132,9 @@ public class CreditController extends JeecgController<Credit, ICreditService> {
* @param id
* @return
*/
//@AutoLog(value = "credit-通过id查询")
@ApiOperation(value="credit-通过id查询", notes="credit-通过id查询")
@GetMapping(value = "/queryById")
public Result<Credit> queryById(@RequestParam(name="id",required=true) String id) {
public Result<Credit> queryById(@RequestParam(name="id") String id) {
Credit credit = creditService.getById(id);
if(credit==null) {
return Result.error("未找到对应数据");

View File

@ -6,11 +6,6 @@ import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.entity.PlatformOrderContent;
import org.jeecg.modules.business.entity.Shop;
import org.jeecg.modules.business.service.IPlatformOrderService;
import org.jeecg.modules.business.service.IShopService;
import org.jeecg.modules.business.service.IUserClientService;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.service.ISysUserRoleService;
@ -32,10 +27,6 @@ public class UserClientController {
private IUserClientService userClientService;
@Autowired
private ISysUserRoleService sysUserRoleService;
@Autowired
private IShopService shopService;
@Autowired
private IPlatformOrderService platformOrderService;
/**
* Checks if the user is a client or internal user
* @return the client's info OR a list of clients
@ -44,7 +35,7 @@ public class UserClientController {
public Result<?> getClientByUserId() {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userId = loginUser.getId();
// userId = "1708866308713140225";
userId = "1708866308713140225";
Client client = userClientService.getClientByUserId(userId);
if(client == null) {
List<SysRole> sysRoles = sysUserRoleService.getUserRole(userId);

View File

@ -15,6 +15,7 @@ import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.business.controller.UserException;
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderStatus;
import org.jeecg.modules.business.entity.*;
import org.jeecg.modules.business.entity.Currency;
import org.jeecg.modules.business.mapper.PlatformOrderContentMapper;
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
import org.jeecg.modules.business.service.*;
@ -24,6 +25,7 @@ import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
@ -36,6 +38,7 @@ import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -52,9 +55,13 @@ import static org.jeecg.modules.business.entity.TaskHistory.TaskStatus.*;
@RequestMapping("/shippingInvoice")
@Slf4j
public class InvoiceController {
@Autowired
private IBalanceService balanceService;
@Autowired
private IClientService clientService;
@Autowired
private ICurrencyService currencyService;
@Autowired
private IShopService shopService;
@Autowired
private PlatformOrderShippingInvoiceService shippingInvoiceService;
@ -197,9 +204,11 @@ public class InvoiceController {
* in case of success, data will contain filename.
*/
@PostMapping(value = "/make")
@Transactional
public Result<?> makeInvoice(@RequestBody ShippingInvoiceParam param) {
try {
InvoiceMetaData metaData = shippingInvoiceService.makeInvoice(param);
balanceService.updateBalance(param.clientID(), metaData.getInvoiceCode(), "shipping");
return Result.OK(metaData);
} catch (UserException e) {
return Result.error(e.getMessage());
@ -213,11 +222,13 @@ public class InvoiceController {
* @param param ClientID, shopIDs[], startDate, endDate, erpStatuses[], warehouses[]
* @return
*/
@Transactional
@PostMapping(value = "/makeComplete")
public Result<?> makeCompleteShippingInvoice(@RequestBody ShippingInvoiceParam param) {
try {
String method = param.getErpStatuses().toString().equals("[3]") ? "post" : param.getErpStatuses().toString().equals("[1, 2]") ? "pre-shipping" : "all";
InvoiceMetaData metaData = shippingInvoiceService.makeCompleteInvoicePostShipping(param, method);
balanceService.updateBalance(param.clientID(), metaData.getInvoiceCode(), "complete");
return Result.OK(metaData);
} catch (UserException e) {
return Result.error(e.getMessage());
@ -234,10 +245,12 @@ public class InvoiceController {
* @return Result of the generation, in case of error, message will be contained,
* in case of success, data will contain filename.
*/
@Transactional
@PostMapping(value = "/makeManualInvoice")
public Result<?> makeManualShippingInvoice(@RequestBody ShippingInvoiceOrderParam param) {
try {
InvoiceMetaData metaData = shippingInvoiceService.makeInvoice(param);
balanceService.updateBalance(param.clientID(), metaData.getInvoiceCode(), "shipping");
return Result.OK(metaData);
} catch (UserException e) {
return Result.error(e.getMessage());
@ -255,10 +268,12 @@ public class InvoiceController {
* @return Result of the generation, in case of error, message will be contained,
* in case of success, data will contain filename.
*/
@Transactional
@PostMapping(value = "/makeManualComplete")
public Result<?> makeManualCompleteInvoice(@RequestBody ShippingInvoiceOrderParam param) {
try {
InvoiceMetaData metaData = shippingInvoiceService.makeCompleteInvoice(param);
balanceService.updateBalance(param.clientID(), metaData.getInvoiceCode(), "complete");
return Result.OK(metaData);
} catch (UserException e) {
return Result.error(e.getMessage());
@ -509,7 +524,7 @@ public class InvoiceController {
log.info("Generating detail files ...{}/{}", cpt++, invoiceList.size());
}
String zipFilename = shippingInvoiceService.zipInvoices(filenameList);
String subject = "Invoices generated from Breakdown Page";
String subject = "[" + LocalDate.now() + "] Invoices generated from Breakdown Page";
String destEmail = sysUser.getEmail() == null ? env.getProperty("spring.mail.username") : sysUser.getEmail();
Properties prop = emailService.getMailSender();
Map <String, Object> templateModel = new HashMap<>();

View File

@ -65,6 +65,8 @@ import java.util.stream.Stream;
@RequestMapping("/generated/shippingInvoice")
@Slf4j
public class ShippingInvoiceController {
@Autowired
private IBalanceService balanceService;
@Autowired
private IClientService clientService;
@Autowired
@ -509,6 +511,8 @@ public class ShippingInvoiceController {
platformOrderService.cancelInvoice(invoiceNumber);
savRefundService.cancelInvoice(invoiceNumber);
shippingInvoiceService.delMain(id);
log.info("Updating balance ...");
balanceService.deleteBalance(id, "Debit");
log.info("Deleting invoice files ...");
String invoiceEntity = clientService.getClientEntity(clientId);
List<Path> invoicePathList = getPath(INVOICE_LOCATION, invoiceNumber, invoiceEntity);
@ -569,7 +573,9 @@ public class ShippingInvoiceController {
platformOrderContentService.cancelBatchInvoice(invoiceNumbers);
platformOrderService.cancelBatchInvoice(invoiceNumbers);
savRefundService.cancelBatchInvoice(invoiceNumbers);
shippingInvoiceService.delBatchMain(ids);
shippingInvoiceService.delBatchMain(ids);;
log.info("Updating balances ...");
balanceService.deleteBatchBalance(ids, "Debit");
log.info("Deleting invoice files ...");
for(int i = 0; i < ids.size(); i++) {

View File

@ -95,10 +95,6 @@ public class TransactionController {
List<ShippingFeesEstimation> shippingFeesEstimations = factory.getEstimations(clientId, orderIds, errorMessages);
if(shippingFeesEstimations.isEmpty())
return Result.OK("No estimation found.");
System.out.println("Estimation size : " + shippingFeesEstimations.size());
for(ShippingFeesEstimation estimation: shippingFeesEstimations) {
System.out.println("estimation : " + estimation.getDueForProcessedOrders());
}
// purchase estimation
List<String> estimationOrderIds = new ArrayList<>();
BigDecimal shippingFeesEstimation = BigDecimal.ZERO;
@ -106,7 +102,6 @@ public class TransactionController {
estimationOrderIds.addAll(estimation.getOrderIds());
shippingFeesEstimation = shippingFeesEstimation.add(estimation.getDueForProcessedOrders());
}
System.out.println("Estimation order ids : " + estimationOrderIds);
List<PlatformOrderContent> orderContents = platformOrderContentMapper.fetchOrderContent(estimationOrderIds);
List<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toList());
List<SkuPrice> skuPrices = platformOrderContentMapper.searchSkuPrice(skuIds);

View File

@ -48,14 +48,10 @@ public class LogisticChannelChoiceJob implements Job {
@Autowired
private IPlatformOrderService platformOrderService;
@Autowired
private IPlatformOrderContentService platformOrderContentService;
@Autowired
private ISensitiveAttributeService sensitiveAttributeService;
@Autowired
private IShopService shopService;
@Autowired
private PlatformOrderContentMapper platformOrderContentMapper;
@Autowired
Environment env;
@Autowired
private FreeMarkerConfigurer freemarkerConfigurer;
@ -115,15 +111,6 @@ public class LogisticChannelChoiceJob implements Job {
}
tempPlatformOrders.remove(orderToAdd);
}
System.out.println("Attributes in orders : ");
for(Map.Entry<String, List<PlatformOrder>> entry : orderMapByAttribute.entrySet()) {
System.out.println("attribute : " + entry.getKey());
if(entry.getKey() != null) {
for(PlatformOrder order : entry.getValue()) {
System.out.println(order.getId());
}
}
}
System.gc();
Map<String, Map<String, List<PlatformOrder>>> orderMapByShopAndCountry = new HashMap<>();
for (PlatformOrder platformOrder : platformOrders) {
@ -147,9 +134,6 @@ public class LogisticChannelChoiceJob implements Job {
List<Country> countryList = countryService.findIdByEnName(countries);
Map<String, String> countryNameToIdMap = countryList.stream().collect(toMap(Country::getNameEn, Country::getId));
System.out.println("Country name to id map : ");
countryNameToIdMap.keySet().forEach(System.out::println);
Map<String, String> logisticChannelIdToNameMap = logisticChannelService.listByIdAndZhName().stream().collect(toMap(LogisticChannel::getId, LogisticChannel::getZhName));
List<SensitiveAttribute> sensitiveAttributes = sensitiveAttributeService.listIdAndPriority();
@ -170,27 +154,18 @@ public class LogisticChannelChoiceJob implements Job {
List<LogisticChannelChoiceError> logisticChoiceErrorList = new ArrayList<>();
for( Map.Entry<String, Map<String, List<PlatformOrder>>> entry: orderMapByShopAndCountry.entrySet()) {
String shopId = entry.getKey();
System.out.println("\nShop => " + shopId);
Map<String, List<PlatformOrder>> orderMapByCountry = entry.getValue();
for(Map.Entry<String, List<PlatformOrder>> countryMapEntry: orderMapByCountry.entrySet()) {
String countryName = countryMapEntry.getKey();
List<PlatformOrder> orders = countryMapEntry.getValue();
System.out.println("---- Country : " + countryName + ", Order number : " + orders.size());
for(PlatformOrder order: orders) {
// reset iterator
attributeMapIterator = new LinkedList(sortedAttributeIdToPriorityMap.entrySet()).listIterator();
// for(Map.Entry<String, Integer> attributeEntry: sortedAttributeIdToPriorityMap.entrySet()) {
String orderAttributeId = sensitiveAttributeService.getHighestPriorityAttributeId(order.getId());
Integer orderAttributePriority = sortedAttributeIdToPriorityMap.get(orderAttributeId);
if(order.getPlatformOrderId().equals("5709926760777")) {
System.out.println("===> 5709926760777");
System.out.println("===> order attribute" + orderAttributeId);
System.out.println("===> order attribute priority" + orderAttributePriority);
}
if(orderMapByAttribute.get(orderAttributeId) == null || orderAttributeId == null) {
continue;
}
//todo : what is happening to EP4 Reunion 5709926760777
List<LogisticChannelChoice> choices = logisticChannelChoiceList.stream().filter(
c -> c.getShopId().equals(shopId) && c.getCountryId().equals(countryNameToIdMap.get(countryName)) && c.getSensitiveAttributeId().equals(orderAttributeId))
.collect(Collectors.toList());
@ -208,7 +183,7 @@ public class LogisticChannelChoiceJob implements Job {
orderToAdd.setId(order.getId());
orderToAdd.setInvoiceLogisticChannelName(logisticChannelIdToNameMap.get(choice.getLogisticChannelId()));
ordersToUpdate.add(orderToAdd);
System.out.println("La ligne " + choice.getLogisticChannelId() + " a été attribué à commande : " + order.getId());
log.info("La ligne " + choice.getLogisticChannelId() + " a été attribué à commande : " + order.getId());
break;
}
//reset search to prepare for lower priority search
@ -226,7 +201,7 @@ public class LogisticChannelChoiceJob implements Job {
PlatformOrder orderToAdd = new PlatformOrder();
orderToAdd.setId(order.getId());
orderToAdd.setInvoiceLogisticChannelName(logisticChannelIdToNameMap.get(choice.getLogisticChannelId()));
System.out.println("La ligne " + choice.getLogisticChannelId() + " a été attribué à commande : " + order.getId());
log.info("La ligne " + choice.getLogisticChannelId() + " a été attribué à commande : " + order.getId());
ordersToUpdate.add(orderToAdd);
break;
}
@ -241,20 +216,19 @@ public class LogisticChannelChoiceJob implements Job {
));
}
else {
System.out.println("Trouvé");
PlatformOrder orderToAdd = new PlatformOrder();
orderToAdd.setId(order.getId());
orderToAdd.setInvoiceLogisticChannelName(logisticChannelIdToNameMap.get(choices.get(0).getLogisticChannelId()));
ordersToUpdate.add(orderToAdd);
System.out.println("La ligne " + choices.get(0).getLogisticChannelId() + " a été attribué à commande : " + order.getId());
log.info("La ligne " + choices.get(0).getLogisticChannelId() + " a été attribué à commande : " + order.getId());
continue;
}
} // end for orders
} // end for in orderMapByCountry
} // end for orderMapByShopAndCountry
System.out.println("Orders to Update => ");
log.info("Orders to Update => ");
for(PlatformOrder order : ordersToUpdate) {
System.out.println(order.getId());
log.info(order.getId());
}
platformOrderService.updateBatchById(ordersToUpdate);
if(!logisticChoiceErrorList.isEmpty()) {
@ -286,10 +260,8 @@ public class LogisticChannelChoiceJob implements Job {
private LogisticChannelChoice getHigherLogisticChannelChoice(String shopId, String countryName, Integer priority,
List<LogisticChannelChoice> logisticChannelChoiceList, ListIterator<Map.Entry<String, Integer>> attributeMapIterator,
Map<String, String> countryNameToIdMap) throws JobExecutionException {
System.out.println("On se rabat sur une priorité plus élevée");
log.info("On se rabat sur une priorité plus élevée");
Map.Entry<String, Integer> nextEntry = attributeMapIterator.next();
System.out.println(nextEntry.getValue() + " ? " + priority);
System.out.println(nextEntry.getKey());
List<LogisticChannelChoice> logisticChannelChoices;
LogisticChannelChoice logisticChannelChoice;
if(nextEntry.getValue() > priority) {
@ -309,10 +281,8 @@ public class LogisticChannelChoiceJob implements Job {
private LogisticChannelChoice getLowerLogisticChannelChoice(String shopId, String countryName, Integer priority,
List<LogisticChannelChoice> logisticChannelChoiceList, ListIterator<Map.Entry<String, Integer>> attributeMapIterator,
Map<String, String> countryNameToIdMap) throws JobExecutionException {
System.out.println("On se rabat sur une priorité plus faible");
log.info("On se rabat sur une priorité plus faible");
Map.Entry<String, Integer> previousEntry = attributeMapIterator.previous();
System.out.println(previousEntry.getValue() + " ? " + priority);
System.out.println(previousEntry.getKey());
List<LogisticChannelChoice> logisticChannelChoices;
LogisticChannelChoice logisticChannelChoice;
if(previousEntry.getValue() <= priority) {

View File

@ -0,0 +1,109 @@
package org.jeecg.modules.business.domain.job;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.jeecg.modules.business.entity.*;
import org.jeecg.modules.business.service.*;
import org.jeecg.modules.business.vo.FactureDetail;
import org.jeecg.modules.business.vo.InvoiceMetaData;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class VipInvoicingJob implements Job {
@Autowired
private IClientService clientService;
@Autowired
private EmailService emailService;
@Autowired
private PlatformOrderShippingInvoiceService platformOrderShippingInvoiceService;
@Autowired
private ISavRefundWithDetailService savRefundWithDetailService;
@Autowired
Environment env;
@Autowired
private FreeMarkerConfigurer freemarkerConfigurer;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info("VIP Invoicing Job executed.");
List<Client> clients = clientService.getClientsByType("vip");
List<String> shippingClientIds = clients.stream().filter(client -> client.getIsCompleteInvoice().equals("0")).map(Client::getId).collect(Collectors.toList());
List<String> completeClientIds = clients.stream().filter(client -> client.getIsCompleteInvoice().equals("1")).map(Client::getId).collect(Collectors.toList());
log.info("shippingClientIds size : " + shippingClientIds.size());
log.info("completeClientIds size : " + completeClientIds.size());
List<InvoiceMetaData> invoiceList = new ArrayList<>();
if(!shippingClientIds.isEmpty()) {
log.info("Making shipping invoice for clients : {}", shippingClientIds);
invoiceList = new ArrayList<>(platformOrderShippingInvoiceService.breakdownInvoiceClientByType(shippingClientIds, 0));
}
if(!completeClientIds.isEmpty()) {
log.info("Making complete shipping invoice for clients : {}", completeClientIds);
invoiceList.addAll(platformOrderShippingInvoiceService.breakdownInvoiceClientByType(completeClientIds, 1));
}
if (invoiceList.isEmpty()) {
log.info("Nothing to invoice.");
return;
}
List<InvoiceMetaData> metaDataErrorList = new ArrayList<>();
log.info("Generating detail files ...0/{}", invoiceList.size());
int cpt = 1;
for(InvoiceMetaData metaData: invoiceList){
if(metaData.getInvoiceCode().equals("error")) {
metaDataErrorList.add(metaData);
}
else {
List<FactureDetail> factureDetails = platformOrderShippingInvoiceService.getInvoiceDetail(metaData.getInvoiceCode());
List<SavRefundWithDetail> refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(metaData.getInvoiceCode());
try {
platformOrderShippingInvoiceService.exportToExcel(factureDetails, refunds, metaData.getInvoiceCode(), metaData.getInvoiceEntity(), metaData.getInternalCode());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
log.info("Generating detail files ...{}/{}", cpt++, invoiceList.size());
}
if(!metaDataErrorList.isEmpty()) {
String subject = "[" + LocalDate.now() + "] VIP invoicing job report";
String destEmail = env.getProperty("spring.mail.username");
Properties prop = emailService.getMailSender();
Map<String, Object> templateModel = new HashMap<>();
templateModel.put("errors", metaDataErrorList);
Session session = Session.getInstance(prop, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(env.getProperty("spring.mail.username"), env.getProperty("spring.mail.password"));
}
});
try {
freemarkerConfigurer = emailService.freemarkerClassLoaderConfig();
Template freemarkerTemplate = freemarkerConfigurer.getConfiguration()
.getTemplate("vipInvoicingJobReport.ftl");
String htmlBody = FreeMarkerTemplateUtils.processTemplateIntoString(freemarkerTemplate, templateModel);
emailService.sendSimpleMessage(destEmail, subject, htmlBody, session);
log.info("Mail sent successfully");
} catch (Exception e) {
log.error("Error while sending mail in VipInvoicingJob", e);
e.printStackTrace();
}
}
log.info("VIP invoicing job finished.");
}
}

View File

@ -66,7 +66,6 @@ public class ShippingInvoice extends AbstractInvoice<String, Object, Integer, Ob
BigDecimal countryPickingFeesPerSKU = BigDecimal.ZERO;
BigDecimal countryPackageMatFeePerOrder = BigDecimal.ZERO;
for (PlatformOrder po : orders) {
System.out.println(po.getId());
countryFretFees = countryFretFees.add(po.getFretFee());
countryServiceFeesPerOrder = countryServiceFeesPerOrder.add(po.getOrderServiceFee());
countryPickingFeesPerOrder = countryPickingFeesPerOrder.add(po.getPickingFee());

View File

@ -767,7 +767,6 @@ public class ShippingInvoiceFactory {
return estimations;
}
Set<String> shopIds = uninvoicedOrdersByShopId.keySet();
System.out.println(shopIds);
Set<String> clientIds = new HashSet<>();
List<Shop> shops = shopMapper.selectBatchIds(shopIds);
shops.forEach(shop -> clientIds.add(clientMapper.selectById(shop.getOwnerId()).getId()));
@ -834,8 +833,6 @@ public class ShippingInvoiceFactory {
return estimations;
}
Set<PlatformOrder> orderSet = ordersMap.keySet();
System.out.println("orderSet : ");
orderSet.forEach(System.out::println);
Map<String, PlatformOrder> orderMap = orderSet.stream().collect(toMap(PlatformOrder::getId, Function.identity()));
Map<String, String> orderMapByShopId = orderSet.stream().collect(toMap(PlatformOrder::getId, PlatformOrder::getShopId));
List<PlatformOrderContent> orderContents = ordersMap.values().stream().flatMap(Collection::stream).collect(toList());
@ -847,7 +844,6 @@ public class ShippingInvoiceFactory {
)
);
Collection<String> shopIds = orderMapByShopId.values();
System.out.println("shopIds : " + shopIds);
Client client = clientMapper.selectById(clientId);
List<Shop> shops = shopMapper.selectBatchIds(shopIds);

View File

@ -1,6 +1,9 @@
package org.jeecg.modules.business.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -67,4 +70,38 @@ public class Balance implements Serializable {
@Excel(name = "balance amount", width = 15)
@ApiModelProperty(value = "balance amount")
private java.math.BigDecimal amount;
public Balance() {
}
public Balance(String id,
String createBy,
Date createTime,
String updateBy,
Date updateTime,
String clientId,
String currencyId,
String operationType,
String operationId,
BigDecimal amount) {
this.id = id;
this.createBy = createBy;
this.createTime = createTime;
this.updateBy = updateBy;
this.updateTime = updateTime;
this.clientId = clientId;
this.currencyId = currencyId;
this.operationType = operationType;
this.operationId = operationId;
this.amount = amount;
}
public static Balance of (String username,
String clientId,
String currencyId,
String operationType,
String operationId,
BigDecimal amount) {
return new Balance(null, username, new Date(), null, null, clientId, currencyId, operationType, operationId, amount);
}
}

View File

@ -0,0 +1,63 @@
package org.jeecg.modules.business.entity;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* @Description: client category
* @Author: jeecg-boot
* @Date: 2023-10-19
* @Version: V1.0
*/
@Data
@TableName("client_category")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="client_category对象", description="client category")
public class ClientCategory implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private java.lang.String id;
/**创建人*/
@ApiModelProperty(value = "创建人")
private java.lang.String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private java.lang.String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private java.util.Date updateTime;
/**category name*/
@Excel(name = "category name", width = 15)
@ApiModelProperty(value = "category name")
private java.lang.String name;
/**description*/
@Excel(name = "description", width = 15)
@ApiModelProperty(value = "description")
private java.lang.String description;
}

View File

@ -0,0 +1,67 @@
package org.jeecg.modules.business.entity;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* @Description:
* @Author: jeecg-boot
* @Date: 2023-10-17
* @Version: V1.0
*/
@Data
@TableName("currency")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="currency对象", description="货币")
public class Currency implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private java.lang.String id;
/**创建人*/
@ApiModelProperty(value = "创建人")
private java.lang.String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private java.lang.String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private java.util.Date updateTime;
/**货币代码*/
@Excel(name = "货币代码", width = 15)
@ApiModelProperty(value = "货币代码")
private java.lang.String code;
/**中文名称*/
@Excel(name = "中文名称", width = 15)
@ApiModelProperty(value = "中文名称")
private java.lang.String zhName;
/**英文名称*/
@Excel(name = "英文名称", width = 15)
@ApiModelProperty(value = "英文名称")
private java.lang.String enName;
}

View File

@ -53,6 +53,7 @@ public class ShippingInvoice implements Serializable {
/**
* ID
*/
@Dict(dictTable = "client", dicText = "internal_code", dicCode = "id")
@Excel(name = "客户", width = 15)
@ApiModelProperty(value = "客户")
private String clientId;
@ -156,7 +157,8 @@ public class ShippingInvoice implements Serializable {
BigDecimal totalAmount,
BigDecimal discountAmount,
BigDecimal finalAmount,
BigDecimal paidAmount) {
BigDecimal paidAmount,
String currencyId) {
this.id = id;
this.createBy = createBy;
this.createTime = createTime;
@ -168,6 +170,7 @@ public class ShippingInvoice implements Serializable {
this.discountAmount = discountAmount;
this.finalAmount = finalAmount;
this.paidAmount = paidAmount;
this.currencyId = currencyId;
}
public static ShippingInvoice of(
String username,
@ -175,9 +178,10 @@ public class ShippingInvoice implements Serializable {
String invoiceNumber,
BigDecimal totalAmount,
BigDecimal discountAmount,
BigDecimal paidAmount
BigDecimal paidAmount,
String currencyId
) {
return new ShippingInvoice(null, username, new Date(), username, new Date(), clientId,
invoiceNumber, totalAmount, discountAmount, totalAmount.subtract(discountAmount), paidAmount);
invoiceNumber, totalAmount, discountAmount, totalAmount.subtract(discountAmount), paidAmount, currencyId);
}
}

View File

@ -9,7 +9,6 @@ import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;

View File

@ -18,4 +18,15 @@ import org.springframework.stereotype.Repository;
public interface BalanceMapper extends BaseMapper<Balance> {
BigDecimal getBalanceByClientIdAndCurrency(@Param("clientId")String clientId, @Param("currency")String currency);
void deleteBalance(@Param("operationId") String operationId, @Param("operationType") String operationType);
void deleteBatchBalance(@Param("operationIds") List<String> operationIds, @Param("operationType") String operationType);
void editBalance(@Param("operationId") String operationId,
@Param("operationType") String operationType,
@Param("username") String username,
@Param("clientId") String clientId,
@Param("amount") BigDecimal amount,
@Param("currencyId") String currencyId);
}

View File

@ -0,0 +1,17 @@
package org.jeecg.modules.business.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.business.entity.ClientCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: client category
* @Author: jeecg-boot
* @Date: 2023-10-19
* @Version: V1.0
*/
public interface ClientCategoryMapper extends BaseMapper<ClientCategory> {
}

View File

@ -20,4 +20,6 @@ public interface ClientMapper extends BaseMapper<Client> {
String getClientEntity(@Param("id") String id);
Map<String, String> getClientsEntity(@Param("ids") List<String> ids);
String getClientByInternalCode(@Param("code") String code);
List<Client> getClientByType(@Param("type") String type);
}

View File

@ -0,0 +1,19 @@
package org.jeecg.modules.business.mapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.business.entity.Currency;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* @Description:
* @Author: jeecg-boot
* @Date: 2023-10-17
* @Version: V1.0
*/
@Repository
public interface CurrencyMapper extends BaseMapper<Currency> {
String getCodeById(@Param("currencyId") String currencyId);
String getIdByCode(@Param("code") String code);
}

View File

@ -188,6 +188,8 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
void cancelBatchInvoice(@Param("invoiceNumbers") List<String> invoiceNumbers);
List<PlatformOrder> findUninvoicedOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
List<String> findUninvoicedOrderIdsByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
List<PlatformOrder> fetchEmptyLogisticChannelOrders(@Param("startDate") String startDate,@Param("endDate") String endDate);
}

View File

@ -22,4 +22,6 @@ public interface ShopMapper extends BaseMapper<Shop> {
List<Shop> selectByClient(@Param("clientID") String clientID);
List<String> selectShopIdByClient(@Param("clientID") String clientID);
List<String> getShopIdsByClientAndType(@Param("clientIds") List<String> clientIds, @Param("type") String clientType);
}

View File

@ -1,14 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.business.mapper.BalanceMapper">
<select id="getBalanceByClientIdAndCurrency" resultType="java.math.BigDecimal">
SELECT amount
FROM balance b
JOIN currency c
ON b.currency_id = c.id
WHERE client_id = #{clientId}
AND c.code = #{currency}
ORDER BY b.create_time DESC
LIMIT 1
</select>
<select id="getBalanceByClientIdAndCurrency" resultType="java.math.BigDecimal">
SELECT amount
FROM balance b
JOIN currency c
ON b.currency_id = c.id
WHERE client_id = #{clientId}
AND c.code = #{currency}
ORDER BY b.create_time DESC
LIMIT 1
</select>
<delete id="deleteBalance">
DELETE
FROM balance
WHERE operation_id = #{operationId}
AND operation_type = #{operationType}
</delete>
<delete id="deleteBatchBalance">
DELETE
FROM balance
WHERE operation_id IN
<foreach collection="operationIds" item="operationId" open="(" separator="," close=")">
#{operationId}
</foreach>
AND operation_type = #{operationType}
</delete>
<update id="editBalance">
UPDATE balance
SET amount = #{amount},
update_by = #{username},
update_time = NOW(),
currency_id = #{currencyId},
client_id = #{clientId}
WHERE operation_id = #{operationId}
AND operation_type = #{operationType}
</update>
</mapper>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.demo.business.mapper.ClientCategoryMapper">
</mapper>

View File

@ -19,4 +19,12 @@
FROM client
WHERE internal_code = #{code}
</select>
<select id="getClientByType" resultType="org.jeecg.modules.business.entity.Client">
SELECT c.*
FROM client c
JOIN client_category cc
ON c.client_category_id = cc.id
WHERE cc.name = #{type}
AND c.active = 1;
</select>
</mapper>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.business.mapper.CurrencyMapper">
<select id="getCodeById" resultType="java.lang.String">
SELECT code
FROM currency
WHERE id = #{currencyId};
</select>
<select id="getIdByCode" resultType="java.lang.String">
SELECT id
FROM currency
WHERE code = #{code};
</select>
</mapper>

View File

@ -567,6 +567,33 @@
#{shopId}
</foreach>;
</select>
<select id="findUninvoicedOrdersByShopForClient" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT id
FROM platform_order
WHERE erp_status IN
<foreach
collection="erpStatuses"
separator=","
open="("
close=")"
index="index"
item="erpStatus"
>
#{erpStatus}
</foreach>
AND shipping_invoice_number IS NULL
AND shop_id IN
<foreach
collection="shopIds"
separator=","
open="("
close=")"
index="index"
item="shopId"
>
#{shopId}
</foreach>;
</select>
<insert id="insertPlatformOrdersArchives" parameterType="list">
INSERT INTO platform_order_delete(id, create_by,
create_time, update_by,

View File

@ -15,7 +15,7 @@
WHERE invoice_number = #{invoiceNumber}
</select>
<select id="fetchShippingInvoice" resultType="org.jeecg.modules.business.entity.ShippingInvoice">
SELECT total_amount, discount_amount, final_amount, paid_amount
SELECT id, total_amount, discount_amount, final_amount, paid_amount, currency_id
FROM shipping_invoice s
WHERE s.invoice_number = #{invoiceNumber}
</select>

View File

@ -22,4 +22,17 @@
FROM shop
WHERE owner_id = #{clientID} AND active = '1'
</select>
<select id="getShopIdsByClientAndType" resultType="org.jeecg.modules.business.entity.Shop">
SELECT s.id
FROM shop s
JOIN client c
ON s.owner_id = c.id
JOIN client_category cc
ON c.client_category_id = cc.id
WHERE c.id IN
<foreach collection="clientIds" item="clientId" open="(" separator="," close=")">
#{clientId}
</foreach>
AND cc.name = #{type}
</select>
</mapper>

View File

@ -2,8 +2,10 @@ package org.jeecg.modules.business.service;
import org.jeecg.modules.business.entity.Balance;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.business.vo.InvoiceMetaData;
import java.math.BigDecimal;
import java.util.List;
/**
* @Description: balance
@ -14,4 +16,25 @@ import java.math.BigDecimal;
public interface IBalanceService extends IService<Balance> {
BigDecimal getBalanceByClientIdAndCurrency(String clientId, String currency);
void updateBalance(String clientId, String invoiceCode, String invoiceType);
void updateBalance(String clientId, String CreditId, BigDecimal amount, String currencyId);
/**
* Delete balance record
* @param operationId operation id : invoice id or credit id
* @param operationType operation type : invoice or credit
*/
void deleteBalance(String operationId, String operationType);
/**
* Edit balance record
* @param operationId operation id : invoice id or credit id
* @param operationType operation type : invoice or credit
* @param clientId
* @param amount
* @param currencyId
*/
void editBalance(String operationId, String operationType, String clientId, BigDecimal amount, String currencyId);
void deleteBatchBalance(List<String> operationIds, String operationType);
}

View File

@ -0,0 +1,14 @@
package org.jeecg.modules.business.service;
import org.jeecg.modules.business.entity.ClientCategory;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: client category
* @Author: jeecg-boot
* @Date: 2023-10-19
* @Version: V1.0
*/
public interface IClientCategoryService extends IService<ClientCategory> {
}

View File

@ -47,4 +47,5 @@ public interface IClientService extends IService<Client> {
*/
Client getCurrentClient();
List<Client> getClientsByType(String type);
}

View File

@ -0,0 +1,17 @@
package org.jeecg.modules.business.service;
import org.jeecg.modules.business.entity.Currency;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description:
* @Author: jeecg-boot
* @Date: 2023-10-17
* @Version: V1.0
*/
public interface ICurrencyService extends IService<Currency> {
String getCodeById(String currencyId);
String getIdByCode(String code);
}

View File

@ -179,11 +179,18 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
/**
* Find all order that can be invoiced by small clients (type 2) themselves.
* Invoices of erp_status 1
* @param shopIds list of shop id
* @param erpStatuses list of erp_status
* @return list of orders
*/
List<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds, List<Integer> erpStatuses);
/**
* Get ids of all order that can be invoiced by small clients (type 2) themselves.
* @param shopIds list of shop id
* @param erpStatuses list of erp_status
* @return list of orders
*/
List<String> findUninvoicedOrderIdsByShopForClient(List<String> shopIds, List<Integer> erpStatuses);
/**
* Find all order with empty logistic_channel_name and invoice_logistic_channel_name

View File

@ -16,4 +16,6 @@ public interface IShopService extends IService<Shop> {
List<Shop> listByClient(String clientID);
List<String> listIdByClient(String clientID);
List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType);
}

View File

@ -3,6 +3,7 @@ package org.jeecg.modules.business.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.business.controller.UserException;
import org.jeecg.modules.business.domain.excel.SheetManager;
@ -40,11 +41,15 @@ import java.util.zip.ZipOutputStream;
@Slf4j
public class PlatformOrderShippingInvoiceService {
@Autowired
ICurrencyService currencyService;
@Autowired
ShippingInvoiceMapper shippingInvoiceMapper;
@Autowired
PlatformOrderMapper platformOrderMapper;
@Autowired
IBalanceService balanceService;
@Autowired
ClientMapper clientMapper;
@Autowired
ShopMapper shopMapper;
@ -165,7 +170,14 @@ public class PlatformOrderShippingInvoiceService {
platformOrderService, clientMapper, shopMapper, logisticChannelMapper, logisticChannelPriceMapper,
platformOrderContentService, skuDeclaredValueService, countryService, exchangeRatesMapper,
purchaseOrderService, purchaseOrderContentMapper, skuPromotionHistoryMapper, savRefundService, savRefundWithDetailService);
String username = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername();
Subject subject = null;
try {
subject = SecurityUtils.getSubject();
}
catch (Exception e) {
log.error("Error while getting subject", e);
}
String username = subject == null ? "admin" : ((LoginUser) subject.getPrincipal()).getUsername();
// Creates invoice by factory
ShippingInvoice invoice = factory.createInvoice(param.clientID(),
param.shopIDs(),
@ -278,6 +290,7 @@ public class PlatformOrderShippingInvoiceService {
Path out = Paths.get(INVOICE_DIR, filename);
Files.copy(src, out, StandardCopyOption.REPLACE_EXISTING);
invoice.toExcelFile(out);
String currencyId = currencyService.getIdByCode(invoice.client().getCurrency());
// save to DB
org.jeecg.modules.business.entity.ShippingInvoice shippingInvoiceEntity = org.jeecg.modules.business.entity.ShippingInvoice.of(
username,
@ -285,7 +298,8 @@ public class PlatformOrderShippingInvoiceService {
invoice.code(),
invoice.getTotalAmount(),
invoice.reducedAmount(),
invoice.paidAmount()
invoice.paidAmount(),
currencyId
);
shippingInvoiceMapper.insert(shippingInvoiceEntity);
return new InvoiceMetaData(filename, invoice.code(), invoice.client().getInternalCode(), invoice.client().getInvoiceEntity(), "");
@ -455,6 +469,11 @@ public class PlatformOrderShippingInvoiceService {
}
for(Map.Entry<String, List<String>> entry: clientShopIDsMap.entrySet()) {
Period period = getValidPeriod(entry.getValue());
if(!period.isValid()) {
String internalCode = clientMapper.selectById(entry.getKey()).getInternalCode();
invoiceList.add(new InvoiceMetaData("", "error", internalCode, entry.getKey(), "No order to invoice."));
continue;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(period.start());
String start = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH)+1 < 10 ? "0" : "") + (calendar.get(Calendar.MONTH)+1) + "-" + (calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "") + (calendar.get(Calendar.DAY_OF_MONTH));
@ -466,13 +485,18 @@ public class PlatformOrderShippingInvoiceService {
try {
ShippingInvoiceParam param = new ShippingInvoiceParam(entry.getKey(), entry.getValue(), start, end, Collections.singletonList(3), Arrays.asList("0", "1"));
InvoiceMetaData metaData;
if(invoiceType == 0)
if(invoiceType == 0) {
metaData = makeInvoice(param);
else
balanceService.updateBalance(entry.getKey(), metaData.getInvoiceCode(), "shipping");
}
else {
metaData = makeCompleteInvoicePostShipping(param, "post");
balanceService.updateBalance(entry.getKey(), metaData.getInvoiceCode(), "complete");
}
invoiceList.add(metaData);
} catch (UserException | IOException | ParseException e) {
invoiceList.add(new InvoiceMetaData("", "error", "", entry.getKey(), e.getMessage()));
String internalCode = clientMapper.selectById(entry.getKey()).getInternalCode();
invoiceList.add(new InvoiceMetaData("", "error", internalCode, entry.getKey(), e.getMessage()));
log.error(e.getMessage());
}
System.gc();

View File

@ -1,14 +1,25 @@
package org.jeecg.modules.business.service.impl;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.modules.business.entity.Balance;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.entity.PlatformOrderContent;
import org.jeecg.modules.business.entity.ShippingInvoice;
import org.jeecg.modules.business.mapper.BalanceMapper;
import org.jeecg.modules.business.service.IBalanceService;
import org.jeecg.modules.business.service.ICurrencyService;
import org.jeecg.modules.business.service.IPlatformOrderService;
import org.jeecg.modules.business.service.IShippingInvoiceService;
import org.jeecg.modules.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description: balance
@ -20,8 +31,64 @@ import java.math.BigDecimal;
public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance> implements IBalanceService {
@Autowired
private BalanceMapper balanceMapper;
@Autowired
private ICurrencyService currencyService;
@Autowired
private IPlatformOrderService platformOrderService;
@Autowired
IShippingInvoiceService iShippingInvoiceService;
@Override
public BigDecimal getBalanceByClientIdAndCurrency(String clientId, String currency) {
return balanceMapper.getBalanceByClientIdAndCurrency(clientId, currency);
}
@Override
public void updateBalance(String clientId, String invoiceCode, String invoiceType) {
// balance update
ShippingInvoice invoice = iShippingInvoiceService.getShippingInvoice(invoiceCode);
String currency = currencyService.getCodeById(invoice.getCurrencyId());
BigDecimal previousBalance = getBalanceByClientIdAndCurrency(clientId, currency);
BigDecimal currentBalance = previousBalance.subtract(invoice.getFinalAmount());
if(invoiceType.equals("complete")) {
List<String> orderIds = iShippingInvoiceService.getPlatformOrder(invoiceCode).stream().map(PlatformOrder::getId).collect(Collectors.toList());
Map<PlatformOrder, List<PlatformOrderContent>> orderMap = platformOrderService.fetchOrderData(orderIds);
BigDecimal purchaseFees = BigDecimal.ZERO;
for(Map.Entry<PlatformOrder, List<PlatformOrderContent>> entry : orderMap.entrySet()) {
for(PlatformOrderContent content : entry.getValue()) {
purchaseFees = purchaseFees.add(content.getPurchaseFee());
}
}
currentBalance = currentBalance.add(purchaseFees);
}
SysUser sysUser = new SysUser();
Balance balance = Balance.of(sysUser.getUsername(), clientId, invoice.getCurrencyId(), "Debit", invoice.getId(), currentBalance);
balanceMapper.insert(balance);
}
@Override
public void updateBalance(String clientId, String CreditId, BigDecimal amount, String currencyId) {
String currency = currencyService.getCodeById(currencyId);
BigDecimal previousBalance = getBalanceByClientIdAndCurrency(clientId, currency);
BigDecimal currentBalance = previousBalance.add(amount);
SysUser sysUser = new SysUser();
Balance balance = Balance.of(sysUser.getUsername(), clientId, currencyId, "Credit", CreditId, currentBalance);
balanceMapper.insert(balance);
}
@Override
public void deleteBalance(String operationId, String operationType) {
balanceMapper.deleteBalance(operationId, operationType);
}
@Override
public void deleteBatchBalance(List<String> operationIds, String operationType) {
balanceMapper.deleteBatchBalance(operationIds, operationType);
}
@Override
public void editBalance(String operationId, String operationType, String clientId, BigDecimal amount, String currencyId) {
SysUser sysUser = new SysUser();
balanceMapper.editBalance(operationId, operationType, sysUser.getUsername(), clientId, amount, currencyId);
}
}

View File

@ -0,0 +1,19 @@
package org.jeecg.modules.business.service.impl;
import org.jeecg.modules.business.entity.ClientCategory;
import org.jeecg.modules.business.mapper.ClientCategoryMapper;
import org.jeecg.modules.business.service.IClientCategoryService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description: client category
* @Author: jeecg-boot
* @Date: 2023-10-19
* @Version: V1.0
*/
@Service
public class ClientCategoryServiceImpl extends ServiceImpl<ClientCategoryMapper, ClientCategory> implements IClientCategoryService {
}

View File

@ -118,6 +118,11 @@ public class ClientServiceImpl extends ServiceImpl<ClientMapper, Client> impleme
return clientUserMap.selectClientByUserId(sysUser.getId());
}
@Override
public List<Client> getClientsByType(String type) {
return clientMapper.getClientByType(type);
}
@Override
public String getClientEntity(String id) {
return clientMapper.getClientEntity(id);

View File

@ -0,0 +1,32 @@
package org.jeecg.modules.business.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.entity.Currency;
import org.jeecg.modules.business.mapper.CurrencyMapper;
import org.jeecg.modules.business.service.ICurrencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description:
* @Author: jeecg-boot
* @Date: 2023-10-17
* @Version: V1.0
*/
@Slf4j
@Service
public class CurrencyServiceImpl extends ServiceImpl<CurrencyMapper, Currency> implements ICurrencyService {
@Autowired
private CurrencyMapper currencyMapper;
@Override
public String getCodeById(String currencyId) {
return currencyMapper.getCodeById(currencyId);
}
@Override
public String getIdByCode(String code) {
return currencyMapper.getIdByCode(code);
}
}

View File

@ -400,6 +400,11 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
return platformOrderMap.findUninvoicedOrdersByShopForClient(shopIds, erpStatuses);
}
@Override
public List<String> findUninvoicedOrderIdsByShopForClient(List<String> shopIds, List<Integer> erpStatuses) {
return platformOrderMap.findUninvoicedOrderIdsByShopForClient(shopIds, erpStatuses);
}
@Override
public List<PlatformOrder> fetchEmptyLogisticChannelOrders(String startDate, String endDate) {
return platformOrderMap.fetchEmptyLogisticChannelOrders(startDate, endDate);

View File

@ -33,4 +33,9 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
public List<String> listIdByClient(String clientID) {
return shopMapper.selectShopIdByClient(clientID);
}
@Override
public List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType) {
return shopMapper.getShopIdsByClientAndType(clientIds, clientType);
}
}

View File

@ -0,0 +1,109 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table align="center" cellpadding="0" cellspacing="0" width="600" bgcolor="#FFF" style="font-family:Arial,Helvetica,sans-serif;text-align:center;table-layout:fixed;font-size: 16px;border: 1px solid #0B49A6">
<tbody>
<tr>
<td width="600" height="90" bgcolor="#0B49A6" valign="top" align="center" style="padding:20px 0;table-layout:fixed">
<a href="http://app.wia-sourcing.com/user/login">
<img src="https://wia-sourcing.com/wp-content/uploads/2022/10/Fichier-24Icons.png" alt="logo" width="360" style="width:100%;max-width:360px;">
</a>
</td>
</tr>
<tr>
<td align="left">
<table width="520" align="center" style="color:#000;">
<tbody>
<tr>
<td style="padding:35px 0;">Cher(s) collègue(s),</td>
</tr>
<tr>
<td style="padding:0 0 35px 0;">Des erreurs se sont produites lors du déroulement de la tâche plannifiée : <b>VIP invoicing job</b></td>
</tr>
<tr>
<td style="padding:10px 0;"><b>Erreurs :</b>
<#if errors?size = 0>
No error
</#if>
</td>
</tr>
<tr>
<table style="border: 1px solid #bbb; text-align: center;">
<thead>
<tr>
<th>Client</th>
<th>Error Message</th>
</tr>
</thead>
<tbody>
<#list errors as error>
<tr>
<td>${error.internalCode}</td>
<td>${error.errorMsg}</td>
</tr>
</#list>
</tbody>
</table>
</tr>
<tr>
<td style="padding:35px 0 5px 0;">Merci dutiliser nos services.</td>
</tr>
<tr>
<td style="padding:5px 0;">Cordialement</td>
</tr>
<tr>
<td style="padding:5px 0 35px 0;">Léquipe WIA Sourcing.</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="left" bgcolor="#0B49A6" width="600">
<table align="center" width="520">
<tbody>
<tr>
<td style="font-style: italic;padding: 20px 0;">Ce message a été envoyé automatiquement. Merci de ne pas répondre. Ce message et ainsi que toutes les pièces jointes sont confidentielles.</td>
</tr>
<tr>
<td style="padding: 0 0 20px 0;">Si vous avez reçu ce message par erreur, merci de nous avertir immédiatement et de détruire ce message.</td>
</tr>
<tr>
<td>Service client :</td>
</tr>
<tr>
<td>Pour obtenir plus dinformations concernant nos services, veuillez nous contacter à ladresse ci-dessous ou en visitant notre site web.</td>
</tr>
</tbody>
</table>
<table align="center" width="520" style="padding: 15px 0">
<tbody>
<tr>
<td width="220" style="text-align:center;border-radius:2em;padding:20px 10px 20px 0;;" bgcolor="#EF5A1A"><a href="https://wia-sourcing.com/contactez-nous" style="color:white;text-decoration:none">Nous contacter</a></td>
<td width="40" ></td>
<td width="220" style="text-align:center;border-radius:2em;padding:20px 0 20px 10px;" bgcolor="#EF5A1A"><a href="https://wia-sourcing.com/" style="color:white;text-decoration:none">Notre site web</a></td>
</tr>
</tbody>
</table>
<table align="center" width="520" style="padding: 0 0 35px 0;">
<tbody>
<tr>
<td style="color:#EF5A1A;">WIA SOURCING</td>
</tr>
<tr>
<td>© 2018/2023 par WIA Sourcing Agency.</td>
</tr>
<tr>
<td>TOUS DROITS RÉSERVÉS©</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>