|
@@ -1,14 +1,19 @@
|
|
|
package com.huimv.management.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.huimv.common.exception.RRException;
|
|
|
import com.huimv.common.utils.R;
|
|
|
import com.huimv.management.dao.PeriodDao;
|
|
|
+import com.huimv.management.dao.TransferPeriodLogDao;
|
|
|
import com.huimv.management.dao.UnitDao;
|
|
|
+import com.huimv.management.entity.PeriodEntity;
|
|
|
import com.huimv.management.entity.SysUserEntity;
|
|
|
+import com.huimv.management.entity.TransferPeriodLogEntity;
|
|
|
import com.huimv.management.entity.YearPigBaseEntity;
|
|
|
import com.huimv.management.entity.vo.CountOut;
|
|
|
import com.huimv.management.entity.vo.DrinkingWaterVo;
|
|
@@ -24,9 +29,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.huimv.common.utils.PageUtils;
|
|
@@ -78,60 +85,59 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
//耳标
|
|
|
String eartag = (String) params.get("eartag");
|
|
|
if (StringUtils.isNotEmpty(eartag)) {
|
|
|
- queryWrapper.like("base.eartag",eartag);
|
|
|
+ queryWrapper.like("base.eartag", eartag);
|
|
|
}
|
|
|
|
|
|
//性别
|
|
|
String sex = (String) params.get("sex");
|
|
|
if (StringUtils.isNotEmpty(sex)) {
|
|
|
- queryWrapper.eq("base.sex",sex);
|
|
|
+ queryWrapper.eq("base.sex", sex);
|
|
|
}
|
|
|
|
|
|
//品种
|
|
|
String breed = (String) params.get("breed");
|
|
|
if (StringUtils.isNotEmpty(breed)) {
|
|
|
- queryWrapper.eq("base.breed",breed);
|
|
|
+ queryWrapper.eq("base.breed", breed);
|
|
|
}
|
|
|
|
|
|
//健康状态
|
|
|
String healthStatus = (String) params.get("healthStatus");
|
|
|
if (StringUtils.isNotEmpty(healthStatus)) {
|
|
|
- queryWrapper.eq("base.health_status",Integer.parseInt(healthStatus));
|
|
|
+ queryWrapper.eq("base.health_status", Integer.parseInt(healthStatus));
|
|
|
}
|
|
|
|
|
|
//养殖状态
|
|
|
String outFenceStatus = (String) params.get("outFenceStatus");
|
|
|
if (StringUtils.isNotEmpty(outFenceStatus)) {
|
|
|
- queryWrapper.eq("base.out_fence_status",Integer.parseInt(outFenceStatus));
|
|
|
+ queryWrapper.eq("base.out_fence_status", Integer.parseInt(outFenceStatus));
|
|
|
}
|
|
|
|
|
|
//栏期
|
|
|
String periodId = (String) params.get("periodId");
|
|
|
if (StringUtils.isNotEmpty(periodId)) {
|
|
|
- queryWrapper.eq("base.period_id",Integer.parseInt(periodId));
|
|
|
+ queryWrapper.eq("base.period_id", Integer.parseInt(periodId));
|
|
|
}
|
|
|
|
|
|
//栋舍
|
|
|
String pigstyId = (String) params.get("pigstyId");
|
|
|
if (StringUtils.isNotEmpty(pigstyId)) {
|
|
|
- queryWrapper.eq("base.pigsty_id",Integer.parseInt(pigstyId));
|
|
|
+ queryWrapper.eq("base.pigsty_id", Integer.parseInt(pigstyId));
|
|
|
}
|
|
|
//单元
|
|
|
String unitId = (String) params.get("unitId");
|
|
|
if (StringUtils.isNotEmpty(unitId)) {
|
|
|
- queryWrapper.eq("base.unit_id",Integer.parseInt(unitId));
|
|
|
+ queryWrapper.eq("base.unit_id", Integer.parseInt(unitId));
|
|
|
}
|
|
|
|
|
|
//牧场
|
|
|
String farmId = (String) params.get("formFarmId");
|
|
|
if (StringUtils.isNotEmpty(farmId)) {
|
|
|
- queryWrapper.eq("base.farm_id",Integer.parseInt(farmId));
|
|
|
+ queryWrapper.eq("base.farm_id", Integer.parseInt(farmId));
|
|
|
}
|
|
|
//排除逻辑删除
|
|
|
queryWrapper.apply(" base.deleted = 0 AND pigsty.deleted = 0 AND period.deleted = 0");
|
|
|
|
|
|
- IPage<PigBaseVo> page = pigBaseDao.list(new Query<>().getPage(params),queryWrapper);
|
|
|
-
|
|
|
+ IPage<PigBaseVo> page = pigBaseDao.list(new Query<>().getPage(params), queryWrapper);
|
|
|
|
|
|
|
|
|
return new PageUtils(page);
|
|
@@ -139,10 +145,10 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void batchLairage(String[] eartags,Integer periodId) {
|
|
|
+ public void batchLairage(String[] eartags, Integer periodId) {
|
|
|
for (String eartag : eartags) {
|
|
|
UpdateWrapper<YearPigBaseEntity> updateWrapper = new UpdateWrapper<YearPigBaseEntity>();
|
|
|
- updateWrapper.eq("eartag",eartag).set("period_id",periodId);
|
|
|
+ updateWrapper.eq("eartag", eartag).set("period_id", periodId);
|
|
|
update(updateWrapper);
|
|
|
}
|
|
|
}
|
|
@@ -155,61 +161,60 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
@Override
|
|
|
public Integer findByoutFenceStatus(int i, Integer farmId) {
|
|
|
LambdaQueryWrapper<YearPigBaseEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(YearPigBaseEntity::getFarmId,farmId);
|
|
|
- wrapper.eq(YearPigBaseEntity::getOutFenceStatus,i);
|
|
|
+ wrapper.eq(YearPigBaseEntity::getFarmId, farmId);
|
|
|
+ wrapper.eq(YearPigBaseEntity::getOutFenceStatus, i);
|
|
|
Integer integer = pigBaseDao.selectCount(wrapper);
|
|
|
return integer;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Map<String ,Object> queryPageByRelationship(Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
|
|
+ public Map<String, Object> queryPageByRelationship(Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
String eartag_no = (String) params.get("eartag");
|
|
|
System.out.println(eartag_no);
|
|
|
- YearPigBaseEntity self = baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, eartag_no));
|
|
|
+ YearPigBaseEntity self = baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, eartag_no));
|
|
|
System.out.println(self);
|
|
|
// result.put("self", self );
|
|
|
|
|
|
- System.out.println("父亲ID"+self.getFatherEartag()); System.out.println("母亲ID"+self.getMotherEartag());
|
|
|
+ System.out.println("父亲ID" + self.getFatherEartag());
|
|
|
+ System.out.println("母亲ID" + self.getMotherEartag());
|
|
|
String math = self.getMotherEartag();
|
|
|
|
|
|
- YearPigBaseEntity father = self.getFatherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, self.getFatherEartag()));
|
|
|
- YearPigBaseEntity mother = self.getMotherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, math));
|
|
|
+ YearPigBaseEntity father = self.getFatherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, self.getFatherEartag()));
|
|
|
+ YearPigBaseEntity mother = self.getMotherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, math));
|
|
|
|
|
|
|
|
|
//父亲父母
|
|
|
// result.put("father", father);
|
|
|
// result.put("mother", mother);
|
|
|
- YearPigBaseEntity fathermother = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getFatherEartag()));
|
|
|
- YearPigBaseEntity fatherfather = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getMotherEartag()));
|
|
|
+ YearPigBaseEntity fathermother = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getFatherEartag()));
|
|
|
+ YearPigBaseEntity fatherfather = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getMotherEartag()));
|
|
|
// result.put("fathermother", fathermother);
|
|
|
// result.put("fatherfather", fatherfather);
|
|
|
//母亲父母
|
|
|
- YearPigBaseEntity mothermother = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getFatherEartag()));
|
|
|
- YearPigBaseEntity motherfather = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getMotherEartag()));
|
|
|
+ YearPigBaseEntity mothermother = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getFatherEartag()));
|
|
|
+ YearPigBaseEntity motherfather = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getMotherEartag()));
|
|
|
// result.put("mothermother", mothermother);
|
|
|
// result.put("motherfather", motherfather);
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
Object[] intArr = new Object[7];
|
|
|
Map<String, String> selfmap = BeanUtils.describe(self);
|
|
|
- selfmap.put("name","self");
|
|
|
+ selfmap.put("name", "self");
|
|
|
Map<String, String> fathermap = BeanUtils.describe(father);
|
|
|
- fathermap.put("name","father");
|
|
|
+ fathermap.put("name", "father");
|
|
|
Map<String, String> mothermap = BeanUtils.describe(mother);
|
|
|
- mothermap.put("name","mother");
|
|
|
+ mothermap.put("name", "mother");
|
|
|
Map<String, String> fathermothermap = BeanUtils.describe(fathermother);
|
|
|
- fathermothermap.put("name","fathermother");
|
|
|
+ fathermothermap.put("name", "fathermother");
|
|
|
Map<String, String> fatherfatherself = BeanUtils.describe(fatherfather);
|
|
|
- fatherfatherself.put("name","fatherfather");
|
|
|
+ fatherfatherself.put("name", "fatherfather");
|
|
|
Map<String, String> mothermotherself = BeanUtils.describe(mothermother);
|
|
|
- mothermotherself.put("name","mothermother");
|
|
|
+ mothermotherself.put("name", "mothermother");
|
|
|
Map<String, String> motherfatherself = BeanUtils.describe(motherfather);
|
|
|
- motherfatherself.put("name","motherfather");
|
|
|
+ motherfatherself.put("name", "motherfather");
|
|
|
|
|
|
|
|
|
intArr[0] = selfmap;
|
|
@@ -220,8 +225,8 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
intArr[5] = mothermotherself;
|
|
|
intArr[6] = motherfatherself;
|
|
|
|
|
|
- result.put("value",intArr);
|
|
|
- return result;
|
|
|
+ result.put("value", intArr);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -239,7 +244,7 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
}
|
|
|
wrapper.apply("deleted = 0 AND out_fence_status = 1 ");
|
|
|
|
|
|
- List<CountOut> endList = pigBaseDao.suchStatistics(farmId,wrapper);
|
|
|
+ List<CountOut> endList = pigBaseDao.suchStatistics(farmId, wrapper);
|
|
|
System.out.println(endList);
|
|
|
}
|
|
|
|
|
@@ -255,6 +260,9 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
@Autowired
|
|
|
private UnitDao unitDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TransferPeriodLogDao transferPeriodLogDao;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void transferPeriod(HashMap<String, Object> map, HttpServletRequest request) {
|
|
@@ -262,37 +270,56 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
String token = request.getHeader("token");
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("token",token);
|
|
|
- HttpEntity httpEntity = new HttpEntity<>(null,headers);
|
|
|
+ headers.add("token", token);
|
|
|
+ HttpEntity httpEntity = new HttpEntity<>(null, headers);
|
|
|
|
|
|
- ResponseEntity<R> responseEntity = restTemplate.exchange(url, HttpMethod.GET,httpEntity, R.class);
|
|
|
+ ResponseEntity<R> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, R.class);
|
|
|
R sysUserEntity = responseEntity.getBody();
|
|
|
+ if (401 == (Integer) (sysUserEntity.get("code"))) {
|
|
|
+ throw new RRException((String) sysUserEntity.get("msg"), (Integer) sysUserEntity.get("code"));
|
|
|
+ }
|
|
|
String jsonString = JSONObject.toJSONString(sysUserEntity.get("user"));
|
|
|
- SysUserEntity user = JSONObject.parseObject(jsonString,SysUserEntity.class);
|
|
|
+ SysUserEntity user = JSONObject.parseObject(jsonString, SysUserEntity.class);
|
|
|
|
|
|
String username = user.getUsername();
|
|
|
System.out.println(username);
|
|
|
|
|
|
- List<String> earTagList = (List<String>) map.get("earTagList");
|
|
|
+ List<Integer> pigIds = (List<Integer>) map.get("pigIds");
|
|
|
Integer periodId = (Integer) map.get("periodId");
|
|
|
- System.out.println(earTagList);
|
|
|
- System.out.println(periodId);
|
|
|
- LambdaQueryWrapper<YearPigBaseEntity> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- UpdateWrapper updateWrapper = new UpdateWrapper();
|
|
|
- for (String earTag : earTagList) {
|
|
|
|
|
|
- queryWrapper.eq(YearPigBaseEntity::getEartag,earTag);
|
|
|
- YearPigBaseEntity oldEntity = baseMapper.selectOne(queryWrapper);
|
|
|
- queryWrapper.clear();
|
|
|
+ if (CollUtil.isEmpty(pigIds) || periodId == null) {
|
|
|
+ throw new RRException("参数有误,请检查!",1001);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TransferPeriodLogEntity> logEntityList = new ArrayList<>();
|
|
|
+ YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
|
|
|
+
|
|
|
+ for (Integer pigId : pigIds) {
|
|
|
+ YearPigBaseEntity oldEntity = baseMapper.selectById(pigId);
|
|
|
|
|
|
Integer oldPeriodId = oldEntity.getPeriodId();
|
|
|
- String oldPeroidName = periodDao.selectById(oldPeriodId).getNumber();
|
|
|
+ String oldPeriodName = periodDao.selectById(oldPeriodId).getNumber();
|
|
|
Integer oldUnitId = oldEntity.getUnitId();
|
|
|
String oldUnitName = unitDao.selectById(oldUnitId).getNumber();
|
|
|
|
|
|
+ PeriodEntity newEntity = periodDao.selectById(periodId);
|
|
|
+ Integer newUnitId = newEntity.getUnitId();
|
|
|
+ String newUnitName = unitDao.selectById(newUnitId).getNumber();
|
|
|
+
|
|
|
+ TransferPeriodLogEntity entity = new TransferPeriodLogEntity();
|
|
|
+ entity.setEarTag(oldEntity.getEartag());
|
|
|
+ entity.setOldPeriod(oldPeriodName);
|
|
|
+ entity.setOldUnit(oldUnitName);
|
|
|
+ entity.setNewPeriod(newEntity.getNumber());
|
|
|
+ entity.setNewUnit(newUnitName);
|
|
|
+ entity.setOperatorUsername(username);
|
|
|
+ logEntityList.add(entity);
|
|
|
|
|
|
-// update()
|
|
|
- }
|
|
|
|
|
|
+ yearPigBaseEntity.setId(pigId);
|
|
|
+ yearPigBaseEntity.setPeriodId(periodId);
|
|
|
+ updateById(yearPigBaseEntity);
|
|
|
+ }
|
|
|
+ transferPeriodLogDao.batchInsert(logEntityList);
|
|
|
}
|
|
|
}
|