Commit c9bcaf21 by levphon

收车管理

1 parent ada35aa3
......@@ -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.view.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.view.VehicleSharedDTO;
import cn.com.glsx.app.modules.service.VehicleService;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R;
......@@ -31,7 +32,7 @@ public class VehicleController {
@ApiOperation(value = "车辆列表")
@GetMapping("/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);
}
......
......@@ -44,6 +44,7 @@ public class UserSharedData extends BaseEntity {
/**
* 状态:0默认,1有效,2失效
*/
private Integer status;
@Column(name = "enable_status")
private Integer enableStatus;
}
\ No newline at end of file
......@@ -34,33 +34,4 @@ public class VehicleShared extends BaseEntity {
@Column(name = "content_id")
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
......@@ -10,4 +10,6 @@ public interface UserSharedDataMapper extends CommonBaseMapper<UserSharedData> {
UserSharedData selectById(@Param("id") Long id);
UserSharedData selectByCreatedByAndContentId(@Param("userId") Long userId, @Param("contentId") Long contentId);
}
\ No newline at end of file
......@@ -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.stat.StatSearch;
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.DataPermShare;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
......@@ -19,9 +20,7 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
@DataPermShare(showSql = true)
List<VehicleDeviceDTO> vehicleSearch(VehicleDeviceSearch search);
@DataPerm(showSql = true)
@DataPermShare(showSql = true)
List<VehicleDeviceDTO> manageSearch(VehicleDeviceSearch search);
List<VehicleSharedDTO> manageSearch(VehicleDeviceSearch search);
/**
* 统计当前用户有权限看到的车辆总数
......
......@@ -7,5 +7,6 @@ import lombok.Data;
public class VehicleDeviceSearch extends Page {
private String term;
private Long userId;
}
......@@ -8,8 +8,8 @@ public class VehicleDeviceDTO {
private Long id;
private String vin;
private String ownerName;
private String workOrderNo;
private String sns;
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;
import cn.com.glsx.app.modules.mapper.VehicleSharedMapper;
import cn.com.glsx.app.modules.model.param.VehicleSharedBO;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.hutool.json.JSONUtil;
import com.glsx.plat.core.enums.SysConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -15,6 +17,7 @@ import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;
@Slf4j
@Service
public class DataShareService {
......@@ -28,16 +31,30 @@ public class DataShareService {
private UserService userService;
public Long shareVehicle(VehicleSharedBO sharedBO) {
UserSharedData sharedData = new UserSharedData();
sharedData.setContentId(sharedBO.getVehicleId());
sharedData.setContentType(0);
sharedData.setPermitType("wr");
sharedData.setEffectiveDate(sharedBO.getEffectiveDate());
sharedData.setExpirationDate(sharedBO.getExpirationDate());
sharedData.setStatus(sharedBO.getEnableStatus());
sharedData.setCreatedBy(userService.getCTerminalUserId());
sharedData.setCreatedDate(new Date());
userSharedDataMapper.insert(sharedData);
Long cTerminalUserId = userService.getCTerminalUserId();
UserSharedData sharedData = userSharedDataMapper.selectByCreatedByAndContentId(cTerminalUserId, sharedBO.getVehicleId());
if (sharedData == null) {
//分享记录不存在,新增记录
sharedData = new UserSharedData();
sharedData.setContentId(sharedBO.getVehicleId());
sharedData.setContentType(0);
sharedData.setPermitType("wr");
sharedData.setEffectiveDate(sharedBO.getEffectiveDate());
sharedData.setExpirationDate(sharedBO.getExpirationDate());
sharedData.setEnableStatus(sharedBO.getEnableStatus());
sharedData.setCreatedBy(cTerminalUserId);
sharedData.setCreatedDate(new Date());
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();
}
......@@ -49,25 +66,24 @@ public class DataShareService {
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("分享失效");
}
Long cTerminalUserId = userService.getCTerminalUserId();
VehicleShared vehicleShared = vehicleSharedMapper.selectBySharedIdAndReceiverId(sharedId, cTerminalUserId);
if (vehicleShared == null) {
vehicleShared = new VehicleShared();
if (vehicleShared != null) {
log.info("车辆记录已存在:{}", JSONUtil.toJsonStr(vehicleShared));
return;
}
//新增分享记录
vehicleShared = new VehicleShared();
vehicleShared.setSharedId(sharedId);
vehicleShared.setAccorderId(sharedData.getCreatedBy());
vehicleShared.setReceiverId(ShieldContextHolder.getUserId());
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.setCreatedBy(cTerminalUserId);
vehicleSharedMapper.insert(vehicleShared);
......
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.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.PageHelper;
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 javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
@Service
......@@ -17,9 +22,24 @@ public class VehicleService {
@Resource
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());
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);
}
......
......@@ -11,7 +11,7 @@
<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="enable_status" jdbcType="TINYINT" property="enableStatus"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
......@@ -22,7 +22,7 @@
<!--
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
</sql>
......@@ -33,4 +33,14 @@
where del_flag = 0
and id = #{id}
</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>
\ No newline at end of file
......@@ -62,11 +62,13 @@
<select id="vehicleSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO">
select tv.id, tv.vin,
tv.owner_name ownerName,
tw.partner_order_no workOrderNo,
group_concat(tvd.sn) as sns,
group_concat(td.source) as sources
from t_vehicle tv
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_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
and tv.created_by is not null
......@@ -75,34 +77,46 @@
tv.owner_name like '%${term}%'
or tv.vin like '%${term}%'
or tvd.sn like '%${term}%'
or tw.partner_order_no like '%${term}%'
)
</if>
group by tv.id
order by tv.id desc
</select>
<select id="manageSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleDeviceDTO">
select tvd.id,
tv.id vid,
<select id="manageSearch" resultType="cn.com.glsx.app.modules.model.view.VehicleSharedDTO">
select tv.id,
tv.vin,
tv.owner_name ownerName,
tvd.sn as sns,
td.source as sources,
(select count(DISTINCT receiver_id) from t_vehicle_shared tvs where tvs.content_id = tv.id and tvs.del_flag = 0) sharedCnt
tv.owner_name as ownerName,
tw.partner_order_no workOrderNo,
group_concat(tvd.sn) as sns,
group_concat(td.source) as sources,
tcusd.permit_type as permitType,
group_concat(tvs.receiver_id) as receiverIds
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
left join t_workorder tw on tw.id = tv.workorder_id
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 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 !=''">
and (
tv.owner_name like '%${term}%'
or tv.vin like '%${term}%'
or tvd.sn like '%${term}%'
or tw.partner_order_no like '%${term}%'
)
</if>
order by tv.id desc
group by tv.id
order by tcusd.created_date desc
</select>
<select id="countDeviceWithAuth" resultType="java.lang.Integer">
......@@ -110,7 +124,7 @@
from t_vehicle tv
<where>
and tv.del_flag = 0
<!-- and tv.validate_status = 1-->
<!-- and tv.validate_status = 1-->
<if test="search.appendSql != null and search.appendSql !=''">
${search.appendSql}
</if>
......
......@@ -10,11 +10,6 @@
<result column="accorder_id" jdbcType="INTEGER" property="accorderId"/>
<result column="receiver_id" jdbcType="INTEGER" property="receiverId"/>
<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="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
......@@ -25,8 +20,7 @@
<!--
WARNING - @mbg.generated
-->
id, shared_id, accorder_id, receiver_id, content_id, content_type, permit_type, effective_date,
expiration_date, `status`, del_flag, created_date, created_by, updated_date, updated_by
id, shared_id, accorder_id, receiver_id, content_id, del_flag, created_date, created_by, updated_date, updated_by
</sql>
<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!