提交 707d662e 编写于 作者: L lsh

完成部分销售模块service

上级 93c39725
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bytechainx.psi</groupId>
<artifactId>psi-opensource</artifactId>
<version>2.1.0</version>
</parent>
<artifactId>psi-sale</artifactId>
<packaging>jar</packaging>
<name>psi-sale</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<dependencies>
<dependency>
<groupId>com.bytechainx.psi</groupId>
<artifactId>psi-common</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<directory>target</directory>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<outputDirectory>target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 不包含使用插件在测试完成后再拷贝资源文件过去防止冲突 -->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerId>csharp</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-csharp</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-XX:PermSize=256M</argLine>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/classes/lib</directory>
<includes>
<include>**/*.jar</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<!-- Source folder -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<defaultGoal>compile</defaultGoal>
</build>
<!-- 使用阿里 maven 库 -->
<repositories>
<repository>
<id>ali-maven</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.model.CustomerCategory;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
/**
* 客户分类
*/
public class CustomerCategoryService extends CommonService {
/**
* 分页列表
*/
public Page<CustomerCategory> paginate(Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
return CustomerCategory.dao.paginate(pageNumber, pageSize, "select * ", "from customer_category "+where.toString()+" order by id desc", params.toArray());
}
/**
* 新增
*/
public Ret create(CustomerCategory category) {
if(category == null) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(category.getName())) {
return Ret.fail("分类名称不能为空");
}
CustomerCategory _category = CustomerCategory.dao.findFirst("select * from customer_category where name = ? limit 1", category.getName());
if(_category != null) {
return Ret.fail("分类名称已存在");
}
category.setCreatedAt(new Date());
category.save();
return Ret.ok("新增分类成功").set("targetId", category.getId());
}
/**
* 修改
*/
public Ret update(CustomerCategory category) {
if(category == null || category.getId() == null || category.getId() <= 0) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(category.getName())) {
return Ret.fail("分类名称不能为空");
}
CustomerCategory _category = CustomerCategory.dao.findFirst("select * from customer_category where name = ? limit 1", category.getName());
if(_category != null && _category.getId().intValue() != category.getId().intValue()) {
return Ret.fail("分类名称已存在");
}
_category = CustomerCategory.dao.findById(category.getId());
if(_category == null) {
return Ret.fail("客户分类不存在,无法修改");
}
category.update();
return Ret.ok("修改分类成功");
}
/**
* 删除
*/
public Ret delete(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerCategory.dao.deleteById(id);
Db.update("update customer_info set customer_category_id = ? where customer_category_id = ?", 0, id);
}
return Ret.ok("删除分类成功");
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.EnumConstant.DataStatusEnum;
import com.bytechainx.psi.common.EnumConstant.FundFlowEnum;
import com.bytechainx.psi.common.kit.DateUtil;
import com.bytechainx.psi.common.kit.PinYinUtil;
import com.bytechainx.psi.common.model.CustomerInfo;
import com.bytechainx.psi.common.model.TenantAdmin;
import com.bytechainx.psi.common.model.TraderBookAccount;
import com.bytechainx.psi.common.model.TraderBookAccountLogs;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
/**
* 客户管理
*/
public class CustomerInfoService extends CommonService {
/**
* 分页列表
* @param moreCondKv 非字段条件
*/
public Page<CustomerInfo> paginate(Kv conditionColumns, Kv moreCondKv, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
conditionFilter(conditionColumns, where, params);
if(moreCondKv != null && moreCondKv.getBoolean("hide_debt_flag") != null && moreCondKv.getBoolean("hide_debt_flag")) { // 是否隐藏无欠款客户
where.append(" and trader_book_account_id in (select id from trader_book_account where (out_amount - in_amount) > 0 )");
}
if(conditionColumns == null || !conditionColumns.containsKey("data_status")) {
where.append(" and data_status != ?");
params.add(DataStatusEnum.delete.getValue());
}
return CustomerInfo.dao.paginate(pageNumber, pageSize, "select * ", "from customer_info "+where.toString()+" order by id desc", params.toArray());
}
/**
*
* @param tenantOrgId
* @param conditionColumns
* @param debtFlag 是否欠款
* @return
*/
public CustomerInfo sumCustomer(Kv conditionColumns, Boolean debtFlag, Date lastOrderTime) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
conditionFilter(conditionColumns, where, params);
if(debtFlag != null && debtFlag) { // 有欠款
where.append(" and trader_book_account_id in (select id from trader_book_account where (out_amount - in_amount) < 0 )");
} else if(debtFlag != null && !debtFlag) { // 有余款
where.append(" and trader_book_account_id in (select id from trader_book_account where (out_amount - in_amount) > 0 )");
}
if(conditionColumns == null || !conditionColumns.containsKey("data_status")) {
where.append(" and data_status != ?");
params.add(DataStatusEnum.delete.getValue());
}
if(lastOrderTime != null) {
where.append(" and last_order_time <= ?");
params.add(DateUtil.getSecondStr(lastOrderTime));
}
return CustomerInfo.dao.findFirst("select count(*) as count from customer_info "+where.toString(), params.toArray());
}
/**
* 新增
* @param adminId
*/
public Ret create(Integer adminId, CustomerInfo customerInfo) {
if(customerInfo == null) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(customerInfo.getName())) {
return Ret.fail("客户名称不能为空");
}
CustomerInfo _customerInfo = CustomerInfo.dao.findFirst("select * from customer_info where name = ? and data_status != ? limit 1", customerInfo.getName(), DataStatusEnum.delete.getValue());
if(_customerInfo != null) {
return Ret.fail("客户名称已存在");
}
// 创建往来帐户,客户欠款=支出-收入,欠供应商款=收入-支出。
TraderBookAccount traderBookAccount = new TraderBookAccount();
traderBookAccount.setInAmount(BigDecimal.ZERO);
traderBookAccount.setOpenBalance(BigDecimal.ZERO);
traderBookAccount.setOutAmount(BigDecimal.ZERO);
traderBookAccount.setPayAmount(BigDecimal.ZERO);
traderBookAccount.setCreatedAt(new Date());
traderBookAccount.setUpdatedAt(new Date());
traderBookAccount.save();
customerInfo.setTraderBookAccountId(traderBookAccount.getId());
customerInfo.setCode(PinYinUtil.getFirstSpell(customerInfo.getName()));
customerInfo.setCreatedAt(new Date());
customerInfo.setUpdatedAt(new Date());
customerInfo.save();
// 更新往来帐户
BigDecimal openBalance = customerInfo.getBigDecimal("open_balance"); // 期初欠款
updateTraderBookAccount(adminId, traderBookAccount, openBalance);
return Ret.ok("新增客户成功").set("targetId", customerInfo.getId());
}
/**
* 修改
*/
public Ret update(Integer adminId, CustomerInfo customerInfo) {
if(customerInfo == null || customerInfo.getId() == null || customerInfo.getId() <= 0) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(customerInfo.getName())) {
return Ret.fail("客户名称不能为空");
}
CustomerInfo _customerInfo = CustomerInfo.dao.findFirst("select * from customer_info where name = ? and data_status != ? limit 1", customerInfo.getName(), DataStatusEnum.delete.getValue());
if(_customerInfo != null && _customerInfo.getId().intValue() != customerInfo.getId().intValue()) {
return Ret.fail("客户名称已存在");
}
_customerInfo = CustomerInfo.dao.findById(customerInfo.getId());
if(_customerInfo == null) {
return Ret.fail("客户不存在,无法修改");
}
customerInfo.setCode(PinYinUtil.getFirstSpell(customerInfo.getName()));
customerInfo.setUpdatedAt(new Date());
customerInfo.update();
// 更新往来帐户
BigDecimal openBalance = customerInfo.getBigDecimal("open_balance"); // 期初欠款
updateTraderBookAccount(adminId, _customerInfo.getTraderBookAccount(), openBalance);
return Ret.ok("修改客户成功");
}
/**
* 删除
*/
public Ret delete(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerInfo customerInfo = CustomerInfo.dao.findById(id);
if(customerInfo == null) {
continue;
}
customerInfo.setDataStatus(DataStatusEnum.delete.getValue());
customerInfo.setUpdatedAt(new Date());
customerInfo.update();
}
return Ret.ok("删除客户成功");
}
/**
* 停用
*/
public Ret disable(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerInfo customerInfo = CustomerInfo.dao.findById(id);
if(customerInfo == null) {
continue;
}
customerInfo.setDataStatus(DataStatusEnum.disable.getValue());
customerInfo.setUpdatedAt(new Date());
customerInfo.update();
}
return Ret.ok("停用客户成功");
}
/**
* 启用
*/
public Ret enable(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerInfo customerInfo = CustomerInfo.dao.findById(id);
if(customerInfo == null) {
continue;
}
customerInfo.setDataStatus(DataStatusEnum.enable.getValue());
customerInfo.setUpdatedAt(new Date());
customerInfo.update();
}
return Ret.ok("启用客户成功");
}
/**
* 更新往来帐户资金
* @param tenantOrgId
* @param adminId
* @param order
* @param changeAmount
* @return
*/
private Ret updateTraderBookAccount(Integer adminId, TraderBookAccount traderBookAccount , BigDecimal openBalance) {
if(openBalance == null) {
return Ret.fail("期初金额不能为空");
}
BigDecimal oldOpenBalance = traderBookAccount.getOpenBalance();
if(oldOpenBalance.compareTo(openBalance) == 0) {
return Ret.fail("期初金额未发生变化");
}
// 修改往来帐户,客户欠款=支出-收入,欠供应商款=收入-支出。
// 先回退老的期初欠款
if (oldOpenBalance.compareTo(BigDecimal.ZERO) > 0) { // 客户有欠款
BigDecimal outAmount = traderBookAccount.getOutAmount().subtract(oldOpenBalance);
traderBookAccount.setOutAmount(outAmount);
} else if (oldOpenBalance.compareTo(BigDecimal.ZERO) < 0) { // 负数,客户有预存款
BigDecimal inAmount = traderBookAccount.getInAmount().subtract(BigDecimal.ZERO.subtract(oldOpenBalance));
traderBookAccount.setInAmount(inAmount);
}
// 再处理新的期初欠款
if (openBalance.compareTo(BigDecimal.ZERO) > 0) { // 客户有欠款
BigDecimal outAmount = traderBookAccount.getOutAmount().add(openBalance);
traderBookAccount.setOutAmount(outAmount);
} else if (openBalance.compareTo(BigDecimal.ZERO) < 0) { // 负数,客户有预存款
BigDecimal inAmount = traderBookAccount.getInAmount().add(BigDecimal.ZERO.subtract(openBalance));
traderBookAccount.setInAmount(inAmount);
}
traderBookAccount.setOpenBalance(openBalance);
traderBookAccount.setUpdatedAt(new Date());
traderBookAccount.update();
BigDecimal balance = traderBookAccount.getCustomerDebtAmount(); // 客户欠款=支出-收入
// 记录往来帐户出入金日志表
TraderBookAccountLogs bookAccountLogs = new TraderBookAccountLogs();
bookAccountLogs.setAmount(openBalance);
bookAccountLogs.setBalance(balance);
bookAccountLogs.setCreatedAt(new Date());
bookAccountLogs.setFundFlow(FundFlowEnum.adjust.getValue());
bookAccountLogs.setTraderBookAccountId(traderBookAccount.getId());
TenantAdmin admin = TenantAdmin.dao.findById(adminId);
bookAccountLogs.setRemark(admin.getRealName()+" 调整期初");
bookAccountLogs.save();
return Ret.ok("调整期初金额成功");
}
/**
* 导入
*/
public Ret createImport() {
return Ret.ok();
}
/**
* 期初调整
* @param tenantOrgId
* @param customerInfoId
* @param customerInfoIdObject
* @param openBalanceObject
* @return
*/
public Ret updateOpenBalance(Integer adminId, Integer customerInfoId, BigDecimal openBalance) {
if(customerInfoId == null || customerInfoId <= 0) {
return Ret.fail("客户不能为空");
}
if(openBalance == null) {
return Ret.fail("期初金额不能为空");
}
CustomerInfo customerInfo = CustomerInfo.dao.findById(customerInfoId);
Ret ret = updateTraderBookAccount(adminId, customerInfo.getTraderBookAccount(), openBalance);
return ret;
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.EnumConstant.DataStatusEnum;
import com.bytechainx.psi.common.model.CustomerPriceLevel;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
/**
* 价格等级
*/
public class CustomerPriceLevelService extends CommonService {
/**
* 分页列表
*/
public Page<CustomerPriceLevel> paginate(Kv conditionColumns, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
conditionFilter(conditionColumns, where, params);
where.append(" and data_status != ?");
params.add(DataStatusEnum.delete.getValue());
return CustomerPriceLevel.dao.paginate(pageNumber, pageSize, "select * ", "from customer_price_level "+where.toString()+" order by id desc", params.toArray());
}
/**
* 新增
*/
public Ret create(CustomerPriceLevel priceLevel) {
if(priceLevel == null) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(priceLevel.getName())) {
return Ret.fail("价格等级名称不能为空");
}
CustomerPriceLevel _priceLevel = CustomerPriceLevel.dao.findFirst("select * from customer_price_level where name = ? and data_status != ? limit 1", priceLevel.getName(), DataStatusEnum.delete.getValue());
if(_priceLevel != null) {
return Ret.fail("价格等级名称已存在");
}
priceLevel.setCreatedAt(new Date());
priceLevel.setUpdatedAt(new Date());
priceLevel.save();
return Ret.ok("新增价格等级成功").set("targetId", priceLevel.getId());
}
/**
* 修改
*/
public Ret update(CustomerPriceLevel priceLevel) {
if(priceLevel == null || priceLevel.getId() == null || priceLevel.getId() <= 0) {
return Ret.fail("参数错误");
}
if(StringUtils.isEmpty(priceLevel.getName())) {
return Ret.fail("价格等级名称不能为空");
}
CustomerPriceLevel _priceLevel = CustomerPriceLevel.dao.findFirst("select * from customer_price_level where name = ? and data_status != ? limit 1", priceLevel.getName(), DataStatusEnum.delete.getValue());
if(_priceLevel != null && _priceLevel.getId().intValue() != priceLevel.getId().intValue()) {
return Ret.fail("价格等级名称已存在");
}
_priceLevel = CustomerPriceLevel.dao.findById(priceLevel.getId());
if(_priceLevel == null) {
return Ret.fail("价格等级不存在,无法修改");
}
priceLevel.setUpdatedAt(new Date());
priceLevel.update();
return Ret.ok("修改价格等级成功");
}
/**
* 删除
*/
public Ret delete(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerPriceLevel priceLevel = CustomerPriceLevel.dao.findById(id);
if(priceLevel == null) {
continue;
}
priceLevel.setDataStatus(DataStatusEnum.delete.getValue());
priceLevel.setUpdatedAt(new Date());
priceLevel.update();
}
return Ret.ok("删除价格等级成功");
}
/**
* 停用
*/
public Ret disable(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerPriceLevel priceLevel = CustomerPriceLevel.dao.findById(id);
if(priceLevel == null) {
continue;
}
priceLevel.setDataStatus(DataStatusEnum.disable.getValue());
priceLevel.setUpdatedAt(new Date());
priceLevel.update();
}
return Ret.ok("停用价格等级成功");
}
/**
* 启用
*/
public Ret enable(List<Integer> ids) {
if(ids == null || ids.isEmpty()) {
return Ret.fail("参数错误");
}
for (Integer id : ids) {
CustomerPriceLevel priceLevel = CustomerPriceLevel.dao.findById(id);
if(priceLevel == null) {
continue;
}
priceLevel.setDataStatus(DataStatusEnum.enable.getValue());
priceLevel.setUpdatedAt(new Date());
priceLevel.update();
}
return Ret.ok("启用价格等级成功");
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.EnumConstant.AuditStatusEnum;
import com.bytechainx.psi.common.EnumConstant.OrderStatusEnum;
import com.bytechainx.psi.common.dto.ConditionFilter;
import com.bytechainx.psi.common.dto.ConditionFilter.Operator;
import com.bytechainx.psi.common.model.SaleOrderGoods;
import com.bytechainx.psi.common.model.SaleRejectOrderGoods;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
/**
* 热销分析
*/
public class StatHotSaleService extends CommonService {
/**
* 分页列表
* 按商品统计
*/
public Page<SaleOrderGoods> paginate(Integer goodsCategoryId, String startTime, String endTime, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append(" order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
ConditionFilter filter = new ConditionFilter();
filter.setOperator(Operator.in);
filter.setValue("select id from sale_order where "+whereOrder.toString());
Kv condKv = Kv.create();
condKv.set("sale_order_id", filter);
if(goodsCategoryId != null && goodsCategoryId > 0) {
StringBuffer whereCategory = new StringBuffer();
whereCategory.append("where 1 = 1 ");
whereCategory.append(" and goods_category_id = "+goodsCategoryId);
ConditionFilter categoryFilter = new ConditionFilter();
categoryFilter.setOperator(Operator.in);
categoryFilter.setValue("select id from goods_info "+whereCategory.toString());
condKv.set("goods_info_id", categoryFilter);
}
conditionFilter(condKv, where, params);
Page<SaleOrderGoods> page = SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select goods_info_id, sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount, sum(reject_number) as reject_number, sum(reject_amount) as reject_amount", "from sale_order_goods "+where.toString()+" group by goods_info_id order by buy_number desc", params.toArray());
for(SaleOrderGoods saleOrderGoods : page.getList()) {
StringBuffer rejectWhere = new StringBuffer();
List<Object> rejectParams = new ArrayList<>();
rejectWhere.append("where 1 = 1 ");
rejectWhere.append(" and sale_reject_order_id in (select id from sale_reject_order where "+whereOrder.toString()+")");
if(goodsCategoryId != null && goodsCategoryId > 0) {
rejectWhere.append(" and goods_info_id in (select id from goods_info where goods_category_id = ? )");
rejectParams.add(goodsCategoryId);
}
rejectWhere.append(" and goods_info_id = ?");
rejectParams.add(saleOrderGoods.getGoodsInfoId());
SaleRejectOrderGoods saleRejectOrderGoods = SaleRejectOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount from sale_reject_order_goods "+rejectWhere.toString()+" limit 1", rejectParams.toArray());
saleOrderGoods.setRejectAmount(saleRejectOrderGoods.getAmount());
saleOrderGoods.setRejectNumber(saleRejectOrderGoods.getBuyNumber());
}
return page;
}
/**
* 分页列表
* 按商品分类统计
*/
public SaleOrderGoods sumByCategory(Integer goodsCategoryId, String startTime, String endTime) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append("order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
ConditionFilter filter = new ConditionFilter();
filter.setOperator(Operator.in);
filter.setValue("select id from sale_order where "+whereOrder.toString());
Kv condKv = Kv.create();
condKv.set("sale_order_id", filter);
StringBuffer whereCategory = new StringBuffer();
whereCategory.append("where 1 = 1 ");
if(goodsCategoryId != null && goodsCategoryId > 0) {
whereCategory.append(" and goods_category_id = "+goodsCategoryId);
}
ConditionFilter categoryFilter = new ConditionFilter();
categoryFilter.setOperator(Operator.in);
categoryFilter.setValue("select id from goods_info "+whereCategory.toString());
condKv.set("goods_info_id", categoryFilter);
conditionFilter(condKv, where, params);
SaleOrderGoods saleOrderGoods = SaleOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount from sale_order_goods "+where.toString(), params.toArray());
StringBuffer rejectWhere = new StringBuffer();
List<Object> rejectParams = new ArrayList<>();
rejectWhere.append("where 1 = 1 ");
rejectWhere.append(" and sale_reject_order_id in (select id from sale_reject_order where "+whereOrder.toString()+")");
if(goodsCategoryId != null && goodsCategoryId > 0) {
rejectWhere.append(" and goods_info_id in (select id from goods_info where goods_category_id = ? )");
rejectParams.add(goodsCategoryId);
}
SaleRejectOrderGoods saleRejectOrderGoods = SaleRejectOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount from sale_reject_order_goods "+rejectWhere.toString()+" limit 1", rejectParams.toArray());
saleOrderGoods.setRejectAmount(saleRejectOrderGoods.getAmount());
saleOrderGoods.setRejectNumber(saleRejectOrderGoods.getBuyNumber());
return saleOrderGoods;
}
/**
* 查询货品的查询明细
* @return
*/
public Page<SaleOrderGoods> paginateByGoods(Integer goodsInfoId, String startTime, String endTime, int pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append("order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
where.append(" and sale_order_id in (select id from sale_order where "+whereOrder.toString()+")");
if(goodsInfoId != null && goodsInfoId > 0) {
where.append(" and goods_info_id = ?");
params.add(goodsInfoId);
}
return SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select * ", "from sale_order_goods "+where.toString()+" order by id", params.toArray());
}
/**
* 分页列表
* 按规格明细统计
*/
public Page<SaleOrderGoods> paginateBySpec(String startDay, String endDay, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
where.append(" and order_status = ?");
params.add(OrderStatusEnum.normal.getValue());
where.append(" and audit_status = ?");
params.add(AuditStatusEnum.pass.getValue());
if(StringUtils.isNotEmpty(startDay)) {
where.append(" and order_time >= ?");
params.add(startDay);
}
if(StringUtils.isNotEmpty(endDay)) {
where.append(" and order_time <= ?");
params.add(endDay);
}
return SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select goods_info_id,spec_1_id,spec_option_1_id,spec_2_id,spec_option_2_id,spec_3_id,spec_option_3_id,unit_id, sum(buy_number) as sum_buy_number ", "from sale_order_goods "+where.toString()+" group by goods_info_id,spec_1_id,spec_option_1_id,spec_2_id,spec_option_2_id,spec_3_id,spec_option_3_id,unit_id order by id desc", params.toArray());
}
public Page<SaleOrderGoods> paginateByCustomer(Integer goodsInfoId, String startTime, String endTime, int pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append("order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
where.append(" and sale_order_id in (select id from sale_order where "+whereOrder.toString()+")");
if(goodsInfoId != null && goodsInfoId > 0) {
where.append(" and goods_info_id = ?");
params.add(goodsInfoId);
}
Page<SaleOrderGoods> page = SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select customer_info_id, sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount ", "from sale_order_goods "+where.toString()+" group by customer_info_id order by buy_number desc", params.toArray());
for (SaleOrderGoods saleOrderGoods : page.getList()) {
StringBuffer rejectWhere = new StringBuffer();
List<Object> rejectParams = new ArrayList<>();
rejectWhere.append("where 1 = 1 ");
rejectWhere.append(" and sale_reject_order_id in (select id from sale_reject_order where "+whereOrder.toString()+")");
rejectWhere.append(" and goods_info_id = ?");
rejectParams.add(goodsInfoId);
rejectWhere.append(" and customer_info_id = ?");
rejectParams.add(saleOrderGoods.getCustomerInfoId());
SaleRejectOrderGoods saleRejectOrderGoods = SaleRejectOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount from sale_reject_order_goods "+rejectWhere.toString()+" limit 1", rejectParams.toArray());
saleOrderGoods.setRejectAmount(saleRejectOrderGoods.getAmount());
saleOrderGoods.setRejectNumber(saleRejectOrderGoods.getBuyNumber());
}
return page;
}
public SaleOrderGoods sumByGoodsId(Integer goodsInfoId, String startTime, String endTime) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append("order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
ConditionFilter filter = new ConditionFilter();
filter.setOperator(Operator.in);
filter.setValue("select id from sale_order where "+whereOrder.toString());
Kv condKv = Kv.create();
condKv.set("sale_order_id", filter);
condKv.set("goods_info_id", goodsInfoId);
conditionFilter(condKv, where, params);
SaleOrderGoods saleOrderGoods = SaleOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount, sum(reject_number) as reject_number, sum(reject_amount) as reject_amount from sale_order_goods "+where.toString(), params.toArray());
StringBuffer rejectWhere = new StringBuffer();
List<Object> rejectParams = new ArrayList<>();
rejectWhere.append("where 1 = 1 ");
rejectWhere.append(" and sale_reject_order_id in (select id from sale_reject_order where "+whereOrder.toString()+")");
rejectWhere.append(" and goods_info_id = ?");
rejectParams.add(goodsInfoId);
SaleRejectOrderGoods saleRejectOrderGoods = SaleRejectOrderGoods.dao.findFirst("select sum(buy_number) as buy_number, sum(amount) as amount from sale_reject_order_goods "+rejectWhere.toString()+" limit 1", rejectParams.toArray());
saleOrderGoods.setRejectAmount(saleRejectOrderGoods.getAmount());
saleOrderGoods.setRejectNumber(saleRejectOrderGoods.getBuyNumber());
return saleOrderGoods;
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.EnumConstant.AuditStatusEnum;
import com.bytechainx.psi.common.EnumConstant.DataStatusEnum;
import com.bytechainx.psi.common.EnumConstant.OrderStatusEnum;
import com.bytechainx.psi.common.dto.ConditionFilter;
import com.bytechainx.psi.common.dto.ConditionFilter.Operator;
import com.bytechainx.psi.common.model.SaleOrder;
import com.bytechainx.psi.common.model.SaleOrderGoods;
import com.bytechainx.psi.common.model.SaleRejectOrder;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
/**
* 销售统计
*/
public class StatSaleService extends CommonService {
/**
* 分页列表
* 按客户统计
* @param customerInfoId2
* @param pageSize2
*/
public Page<SaleOrder> paginateByCustomer(Integer customerCategoryId, Integer customerInfoId, String startDay, String endDay, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
where.append(" and order_status = ?");
params.add(OrderStatusEnum.normal.getValue());
where.append(" and audit_status = ?");
params.add(AuditStatusEnum.pass.getValue());
if(StringUtils.isNotEmpty(startDay)) {
where.append(" and order_time >= ?");
params.add(startDay);
}
if(StringUtils.isNotEmpty(endDay)) {
where.append(" and order_time <= ?");
params.add(endDay);
}
StringBuffer rejectWhere = new StringBuffer(where);
List<Object> rejectParams = new ArrayList<>();
rejectParams.addAll(params);
if(customerInfoId != null && customerInfoId > 0) {
where.append(" and customer_info_id = ?");
params.add(customerInfoId);
}
if(customerCategoryId != null && customerCategoryId > 0) {
where.append(" and customer_info_id in (select id from customer_info where customer_category_id = ? and data_status = ?)");
params.add(customerCategoryId);
params.add(DataStatusEnum.enable.getValue());
}
Page<SaleOrder> page = SaleOrder.dao.paginate(pageNumber, pageSize, "select customer_info_id, sum(amount) as amount, sum(goods_cost_amount) as cost_amount, count(id) as order_count, sum(other_amount) as other_amount", "from sale_order "+where.toString()+" group by customer_info_id order by amount desc", params.toArray());
for(SaleOrder saleOrder : page.getList()) {
StringBuffer _rejectWhere = new StringBuffer(rejectWhere);
List<Object> _rejectParams = new ArrayList<>();
_rejectParams.addAll(rejectParams);
_rejectWhere.append(" and customer_info_id = ?");
_rejectParams.add(saleOrder.getCustomerInfoId());
SaleRejectOrder saleRejectOrder = SaleRejectOrder.dao.findFirst("select sum(amount) as amount, count(id) as order_count from sale_reject_order "+_rejectWhere+" limit 1", _rejectParams.toArray());
saleOrder.setRejectAmount(saleRejectOrder.getAmount());
saleOrder.put("reject_order_count", saleRejectOrder.getInt("order_count"));
}
return page;
}
/**
* 分页列表
* 按客户统计
* @param customerInfoId2
*/
public SaleOrder sumByCustomer(Integer customerCategoryId, Integer customerInfoId, String startDay, String endDay) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
where.append(" and order_status = ?");
params.add(OrderStatusEnum.normal.getValue());
where.append(" and audit_status = ?");
params.add(AuditStatusEnum.pass.getValue());
if(StringUtils.isNotEmpty(startDay)) {
where.append(" and order_time >= ?");
params.add(startDay);
}
if(StringUtils.isNotEmpty(endDay)) {
where.append(" and order_time <= ?");
params.add(endDay);
}
if(customerInfoId != null && customerInfoId > 0) {
where.append(" and customer_info_id = ?");
params.add(customerInfoId);
}
if(customerCategoryId != null && customerCategoryId > 0) {
where.append(" and customer_info_id in (select id from customer_info where customer_category_id = ? and data_status = ?)");
params.add(customerCategoryId);
params.add(DataStatusEnum.enable.getValue());
}
SaleOrder saleOrder = SaleOrder.dao.findFirst("select sum(amount) as amount, sum(paid_amount) as paid_amount, sum(goods_cost_amount) as cost_amount, count(id) as order_count, sum(other_amount) as other_amount from sale_order "+where.toString()+" limit 1", params.toArray());
SaleRejectOrder saleRejectOrder = SaleRejectOrder.dao.findFirst("select sum(amount) as amount, sum(paid_amount) as paid_amount, count(id) as order_count from sale_reject_order "+where.toString()+" limit 1", params.toArray());
saleOrder.setRejectAmount(saleRejectOrder.getAmount());
saleOrder.put("reject_paid_amount", saleRejectOrder.getPaidAmount());
saleOrder.put("reject_order_count", saleRejectOrder.getInt("order_count"));
return saleOrder;
}
/**
* 查询客户的销售明细
* @param tenantOrgId
* @param startTime
* @param endTime
* @param condKv
* @param pageNumber
* @param pageSize
* @return
*/
public Page<SaleOrderGoods> paginateByCustomerGoods(Integer customerInfoId, String startTime, String endTime, int pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append("customer_info_id = "+customerInfoId+" and order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
ConditionFilter filter = new ConditionFilter();
filter.setOperator(Operator.in);
filter.setValue("select id from sale_order where "+whereOrder.toString());
Kv condKv = Kv.create();
condKv.set("sale_order_id", filter);
conditionFilter(condKv, where, params);
return SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select goods_info_id, sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount, sum(reject_number) as reject_number, sum(reject_amount) as reject_amount", "from sale_order_goods "+where.toString()+" group by goods_info_id order by buy_number desc", params.toArray());
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.bytechainx.psi.common.EnumConstant.AuditStatusEnum;
import com.bytechainx.psi.common.EnumConstant.OrderStatusEnum;
import com.bytechainx.psi.common.dto.ConditionFilter;
import com.bytechainx.psi.common.dto.ConditionFilter.Operator;
import com.bytechainx.psi.common.model.SaleOrder;
import com.bytechainx.psi.common.model.SaleOrderGoods;
import com.bytechainx.psi.common.model.SaleRejectOrder;
import com.bytechainx.psi.common.service.base.CommonService;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
/**
* 门店统计
*/
public class StatStoreSaleService extends CommonService {
/**
* 分页列表
* 按门店统计
* @param customerInfoId2
* @param pageSize2
*/
public Page<SaleOrder> paginateByStore(String startDay, String endDay, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
where.append(" and order_status = ?");
params.add(OrderStatusEnum.normal.getValue());
where.append(" and audit_status = ?");
params.add(AuditStatusEnum.pass.getValue());
if(StringUtils.isNotEmpty(startDay)) {
where.append(" and order_time >= ?");
params.add(startDay);
}
if(StringUtils.isNotEmpty(endDay)) {
where.append(" and order_time <= ?");
params.add(endDay);
}
StringBuffer rejectWhere = new StringBuffer(where);
List<Object> rejectParams = new ArrayList<>();
rejectParams.addAll(params);
Page<SaleOrder> page = SaleOrder.dao.paginate(pageNumber, pageSize, "select tenant_store_id, sum(amount) as amount, sum(goods_cost_amount) as cost_amount, count(id) as order_count, sum(other_amount) as other_amount", "from sale_order "+where.toString()+" group by tenant_store_id order by amount desc", params.toArray());
for(SaleOrder saleOrder : page.getList()) {
StringBuffer _rejectWhere = new StringBuffer(rejectWhere);
List<Object> _rejectParams = new ArrayList<>();
_rejectParams.addAll(rejectParams);
SaleRejectOrder saleRejectOrder = SaleRejectOrder.dao.findFirst("select sum(amount) as amount, count(id) as order_count from sale_reject_order "+_rejectWhere+" limit 1", _rejectParams.toArray());
saleOrder.setRejectAmount(saleRejectOrder.getAmount());
saleOrder.put("reject_order_count", saleRejectOrder.getInt("order_count"));
}
return page;
}
/**
* 分页列表
* 按门店统计
* @param customerInfoId2
*/
public SaleOrder sumByStore(String startDay, String endDay, Integer pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
where.append(" and order_status = ?");
params.add(OrderStatusEnum.normal.getValue());
where.append(" and audit_status = ?");
params.add(AuditStatusEnum.pass.getValue());
if(StringUtils.isNotEmpty(startDay)) {
where.append(" and order_time >= ?");
params.add(startDay);
}
if(StringUtils.isNotEmpty(endDay)) {
where.append(" and order_time <= ?");
params.add(endDay);
}
SaleOrder saleOrder = SaleOrder.dao.findFirst("select sum(amount) as amount, sum(goods_cost_amount) as cost_amount, count(id) as order_count, sum(other_amount) as other_amount from sale_order "+where.toString()+" limit 1", params.toArray());
SaleRejectOrder saleRejectOrder = SaleRejectOrder.dao.findFirst("select sum(amount) as amount, count(id) as order_count from sale_reject_order "+where.toString()+" limit 1", params.toArray());
saleOrder.setRejectAmount(saleRejectOrder.getAmount());
saleOrder.put("reject_order_count", saleRejectOrder.getInt("order_count"));
return saleOrder;
}
/**
* 查询门店的销售明细
* @param tenantOrgId
* @param startTime
* @param endTime
* @param condKv
* @param pageNumber
* @param pageSize
* @return
*/
public Page<SaleOrderGoods> paginateByStoreGoods(String startTime, String endTime, int pageNumber, int pageSize) {
StringBuffer where = new StringBuffer();
List<Object> params = new ArrayList<Object>();
where.append("where 1 = 1 ");
StringBuffer whereOrder = new StringBuffer();
if(StringUtils.isNotEmpty(startTime)) {
whereOrder.append(" order_time >= '"+startTime+"' and ");
}
if(StringUtils.isNotEmpty(endTime)) {
whereOrder.append(" order_time <= '"+endTime+"' and ");
}
whereOrder.append(" order_status = "+OrderStatusEnum.normal.getValue()+" and audit_status = "+AuditStatusEnum.pass.getValue());
ConditionFilter filter = new ConditionFilter();
filter.setOperator(Operator.in);
filter.setValue("select id from sale_order where "+whereOrder.toString());
Kv condKv = Kv.create();
condKv.set("sale_order_id", filter);
conditionFilter(condKv, where, params);
return SaleOrderGoods.dao.paginate(pageNumber, pageSize, "select goods_info_id, sum(buy_number) as buy_number, sum(amount) as amount, sum(cost_amount) as cost_amount, sum(reject_number) as reject_number, sum(reject_amount) as reject_amount", "from sale_order_goods "+where.toString()+" group by goods_info_id order by buy_number desc", params.toArray());
}
}
\ No newline at end of file
package com.bytechainx.psi.sale.service.base;
import com.bytechainx.psi.common.service.base.CommonService;
public class BaseService extends CommonService {
}
......@@ -14,6 +14,7 @@ import com.bytechainx.psi.common.model.TenantOperLog;
import com.bytechainx.psi.web.web.controller.base.BaseController;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.ThreadPoolKit;
import cn.hutool.extra.servlet.ServletUtil;
......@@ -29,7 +30,7 @@ public class OperLogInterceptor implements Interceptor {
public void intercept(Invocation ai) {
ai.invoke();
// ACTION执行后记录日志,多线程记录,提升访问性能
new Thread(() -> writeOperLog(ai)).start();
ThreadPoolKit.execute( () -> writeOperLog(ai));
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册