|
@@ -1,14 +1,21 @@
|
|
|
package com.huimv.management.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.huimv.common.exception.RRException;
|
|
|
+import com.huimv.management.dao.UnitDao;
|
|
|
import com.huimv.management.entity.PeriodEntity;
|
|
|
import com.huimv.management.entity.PeriodEntity;
|
|
|
+import com.huimv.management.entity.UnitEntity;
|
|
|
+import com.huimv.management.entity.vo.PeriodVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -20,6 +27,9 @@ import com.huimv.common.utils.Query;
|
|
|
import com.huimv.management.dao.PeriodDao;
|
|
|
import com.huimv.management.entity.PeriodEntity;
|
|
|
import com.huimv.management.service.PeriodService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
|
|
|
|
|
|
@Service("periodService")
|
|
@@ -28,30 +38,37 @@ public class PeriodServiceImpl extends ServiceImpl<PeriodDao, PeriodEntity> impl
|
|
|
@Autowired
|
|
|
private PeriodDao periodDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UnitDao unitDao;
|
|
|
+
|
|
|
@Override
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
|
|
- LambdaQueryWrapper<PeriodEntity> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
- String farmId = (String)params.get("fromFarmId");
|
|
|
- lambdaQuery.eq(StringUtils.isNotBlank(farmId),PeriodEntity::getPigstyId,farmId);
|
|
|
-
|
|
|
- String keywords = (String) params.get("keywords");
|
|
|
- //没有参数
|
|
|
- if (keywords == null || keywords.equals("")){
|
|
|
- IPage<PeriodEntity> page = this.page(
|
|
|
- new Query<PeriodEntity>().getPage(params),
|
|
|
- new QueryWrapper<PeriodEntity>()
|
|
|
- );
|
|
|
-
|
|
|
- return new PageUtils(page);
|
|
|
+ QueryWrapper<PeriodVo> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ String farmId = (String) params.get("formFarmId");
|
|
|
+ if (StringUtils.isBlank(farmId)) {
|
|
|
+ throw new RRException("参数有误,请检查!",1001);
|
|
|
}
|
|
|
+ queryWrapper.eq("period.farm_id",Integer.parseInt(farmId));
|
|
|
|
|
|
- lambdaQuery.like(PeriodEntity::getPigstyId,keywords);
|
|
|
- IPage<PeriodEntity> page = page(this.page(
|
|
|
- new Query<PeriodEntity>().getPage(params)
|
|
|
- ), lambdaQuery);
|
|
|
+ String pigstyId = (String) params.get("pigstyId");
|
|
|
+ if (StringUtils.isNotBlank(pigstyId)) {
|
|
|
+ queryWrapper.eq("period.pigsty_id",Integer.parseInt(pigstyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ String unitId = (String) params.get("unitId");
|
|
|
+ if (StringUtils.isNotBlank(unitId)) {
|
|
|
+ queryWrapper.eq("period.unit_id",unitId);
|
|
|
+ }
|
|
|
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
+ if (StringUtils.isNotBlank(keyword)) {
|
|
|
+ queryWrapper.like("period.number", keyword);
|
|
|
+ }
|
|
|
|
|
|
+ queryWrapper.apply("period.deleted = 0 AND pigsty.deleted = 0 AND unit.deleted = 0");
|
|
|
+ IPage<PeriodVo> page = baseMapper.page(new Query<>().getPage(params),queryWrapper);
|
|
|
return new PageUtils(page);
|
|
|
}
|
|
|
|
|
@@ -75,4 +92,30 @@ public class PeriodServiceImpl extends ServiceImpl<PeriodDao, PeriodEntity> impl
|
|
|
return periodEntities;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public void insert(PeriodEntity period) {
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ String periodId = sb.append(period.getFarmId()).append(period.getPigstyId()).append(period.getUnitId()).append(DateUtil.format(new Date(), "yyyyMMdd")).toString();
|
|
|
+ period.setNumber(periodId);
|
|
|
+ Integer unitId = period.getUnitId();
|
|
|
+ UnitEntity unitEntity = unitDao.selectById(unitId);
|
|
|
+ if (unitEntity != null) {
|
|
|
+ Integer currentPeriodId = unitEntity.getCurrentPeriodId();
|
|
|
+ if (currentPeriodId != null) {
|
|
|
+ throw new RRException("当前单元已存在栏期!",1001);
|
|
|
+ }
|
|
|
+
|
|
|
+ baseMapper.insert(period);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<UnitEntity> updateWrapper = Wrappers.lambdaUpdate();
|
|
|
+ updateWrapper.eq(UnitEntity::getId,unitId)
|
|
|
+ .set(UnitEntity::getCurrentPeriodId,period.getId());
|
|
|
+
|
|
|
+ unitDao.update(null,updateWrapper);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|