123
whywhyo
2023-06-05 dc194fb281e0e4c4ec34549adb4ad11f3cb67b35
123
9个文件已修改
630 ■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZIdeaController.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZPropertyController.java 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-druid.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZIdea.java 103 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZProperty.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/ZIdeaService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/ZPropertyService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZIdeaServiceImpl.java 119 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZIdeaController.java
@@ -1,9 +1,27 @@
package com.ruoyi.web.controller.zhang;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ZIdea;
import com.ruoyi.service.ZIdeaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
/**
 * <p>
@@ -15,7 +33,97 @@
 */
@RestController
@RequestMapping("/zIdea")
public class ZIdeaController {
@Slf4j
public class ZIdeaController extends BaseController {
    @Autowired
    private ZIdeaService zIdeaService;
    /**
     * 查询所有记录
     */
    @GetMapping("/all")
    public AjaxResult listAll(ZIdea zIdea){
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return zIdeaService.selectDataList(zIdea,pageNum,pageSize);
    }
    /**
     * 根据id查询
     */
    @GetMapping()
    public AjaxResult listById(Long id){
        return AjaxResult.success(zIdeaService.getById(id));
    }
    /**
     * 模板
     */
    @GetMapping("/model")
    public void getModel(HttpServletResponse response){
        ZIdea zIdea = new ZIdea();
        List<ZIdea> emptyList = Collections.singletonList(zIdea);
        ExcelUtil<ZIdea> util = new ExcelUtil<>(ZIdea.class);
        util.exportExcel(response, emptyList, "百年心愿记录数据");
    }
    /**
     * 导出百年心愿记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:property:export')")
    @Log(title = "百年心愿记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export/{ids}")
    public void export(HttpServletResponse response,@PathVariable Long[] ids)
    {
        List<ZIdea> list = zIdeaService.selectByIds(ids);
        log.info("导出记录为:{}",list);
        ExcelUtil<ZIdea> util = new ExcelUtil<>(ZIdea.class);
        util.exportExcel(response, list, "百年心愿记录数据");
    }
    /**
     * 导入百年心愿记录列表
     */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception
    {
        return zIdeaService.importExcel(file);
    }
    /**
     * 新增百年心愿记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:add')")
    @Log(title = "百年心愿记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZIdea zIdea)
    {
        return zIdeaService.mySave(zIdea);
    }
    /**
     * 修改百年心愿记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:edit')")
    @Log(title = "百年心愿记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZIdea zIdea)
    {
        return toAjax(zIdeaService.updateById(zIdea));
    }
//
    /**
     * 批量删除百年心愿记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:remove')")
    @Log(title = "百年心愿记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zIdeaService.removeByIds(Arrays.asList(ids)));
    }
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZPropertyController.java
@@ -1,9 +1,27 @@
package com.ruoyi.web.controller.zhang;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ZProperty;
import com.ruoyi.service.ZPropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
/**
 * <p>
@@ -15,7 +33,96 @@
 */
@RestController
@RequestMapping("/zProperty")
public class ZPropertyController {
@Slf4j
public class ZPropertyController extends BaseController {
    @Autowired
    private ZPropertyService zPropertyService;
    /**
     * 查询所有记录
     */
    @GetMapping("/all")
    public AjaxResult listAll(ZProperty zProperty){
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
        return zPropertyService.selectDataList(zProperty,pageNum,pageSize);
    }
    /**
     * 根据id查询
     */
    @GetMapping()
    public AjaxResult listById(Long id){
        return AjaxResult.success(zPropertyService.getById(id));
    }
    /**
     * 模板
     */
    @GetMapping("/model")
    public void getModel(HttpServletResponse response){
        ZProperty zProperty = new ZProperty();
        List<ZProperty> emptyList = Collections.singletonList(zProperty);
        ExcelUtil<ZProperty> util = new ExcelUtil<>(ZProperty.class);
        util.exportExcel(response, emptyList, "个人财产记录数据");
    }
    /**
     * 导出个人财产记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:property:export')")
    @Log(title = "个人财产记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export/{ids}")
    public void export(HttpServletResponse response,@PathVariable Long[] ids)
    {
        List<ZProperty> list = zPropertyService.selectByIds(ids);
        log.info("导出记录为:{}",list);
        ExcelUtil<ZProperty> util = new ExcelUtil<>(ZProperty.class);
        util.exportExcel(response, list, "个人财产记录数据");
    }
    /**
     * 导入个人财产记录列表
     */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception
    {
        return zPropertyService.importExcel(file);
    }
    /**
     * 新增个人财产记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:add')")
    @Log(title = "个人财产记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZProperty zProperty)
    {
        return zPropertyService.mySave(zProperty);
    }
    /**
     * 修改个人财产记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:edit')")
    @Log(title = "个人财产记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZProperty zProperty)
    {
        return toAjax(zPropertyService.updateById(zProperty));
    }
//
    /**
     * 批量删除个人财产记录
     */
//    @PreAuthorize("@ss.hasPermi('system:property:remove')")
    @Log(title = "个人财产记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zPropertyService.removeByIds(Arrays.asList(ids)));
    }
}
ruoyi-admin/src/main/resources/application-druid.yml
@@ -6,8 +6,8 @@
        druid:
            # 主库数据源
            master:
#                url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
#                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: ZhangApp123!
#                password: 123456
zhang-content/src/main/java/com/ruoyi/domain/ZIdea.java
@@ -1,9 +1,15 @@
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;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
@@ -14,124 +20,75 @@
 * @since 2023-03-14
 */
@TableName("z_idea")
@Data
public class ZIdea implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private Long id;
    private Long uid;
    @Excel(name = "时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenTime;
    /**
     * 理想标题/百年愿望
     */
    @Excel(name = "理想标题/百年愿望")
    private String title;
    /**
     * 始于何因
     */
    @Excel(name = "始于何因")
    private String cause;
    /**
     * 受惠人名字
     */
    @Excel(name = "受惠人名字")
    private String beneficiary;
    /**
     * 继承人名字
     */
    @Excel(name = "继承人名字")
    private String heir;
    /**
     * 实现难度
     */
    @Excel(name = "实现难度")
    private String difficulty;
    /**
     * 是否依旧有效
     */
    @Excel(name = "是否依旧有效(填是或否)",readConverterExp = "1=是,0=否")
    private Integer isEffective;
    /**
     * 备注
     */
    @Excel(name = "备注")
    private String remark;
    private String url;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenStartTime;
    public String getTitle() {
        return title;
    }
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenEndTime;
    public void setTitle(String title) {
        this.title = title;
    }
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    public String getCause() {
        return cause;
    }
    public void setCause(String cause) {
        this.cause = cause;
    }
    public String getBeneficiary() {
        return beneficiary;
    }
    public void setBeneficiary(String beneficiary) {
        this.beneficiary = beneficiary;
    }
    public String getHeir() {
        return heir;
    }
    public void setHeir(String heir) {
        this.heir = heir;
    }
    public String getDifficulty() {
        return difficulty;
    }
    public void setDifficulty(String difficulty) {
        this.difficulty = difficulty;
    }
    public Integer getIsEffective() {
        return isEffective;
    }
    public void setIsEffective(Integer isEffective) {
        this.isEffective = isEffective;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    @Override
    public String toString() {
        return "ZIdea{" +
        "id=" + id +
        ", title=" + title +
        ", cause=" + cause +
        ", beneficiary=" + beneficiary +
        ", heir=" + heir +
        ", difficulty=" + difficulty +
        ", isEffective=" + isEffective +
        ", remark=" + remark +
        "}";
    }
}
zhang-content/src/main/java/com/ruoyi/domain/ZProperty.java
@@ -1,12 +1,15 @@
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;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
@@ -23,18 +26,27 @@
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private Long id;
    /**
     * 本人id
     */
    private Integer userId;
    private Long userId;
    @Excel(name = "日期",dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenTime;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /**
     * 财产类别
     */
    @Excel(name = "财产类别",readConverterExp = "1=工资,2=存款,3=理财,4=实业,5=房产,6=证券,7=股票,8=债券,9=期货,10=人身,11=财产保险,12=黄金,13=邮票,14=古玩")
    private Integer type;
    @Excel(name = "财产类别")
    private String type;
    /**
     * 收支名称
@@ -46,7 +58,7 @@
     * 金额
     */
    @Excel(name = "金额")
    private Double price;
    private String price;
    /**
     * 期限
@@ -57,6 +69,7 @@
    /**
     * 变更或注销
     */
    @Excel(name = "变更或注销")
    private String isChange;
    /**
@@ -79,8 +92,16 @@
    private String url;
    @Excel(name = "是否注销",readConverterExp = "0=正常,1=已注销")
    @Excel(name = "是否注销(填是或否)",readConverterExp = "0=否,1=是")
    private Integer status;
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenStartTime;
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date happenEndTime;
}
zhang-content/src/main/java/com/ruoyi/service/ZIdeaService.java
@@ -2,7 +2,12 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ZIdea;
import com.ruoyi.domain.ZIdea;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
 * <p>
@@ -13,5 +18,13 @@
 * @since 2023-03-14
 */
public interface ZIdeaService extends IService<ZIdea> {
    AjaxResult selectDataList(ZIdea zIdea, Integer pageNum, Integer pageSize);
    List<ZIdea> selectByIds(Long[] ids);
    AjaxResult importExcel(MultipartFile file);
    AjaxResult mySave(ZIdea zIdea);
}
zhang-content/src/main/java/com/ruoyi/service/ZPropertyService.java
@@ -2,7 +2,12 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ZProperty;
import com.ruoyi.domain.ZProperty;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
 * <p>
@@ -14,4 +19,12 @@
 */
public interface ZPropertyService extends IService<ZProperty> {
    AjaxResult selectDataList(ZProperty zProperty, Integer pageNum, Integer pageSize);
    List<ZProperty> selectByIds(Long[] ids);
    AjaxResult importExcel(MultipartFile file);
    AjaxResult mySave(ZProperty zProperty);
}
zhang-content/src/main/java/com/ruoyi/service/impl/ZIdeaServiceImpl.java
@@ -1,11 +1,28 @@
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
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.domain.ZIdea;
import com.ruoyi.domain.ZIdea;
import com.ruoyi.mapper.ZIdeaMapper;
import com.ruoyi.service.ZIdeaService;
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
 * <p>
@@ -18,4 +35,106 @@
@Service
public class ZIdeaServiceImpl extends ServiceImpl<ZIdeaMapper, ZIdea> implements ZIdeaService {
    @Autowired
    ZIdeaServiceImpl zIdeaService;
    private LambdaQueryWrapper<ZIdea> uniqueCondition(ZIdea zIdea) {
        LambdaQueryWrapper<ZIdea> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(zIdea.getTitle()), ZIdea::getTitle, zIdea.getTitle())
                .eq(StringUtils.isNotEmpty(zIdea.getCause()), ZIdea::getCause, zIdea.getCause())
                .eq(StringUtils.isNotEmpty(zIdea.getBeneficiary()), ZIdea::getBeneficiary, zIdea.getBeneficiary())
                .eq(StringUtils.isNotEmpty(zIdea.getHeir()), ZIdea::getHeir, zIdea.getHeir())
                .eq(StringUtils.isNotEmpty(zIdea.getDifficulty()), ZIdea::getDifficulty, zIdea.getDifficulty())
                .eq(zIdea.getHappenTime() != null, ZIdea::getHappenTime, zIdea.getHappenTime())
                .eq(zIdea.getIsEffective() != null, ZIdea::getIsEffective, zIdea.getIsEffective())
                .eq(StringUtils.isNotEmpty(zIdea.getRemark()), ZIdea::getRemark, zIdea.getRemark())
                .eq(zIdea.getUid() != null, ZIdea::getUid, zIdea.getUid());
        return lqw;
    }
    private LambdaQueryWrapper<ZIdea> buildCondition(ZIdea zIdea, Long userId) {
        LambdaQueryWrapper<ZIdea> lqw = new LambdaQueryWrapper<>();
        lqw.eq(userId != null, ZIdea::getUid, userId)
                .like(StringUtils.isNotEmpty(zIdea.getTitle()), ZIdea::getTitle, zIdea.getTitle())
                .like(StringUtils.isNotEmpty(zIdea.getBeneficiary()), ZIdea::getBeneficiary, zIdea.getBeneficiary())
                .like(StringUtils.isNotEmpty(zIdea.getHeir()), ZIdea::getHeir, zIdea.getHeir())
                .between(zIdea.getHappenStartTime() != null && zIdea.getHappenEndTime() != null, ZIdea::getHappenTime, zIdea.getHappenStartTime(), zIdea.getHappenEndTime())
                .orderByDesc(ZIdea::getCreateTime);
        return lqw;
    }
    /**
     * 分页查找
     */
    @Override
    public AjaxResult selectDataList(ZIdea zIdea, Integer pageNum, Integer pageSize) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        LambdaQueryWrapper<ZIdea> lqw = buildCondition(zIdea, userId);
        Page<ZIdea> pageBean = new Page<>(pageNum, pageSize);
        Page<ZIdea> pageResult = page(pageBean, lqw);
        List<ZIdea> beanRecords = pageResult.getRecords();//得到查询出来的数据
        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
        return AjaxResult.success(data);
    }
    @Override
    public List<ZIdea> selectByIds(Long[] ids) {
        List<ZIdea> list = new ArrayList<>();
        if (ids.length != 0)
            list = listByIds(Arrays.asList(ids));
        else
            list = list();
        return list;
    }
    @Override
    public AjaxResult mySave(ZIdea zIdea) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        zIdea.setUid(userId);
        //检查是否有重复数据插入
        LambdaQueryWrapper<ZIdea> lqw = uniqueCondition(zIdea);
        List<ZIdea> list = list(lqw);
        if (list.size() > 0) {
            throw new RuntimeException("请勿新增重复数据");
        }
        if (save(zIdea)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
    @Override
    @Transactional
    public AjaxResult importExcel(MultipartFile file) {
        ExcelUtil<ZIdea> util = new ExcelUtil<>(ZIdea.class);
        List<ZIdea> dataList = null;
        try {
            dataList = util.importExcel(file.getInputStream());
        } catch (Exception e) {
            throw new RuntimeException("没有按照规则导入数据");
        }
        assert dataList != null;
        for (ZIdea zIdea : dataList) {
            zIdeaService.mySave(zIdea);
        }
        return AjaxResult.success();
    }
}
zhang-content/src/main/java/com/ruoyi/service/impl/ZPropertyServiceImpl.java
@@ -1,11 +1,28 @@
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
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.domain.ZProperty;
import com.ruoyi.domain.ZProperty;
import com.ruoyi.mapper.ZPropertyMapper;
import com.ruoyi.service.ZPropertyService;
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
 * <p>
@@ -18,4 +35,105 @@
@Service
public class ZPropertyServiceImpl extends ServiceImpl<ZPropertyMapper, ZProperty> implements ZPropertyService {
    @Autowired
    ZPropertyServiceImpl zPropertyService;
    private LambdaQueryWrapper<ZProperty> uniqueCondition(ZProperty zProperty) {
        LambdaQueryWrapper<ZProperty> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
                .eq(StringUtils.isNotEmpty(zProperty.getIncomeName()), ZProperty::getIncomeName, zProperty.getIncomeName())
                .eq(StringUtils.isNotEmpty(zProperty.getPrice()), ZProperty::getPrice, zProperty.getPrice())
                .eq(StringUtils.isNotEmpty(zProperty.getTimeLimit()), ZProperty::getTimeLimit, zProperty.getTimeLimit())
                .eq(StringUtils.isNotEmpty(zProperty.getIsChange()), ZProperty::getIsChange, zProperty.getIsChange())
                .eq(StringUtils.isNotEmpty(zProperty.getPropertyRight()), ZProperty::getPropertyRight, zProperty.getPropertyRight())
                .eq(zProperty.getHappenTime() != null, ZProperty::getHappenTime, zProperty.getHappenTime())
                .eq(StringUtils.isNotEmpty(zProperty.getLocation()), ZProperty::getLocation, zProperty.getLocation())
                .eq(StringUtils.isNotEmpty(zProperty.getRemark()), ZProperty::getRemark, zProperty.getRemark())
                .eq(zProperty.getUserId() != null, ZProperty::getUserId, zProperty.getUserId());
        return lqw;
    }
    private LambdaQueryWrapper<ZProperty> buildCondition(ZProperty zProperty, Long userId) {
        LambdaQueryWrapper<ZProperty> lqw = new LambdaQueryWrapper<>();
        lqw.eq(userId != null, ZProperty::getUserId, userId)
                .like(StringUtils.isNotEmpty(zProperty.getType()), ZProperty::getType, zProperty.getType())
                .like(StringUtils.isNotEmpty(zProperty.getIncomeName()), ZProperty::getIncomeName, zProperty.getIncomeName())
                .between(zProperty.getHappenStartTime() != null && zProperty.getHappenEndTime() != null, ZProperty::getHappenTime, zProperty.getHappenStartTime(), zProperty.getHappenEndTime())
                .orderByDesc(ZProperty::getCreateTime);
        return lqw;
    }
    /**
     * 分页查找
     */
    @Override
    public AjaxResult selectDataList(ZProperty zProperty, Integer pageNum, Integer pageSize) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        LambdaQueryWrapper<ZProperty> lqw = buildCondition(zProperty, userId);
        Page<ZProperty> pageBean = new Page<>(pageNum, pageSize);
        Page<ZProperty> pageResult = page(pageBean, lqw);
        List<ZProperty> beanRecords = pageResult.getRecords();//得到查询出来的数据
        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
        return AjaxResult.success(data);
    }
    @Override
    public List<ZProperty> selectByIds(Long[] ids) {
        List<ZProperty> list = new ArrayList<>();
        if (ids.length != 0)
            list = listByIds(Arrays.asList(ids));
        else
            list = list();
        return list;
    }
    @Override
    public AjaxResult mySave(ZProperty zProperty) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        zProperty.setUserId(userId);
        //检查是否有重复数据插入
        LambdaQueryWrapper<ZProperty> lqw = uniqueCondition(zProperty);
        List<ZProperty> list = list(lqw);
        if (list.size() > 0) {
            throw new RuntimeException("请勿新增重复数据");
        }
        if (save(zProperty)) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
    @Override
    @Transactional
    public AjaxResult importExcel(MultipartFile file) {
        ExcelUtil<ZProperty> util = new ExcelUtil<>(ZProperty.class);
        List<ZProperty> dataList = null;
        try {
            dataList = util.importExcel(file.getInputStream());
        } catch (Exception e) {
            throw new RuntimeException("没有按照规则导入数据");
        }
        assert dataList != null;
        for (ZProperty zProperty : dataList) {
            zPropertyService.mySave(zProperty);
        }
        return AjaxResult.success();
    }
}