a
jiangping
2023-09-11 3b7250f1bcaeb5663e75ddf0cc14bbac6930a334
a
已添加9个文件
已修改3个文件
637 ■■■■■ 文件已修改
server/company/src/main/java/com/doumee/api/business/CateParamSelectController.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/GoodsController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/db/cate_param_select.permissions.sql 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/platform/src/main/java/com/doumee/api/business/CateParamSelectController.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/CateParamSelectMapper.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/CateParamSelect.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/dto/GoodCreatePlatRequest.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/dto/PlatGoodsParam.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/CateParamSelectService.java 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/GoodsService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java 145 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/CateParamSelectController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,90 @@
package com.doumee.api.business;
import com.doumee.api.BaseController;
import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.model.CateParamSelect;
import com.doumee.service.CateParamSelectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
@Api(tags = "品类参数筛选项信息表")
@RestController
@RequestMapping("/cateParamSelect")
public class CateParamSelectController extends BaseController {
    @Autowired
    private CateParamSelectService cateParamSelectService;
    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @RequiresPermissions("cateparamselect:cateparamselect:create")
    public ApiResponse create(@RequestBody CateParamSelect cateParamSelect) {
        return ApiResponse.success(cateParamSelectService.create(cateParamSelect));
    }
    @ApiOperation("根据ID删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("cateparamselect:cateparamselect:delete")
    public ApiResponse deleteById(@PathVariable Integer id) {
        cateParamSelectService.deleteById(id);
        return ApiResponse.success(null);
    }
    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @RequiresPermissions("cateparamselect:cateparamselect:delete")
    public ApiResponse deleteByIdInBatch(@RequestParam String ids) {
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            idList.add(Integer.valueOf(id));
        }
        cateParamSelectService.deleteByIdInBatch(idList);
        return ApiResponse.success(null);
    }
    @ApiOperation("根据ID修改")
    @PostMapping("/updateById")
    @RequiresPermissions("cateparamselect:cateparamselect:update")
    public ApiResponse updateById(@RequestBody CateParamSelect cateParamSelect) {
        cateParamSelectService.updateById(cateParamSelect);
        return ApiResponse.success(null);
    }
    @ApiOperation("分页查询")
    @PostMapping("/page")
    @RequiresPermissions("cateparamselect:cateparamselect:query")
    public ApiResponse<PageData<CateParamSelect>> findPage (@RequestBody PageWrap<CateParamSelect> pageWrap) {
        return ApiResponse.success(cateParamSelectService.findPage(pageWrap));
    }
    @ApiOperation("导出Excel")
    @PostMapping("/exportExcel")
    @RequiresPermissions("cateparamselect:cateparamselect:exportExcel")
    public void exportExcel (@RequestBody PageWrap<CateParamSelect> pageWrap, HttpServletResponse response) {
        ExcelExporter.build(CateParamSelect.class).export(cateParamSelectService.findPage(pageWrap).getRecords(), "品类参数筛选项信息表", response);
    }
    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    @RequiresPermissions("cateparamselect:cateparamselect:query")
    public ApiResponse findById(@PathVariable Integer id) {
        return ApiResponse.success(cateParamSelectService.findById(id));
    }
}
server/company/src/main/java/com/doumee/api/business/GoodsController.java
@@ -6,6 +6,7 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.model.Goods;
import com.doumee.dao.business.model.dto.GoodCreatePlatRequest;
import com.doumee.dao.business.model.dto.GoodsRequest;
import com.doumee.service.business.GoodsService;
import io.swagger.annotations.*;
@@ -40,6 +41,13 @@
    public ApiResponse create(@RequestBody Goods goods) {
        return ApiResponse.success(goodsService.create(goods));
    }
    @PreventRepeat
    @ApiOperation("从平台选择商品")
    @PostMapping("/createPlat")
    @RequiresPermissions("business:goods:create")
    public ApiResponse createPlat(@RequestBody GoodCreatePlatRequest param) {
        return ApiResponse.success(goodsService.createPlat(param));
    }
    @ApiOperation("根据ID删除")
    @GetMapping("/delete/{id}")
server/db/cate_param_select.permissions.sql
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,6 @@
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('cateparamselect:cateparamselect:create', '新建品类参数筛选项信息表', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('cateparamselect:cateparamselect:delete', '删除品类参数筛选项信息表', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('cateparamselect:cateparamselect:update', '修改品类参数筛选项信息表', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('cateparamselect:cateparamselect:query', '查询品类参数筛选项信息表', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('cateparamselect:cateparamselect:exportExcel', '导出品类参数筛选项信息表(Excel)', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
server/platform/src/main/java/com/doumee/api/business/CateParamSelectController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,90 @@
package com.doumee.api.business;
import com.doumee.api.BaseController;
import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.model.CateParamSelect;
import com.doumee.service.CateParamSelectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
@Api(tags = "品类参数筛选项信息表")
@RestController
@RequestMapping("/cateParamSelect")
public class CateParamSelectController extends BaseController {
    @Autowired
    private CateParamSelectService cateParamSelectService;
    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @RequiresPermissions("cateparamselect:cateparamselect:create")
    public ApiResponse create(@RequestBody CateParamSelect cateParamSelect) {
        return ApiResponse.success(cateParamSelectService.create(cateParamSelect));
    }
    @ApiOperation("根据ID删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("cateparamselect:cateparamselect:delete")
    public ApiResponse deleteById(@PathVariable Integer id) {
        cateParamSelectService.deleteById(id);
        return ApiResponse.success(null);
    }
    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @RequiresPermissions("cateparamselect:cateparamselect:delete")
    public ApiResponse deleteByIdInBatch(@RequestParam String ids) {
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            idList.add(Integer.valueOf(id));
        }
        cateParamSelectService.deleteByIdInBatch(idList);
        return ApiResponse.success(null);
    }
    @ApiOperation("根据ID修改")
    @PostMapping("/updateById")
    @RequiresPermissions("cateparamselect:cateparamselect:update")
    public ApiResponse updateById(@RequestBody CateParamSelect cateParamSelect) {
        cateParamSelectService.updateById(cateParamSelect);
        return ApiResponse.success(null);
    }
    @ApiOperation("分页查询")
    @PostMapping("/page")
    @RequiresPermissions("cateparamselect:cateparamselect:query")
    public ApiResponse<PageData<CateParamSelect>> findPage (@RequestBody PageWrap<CateParamSelect> pageWrap) {
        return ApiResponse.success(cateParamSelectService.findPage(pageWrap));
    }
    @ApiOperation("导出Excel")
    @PostMapping("/exportExcel")
    @RequiresPermissions("cateparamselect:cateparamselect:exportExcel")
    public void exportExcel (@RequestBody PageWrap<CateParamSelect> pageWrap, HttpServletResponse response) {
        ExcelExporter.build(CateParamSelect.class).export(cateParamSelectService.findPage(pageWrap).getRecords(), "品类参数筛选项信息表", response);
    }
    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    @RequiresPermissions("cateparamselect:cateparamselect:query")
    public ApiResponse findById(@PathVariable Integer id) {
        return ApiResponse.success(cateParamSelectService.findById(id));
    }
}
server/service/src/main/java/com/doumee/dao/business/CateParamSelectMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
package com.doumee.dao.business;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.doumee.dao.business.model.CateParamSelect;
/**
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
public interface CateParamSelectMapper extends BaseMapper<CateParamSelect> {
}
server/service/src/main/java/com/doumee/dao/business/model/CateParamSelect.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
package com.doumee.dao.business.model;
import com.doumee.core.annotation.excel.ExcelColumn;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
/**
 * å“ç±»å‚数筛选项信息表
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
@Data
@ApiModel("品类参数筛选项信息表")
@TableName("`cate_param_select`")
public class CateParamSelect {
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "主键", example = "1")
    @ExcelColumn(name="主键")
    private Integer id;
    @ApiModelProperty(value = "创建人编码", example = "1")
    @ExcelColumn(name="创建人编码")
    private Integer creator;
    @ApiModelProperty(value = "创建时间")
    @ExcelColumn(name="创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createDate;
    @ApiModelProperty(value = "更新人编码", example = "1")
    @ExcelColumn(name="更新人编码")
    private Integer editor;
    @ApiModelProperty(value = "更新时间")
    @ExcelColumn(name="更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date editDate;
    @ApiModelProperty(value = "是否删除0否 1是", example = "1")
    @ExcelColumn(name="是否删除0否 1是")
    private Integer isdeleted;
    @ApiModelProperty(value = "备注")
    @ExcelColumn(name="备注")
    private String remark;
    @ApiModelProperty(value = "属性值")
    @ExcelColumn(name="属性值")
    private String name;
    @ApiModelProperty(value = "所属参数配置编码(关联cate_param表)", example = "1")
    @ExcelColumn(name="所属参数配置编码(关联cate_param表)")
    private Integer paramId;
    @ApiModelProperty(value = "所属品类编码(关联category表)", example = "1")
    @ExcelColumn(name="所属品类编码(关联category表)")
    private Integer categoryId;
    @ApiModelProperty(value = "状态 0启用 1禁用", example = "1")
    @ExcelColumn(name="状态 0启用 1禁用")
    private Integer status;
    @ApiModelProperty(value = "排序码", example = "1")
    @ExcelColumn(name="排序码")
    private Integer sortnum;
}
server/service/src/main/java/com/doumee/dao/business/model/dto/GoodCreatePlatRequest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
package com.doumee.dao.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : JP
 * @create 2023/6/7 15:09
 */
@Data
public class GoodCreatePlatRequest {
    @ApiModelProperty(value = "类别编码",example = "1")
    private Integer categoryId;
    @ApiModelProperty(value = "商品范围 0全部 1部分",example = "1")
    private Integer type;
    @ApiModelProperty(value = "加价系数",example = "1")
    private BigDecimal rate;
    @ApiModelProperty(value = "品牌主键")
    private List<PlatGoodsParam> goodsParamList;
}
server/service/src/main/java/com/doumee/dao/business/model/dto/PlatGoodsParam.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,22 @@
package com.doumee.dao.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : JP
 * @create 2023/6/7 15:09
 */
@Data
public class PlatGoodsParam {
    @ApiModelProperty(value = "商品编码",example = "1")
    private Integer goodsId;
    @ApiModelProperty(value = "入手价格 å…ƒ",example = "1")
    private BigDecimal price;
}
server/service/src/main/java/com/doumee/service/CateParamSelectService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,98 @@
package com.doumee.service;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.model.CateParamSelect;
import java.util.List;
/**
 * å“ç±»å‚数筛选项信息表Service定义
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
public interface CateParamSelectService {
    /**
     * åˆ›å»º
     *
     * @param cateParamSelect å®žä½“对象
     * @return Integer
     */
    Integer create(CateParamSelect cateParamSelect);
    /**
     * ä¸»é”®åˆ é™¤
     *
     * @param id ä¸»é”®
     */
    void deleteById(Integer id);
    /**
     * åˆ é™¤
     *
     * @param cateParamSelect å®žä½“对象
     */
    void delete(CateParamSelect cateParamSelect);
    /**
     * æ‰¹é‡ä¸»é”®åˆ é™¤
     *
     * @param ids ä¸»é”®é›†
     */
    void deleteByIdInBatch(List<Integer> ids);
    /**
     * ä¸»é”®æ›´æ–°
     *
     * @param cateParamSelect å®žä½“对象
     */
    void updateById(CateParamSelect cateParamSelect);
    /**
     * æ‰¹é‡ä¸»é”®æ›´æ–°
     *
     * @param cateParamSelects å®žä½“集
     */
    void updateByIdInBatch(List<CateParamSelect> cateParamSelects);
    /**
     * ä¸»é”®æŸ¥è¯¢
     *
     * @param id ä¸»é”®
     * @return CateParamSelect
     */
    CateParamSelect findById(Integer id);
    /**
     * æ¡ä»¶æŸ¥è¯¢å•条记录
     *
     * @param cateParamSelect å®žä½“对象
     * @return CateParamSelect
     */
    CateParamSelect findOne(CateParamSelect cateParamSelect);
    /**
     * æ¡ä»¶æŸ¥è¯¢
     *
     * @param cateParamSelect å®žä½“对象
     * @return List<CateParamSelect>
     */
    List<CateParamSelect> findList(CateParamSelect cateParamSelect);
    /**
     * åˆ†é¡µæŸ¥è¯¢
     *
     * @param pageWrap åˆ†é¡µå¯¹è±¡
     * @return PageData<CateParamSelect>
     */
    PageData<CateParamSelect> findPage(PageWrap<CateParamSelect> pageWrap);
    /**
     * æ¡ä»¶ç»Ÿè®¡
     *
     * @param cateParamSelect å®žä½“对象
     * @return long
     */
    long count(CateParamSelect cateParamSelect);
}
server/service/src/main/java/com/doumee/service/business/GoodsService.java
@@ -4,6 +4,7 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.model.Goods;
import com.doumee.dao.business.model.dto.GoodCreatePlatRequest;
import com.doumee.dao.business.model.dto.GoodsRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -114,4 +115,6 @@
    PageData<Goods> getGoodsPage(PageWrap<GoodsRequest> pageWrap);
    List<Goods> findListForH5(GoodsRequest goodsRequest);
    Integer createPlat(GoodCreatePlatRequest param);
}
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -17,6 +17,7 @@
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.GoodsJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.model.dto.GoodCreatePlatRequest;
import com.doumee.dao.business.model.dto.GoodsRequest;
import com.doumee.service.business.GoodsService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -120,6 +121,65 @@
        return goods.getId();
    }
    @Override
    public  Integer createPlat(GoodCreatePlatRequest param){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
            //非企业用户不能操作
            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
        }
        if(param.getCategoryId() == null
                || param.getType() == null
                || param.getRate() == null
                || (Constants.equalsInteger(param.getType(), Constants.ONE)
                && (param.getGoodsParamList() == null
                || param.getGoodsParamList().size()==0))){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        Goods goods = new Goods();
        if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",goods.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在");
        }
        goods.setStatus(Constants.ZERO);
        goods.setCreateDate(new Date());
        goods.setCreator(user.getId());
        goods.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
        goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
        goodsMapper.insert(goods);
        List<Multifile> multifileList = goods.getMultifileList();
        if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
            for (int i = 0; i < multifileList.size(); i++) {
                Multifile multifile = multifileList.get(i);
                multifile.setCreator(user.getId());
                multifile.setCreateDate(new Date());
                multifile.setIsdeleted(Constants.ZERO);
                multifile.setSortnum(i+Constants.ONE);
                multifile.setObjId(goods.getId());
                multifile.setType(Constants.ZERO);
                multifile.setObjType(Constants.ZERO);
                multifileMapper.insert(multifile);
            }
        }
        List<GoodsParam> goodsParamList = goods.getGoodsParamList();
        if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
            for (int i = 0; i < goodsParamList.size(); i++) {
                GoodsParam goodsParam = goodsParamList.get(i);
                goodsParam.setCreator(user.getId());
                goodsParam.setCreateDate(new Date());
                goodsParam.setIsdeleted(Constants.ZERO);
                goodsParam.setSortnum(i+Constants.ONE);
                goodsParam.setStatus(Constants.ZERO);
                goodsParam.setGoodsId(goods.getId());
                goodsParamMapper.insert(goodsParam);
            }
        }
        return goods.getId();
    }
    @Override
    public void deleteById(Integer id) {
server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,145 @@
package com.doumee.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CateParamSelectMapper;
import com.doumee.dao.business.model.CateParamSelect;
import com.doumee.service.CateParamSelectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
 * å“ç±»å‚数筛选项信息表Service实现
 * @author æ±Ÿè¹„蹄
 * @date 2023/09/11 14:45
 */
@Service
public class CateParamSelectServiceImpl implements CateParamSelectService {
    @Autowired
    private CateParamSelectMapper cateParamSelectMapper;
    @Override
    public Integer create(CateParamSelect cateParamSelect) {
        cateParamSelectMapper.insert(cateParamSelect);
        return cateParamSelect.getId();
    }
    @Override
    public void deleteById(Integer id) {
        cateParamSelectMapper.deleteById(id);
    }
    @Override
    public void delete(CateParamSelect cateParamSelect) {
        UpdateWrapper<CateParamSelect> deleteWrapper = new UpdateWrapper<>(cateParamSelect);
        cateParamSelectMapper.delete(deleteWrapper);
    }
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        cateParamSelectMapper.deleteBatchIds(ids);
    }
    @Override
    public void updateById(CateParamSelect cateParamSelect) {
        cateParamSelectMapper.updateById(cateParamSelect);
    }
    @Override
    public void updateByIdInBatch(List<CateParamSelect> cateParamSelects) {
        if (CollectionUtils.isEmpty(cateParamSelects)) {
            return;
        }
        for (CateParamSelect cateParamSelect: cateParamSelects) {
            this.updateById(cateParamSelect);
        }
    }
    @Override
    public CateParamSelect findById(Integer id) {
        return cateParamSelectMapper.selectById(id);
    }
    @Override
    public CateParamSelect findOne(CateParamSelect cateParamSelect) {
        QueryWrapper<CateParamSelect> wrapper = new QueryWrapper<>(cateParamSelect);
        return cateParamSelectMapper.selectOne(wrapper);
    }
    @Override
    public List<CateParamSelect> findList(CateParamSelect cateParamSelect) {
        QueryWrapper<CateParamSelect> wrapper = new QueryWrapper<>(cateParamSelect);
        return cateParamSelectMapper.selectList(wrapper);
    }
    @Override
    public PageData<CateParamSelect> findPage(PageWrap<CateParamSelect> pageWrap) {
        IPage<CateParamSelect> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<CateParamSelect> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(CateParamSelect::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(CateParamSelect::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(CateParamSelect::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(CateParamSelect::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getParamId() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getParamId, pageWrap.getModel().getParamId());
        }
        if (pageWrap.getModel().getCategoryId() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getCategoryId, pageWrap.getModel().getCategoryId());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(CateParamSelect::getSortnum, pageWrap.getModel().getSortnum());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(cateParamSelectMapper.selectPage(page, queryWrapper));
    }
    @Override
    public long count(CateParamSelect cateParamSelect) {
        QueryWrapper<CateParamSelect> wrapper = new QueryWrapper<>(cateParamSelect);
        return cateParamSelectMapper.selectCount(wrapper);
    }
}