559
whywhyo
2023-07-16 8e93f63d7eab5c4f5d193763cbb2e81ea5476923
559
8个文件已修改
363 ■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPetController.java 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZExperience.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZfPet.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZfPetNote.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/ZfPetService.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCollectionServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfPetServiceImpl.java 245 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPetController.java
@@ -43,7 +43,7 @@
    public AjaxResult listAll(ZfPet zfPet){
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return zfPetService.selectPetList(zfPet, pageNum, pageSize);
        return zfPetService.selectDataList(zfPet, pageNum, pageSize);
    }
    /**
@@ -56,25 +56,26 @@
        util.exportExcel(response,list,"魅宠记录导入模板");
    }
//    /**
//     * 导出魅宠记录列表
//     */
////    @PreAuthorize("@ss.hasPermi('system:property:export')")
//    @Log(title = "魅宠记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZfPet zfPet)
//    {
//        List<ZfPet> list = zfPetService.selectByCondition(zfPet);
//        log.info("导出记录为:{}",list);
//        ExcelUtil<ZfPet> util = new ExcelUtil<>(ZfPet.class);
//        util.exportExcel(response, list, "魅宠记录数据");
//    }
    /**
     * 导出魅宠记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:property:export')")
    @Log(title = "魅宠记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZfPet zfPet)
    {
        List<ZfPet> list = zfPetService.selectByCondition(zfPet);
        log.info("导出记录为:{}",list);
        ExcelUtil<ZfPet> util = new ExcelUtil<>(ZfPet.class);
        util.exportExcel(response, list, "魅宠记录数据");
    }
    /**
     * 导出魅宠记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:property:export')")
    @Log(title = "魅宠记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export1/{ids}")
    @PostMapping("/export/{ids}")
    public void export(HttpServletResponse response, @PathVariable Long[] ids)
    {
        List<ZfPet> list = zfPetService.selectByIds(ids);
@@ -90,14 +91,15 @@
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception
    {
        ExcelUtil<ZfPet> util = new ExcelUtil<>(ZfPet.class);
        List<ZfPet> eventList = util.importExcel(file.getInputStream());
        log.info("魅宠列表为:{}",eventList);
        if (zfPetService.saveBatch(eventList)) {
            return AjaxResult.success("导入数据成功");
        }
        return AjaxResult.error("导入数据失败");
//        ExcelUtil<ZfPet> util = new ExcelUtil<>(ZfPet.class);
//        List<ZfPet> eventList = util.importExcel(file.getInputStream());
//        log.info("魅宠列表为:{}",eventList);
//
//        if (zfPetService.saveBatch(eventList)) {
//            return AjaxResult.success("导入数据成功");
//        }
//        return AjaxResult.error("导入数据失败");
        return zfPetService.importExcel(file);
    }
    /**
@@ -118,7 +120,7 @@
    @PostMapping
    public AjaxResult add(@RequestBody ZfPet zfPet)
    {
        return zfPetService.mySave(zfPet);
        return zfPetService.addData(zfPet);
    }
    /**
@@ -129,7 +131,7 @@
    @PutMapping
    public AjaxResult edit(@RequestBody ZfPet zfPet)
    {
        return toAjax(zfPetService.updateById(zfPet));
        return zfPetService.updateData(zfPet);
    }
//
    /**
@@ -140,7 +142,7 @@
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zfPetService.removeByIds(Arrays.asList(ids)));
        return zfPetService.deleteData(ids);
    }
}
zhang-content/src/main/java/com/ruoyi/constant/MenuAuthority.java
@@ -46,7 +46,7 @@
    public static final String DOCTOR_LIST_UPDATE="2031";
    public static final String DOCTOR_LIST_REMOVE="2032";
    public static final String FAMILY_PET="2033";
    public static final String FAMILY_PET_LIST="2033";
    public static final String FAMILY_PET_ADD="2034";
    public static final String FAMILY_PET_UPDATE="2035";
    public static final String FAMILY_PET_REMOVE="2036";
zhang-content/src/main/java/com/ruoyi/domain/ZExperience.java
@@ -51,6 +51,13 @@
    private Date startDate;
    /**
     * 结束日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "结束日期", dateFormat = "yyyy-MM-dd")
    private Date endDate;
    /**
     * 证明人名字
     */
    @Excel(name = "证明人名字")
zhang-content/src/main/java/com/ruoyi/domain/ZfPet.java
@@ -1,6 +1,7 @@
package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -109,9 +110,38 @@
    @Excel(name = "能听懂的方言")
    private String dialect;
    private String url;
    private Long familyId;
    @TableField(exist = false)
    private Integer ownData;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /**
     * 头像
     */
    private String headPicture;
    /**
     * 全身照
     */
    private String fullPicture;
    //以下是主人信息
    @Excel(name = "主人名字")
    private String masterName;
    @Excel(name = "主人证件号码")
    private String masterIdNum;
    @Excel(name = "主人电话号码")
    private String phone;
    @Excel(name = "主人地址")
    private String masterAddress;
}
zhang-content/src/main/java/com/ruoyi/domain/ZfPetNote.java
@@ -58,6 +58,7 @@
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /**
@@ -70,15 +71,19 @@
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenStartTime;
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenEndTime;
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date remindStartTime;
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date remindEndTime;
zhang-content/src/main/java/com/ruoyi/service/ZfPetService.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ZfPet;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -17,9 +18,20 @@
 */
public interface ZfPetService extends IService<ZfPet> {
    AjaxResult selectPetList(ZfPet zfPet, Integer pageNum, Integer pageSize);
//    AjaxResult selectPetList(ZfPet zfPet, Integer pageNum, Integer pageSize);
    AjaxResult selectDataList(ZfPet zfPet, Integer pageNum, Integer pageSize);
    List<ZfPet> selectByCondition(ZfPet zfPet);
    List<ZfPet> selectByIds(Long[] ids);
    AjaxResult mySave(ZfPet zfPet);
//    AjaxResult mySave(ZfPet zfPet);
    AjaxResult importExcel(MultipartFile file);
    AjaxResult addData(ZfPet zfPet);
    AjaxResult updateData(ZfPet zfPet);
    AjaxResult deleteData(Long[] ids);
}
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCollectionServiceImpl.java
@@ -354,7 +354,7 @@
        }
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList());
        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(COLLECTION_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList());
        familyIdList.add(familyId);
        if (zfCollection.getFamilyId()!=null && !familyIdList.contains(zfCollection.getFamilyId())) {
zhang-content/src/main/java/com/ruoyi/service/impl/ZfPetServiceImpl.java
@@ -9,13 +9,11 @@
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfMaster;
import com.ruoyi.domain.ZfEquipment;
import com.ruoyi.domain.ZfPet;
import com.ruoyi.domain.ZfProperty;
import com.ruoyi.domain.*;
import com.ruoyi.mapper.ZfPetMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfMasterService;
import com.ruoyi.service.ZfPetService;
@@ -24,11 +22,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
/**
 * <p>
@@ -50,23 +53,77 @@
    @Autowired
    ZfPetService zfPetService;
    @Resource
    ZAuthorityService zAuthorityService;
    @Override
    public AjaxResult selectPetList(ZfPet zfPet, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<ZfPet> lqw = buildCondition(zfPet);
        lqw.orderByDesc(ZfPet::getCreateTime);
        Page<ZfPet> ZfPetPage = new Page<>(pageNum,pageSize);
        Page<ZfPet> pageResult = page(ZfPetPage, lqw);
        HashMap<String, Object> data = MapUtils.getResult(pageResult);
    public AjaxResult selectDataList(ZfPet zfPet, Integer pageNum, Integer pageSize) {
//        LambdaQueryWrapper<ZfPet> lqw = buildCondition(zfPet);
//        lqw.orderByDesc(ZfPet::getCreateTime);
//        Page<ZfPet> ZfPetPage = new Page<>(pageNum,pageSize);
//        Page<ZfPet> pageResult = page(ZfPetPage, lqw);
//        HashMap<String, Object> data = MapUtils.getResult(pageResult);
//        return AjaxResult.success(data);
        //要查自己家庭的
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(FAMILY_PET_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
        //加上自己家庭的id
        idList.add(familyId);
//        String familyIds = listFamilyIds();
//        String secondFamilyAuthority = listSecondFamilyIds();
        LambdaQueryWrapper<ZfPet> lqw = buildCondition(zfPet, idList);
        Page<ZfPet> zfPetPage = new Page<>(pageNum, pageSize);
        Page<ZfPet> pageResult = page(zfPetPage, lqw);
        List<ZfPet> beanRecords = pageResult.getRecords();//得到查询出来的数据
        List<ZfPet> dtoResult = markOwnData(familyId, beanRecords);
        HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult);
        return AjaxResult.success(data);
    }
    public List<ZfPet> markOwnData(Long familyId,List<ZfPet> beanRecords){
        return beanRecords.stream().peek(
                bean -> {
                    if (bean.getFamilyId() == familyId) {
                        bean.setOwnData(1);
                    } else {
                        bean.setOwnData(0);
                    }
                }
        ).collect(Collectors.toList());
    }
    @Override
    public List<ZfPet> selectByCondition(ZfPet zfPet) {
        LambdaQueryWrapper<ZfPet> lambdaQueryWrapper = buildCondition(zfPet);
        lambdaQueryWrapper.orderByDesc(ZfPet::getCreateTime);
        List<ZfPet> list = list(lambdaQueryWrapper);
        log.info("返回的数据为:{}",list);
        return list;
//        LambdaQueryWrapper<ZfPet> lambdaQueryWrapper = buildCondition(zfPet);
//        lambdaQueryWrapper.orderByDesc(ZfPet::getCreateTime);
//        List<ZfPet> list = list(lambdaQueryWrapper);
//        log.info("返回的数据为:{}",list);
//        return list;
        //要查自己家庭的
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(FAMILY_PET_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
        //加上自己家庭的id
        idList.add(familyId);
        LambdaQueryWrapper<ZfPet> lambdaQueryWrapper = buildCondition(zfPet, idList);
        List<ZfPet> beanRecords = list(lambdaQueryWrapper);
        log.info("从数据库中查到的为:{}", beanRecords);
        return markOwnData(familyId, beanRecords);
    }
    @Override
@@ -80,44 +137,148 @@
    }
    @Override
    @Transactional
    public AjaxResult mySave(ZfPet zfPet) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
    public AjaxResult importExcel(MultipartFile file) {
        ExcelUtil<ZfPet> util = new ExcelUtil<>(ZfPet.class);
        List<ZfPet> dataList = null;
        try {
            dataList = util.importExcel(file.getInputStream());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        log.info("数据列表为:{}", dataList);
        String pid = IdUtils.fastSimpleUUID();
        zfPet.setId(pid);
        for (ZfPet zfPet : dataList) {
            zfPetService.addData(zfPet);
        }
        return AjaxResult.success("导入数据成功");
    }
    @Override
    public AjaxResult addData(ZfPet zfPet) {
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        if(familyId == null){
            throw new RuntimeException("您还未加入任何家庭");
        }
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(FAMILY_PET_ADD)).map(ZAuthority::getFid).collect(Collectors.toList());
        familyIdList.add(familyId);
        if (zfPet.getFamilyId()!=null && !familyIdList.contains(zfPet.getFamilyId())) {
            throw new RuntimeException("你没有权限操作此家庭的数据");
        }
        if(zfPet.getFamilyId() == null){
            //默认添加自己家庭的数据
            zfPet.setFamilyId(familyId);
        }
        //判断是否有重复数据
        LambdaQueryWrapper<ZfPet> lqw = uniqueCondition(zfPet);
        List<ZfPet> list = list(lqw);
        if(list.size()>0){
            throw new RuntimeException("请勿新增重复数据");
        }
        //先查找本人的数据
        LambdaQueryWrapper<ZInfoUser> zInfoLqw = new LambdaQueryWrapper<>();
        zInfoLqw.eq(ZInfoUser::getUserId,userId);
        ZInfoUser master = zInfoUserService.getOne(zInfoLqw);
        ZfMaster zfMaster = new ZfMaster();
        zfMaster.setPetId(zfPet.getId());
        zfMaster.setName(master.getNickName());
        zfMaster.setCertificateType("身份证");
        zfMaster.setCertificateNo(master.getIdNo());
        zfMaster.setPhoneNo(master.getPhoneNumber());
        zfMaster.setAddress(master.getAlwaysAddress());
        zfMasterService.save(zfMaster);
        zfPetService.save(zfPet);
        if (save(zfPet)) {
        return AjaxResult.success();
        } else {
            return AjaxResult.error();
    }
    }
    @Override
    public AjaxResult updateData(ZfPet zfPet) {
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        //先根据id查询出数据的familyId,看看有没有权限操作
        Long dataFamilyId = getById(zfPet.getId()).getFamilyId();
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(FAMILY_PET_UPDATE)).map(ZAuthority::getFid).collect(Collectors.toList());
        familyIdList.add(familyId);
        if (dataFamilyId!=null && !familyIdList.contains(dataFamilyId)) {
            throw new RuntimeException("你没有权限操作此家庭的数据");
        }
        if(updateById(zfPet)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
    @Override
    public AjaxResult deleteData(Long[] ids) {
        List<ZfPet> dataList = zfPetService.listByIds(Arrays.asList(ids));
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(FAMILY_PET_REMOVE)).map(ZAuthority::getFid).collect(Collectors.toList());
        familyIdList.add(familyId);
        for (ZfPet data : dataList) {
            if (!familyIdList.contains(data.getFamilyId())){
                throw new RuntimeException("你没有权限操作此家庭的数据");
            }
        }
        if (zfPetService.removeByIds(Arrays.asList(ids))) {
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
//    @Override
//    @Transactional
//    public AjaxResult mySave(ZfPet zfPet) {
//        SysUser user = SecurityUtils.getLoginUser().getUser();
//        Long userId = user.getUserId();
//
//        String pid = IdUtils.fastSimpleUUID();
//        zfPet.setId(pid);
//
//        //判断是否有重复数据
//        LambdaQueryWrapper<ZfPet> lqw = uniqueCondition(zfPet);
//        List<ZfPet> list = list(lqw);
//        if(list.size()>0){
//            throw new RuntimeException("请勿新增重复数据");
//        }
//
//        //先查找本人的数据
//        LambdaQueryWrapper<ZInfoUser> zInfoLqw = new LambdaQueryWrapper<>();
//        zInfoLqw.eq(ZInfoUser::getUserId,userId);
//        ZInfoUser master = zInfoUserService.getOne(zInfoLqw);
//
//        ZfMaster zfMaster = new ZfMaster();
//        zfMaster.setPetId(zfPet.getId());
//        zfMaster.setName(master.getNickName());
//        zfMaster.setCertificateType("身份证");
//        zfMaster.setCertificateNo(master.getIdNo());
//        zfMaster.setPhoneNo(master.getPhoneNumber());
//        zfMaster.setAddress(master.getAlwaysAddress());
//
//        zfMasterService.save(zfMaster);
//
//        zfPetService.save(zfPet);
//
//        return AjaxResult.success();
//
//    }
    private LambdaQueryWrapper<ZfPet> uniqueCondition(ZfPet zfPet) {
        LambdaQueryWrapper<ZfPet> lqw = new LambdaQueryWrapper<>();
        lqw.eq(zfPet.getFamilyId()!=null,ZfPet::getFamilyId,zfPet.getFamilyId());
        lqw.eq(StringUtils.isNotEmpty(zfPet.getIdNum()),ZfPet::getIdNum,zfPet.getIdNum());
        lqw.eq(StringUtils.isNotEmpty(zfPet.getSecurityCode()),ZfPet::getSecurityCode,zfPet.getSecurityCode());
        lqw.eq(StringUtils.isNotEmpty(zfPet.getType()),ZfPet::getType,zfPet.getType());
@@ -135,8 +296,10 @@
        return lqw;
    }
    private LambdaQueryWrapper<ZfPet> buildCondition(ZfPet zfPet) {
    private LambdaQueryWrapper<ZfPet> buildCondition(ZfPet zfPet,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfPet> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(ZfPet::getCreateTime);
        lqw.in(ZfPet::getFamilyId,familyIdList);
        lqw.like(StringUtils.isNotEmpty(zfPet.getIdNum()),ZfPet::getIdNum,zfPet.getIdNum());
        lqw.like(StringUtils.isNotEmpty(zfPet.getSecurityCode()),ZfPet::getSecurityCode,zfPet.getSecurityCode());
        lqw.like(StringUtils.isNotEmpty(zfPet.getType()),ZfPet::getType,zfPet.getType());