|
@@ -16,6 +16,7 @@ import com.huimv.env.produce.service.SalesDetailService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
@@ -65,6 +66,7 @@ public class SalesDetailServiceImpl extends ServiceImpl<SalesDetailMapper, Sales
|
|
|
//查询明细表
|
|
|
QueryWrapper<SalesDetail> detailQueryWrapper = new QueryWrapper<>();
|
|
|
detailQueryWrapper.eq("farm_code",farmCode);
|
|
|
+ detailQueryWrapper.orderByAsc("id");
|
|
|
List<SalesDetail> salesDetailList = salesDetailMapper.selectList(detailQueryWrapper);
|
|
|
resultJo.put("list",salesDetailList);
|
|
|
return new Result(ResultCode.SUCCESS,resultJo);
|
|
@@ -125,23 +127,31 @@ public class SalesDetailServiceImpl extends ServiceImpl<SalesDetailMapper, Sales
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result save2(Map<String, String> paramsMap) {
|
|
|
//
|
|
|
String farmCode = paramsMap.get("farmCode");
|
|
|
if(farmCode == null){
|
|
|
farmCode = DEFAULT_FARM_CODE;
|
|
|
}
|
|
|
+ //删除原先总表
|
|
|
+ QueryWrapper<Sales> totalQueryWrapper = new QueryWrapper();
|
|
|
+ totalQueryWrapper.eq("farm_code",farmCode);
|
|
|
+ salesMapper.delete(totalQueryWrapper);
|
|
|
//删除原先明细表
|
|
|
QueryWrapper<SalesDetail> detailQueryWrapper = new QueryWrapper<>();
|
|
|
detailQueryWrapper.eq("farm_code",farmCode);
|
|
|
salesDetailMapper.delete(detailQueryWrapper);
|
|
|
//新增明细表
|
|
|
DateUtil dateUtil = new DateUtil();
|
|
|
-
|
|
|
+ String thisMonth = dateUtil.getThisMonthAndYear();
|
|
|
+ String thisMonthSaleMoney = "0";
|
|
|
+ String thisMonthSaleCount = "0";
|
|
|
+ String lastMonth = dateUtil.getLastMonthAndYear();
|
|
|
+ String lastMonthSaleMoney = "0";
|
|
|
+ String lastMonthSaleCount = "0";
|
|
|
String list = paramsMap.get("list");
|
|
|
JSONArray listJa = JSONArray.parseArray(list);
|
|
|
- BigDecimal moneyBd = new BigDecimal(0);
|
|
|
- int count = 0;
|
|
|
for(int a=0;a<listJa.size();a++){
|
|
|
JSONObject listJo = listJa.getJSONObject(a);
|
|
|
SalesDetail salesDetail = new SalesDetail();
|
|
@@ -150,15 +160,21 @@ public class SalesDetailServiceImpl extends ServiceImpl<SalesDetailMapper, Sales
|
|
|
salesDetail.setAddDate(listJo.getString("addDate"));
|
|
|
salesDetail.setFarmCode(farmCode);
|
|
|
salesDetailMapper.insert(salesDetail);
|
|
|
-
|
|
|
+ if(thisMonth.trim().equalsIgnoreCase(listJo.getString("addDate"))){
|
|
|
+ thisMonthSaleMoney = listJo.getString("saleMoney");
|
|
|
+ thisMonthSaleCount = listJo.getString("saleCount");
|
|
|
+ }
|
|
|
+ if(lastMonth.trim().equalsIgnoreCase(listJo.getString("addDate"))){
|
|
|
+ lastMonthSaleMoney = listJo.getString("saleMoney");
|
|
|
+ lastMonthSaleCount = listJo.getString("saleCount");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
//新增总表
|
|
|
Sales Sales = new Sales();
|
|
|
- Sales.setThisSaleMoney(moneyBd);
|
|
|
- Sales.setThisSaleCount(count);
|
|
|
-// Sales.setLastSaleMoney(new BigDecimal(lastSaleMoney));
|
|
|
-// Sales.setLastSaleCount(Integer.parseInt(lastSaleCount));
|
|
|
+ Sales.setThisSaleMoney(new BigDecimal(thisMonthSaleMoney));
|
|
|
+ Sales.setThisSaleCount(Integer.parseInt(thisMonthSaleCount));
|
|
|
+ Sales.setLastSaleMoney(new BigDecimal(lastMonthSaleMoney));
|
|
|
+ Sales.setLastSaleCount(Integer.parseInt(lastMonthSaleCount));
|
|
|
Sales.setFarmCode(farmCode);
|
|
|
salesMapper.insert(Sales);
|
|
|
return new Result(ResultCode.SUCCESS);
|