|
@@ -6,15 +6,19 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import vip.xiaonuo.sale.entity.ErpBaseMaterial;
|
|
|
import vip.xiaonuo.sale.entity.SaleProduce;
|
|
|
+import vip.xiaonuo.sale.mapper.ErpBaseMaterialMapper;
|
|
|
import vip.xiaonuo.sale.mapper.SaleProduceMapper;
|
|
|
import vip.xiaonuo.sale.param.SaleProduceParam;
|
|
|
import vip.xiaonuo.sale.service.ISaleProduceService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -31,57 +35,90 @@ public class SaleProduceServiceImpl extends ServiceImpl<SaleProduceMapper, SaleP
|
|
|
|
|
|
@Autowired
|
|
|
private SaleProduceMapper produceMapper;
|
|
|
+ @Autowired
|
|
|
+ private ErpBaseMaterialMapper materialMapper;
|
|
|
|
|
|
@Override
|
|
|
public JSONObject getProduceOne(SaleProduceParam produceParam) {
|
|
|
- String orgId = produceParam.getOrgId();
|
|
|
- String produceName = produceParam.getProduceName();
|
|
|
- QueryWrapper<SaleProduce> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(produceName), "produce_name", produceName);
|
|
|
- queryWrapper.ge("create_time", DateUtil.beginOfMonth(new Date()));
|
|
|
- queryWrapper.select(" IFNULL(sum(sale_money),'0') saleMoney,convert(IFNULL(avg(price),'0'),decimal(10,2))");
|
|
|
- SaleProduce monthProduce = produceMapper.selectOne(queryWrapper);
|
|
|
- QueryWrapper<SaleProduce> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
|
|
|
- queryWrapper1.eq(StringUtils.isNotBlank(produceName), "produce_name", produceName);
|
|
|
- queryWrapper1.ge("create_time", DateUtil.beginOfYear(new Date()));
|
|
|
- queryWrapper1.select(" IFNULL(sum(sale_money),'0') saleMoney,convert(IFNULL(avg(price),'0'),decimal(10,2))");
|
|
|
- SaleProduce yearProduce = produceMapper.selectOne(queryWrapper1);
|
|
|
+ Integer parentId = produceParam.getParentId();
|
|
|
+ String time = produceParam.getDate();
|
|
|
+ String year = time.substring(0, 4);
|
|
|
+ QueryWrapper<ErpBaseMaterial> materialQueryWrapper = new QueryWrapper<>();
|
|
|
+ materialQueryWrapper.eq("parent_id", parentId);
|
|
|
+ List<ErpBaseMaterial> materials = materialMapper.selectList(materialQueryWrapper);
|
|
|
+ Double monthSaleMoney = 0.00;
|
|
|
+ Double yearSaleMoney = 0.00;
|
|
|
+ Double monthPrice = 0.00;
|
|
|
+ Double yearPrice = 0.00;
|
|
|
+ if (materials.size() != 0) {
|
|
|
+ for (ErpBaseMaterial material : materials) {
|
|
|
+ QueryWrapper<SaleProduce> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.like("produce_name", material.getMaterialName());
|
|
|
+ queryWrapper.between("create_time", time + "-01 00:00:00", time + "-31 23:59:59");
|
|
|
+ queryWrapper.select(" IFNULL(sum(sale_money),'0') saleMoney,convert(IFNULL(avg(price),'0'),decimal(10,2))");
|
|
|
+ SaleProduce monthProduce = produceMapper.selectOne(queryWrapper);
|
|
|
+ QueryWrapper<SaleProduce> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.like("produce_name", material.getMaterialName());
|
|
|
+ queryWrapper1.between("create_time", year + "-01-01 00:00:00", year + "-12-31 23:59:59");
|
|
|
+ queryWrapper1.select(" IFNULL(sum(sale_money),'0') saleMoney,convert(IFNULL(avg(price),'0'),decimal(10,2))");
|
|
|
+ SaleProduce yearProduce = produceMapper.selectOne(queryWrapper1);
|
|
|
+
|
|
|
+ monthSaleMoney = monthSaleMoney + Double.valueOf(monthProduce.getSaleMoney());
|
|
|
+ yearSaleMoney = yearSaleMoney + Double.valueOf(yearProduce.getSaleMoney());
|
|
|
+ monthPrice = monthPrice + Double.valueOf(monthProduce.getPrice());
|
|
|
+ yearPrice = yearPrice + Double.valueOf(yearProduce.getPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("monthSaleMoney", monthProduce.getSaleMoney());
|
|
|
- jsonObject.put("monthPrice", monthProduce.getPrice());
|
|
|
- jsonObject.put("yearSaleMoney", yearProduce.getSaleMoney());
|
|
|
- jsonObject.put("yearPrice", yearProduce.getPrice());
|
|
|
+ jsonObject.put("monthSaleMoney", monthSaleMoney);
|
|
|
+ jsonObject.put("yearSaleMoney",yearSaleMoney);
|
|
|
+ DecimalFormat def = new DecimalFormat("0.00");
|
|
|
+ if (materials.size() != 0) {
|
|
|
+ double v = monthPrice / materials.size();
|
|
|
+ double v1 = yearPrice / materials.size();
|
|
|
+ jsonObject.put("monthPrice", def.format(v));
|
|
|
+ jsonObject.put("yearPrice", v1);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("monthPrice", "0");
|
|
|
+ jsonObject.put("yearPrice", "0");
|
|
|
+ }
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONArray getPriceList(SaleProduceParam produceParam) {
|
|
|
- String orgId = produceParam.getOrgId();
|
|
|
- String produceName = produceParam.getProduceName();
|
|
|
- QueryWrapper<SaleProduce> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(produceName), "produce_name", produceName);
|
|
|
- queryWrapper.ge("create_time", DateUtil.beginOfYear(new Date()));
|
|
|
- queryWrapper.select(" sum(sale_money) saleMoney,create_time createTime");
|
|
|
- queryWrapper.groupBy("DATE_FORMAT(create_time,'%Y-%m')");
|
|
|
- List<SaleProduce> yearList = produceMapper.selectList(queryWrapper);
|
|
|
+ Integer parentId = produceParam.getParentId();
|
|
|
+ String time = produceParam.getDate();
|
|
|
+ String year = time.substring(0, 4);
|
|
|
+ QueryWrapper<ErpBaseMaterial> materialQueryWrapper = new QueryWrapper<>();
|
|
|
+ materialQueryWrapper.eq("parent_id", parentId);
|
|
|
+ List<ErpBaseMaterial> materials = materialMapper.selectList(materialQueryWrapper);
|
|
|
+ List<SaleProduce> yearList = new ArrayList<>();
|
|
|
+ List<SaleProduce> lastYearList = new ArrayList<>();
|
|
|
+ if (materials.size() != 0) {
|
|
|
+ for (ErpBaseMaterial material : materials) {
|
|
|
+ QueryWrapper<SaleProduce> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.like("produce_name", material.getMaterialName());
|
|
|
+ queryWrapper.between("create_time", year + "-01 00:00:00", year + "-31 23:59:59");
|
|
|
+ queryWrapper.select(" sum(sale_money) saleMoney,create_time createTime");
|
|
|
+ queryWrapper.groupBy("DATE_FORMAT(create_time,'%Y-%m')");
|
|
|
+ SaleProduce lastProduce = produceMapper.selectOne(queryWrapper);
|
|
|
+ lastYearList.add(lastProduce);
|
|
|
+ QueryWrapper<SaleProduce> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.like("produce_name", material.getMaterialName());
|
|
|
+ queryWrapper1.between("create_time", Integer.parseInt(year)-1 + "-01-01 00:00:00", Integer.parseInt(year)-1 + "-12-31 23:59:59");
|
|
|
+ queryWrapper1.select(" sum(sale_money) saleMoney,create_time createTime");
|
|
|
+ queryWrapper1.groupBy("DATE_FORMAT(create_time,'%Y-%m')");
|
|
|
+ SaleProduce yearProduce = produceMapper.selectOne(queryWrapper1);
|
|
|
+ yearList.add(yearProduce);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- int lastYear = currentDate.getYear() - 1;
|
|
|
- QueryWrapper<SaleProduce> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
|
|
|
- queryWrapper1.eq(StringUtils.isNotBlank(produceName), "produce_name", produceName);
|
|
|
- queryWrapper1.between("create_time", lastYear + "-01-01 00:00:00", lastYear + "-12-31 23:59:59");
|
|
|
- queryWrapper1.select(" sum(sale_money) saleMoney,create_time createTime");
|
|
|
- queryWrapper.groupBy("DATE_FORMAT(create_time,'%Y-%m')");
|
|
|
- List<SaleProduce> lastYearList = produceMapper.selectList(queryWrapper1);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("MM");
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
- for (int i = 1; i <13 ; i++) {
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("time", i+"月");
|
|
|
+ jsonObject.put("time", i + "月");
|
|
|
jsonObject.put("year", "0");
|
|
|
jsonObject.put("lastYear", "0");
|
|
|
if (yearList.size() != 0) {
|