|
@@ -11,13 +11,11 @@ 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.*;
|
|
|
import com.huimv.management.entity.vo.CountOut;
|
|
|
import com.huimv.management.entity.vo.DrinkingWaterVo;
|
|
|
import com.huimv.management.entity.vo.PigBaseVo;
|
|
|
+import com.huimv.management.util.GetUserUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -288,57 +286,67 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void transferPeriod(HashMap<String, Object> map, HttpServletRequest request) {
|
|
|
|
|
|
- String token = request.getHeader("token");
|
|
|
-
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("token", token);
|
|
|
- HttpEntity httpEntity = new HttpEntity<>(null, headers);
|
|
|
+// String token = request.getHeader("token");
|
|
|
+//
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
+// headers.add("token", token);
|
|
|
+// HttpEntity httpEntity = new HttpEntity<>(null, headers);
|
|
|
+//
|
|
|
+// 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);
|
|
|
|
|
|
- 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);
|
|
|
-
|
|
|
- String username = user.getUsername();
|
|
|
- System.out.println(username);
|
|
|
|
|
|
List<Integer> pigIds = (List<Integer>) map.get("pigIds");
|
|
|
- Integer periodId = (Integer) map.get("periodId");
|
|
|
+ Integer unitId = (Integer) map.get("unitId");
|
|
|
|
|
|
- if (CollUtil.isEmpty(pigIds) || periodId == null) {
|
|
|
+ if (CollUtil.isEmpty(pigIds) || unitId == null) {
|
|
|
throw new RRException("参数有误,请检查!",1001);
|
|
|
}
|
|
|
|
|
|
List<TransferPeriodLogEntity> logEntityList = new ArrayList<>();
|
|
|
YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
|
|
|
+ //获取当前操作用户
|
|
|
+ SysUserEntity user = GetUserUtil.getUser(request);
|
|
|
+ String username = user.getUsername();
|
|
|
|
|
|
for (Integer pigId : pigIds) {
|
|
|
YearPigBaseEntity oldEntity = baseMapper.selectById(pigId);
|
|
|
-
|
|
|
+ if (oldEntity == null) {
|
|
|
+ throw new RRException("查不到id为" + pigId + "的猪的信息,请检查参数!",1001);
|
|
|
+ }
|
|
|
+ if (oldEntity.getUnitId().equals(unitId)) {
|
|
|
+ throw new RRException("所转单元不能和原单元相同!",1001);
|
|
|
+ }
|
|
|
Integer oldPeriodId = oldEntity.getPeriodId();
|
|
|
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();
|
|
|
+ UnitEntity unitEntity = unitDao.selectById(unitId);
|
|
|
+ if (unitEntity == null) {
|
|
|
+ throw new RRException("查不到id为" + unitId + "的单元的信息,请检查参数!",1001);
|
|
|
+ }
|
|
|
+ String newUnitName = unitEntity.getNumber();
|
|
|
+ String newPeriodName = periodDao.selectById(unitEntity.getCurrentPeriodId()).getNumber();
|
|
|
+
|
|
|
|
|
|
TransferPeriodLogEntity entity = new TransferPeriodLogEntity();
|
|
|
+ entity.setFarmId(unitEntity.getFarmId());
|
|
|
entity.setEarTag(oldEntity.getEartag());
|
|
|
entity.setOldPeriod(oldPeriodName);
|
|
|
entity.setOldUnit(oldUnitName);
|
|
|
- entity.setNewPeriod(newEntity.getNumber());
|
|
|
+ entity.setNewPeriod(newPeriodName);
|
|
|
entity.setNewUnit(newUnitName);
|
|
|
entity.setOperatorUsername(username);
|
|
|
logEntityList.add(entity);
|
|
|
|
|
|
-
|
|
|
yearPigBaseEntity.setId(pigId);
|
|
|
- yearPigBaseEntity.setPeriodId(periodId);
|
|
|
+ yearPigBaseEntity.setPeriodId(unitEntity.getCurrentPeriodId());
|
|
|
updateById(yearPigBaseEntity);
|
|
|
}
|
|
|
transferPeriodLogDao.batchInsert(logEntityList);
|