Commit 8a634b8c by 杨林龙

Merge remote-tracking branch 'origin/master'

2 parents 4ddba025 5d8bc2a3
...@@ -2,6 +2,7 @@ package cn.com.glsx.app.modules.controller; ...@@ -2,6 +2,7 @@ package cn.com.glsx.app.modules.controller;
import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch; import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch;
import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO; import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.view.VehicleSharedDTO;
import cn.com.glsx.app.modules.service.VehicleService; import cn.com.glsx.app.modules.service.VehicleService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
...@@ -31,7 +32,7 @@ public class VehicleController { ...@@ -31,7 +32,7 @@ public class VehicleController {
@ApiOperation(value = "车辆列表") @ApiOperation(value = "车辆列表")
@GetMapping("/search") @GetMapping("/search")
public R<List<VehicleDeviceDTO>> search(VehicleDeviceSearch search) { public R<List<VehicleDeviceDTO>> search(VehicleDeviceSearch search) {
PageInfo<VehicleDeviceDTO> pageInfo = vehicleService.search(search); PageInfo<VehicleSharedDTO> pageInfo = vehicleService.search(search);
return R.ok().putPageData(pageInfo); return R.ok().putPageData(pageInfo);
} }
......
...@@ -44,6 +44,7 @@ public class UserSharedData extends BaseEntity { ...@@ -44,6 +44,7 @@ public class UserSharedData extends BaseEntity {
/** /**
* 状态:0默认,1有效,2失效 * 状态:0默认,1有效,2失效
*/ */
private Integer status; @Column(name = "enable_status")
private Integer enableStatus;
} }
\ No newline at end of file \ No newline at end of file
...@@ -34,33 +34,4 @@ public class VehicleShared extends BaseEntity { ...@@ -34,33 +34,4 @@ public class VehicleShared extends BaseEntity {
@Column(name = "content_id") @Column(name = "content_id")
private Long contentId; private Long contentId;
// /**
// * 内容类型:0车辆
// */
// @Column(name = "content_type")
// private Integer contentType;
//
// /**
// * 权限类型 r=只读 wr=读写
// */
// @Column(name = "permit_type")
// private String permitType;
//
// /**
// * 生效时间
// */
// @Column(name = "effective_date")
// private Date effectiveDate;
//
// /**
// * 失效时间
// */
// @Column(name = "expiration_date")
// private Date expirationDate;
//
// /**
// * 状态:0默认,1有效,2失效
// */
// private Integer status;
} }
\ No newline at end of file \ No newline at end of file
...@@ -10,4 +10,6 @@ public interface UserSharedDataMapper extends CommonBaseMapper<UserSharedData> { ...@@ -10,4 +10,6 @@ public interface UserSharedDataMapper extends CommonBaseMapper<UserSharedData> {
UserSharedData selectById(@Param("id") Long id); UserSharedData selectById(@Param("id") Long id);
UserSharedData selectByCreatedByAndContentId(@Param("userId") Long userId, @Param("contentId") Long contentId);
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ import cn.com.glsx.app.modules.entity.Vehicle; ...@@ -4,6 +4,7 @@ import cn.com.glsx.app.modules.entity.Vehicle;
import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch; import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch;
import cn.com.glsx.app.modules.model.stat.StatSearch; import cn.com.glsx.app.modules.model.stat.StatSearch;
import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO; import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.view.VehicleSharedDTO;
import com.glsx.plat.common.annotation.DataPerm; import com.glsx.plat.common.annotation.DataPerm;
import com.glsx.plat.common.annotation.DataPermShare; import com.glsx.plat.common.annotation.DataPermShare;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
...@@ -19,9 +20,7 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> { ...@@ -19,9 +20,7 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
@DataPermShare(showSql = true) @DataPermShare(showSql = true)
List<VehicleDeviceDTO> vehicleSearch(VehicleDeviceSearch search); List<VehicleDeviceDTO> vehicleSearch(VehicleDeviceSearch search);
@DataPerm(showSql = true) List<VehicleSharedDTO> manageSearch(VehicleDeviceSearch search);
@DataPermShare(showSql = true)
List<VehicleDeviceDTO> manageSearch(VehicleDeviceSearch search);
/** /**
* 统计当前用户有权限看到的车辆总数 * 统计当前用户有权限看到的车辆总数
......
...@@ -7,5 +7,6 @@ import lombok.Data; ...@@ -7,5 +7,6 @@ import lombok.Data;
public class VehicleDeviceSearch extends Page { public class VehicleDeviceSearch extends Page {
private String term; private String term;
private Long userId;
} }
...@@ -8,8 +8,8 @@ public class VehicleDeviceDTO { ...@@ -8,8 +8,8 @@ public class VehicleDeviceDTO {
private Long id; private Long id;
private String vin; private String vin;
private String ownerName; private String ownerName;
private String workOrderNo;
private String sns; private String sns;
private String sources; private String sources;
private Integer sharedCnt;
} }
package cn.com.glsx.app.modules.model.view;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.util.List;
@Data
public class VehicleSharedDTO {
private Long shareId;
private Long vehicleId;
private String vin;
private String ownerName;
private String workOrderNo;
private String sns;
private String sources;
private String permitType;
@JsonIgnore
private String receiverIds;
private List<String> sharedUserIds;
}
...@@ -7,7 +7,9 @@ import cn.com.glsx.app.modules.mapper.UserSharedDataMapper; ...@@ -7,7 +7,9 @@ import cn.com.glsx.app.modules.mapper.UserSharedDataMapper;
import cn.com.glsx.app.modules.mapper.VehicleSharedMapper; import cn.com.glsx.app.modules.mapper.VehicleSharedMapper;
import cn.com.glsx.app.modules.model.param.VehicleSharedBO; import cn.com.glsx.app.modules.model.param.VehicleSharedBO;
import cn.com.glsx.auth.utils.ShieldContextHolder; import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.hutool.json.JSONUtil;
import com.glsx.plat.core.enums.SysConstants; import com.glsx.plat.core.enums.SysConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -15,6 +17,7 @@ import javax.annotation.Resource; ...@@ -15,6 +17,7 @@ import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@Slf4j
@Service @Service
public class DataShareService { public class DataShareService {
...@@ -28,16 +31,30 @@ public class DataShareService { ...@@ -28,16 +31,30 @@ public class DataShareService {
private UserService userService; private UserService userService;
public Long shareVehicle(VehicleSharedBO sharedBO) { public Long shareVehicle(VehicleSharedBO sharedBO) {
UserSharedData sharedData = new UserSharedData(); Long cTerminalUserId = userService.getCTerminalUserId();
UserSharedData sharedData = userSharedDataMapper.selectByCreatedByAndContentId(cTerminalUserId, sharedBO.getVehicleId());
if (sharedData == null) {
//分享记录不存在,新增记录
sharedData = new UserSharedData();
sharedData.setContentId(sharedBO.getVehicleId()); sharedData.setContentId(sharedBO.getVehicleId());
sharedData.setContentType(0); sharedData.setContentType(0);
sharedData.setPermitType("wr"); sharedData.setPermitType("wr");
sharedData.setEffectiveDate(sharedBO.getEffectiveDate()); sharedData.setEffectiveDate(sharedBO.getEffectiveDate());
sharedData.setExpirationDate(sharedBO.getExpirationDate()); sharedData.setExpirationDate(sharedBO.getExpirationDate());
sharedData.setStatus(sharedBO.getEnableStatus()); sharedData.setEnableStatus(sharedBO.getEnableStatus());
sharedData.setCreatedBy(userService.getCTerminalUserId()); sharedData.setCreatedBy(cTerminalUserId);
sharedData.setCreatedDate(new Date()); sharedData.setCreatedDate(new Date());
userSharedDataMapper.insert(sharedData); userSharedDataMapper.insert(sharedData);
} else {
//分享记录存在,则更新分享设置
sharedData.setEffectiveDate(sharedBO.getEffectiveDate());
sharedData.setExpirationDate(sharedBO.getExpirationDate());
sharedData.setEnableStatus(sharedBO.getEnableStatus());
sharedData.setUpdatedBy(cTerminalUserId);
sharedData.setUpdatedDate(new Date());
userSharedDataMapper.updateByPrimaryKeySelective(sharedData);
}
return sharedData.getId(); return sharedData.getId();
} }
...@@ -49,25 +66,24 @@ public class DataShareService { ...@@ -49,25 +66,24 @@ public class DataShareService {
long difference = System.currentTimeMillis() - sharedData.getExpirationDate().getTime(); long difference = System.currentTimeMillis() - sharedData.getExpirationDate().getTime();
//禁用或者失效状态返回失败 //禁用或者失效状态返回失败
if (!Objects.equals(SysConstants.EnableStatus.enable.getCode(), sharedData.getStatus()) || difference >= 0) { if (!Objects.equals(SysConstants.EnableStatus.enable.getCode(), sharedData.getEnableStatus()) || difference >= 0) {
throw new AppServerException("分享失效"); throw new AppServerException("分享失效");
} }
Long cTerminalUserId = userService.getCTerminalUserId(); Long cTerminalUserId = userService.getCTerminalUserId();
VehicleShared vehicleShared = vehicleSharedMapper.selectBySharedIdAndReceiverId(sharedId, cTerminalUserId); VehicleShared vehicleShared = vehicleSharedMapper.selectBySharedIdAndReceiverId(sharedId, cTerminalUserId);
if (vehicleShared == null) { if (vehicleShared != null) {
vehicleShared = new VehicleShared(); log.info("车辆记录已存在:{}", JSONUtil.toJsonStr(vehicleShared));
return;
} }
//新增分享记录
vehicleShared = new VehicleShared();
vehicleShared.setSharedId(sharedId); vehicleShared.setSharedId(sharedId);
vehicleShared.setAccorderId(sharedData.getCreatedBy()); vehicleShared.setAccorderId(sharedData.getCreatedBy());
vehicleShared.setReceiverId(ShieldContextHolder.getUserId()); vehicleShared.setReceiverId(ShieldContextHolder.getUserId());
vehicleShared.setContentId(sharedData.getContentId()); vehicleShared.setContentId(sharedData.getContentId());
// vehicleShared.setContentType(sharedData.getContentType());
// vehicleShared.setPermitType(sharedData.getPermitType());
// vehicleShared.setEffectiveDate(sharedData.getEffectiveDate());
// vehicleShared.setExpirationDate(sharedData.getExpirationDate());
// vehicleShared.setStatus(sharedData.getStatus());
vehicleShared.setCreatedDate(new Date()); vehicleShared.setCreatedDate(new Date());
vehicleShared.setCreatedBy(cTerminalUserId); vehicleShared.setCreatedBy(cTerminalUserId);
vehicleSharedMapper.insert(vehicleShared); vehicleSharedMapper.insert(vehicleShared);
......
package cn.com.glsx.app.modules.service; package cn.com.glsx.app.modules.service;
import cn.com.glsx.admin.common.constant.UserConstants;
import cn.com.glsx.app.modules.mapper.VehicleMapper; import cn.com.glsx.app.modules.mapper.VehicleMapper;
import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch; import cn.com.glsx.app.modules.model.param.VehicleDeviceSearch;
import cn.com.glsx.app.modules.model.view.VehicleDeviceDTO; import cn.com.glsx.app.modules.model.view.VehicleSharedDTO;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Service @Service
...@@ -17,9 +22,24 @@ public class VehicleService { ...@@ -17,9 +22,24 @@ public class VehicleService {
@Resource @Resource
private VehicleMapper vehicleMapper; private VehicleMapper vehicleMapper;
public PageInfo<VehicleDeviceDTO> search(VehicleDeviceSearch search) { @Autowired
private UserService userService;
public PageInfo<VehicleSharedDTO> search(VehicleDeviceSearch search) {
search.setUserId(userService.getCTerminalUserId());
Page page = PageHelper.startPage(search.getPageNumber(), search.getPageSize()); Page page = PageHelper.startPage(search.getPageNumber(), search.getPageSize());
List<VehicleDeviceDTO> list = vehicleMapper.manageSearch(search); List<VehicleSharedDTO> list = vehicleMapper.manageSearch(search);
list.forEach(vdd -> {
if (StringUtils.isNotEmpty(vdd.getReceiverIds())) {
vdd.setSharedUserIds(Arrays.asList(vdd.getReceiverIds().split(",")));
}
if (UserConstants.RolePermitCastType.wxShared.getCode().equals(ShieldContextHolder.getRolePermissionType())) {
//被分享用户设为只读
vdd.setPermitType("r");
}
});
return new PageInfo<>(list); return new PageInfo<>(list);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<result column="permit_type" jdbcType="VARCHAR" property="permitType"/> <result column="permit_type" jdbcType="VARCHAR" property="permitType"/>
<result column="effective_date" jdbcType="TIMESTAMP" property="effectiveDate"/> <result column="effective_date" jdbcType="TIMESTAMP" property="effectiveDate"/>
<result column="expiration_date" jdbcType="TIMESTAMP" property="expirationDate"/> <result column="expiration_date" jdbcType="TIMESTAMP" property="expirationDate"/>
<result column="status" jdbcType="TINYINT" property="status"/> <result column="enable_status" jdbcType="TINYINT" property="enableStatus"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/> <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/> <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/> <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, content_id, content_type, permit_type, effective_date, expiration_date, `status`, id, content_id, content_type, permit_type, effective_date, expiration_date, enable_status,
del_flag, created_date, created_by, updated_date, updated_by del_flag, created_date, created_by, updated_date, updated_by
</sql> </sql>
...@@ -33,4 +33,14 @@ ...@@ -33,4 +33,14 @@
where del_flag = 0 where del_flag = 0
and id = #{id} and id = #{id}
</select> </select>
<select id="selectByCreatedByAndContentId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_cust_user_shared_data
where del_flag = 0
and created_by = #{userId}
and content_id = #{contentId}
and content_type = 0
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -62,11 +62,13 @@ ...@@ -62,11 +62,13 @@
<select id="vehicleSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO"> <select id="vehicleSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO">
select tv.id, tv.vin, select tv.id, tv.vin,
tv.owner_name ownerName, tv.owner_name ownerName,
tw.partner_order_no workOrderNo,
group_concat(tvd.sn) as sns, group_concat(tvd.sn) as sns,
group_concat(td.source) as sources group_concat(td.source) as sources
from t_vehicle tv from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0 and tvd.del_flag = 0 where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1 and tvd.bind_status = 1
and tv.created_by is not null and tv.created_by is not null
...@@ -75,34 +77,47 @@ ...@@ -75,34 +77,47 @@
tv.owner_name like '%${term}%' tv.owner_name like '%${term}%'
or tv.vin like '%${term}%' or tv.vin like '%${term}%'
or tvd.sn like '%${term}%' or tvd.sn like '%${term}%'
or tw.partner_order_no like '%${term}%'
) )
</if> </if>
group by tv.id group by tv.id
order by tv.id desc order by tv.id desc
</select> </select>
<select id="manageSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO"> <select id="manageSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleSharedDTO">
select tvd.id, select tcusd.id as shareId,
tv.id vid, tv.id as vehicleId,
tv.vin, tv.vin,
tv.owner_name ownerName, tv.owner_name as ownerName,
tvd.sn as sns, tw.partner_order_no workOrderNo,
td.source as sources, group_concat(tvd.sn) as sns,
(select count(DISTINCT receiver_id) from t_vehicle_shared tvs where tvs.content_id = tv.id and tvs.del_flag = 0) sharedCnt group_concat(td.source) as sources,
tcusd.permit_type as permitType,
group_concat(tvs.receiver_id) as receiverIds
from t_vehicle tv from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0 and tvd.del_flag = 0 left join t_workorder tw on tw.id = tv.workorder_id
and tvd.bind_status = 1 left join t_cust_user_shared_data tcusd on tcusd.content_id = tv.id and tcusd.content_type = 0
left join t_vehicle_shared tvs on tcusd.content_id = tv.id and tcusd.id = tvs.shared_id
where tcusd.del_flag = 0
and tv.created_by is not null and tv.created_by is not null
and tcusd.id is not null
and (
tcusd.created_by = #{userId}
or
(tvs.receiver_id = #{userId} and tcusd.enable_status = 1 and curdate() between tcusd.effective_date and tcusd.expiration_date)
)
<if test="term != null and term !=''"> <if test="term != null and term !=''">
and ( and (
tv.owner_name like '%${term}%' tv.owner_name like '%${term}%'
or tv.vin like '%${term}%' or tv.vin like '%${term}%'
or tvd.sn like '%${term}%' or tvd.sn like '%${term}%'
or tw.partner_order_no like '%${term}%'
) )
</if> </if>
order by tv.id desc group by tv.id
order by tcusd.created_date desc
</select> </select>
<select id="countDeviceWithAuth" resultType="java.lang.Integer"> <select id="countDeviceWithAuth" resultType="java.lang.Integer">
...@@ -110,7 +125,7 @@ ...@@ -110,7 +125,7 @@
from t_vehicle tv from t_vehicle tv
<where> <where>
and tv.del_flag = 0 and tv.del_flag = 0
<!-- and tv.validate_status = 1--> <!-- and tv.validate_status = 1-->
<if test="search.appendSql != null and search.appendSql !=''"> <if test="search.appendSql != null and search.appendSql !=''">
${search.appendSql} ${search.appendSql}
</if> </if>
......
...@@ -10,11 +10,6 @@ ...@@ -10,11 +10,6 @@
<result column="accorder_id" jdbcType="INTEGER" property="accorderId"/> <result column="accorder_id" jdbcType="INTEGER" property="accorderId"/>
<result column="receiver_id" jdbcType="INTEGER" property="receiverId"/> <result column="receiver_id" jdbcType="INTEGER" property="receiverId"/>
<result column="content_id" jdbcType="INTEGER" property="contentId"/> <result column="content_id" jdbcType="INTEGER" property="contentId"/>
<!-- <result column="content_type" jdbcType="TINYINT" property="contentType"/>-->
<!-- <result column="permit_type" jdbcType="VARCHAR" property="permitType"/>-->
<!-- <result column="effective_date" jdbcType="TIMESTAMP" property="effectiveDate"/>-->
<!-- <result column="expiration_date" jdbcType="TIMESTAMP" property="expirationDate"/>-->
<!-- <result column="status" jdbcType="TINYINT" property="status"/>-->
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/> <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/> <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/> <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
...@@ -25,8 +20,7 @@ ...@@ -25,8 +20,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, shared_id, accorder_id, receiver_id, content_id, content_type, permit_type, effective_date, id, shared_id, accorder_id, receiver_id, content_id, del_flag, created_date, created_by, updated_date, updated_by
expiration_date, `status`, del_flag, created_date, created_by, updated_date, updated_by
</sql> </sql>
<select id="selectBySharedIdAndReceiverId" resultMap="BaseResultMap"> <select id="selectBySharedIdAndReceiverId" resultMap="BaseResultMap">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!