Commit c6fe8a3f authored by fangxinjiang's avatar fangxinjiang

B端服务添加:政策中心

parent 13292350
package com.yifu.cloud.plus.v1.business.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
/**
* @Author fxj
* @Description B端-政策
* @Date 16:44 2023/1/3
* @Param
* @return
**/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("t_policy")
@Tag(name = "B端-政策")
public class TPolicy extends Model<TPolicy> {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键", name = "id")
private String id;
/**
*
*/
@NotBlank(message = "标题不能为空")
@Length(max = 200, message = "标题不能超过200个字符")
@ExcelAttribute(name = "标题", isNotEmpty = true, errorInfo = "标题不能为空", maxLength = 200)
@Schema(description = "标题", name = "title")
private String title;
/**
*
*/
@ExcelAttribute(name = "内容")
@Schema(description = "内容", name = "content")
private String content;
/**
* 省
*/
@ExcelAttribute(name = "省")
@Schema(description = "省", name = "province")
private Integer province;
/**
* 市
*/
@Length(max = 200, message = "市不能超过200个字符")
@ExcelAttribute(name = "市", maxLength = 200)
@Schema(description = "市", name = "city")
private String city;
/**
* 创建人
*/
@NotBlank(message = "创建人不能为空")
@Length(max = 32, message = "创建人不能超过32个字符")
@ExcelAttribute(name = "创建人", isNotEmpty = true, errorInfo = "创建人不能为空", maxLength = 32)
@Schema(description = "创建人", name = "createUser")
private String createUser;
/**
* 创建时间
*/
@ExcelAttribute(name = "创建时间")
@Schema(description = "创建时间", name = "createTime")
private LocalDateTime createTime;
/**
* 阅读量
*/
@ExcelAttribute(name = "阅读量")
@Schema(description = "阅读量", name = "readings")
private Integer readings;
}
package com.yifu.cloud.plus.v1.business.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.business.entity.TPolicy;
import com.yifu.cloud.plus.v1.business.service.TPolicyService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
/**
* B端-政策
*
* @author hgw
* @date 2020-8-27 11:31:42
*/
@RestController
@AllArgsConstructor
@RequestMapping("/customerBusiness/tpolicy")
@Tag(name = "B端-政策")
public class TPolicyController {
private final TPolicyService tPolicyService;
/**
* 简单分页查询
*
* @param page 分页对象
* @param tPolicy B端-政策
* @return
*/
@Operation(description = "简单分页查询")
@GetMapping("/page")
public R<IPage<TPolicy>> getTPolicyPage(Page<TPolicy> page, TPolicy tPolicy) {
// 倒序
OrderItem order = new OrderItem();
order.setColumn("CREATE_TIME");
order.setAsc(false);
page.addOrder(order);
return new R<>(tPolicyService.getTPolicyPage(page, tPolicy));
}
/**
* 通过id查询单条记录
*
* @param id
* @return R
*/
@Operation(description = "id查询")
@GetMapping("/{id}")
public R<TPolicy> getById(@PathVariable("id") String id) {
TPolicy policy = tPolicyService.getById(id);
if (policy != null) {
policy.setReadings(policy.getReadings() == null ? 1 : policy.getReadings() + 1);
tPolicyService.updateById(policy);
}
return new R<>(policy);
}
/**
* 新增记录
*
* @param tPolicy
* @return R
*/
@Operation(description = "新增(wxhr:tpolicy_add)")
@PostMapping
@PreAuthorize("@pms.hasPermission('wxhr:tpolicy_add')")
public R<Boolean> save(@RequestBody TPolicy tPolicy) {
if (Common.isEmpty(tPolicy.getTitle())) {
return R.failed("请输入标题!");
}
YifuUser user = SecurityUtils.getUser();
tPolicy.setCreateUser(String.valueOf(user.getId()));
tPolicy.setCreateTime(LocalDateTime.now());
return new R<>(tPolicyService.save(tPolicy));
}
/**
* 修改记录
*
* @param tPolicy
* @return R
*/
@Operation(description = "修改(wxhr:tpolicy_edit)")
@SysLog("修改B端-政策")
@PutMapping
@PreAuthorize("@pms.hasPermission('wxhr:tpolicy_edit')")
public R<Boolean> update(@RequestBody TPolicy tPolicy) {
return new R<>(tPolicyService.updateById(tPolicy));
}
/**
* 通过id删除一条记录
*
* @param id
* @return R
*/
@Operation(description = "删除(wxhr:tpolicy_del)")
@SysLog("删除B端-政策")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('wxhr:tpolicy_del')")
public R<Boolean> removeById(@PathVariable String id) {
return new R<>(tPolicyService.removeById(id));
}
}
package com.yifu.cloud.plus.v1.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.business.entity.TPolicy;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* B端-政策
*
* @author hgw
* @date 2020-08-26 17:41:55
*/
@Mapper
public interface TPolicyMapper extends BaseMapper<TPolicy> {
/**
* B端-政策简单分页查询
*
* @param tPolicy B端-政策
* @return
*/
IPage<TPolicy> getTPolicyPage(Page<TPolicy> page, @Param("tPolicy") TPolicy tPolicy);
}
package com.yifu.cloud.plus.v1.business.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.business.entity.TPolicy;
/**
* B端-政策
*
* @author hgw
* @date 2020-08-26 17:41:55
*/
public interface TPolicyService extends IService<TPolicy> {
/**
* B端-政策简单分页查询
*
* @param tPolicy B端-政策
* @return
*/
IPage<TPolicy> getTPolicyPage(Page<TPolicy> page, TPolicy tPolicy);
}
package com.yifu.cloud.plus.v1.business.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.business.entity.TPolicy;
import com.yifu.cloud.plus.v1.business.mapper.TPolicyMapper;
import com.yifu.cloud.plus.v1.business.service.TPolicyService;
import org.springframework.stereotype.Service;
/**
* B端-政策
*
* @author hgw
* @date 2020-08-26 17:41:55
*/
@Service("tPolicyService")
public class TPolicyServiceImpl extends ServiceImpl<TPolicyMapper, TPolicy> implements TPolicyService {
/**
* B端-政策简单分页查询
*
* @param tPolicy B端-政策
* @return
*/
@Override
public IPage<TPolicy> getTPolicyPage(Page<TPolicy> page, TPolicy tPolicy) {
return baseMapper.getTPolicyPage(page, tPolicy);
}
}
<?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.yifu.cloud.plus.v1.business.mapper.TPolicyMapper">
<resultMap id="tPolicyMap" type="com.yifu.cloud.plus.v1.business.entity.TPolicy">
<id property="id" column="ID"/>
<result property="title" column="TITLE"/>
<result property="content" column="CONTENT"/>
<result property="province" column="PROVINCE"/>
<result property="city" column="CITY"/>
<result property="createUser" column="CREATE_USER"/>
<result property="createTime" column="CREATE_TIME"/>
<result property="readings" column="READINGS"/>
</resultMap>
<sql id="Base_Column_List">
a.ID,
a.TITLE,
a.CONTENT,
a.PROVINCE,
a.CITY,
a.CREATE_USER,
a.CREATE_TIME,
a.READINGS
</sql>
<sql id="tPolicy_where">
<if test="tPolicy != null">
<if test="tPolicy.id != null and tPolicy.id.trim() != ''">
AND a.ID = #{tPolicy.id}
</if>
<if test="tPolicy.title != null and tPolicy.title.trim() != ''">
AND a.TITLE = #{tPolicy.title}
</if>
<if test="tPolicy.content != null and tPolicy.content.trim() != ''">
AND a.CONTENT = #{tPolicy.content}
</if>
<if test="tPolicy.province != null">
AND a.PROVINCE = #{tPolicy.province}
</if>
<if test="tPolicy.city != null and tPolicy.city.trim() != ''">
AND a.CITY like '%${tPolicy.city}%'
</if>
<if test="tPolicy.createUser != null and tPolicy.createUser.trim() != ''">
AND a.CREATE_USER = #{tPolicy.createUser}
</if>
<if test="tPolicy.createTime != null">
AND a.CREATE_TIME = #{tPolicy.createTime}
</if>
</if>
</sql>
<!--tPolicy简单分页查询-->
<select id="getTPolicyPage" resultMap="tPolicyMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_policy a
<where>
1=1
<include refid="tPolicy_where"/>
</where>
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment