|
@@ -1,12 +1,15 @@
|
|
package com.huimv.admin.controller;
|
|
package com.huimv.admin.controller;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.huimv.admin.common.utils.Result;
|
|
import com.huimv.admin.common.utils.Result;
|
|
import com.huimv.admin.common.utils.ResultCode;
|
|
import com.huimv.admin.common.utils.ResultCode;
|
|
import com.huimv.admin.entity.ProtSheepInfo;
|
|
import com.huimv.admin.entity.ProtSheepInfo;
|
|
|
|
+import com.huimv.admin.entity.SheepEarmark;
|
|
import com.huimv.admin.service.IProtSheepInfoService;
|
|
import com.huimv.admin.service.IProtSheepInfoService;
|
|
|
|
+import com.huimv.admin.service.ISheepEarmarkService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -14,6 +17,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Date;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -31,6 +38,8 @@ public class ProtSheepInfoController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private IProtSheepInfoService sheepInfoService;
|
|
private IProtSheepInfoService sheepInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISheepEarmarkService earmarkService;
|
|
|
|
|
|
@RequestMapping("/listPage")
|
|
@RequestMapping("/listPage")
|
|
public Result listPage(@RequestBody Map<String, String> paramsMap) {
|
|
public Result listPage(@RequestBody Map<String, String> paramsMap) {
|
|
@@ -41,8 +50,60 @@ public class ProtSheepInfoController {
|
|
public Result list(@RequestBody Map<String, String> paramsMap) {
|
|
public Result list(@RequestBody Map<String, String> paramsMap) {
|
|
String farmId = paramsMap.get("farmId");
|
|
String farmId = paramsMap.get("farmId");
|
|
String sheepType = paramsMap.get("sheepType");
|
|
String sheepType = paramsMap.get("sheepType");
|
|
|
|
+ String sex = paramsMap.get("sex");
|
|
|
|
+ String isLeave = paramsMap.get("isLeave");
|
|
QueryWrapper<ProtSheepInfo> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ProtSheepInfo> queryWrapper = new QueryWrapper<>();
|
|
- queryWrapper.eq("farm_id", farmId).eq(StringUtils.isNotBlank(sheepType), "sheep_type", sheepType);
|
|
|
|
|
|
+ queryWrapper.eq("farm_id", farmId).eq(StringUtils.isNotBlank(sheepType), "sheep_type", sheepType)
|
|
|
|
+ .eq(StringUtils.isNotBlank(sex), "sex", sex)
|
|
|
|
+ .eq(StringUtils.isNotBlank(isLeave), "is_leave", isLeave);
|
|
return new Result(ResultCode.SUCCESS,sheepInfoService.list(queryWrapper));
|
|
return new Result(ResultCode.SUCCESS,sheepInfoService.list(queryWrapper));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/add")
|
|
|
|
+ public Result add(@RequestBody ProtSheepInfo protSheepInfo) throws ParseException {
|
|
|
|
+ String sheepId = protSheepInfo.getSheepId();
|
|
|
|
+ int count = sheepInfoService.count(new QueryWrapper<ProtSheepInfo>().eq("sheep_id", sheepId));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ return new Result(10001, "添加失败,羊只档案已存在", false);
|
|
|
|
+ }
|
|
|
|
+ SheepEarmark earmark = earmarkService.getOne(new QueryWrapper<SheepEarmark>().eq("earmark", sheepId));
|
|
|
|
+ earmark.setIsUse(1);
|
|
|
|
+ earmarkService.updateById(earmark);
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ protSheepInfo.setCreateTime(date);
|
|
|
|
+ long l = date.getTime() - protSheepInfo.getBirthTime().getTime();
|
|
|
|
+ long l1 = l / (24 * 60 * 60 * 1000);
|
|
|
|
+ protSheepInfo.setSheepDay((int) l1);
|
|
|
|
+ sheepInfoService.save(protSheepInfo);
|
|
|
|
+ return new Result(10000, "添加成功", true);
|
|
|
|
+ }
|
|
|
|
+ @RequestMapping("/remove")
|
|
|
|
+ public Result remove(@RequestBody Map<String, String> paramsMap) {
|
|
|
|
+ String ids = paramsMap.get("ids");
|
|
|
|
+ String[] split = ids.split(",");
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ ProtSheepInfo sheepInfo = sheepInfoService.getById(s);
|
|
|
|
+ if (StringUtils.isNotBlank(sheepInfo.getSheepId())) {
|
|
|
|
+ SheepEarmark earmark = earmarkService.getOne(new QueryWrapper<SheepEarmark>().eq("earmark", sheepInfo.getSheepId()));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(earmark)) {
|
|
|
|
+ earmark.setIsUse(0);
|
|
|
|
+ earmarkService.updateById(earmark);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sheepInfoService.removeById(s);
|
|
|
|
+ }
|
|
|
|
+ return new Result(10000, "删除成功!", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping("/edit")
|
|
|
|
+ public Result edit(@RequestBody ProtSheepInfo protSheepInfo) {
|
|
|
|
+ String sheepId = protSheepInfo.getSheepId();
|
|
|
|
+ int count = sheepInfoService.count(new QueryWrapper<ProtSheepInfo>().eq("sheep_id", sheepId).ne("id", protSheepInfo.getId()));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ return new Result(10001, "修改失败,羊只档案已存在", false);
|
|
|
|
+ }
|
|
|
|
+ sheepInfoService.updateById(protSheepInfo);
|
|
|
|
+ return new Result(10000, "修改成功!", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|