1、用querywrapper查看列表
@GetMapping("/pclist")
@ApiOperation(value = "pc合同管理-合同列表")
public ResponseVo<?> list(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
@RequestParam(name = "farmCompanyName", required = false) String farmCompanyName,//牧场企业名称
@RequestParam(name = "farmerName", required = false) String farmerName,
@RequestParam(name = "signTime", required = false) String signTime,//签订时间
@RequestParam(name = "pastureName", required = false) String pastureName,//牧场名称
HttpServletRequest req){
QueryWrapper<Contract> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(StringUtils.isNotBlank(farmCompanyName), wrapper -> wrapper.like(Contract::getFarmCompanyName, farmCompanyName))
.and(StringUtils.isNotBlank(farmerName), wrapper -> wrapper.like(Contract::getFarmerName, farmerName))
.and(StringUtils.isNotBlank(pastureName), wrapper -> wrapper.like(Contract::getPastureName, pastureName))
.and(StringUtils.isNotBlank(signTime), wrapper -> wrapper.eq(Contract::getSignTime, signTime));
Page<Contract> page = new Page<>(pageNo, pageSize);
IPage<Contract> list = contractService.page(page,queryWrapper);
return ResponseVo.ok(list);
}
2、获取确定合同数
impl:
@Override
public int getAssignStatusContractCount(String username, String contractStatus) {
Integer count = contractMapper.getAssignStatusContractCount(username, contractStatus);
return count == null ? 0 : count;
}
mapper:
@Mapper
public interface ContractMapper extends BaseMapper<Contract> {
Integer getAssignStatusContractCount(@Param("username") String username,@Param("contractStatus") String contractStatus);
}
xml:
<select id="getAssignStatusContractCount" resultType="java.lang.Integer">
select count(c.id) from contract c
left join adopt_apply a on c.adopt_apply_no = a.adopt_apply_no
where a.create_user_id = #{username}
and c.contract_status = #{contractStatus};
</select>
3、增加或更新
impl:
@Override
public boolean addOrUpdate(BioCommodityDto bioCommodityDto) {
log.info("新增/更新接口入参为:{}", bioCommodityDto);
ValidationUtils.validateWithException(bioCommodityDto);
BioCommodityEntity bioCommodityEntity = new BioCommodityEntity();
BeanUtils.copyProperties(bioCommodityDto, bioCommodityEntity);
boolean flag;
if (ObjectUtils.isEmpty(bioCommodityEntity.getId())){
// insert
// 默认启用状态
installDefaultParam(bioCommodityEntity, false);
flag = this.save(bioCommodityEntity);
}else {
// update
// 监测商品状态
checkCommodityStatus(bioCommodityEntity.getId());
installDefaultParam(bioCommodityEntity, true);
flag = this.updateById(bioCommodityEntity);
}
return flag;
}
private void installDefaultParam(BioCommodityEntity bioCommodityEntity, boolean update) {
Claims userClaims = LoginUserContextHolder.getUserClaims();
if (!update){
bioCommodityEntity.setStatus(CommodityStatusEnum.UP.getCode());
bioCommodityEntity.setCreateUser(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_NICKNAME)));
bioCommodityEntity.setCreateUserId(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_USERNAME)));
bioCommodityEntity.setUpdateUser(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_NICKNAME)));
bioCommodityEntity.setUpdateUserId(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_USERNAME)));
} else {
bioCommodityEntity.setUpdateUser(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_NICKNAME)));
bioCommodityEntity.setUpdateUserId(String.valueOf(userClaims.get(SystemManagerConstant.LOGIN_USER_USERNAME)));
}
}
private void checkCommodityStatus(Long id) {
BioCommodityEntity bioCommodityEntity = this.getById(id);
if (ObjectUtils.isEmpty(bioCommodityEntity)){
log.info("商品id为{}的数据不存在", id);
throw new BaseException("商品信息不存在");
}
String status = bioCommodityEntity.getStatus();
if (!CommodityStatusEnum.DOWN.getCode().equals(status)){
throw new BaseException("商品处于下架状态方可进行操作");
}
}
4、上架或下架
impl:
@Override
public boolean upOrDown(BioCommodityDto bioCommodityDto) {
Long id = bioCommodityDto.getId();
String status = bioCommodityDto.getStatus();
Assert.notNull(id, "主键不能为空");
Assert.notBlank(status, "状态不能为空");
return this.lambdaUpdate()
.ge(BioCommodityEntity::getId, id)
.set(BioCommodityEntity::getStatus, status)
.update();
}
5、首页信息统计
controller:
@ApiOperation(value = "农户首页-信息统计")
@GetMapping("/statistics")
public ResponseVo<FarmerStatisticsVo> statistics(@RequestParam(value = "username")String username){
FarmerStatisticsVo farmerStatisticsVo = farmerHomeService.statistics(username);
return ResponseVo.ok(farmerStatisticsVo);
}
impl:
@Override
public FarmerStatisticsVo statistics(String username) {
log.info("获取农户首页统计信息的账号为{}", username);
Assert.notBlank(username, "农户登录账号不能为空");
FarmerStatisticsVo farmerStatisticsVo = new FarmerStatisticsVo();
// 统计牛只信息
statisticsBioInfo(farmerStatisticsVo, username);
// todo 统计授信
statisticsCreditInfo(farmerStatisticsVo, username);
// todo 统计贷款
statisticsLoanInfo(farmerStatisticsVo, username);
return farmerStatisticsVo;
}
private void statisticsLoanInfo(FarmerStatisticsVo farmerStatisticsVo, String username) {
}
private void statisticsCreditInfo(FarmerStatisticsVo farmerStatisticsVo, String username) {
}
/**
* 统计生物数据信息
* @param farmerStatisticsVo 统计数据
* @param username 登录账号
*/
private void statisticsBioInfo(FarmerStatisticsVo farmerStatisticsVo, String username) {
List<AdoptApplyBioRelEntity> adoptApplyBioRelList = adoptApplyBioRelService.getBioTotal(username);
int bioTotal,fyCount,ycCount;
bioTotal = fyCount = ycCount = 0;
if (CollectionUtil.isNotEmpty(adoptApplyBioRelList)){
bioTotal = adoptApplyBioRelList.size();
List<String> bioCodeList = new ArrayList<>(bioTotal);
adoptApplyBioRelList.forEach(adoptApplyBioRelEntity -> {
if (adoptApplyBioRelEntity != null && StringUtils.isNotBlank(adoptApplyBioRelEntity.getBioCode())){
bioCodeList.add(adoptApplyBioRelEntity.getBioCode());
}
});
ResponseVo<List<BiologicalInfoVo>> bioInfoResponseVo = biologicalFeignClient.queryByBioCodes(bioCodeList);
if (ObjectUtils.isEmpty(bioInfoResponseVo) || !ResultCode.COMMON_SUCCESS.code().equals(bioInfoResponseVo.getCode())){
throw new BaseException("biologicalFeignClient远程调用失败");
}
if (CollectionUtil.isNotEmpty(bioInfoResponseVo.getData())){
ycCount = (int) bioInfoResponseVo.getData()
.stream()
.filter(biologicalInfoVo ->
BreedStateEnum.FATTEN.getValue().equals(biologicalInfoVo.getBreedState()))
.count();
fyCount = (int) bioInfoResponseVo.getData()
.stream()
.filter(biologicalInfoVo ->
BreedStateEnum.BREED.getValue().equals(biologicalInfoVo.getBreedState()))
.count();
}
}
log.info("用户账号账号为{},饲养生物总数为{},育成类型个数为{},繁育类型个数为{}", username, bioTotal, ycCount, fyCount);
farmerStatisticsVo.setBioTotal(bioTotal);
farmerStatisticsVo.setFyCount(fyCount);
farmerStatisticsVo.setYcCount(ycCount);
}
AdoptApplyBioRelServiceImpl:
@Service("AdoptApplyBioRelService")
public class AdoptApplyBioRelServiceImpl extends ServiceImpl<AdoptApplyBioRelMapper, AdoptApplyBioRelEntity> implements AdoptApplyBioRelService {
@Override
public List<AdoptApplyBioRelEntity> getBioTotal(String username) {
return this.lambdaQuery()
.eq(AdoptApplyBioRelEntity::getCreateUserId, username)
.list();
}
}
6、代办数量
controller:
@ApiOperation(value = "农户首页-代办任务数量")
@GetMapping("/unHandleTaskCount")
public ResponseVo<Integer> unHandleTaskCount(@RequestParam(value = "username")String username){
int count = farmerHomeService.unHandleTaskCount(username);
return ResponseVo.ok(count);
}
impl:
// todo 二期需求进行完善
@Override
public int unHandleTaskCount(String username) {
log.info("获取代办任务数量的账号为{}", username);
int count = contractService.getAssignStatusContractCount(username, "0");
return count;
}
Impl:
@Override
public int getAssignStatusContractCount(String username, String contractStatus) {
Integer count = contractMapper.getAssignStatusContractCount(username, contractStatus);
return count == null ? 0 : count;
}
mapper:
@Mapper
public interface ContractMapper extends BaseMapper<Contract> {
Integer getAssignStatusContractCount(@Param("username") String username,@Param("contractStatus") String contractStatus);
}
xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cib.fintech.cibiot.livestock.finance.modules.contract.dao.mapper.ContractMapper" >
<select id="getAssignStatusContractCount" resultType="java.lang.Integer">
select count(c.id) from contract c
left join adopt_apply a on c.adopt_apply_no = a.adopt_apply_no
where a.create_user_id = #{username}
and c.contract_status = #{contractStatus};
</select>
</mapper>