|
@@ -7,12 +7,14 @@ import com.huimv.cattle.pojo.OutStock;
|
|
import com.huimv.cattle.mapper.OutStockMapper;
|
|
import com.huimv.cattle.mapper.OutStockMapper;
|
|
import com.huimv.cattle.service.OutStockService;
|
|
import com.huimv.cattle.service.OutStockService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.huimv.cattle.token.TokenSign;
|
|
import com.huimv.cattle.utils.DateUtil;
|
|
import com.huimv.cattle.utils.DateUtil;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.Month;
|
|
import java.time.Month;
|
|
import java.time.ZonedDateTime;
|
|
import java.time.ZonedDateTime;
|
|
@@ -33,20 +35,29 @@ public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStock> i
|
|
private OutStockMapper outStockMapper;
|
|
private OutStockMapper outStockMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Result listOutStock(Map<String, String> paramsMap) {
|
|
|
|
- Integer months = Integer.parseInt(paramsMap.get("months"));
|
|
|
|
-
|
|
|
|
|
|
+ public Result listOutStock(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
|
|
|
|
+ String farmCode =paramsMap.get("farmCode");
|
|
|
|
+ if (farmCode==null) {
|
|
|
|
+ farmCode = TokenSign.getFarmCode(httpServletRequest);
|
|
|
|
+ }
|
|
|
|
+ String month = paramsMap.get("months");
|
|
|
|
+ if (month==null || month=="") {
|
|
|
|
+ month = "1";
|
|
|
|
+ }
|
|
|
|
+ Integer months = Integer.parseInt(month);
|
|
ZonedDateTime zonedDateTime = ZonedDateTime.now();
|
|
ZonedDateTime zonedDateTime = ZonedDateTime.now();
|
|
List<OutStock> list = new ArrayList<>();
|
|
List<OutStock> list = new ArrayList<>();
|
|
for (int i = 0; i < months; i++) {
|
|
for (int i = 0; i < months; i++) {
|
|
if ((zonedDateTime.getMonth().getValue() - i) > 0) {
|
|
if ((zonedDateTime.getMonth().getValue() - i) > 0) {
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_code", farmCode);
|
|
queryWrapper.eq("month", zonedDateTime.getMonth().getValue() - i)
|
|
queryWrapper.eq("month", zonedDateTime.getMonth().getValue() - i)
|
|
.and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear()));
|
|
.and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear()));
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
list.add(outStock);
|
|
list.add(outStock);
|
|
} else {
|
|
} else {
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_code", farmCode);
|
|
queryWrapper.eq("month", 12 + zonedDateTime.getMonth().getValue() - i)
|
|
queryWrapper.eq("month", 12 + zonedDateTime.getMonth().getValue() - i)
|
|
.and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear() - 1));
|
|
.and(Wrapper -> Wrapper.eq("year", zonedDateTime.getYear() - 1));
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
@@ -59,10 +70,15 @@ public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStock> i
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Result addOutStock(Map<String, String> paramsMap) {
|
|
|
|
|
|
+ public Result addOutStock(HttpServletRequest httpServletRequest,Map<String, String> paramsMap) {
|
|
|
|
+ String farmCode =paramsMap.get("farmCode");
|
|
|
|
+ if (farmCode==null) {
|
|
|
|
+ farmCode = TokenSign.getFarmCode(httpServletRequest);
|
|
|
|
+ }
|
|
String year = paramsMap.get("year");
|
|
String year = paramsMap.get("year");
|
|
String month = paramsMap.get("month");
|
|
String month = paramsMap.get("month");
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<OutStock> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_code", farmCode);
|
|
queryWrapper.eq("month", month).and(Wrapper -> Wrapper.eq("year", year));
|
|
queryWrapper.eq("month", month).and(Wrapper -> Wrapper.eq("year", year));
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
OutStock outStock = outStockMapper.selectOne(queryWrapper);
|
|
if (ObjectUtil.isEmpty(outStock)) {
|
|
if (ObjectUtil.isEmpty(outStock)) {
|
|
@@ -72,6 +88,7 @@ public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStock> i
|
|
outStock1.setMonthName(paramsMap.get("monthName"));
|
|
outStock1.setMonthName(paramsMap.get("monthName"));
|
|
outStock1.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
outStock1.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
outStock1.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
outStock1.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
|
|
+ outStock1.setFarmCode(farmCode);
|
|
outStockMapper.insert(outStock1);
|
|
outStockMapper.insert(outStock1);
|
|
return new Result(ResultCode.SUCCESS, "添加成功");
|
|
return new Result(ResultCode.SUCCESS, "添加成功");
|
|
} else {
|
|
} else {
|
|
@@ -80,6 +97,7 @@ public class OutStockServiceImpl extends ServiceImpl<OutStockMapper, OutStock> i
|
|
outStock.setMonthName(paramsMap.get("monthName"));
|
|
outStock.setMonthName(paramsMap.get("monthName"));
|
|
outStock.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
outStock.setMonth(Integer.parseInt(paramsMap.get("month")));
|
|
outStock.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
outStock.setOutStock(Integer.parseInt(paramsMap.get("outStock")));
|
|
|
|
+ outStock.setFarmCode(farmCode);
|
|
outStockMapper.updateById(outStock);
|
|
outStockMapper.updateById(outStock);
|
|
return new Result(ResultCode.SUCCESS, "修改成功");
|
|
return new Result(ResultCode.SUCCESS, "修改成功");
|
|
}
|
|
}
|