|
@@ -1,14 +1,26 @@
|
|
|
package com.huimv.cattle.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.huimv.cattle.pojo.OutStock;
|
|
|
import com.huimv.cattle.mapper.OutStockMapper;
|
|
|
import com.huimv.cattle.service.OutStockService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.huimv.cattle.utils.DateUtil;
|
|
|
+import com.huimv.common.utils.Result;
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.Month;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author zn
|
|
@@ -17,4 +29,60 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStock> implements OutStockService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OutStockMapper outStockMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listOutStock(Map<String, String> paramsMap) {
|
|
|
+ Integer months = Integer.parseInt(paramsMap.get("months"));
|
|
|
+
|
|
|
+ ZonedDateTime zonedDateTime = ZonedDateTime.now();
|
|
|
+ List<OutStock> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < months; i++) {
|
|
|
+ if ((zonedDateTime.getMonth().getValue() - i) > 0) {
|
|
|
+ QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("month", zonedDateTime.getMonth().getValue() - i)
|
|
|
+ .and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear()));
|
|
|
+ OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
|
+ list.add(outStock);
|
|
|
+ } else {
|
|
|
+ QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("month", 12 + zonedDateTime.getMonth().getValue() - i)
|
|
|
+ .and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear() - 1));
|
|
|
+ OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
|
+ list.add(outStock);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result addOutStock(Map<String, String> paramsMap) {
|
|
|
+ String year = paramsMap.get("year");
|
|
|
+ String month = paramsMap.get("month");
|
|
|
+ QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("month", month).and(Wrapper -> Wrapper.eq("year", year));
|
|
|
+ OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isEmpty(outStock)) {
|
|
|
+ OutStock outStock1 = new OutStock();
|
|
|
+ outStock1.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
|
+ outStock1.setYear(Integer.parseInt(paramsMap.get("year")));
|
|
|
+ outStock1.setMonthName(paramsMap.get("monthName"));
|
|
|
+ outStock1.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
|
+ outStock1.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
|
+ outStockMapper.insert(outStock1);
|
|
|
+ return new Result(ResultCode.SUCCESS, "添加成功");
|
|
|
+ } else {
|
|
|
+ outStock.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
|
+ outStock.setYear(Integer.parseInt(paramsMap.get("year")));
|
|
|
+ outStock.setMonthName(paramsMap.get("monthName"));
|
|
|
+ outStock.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
|
+ outStock.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
|
+ outStockMapper.updateById(outStock);
|
|
|
+ return new Result(ResultCode.SUCCESS, "修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|