Commit 6d940399 authored by leyboy's avatar leyboy

1.位置信息接口

2.锁记录接口修改
parent 670858a4
This diff is collapsed.
......@@ -13,12 +13,12 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class DozerConfig {
@Bean(name = "org.dozer.Mapper")
public DozerBeanMapper dozer() {
List<String> mappingFiles = Arrays.asList("dozer/dozer-mappings-sys.xml");
DozerBeanMapper dozerBean = new DozerBeanMapper();
dozerBean.setMappingFiles(mappingFiles);
return dozerBean;
}
@Bean(name = "org.dozer.Mapper")
public DozerBeanMapper dozer() {
List<String> mappingFiles = Arrays.asList("dozer/dozer-mappings.xml");
DozerBeanMapper dozerBean = new DozerBeanMapper();
dozerBean.setMappingFiles(mappingFiles);
return dozerBean;
}
}
package com.adc.da.znks.controller;
import com.adc.da.util.utils.BeanMapper;
import com.adc.da.znks.entity.Position;
import com.adc.da.znks.entity.ResponseEntity;
import com.adc.da.znks.entity.User;
import com.adc.da.znks.page.PositionPage;
import com.adc.da.znks.service.PositionService;
import com.adc.da.znks.service.UserService;
import com.adc.da.znks.util.GenResponse;
import com.adc.da.znks.vo.PositionVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.adc.da.base.web.BaseController;
import com.adc.da.util.http.PageInfo;
import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
......@@ -29,37 +35,48 @@ public class PositionController extends BaseController<Position> {
@Autowired
private PositionService positionService;
@Autowired
private UserService userService;
@Autowired
private BeanMapper beanMapper;
private static final Logger logger = LoggerFactory.getLogger(PositionController.class);
// @ApiOperation(value = "|Position|分页查询")
// @GetMapping("/page")
// public ResponseMessage<PageInfo<Position>> page(PositionPage page) throws Exception {
// List<Position> rows = positionService.queryByPage(page);
// return Result.success(getPageInfo(page.getPager(), rows));
// }
//
// @ApiOperation(value = "|Position|查询")
// @GetMapping("")
// public ResponseMessage<List<Position>> list(PositionPage page) throws Exception {
// return Result.success(positionService.queryByList(page));
// }
//
// @ApiOperation(value = "|Position|详情")
// @GetMapping("/position/{positionId}")
// public ResponseMessage<Position> find(@PathVariable String positionId) throws Exception {
// return Result.success(positionService.selectByPrimaryKey(positionId));
// }
@ApiOperation(value = "|Position|分页查询")
@GetMapping("/page")
public ResponseEntity<PageInfo> page(@RequestParam(required = false) String telphone, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "8") Integer pageSize) throws Exception {
try {
PageHelper.startPage(pageNum, pageSize);
List<PositionVO> positionVOS = positionService.listPositionsByPage(telphone, pageNum, pageSize);
PageInfo positionVOPageInfo = new PageInfo(positionVOS);
return GenResponse.success(String.valueOf(HttpStatus.OK.value()),
"查询位置信息成功", positionVOPageInfo);
} catch (Exception e) {
e.printStackTrace();
return GenResponse.fail("查询位置信息失败");
}
}
@ApiOperation(value = "|Position|新增")
@PostMapping("/position")
public ResponseMessage<Boolean> create(@RequestBody Position position) throws Exception {
position.setPositionId(UUID.randomUUID().toString());
position.setRecordTime(new Date(System.currentTimeMillis()));
int result = positionService.insertSelective(position);
if (result != 0) {
return Result.success(String.valueOf(HttpStatus.OK.value()), "新增位置成功", true);
@PostMapping(value = "/position", consumes = {"application/x-www-form-urlencoded"})
public ResponseEntity<Boolean> create(PositionVO positionVO) throws Exception {
Position position = beanMapper.map(positionVO, Position.class);
String userTelphone = positionVO.getTelphone();
User user = userService.getByPhoneNumber(userTelphone);
if (user != null) {
position.setPositionId(UUID.randomUUID().toString());
position.setRecordTime(new Date(System.currentTimeMillis()));
position.setUserId(user.getId());
int result = positionService.insertSelective(position);
if (result != 0) {
return GenResponse.success(String.valueOf(HttpStatus.OK.value()), "新增位置成功", true);
} else {
return GenResponse.fail("新增位置失败");
}
} else {
return Result.error(String.valueOf(HttpStatus.OK.value()), "新增位置失败", false);
return GenResponse.fail("用户手机号在数据库不存在");
}
}
......
......@@ -2,15 +2,18 @@ package com.adc.da.znks.dao;
import com.adc.da.base.dao.BaseDao;
import com.adc.da.znks.entity.Position;
import com.adc.da.znks.vo.PositionVO;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;
/**
*
* <br>
* <b>功能:</b>PositionDao<br>
*/
@Mapper
public interface PositionDao extends BaseDao<Position> {
List<PositionVO> listPositionByPage(@Param("telphone") String telphone, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
}
......@@ -3,6 +3,7 @@ package com.adc.da.znks.service;
import com.adc.da.base.service.BaseService;
import com.adc.da.znks.dao.PositionDao;
import com.adc.da.znks.entity.Position;
import com.adc.da.znks.vo.PositionVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,6 +11,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* <br>
......@@ -28,4 +31,8 @@ public class PositionService extends BaseService<Position, String> {
return dao;
}
public List<PositionVO> listPositionsByPage(String telphone, Integer pageNum, Integer pageSize) {
return dao.listPositionByPage(telphone,pageNum, pageSize);
}
}
package com.adc.da.znks.vo;
import com.adc.da.znks.entity.Position;
import org.apache.commons.lang3.time.DateFormatUtils;
/**
* @author ley
**/
public class PositionVO extends Position {
private String telphone;
private String recordTimeStr;
public String getTelphone() {
return telphone;
}
public void setTelphone(String telphone) {
this.telphone = telphone;
}
public String getRecordTimeStr() {
recordTimeStr = DateFormatUtils.format(getRecordTime(), "yyyy-MM-dd HH:mm:ss");
return recordTimeStr;
}
public void setRecordTimeStr(String recordTimeStr) {
this.recordTimeStr = recordTimeStr;
}
}
......@@ -6,4 +6,4 @@ ${AnsiColor.RED} _ _
${AnsiColor.YELLOW}------------------------------------------------
${AnsiColor.YELLOW} :: ${AnsiColor.YELLOW}@数据资源中心
${AnsiColor.YELLOW}------------------------------------------------${AnsiColor.WHITE}
\ No newline at end of file
${AnsiColor.YELLOW}------------------------------------------------${AnsiColor.BLACK}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping>
<!--配置EO和VO全类名对应-->
<class-a>com.adc.da.znks.entity.Position</class-a>
<class-b>com.adc.da.znks.vo.PositionVO</class-b>
</mapping>
</mappings>
\ No newline at end of file
......@@ -52,8 +52,8 @@
u.temphone LIKE #{telphoneLike} and
</if>
u.id = d.user_id and
d.code = lr.device_id
and lr.lock_type != ''
d.id = lr.device_id and
lr.lock_type != ''
</where>
</select>
......
......@@ -41,20 +41,21 @@
<!-- 插入记录 -->
<insert id="insert" parameterType="com.adc.da.znks.entity.Position">
<!-- <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="position_id">
SELECT SEQ_tb_position.NEXTVAL FROM DUAL
</selectKey> -->
<!-- <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="position_id">
SELECT SEQ_tb_position.NEXTVAL FROM DUAL
</selectKey> -->
insert into tb_position(
<include refid="Base_Column_List"/>
)
values (#{positionId, jdbcType=VARCHAR}, #{recordTime, jdbcType=TIMESTAMP}, #{positionName, jdbcType=VARCHAR}, #{userId, jdbcType=VARCHAR})
values (#{positionId, jdbcType=VARCHAR}, #{recordTime, jdbcType=TIMESTAMP}, #{positionName, jdbcType=VARCHAR},
#{userId, jdbcType=VARCHAR})
</insert>
<!-- 动态插入记录 主键是序列 -->
<insert id="insertSelective" parameterType="com.adc.da.znks.entity.Position">
<!-- <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="position_id">
SELECT SEQ_tb_position.NEXTVAL FROM DUAL
</selectKey> -->
<!-- <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="position_id">
SELECT SEQ_tb_position.NEXTVAL FROM DUAL
</selectKey> -->
insert into tb_position
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="positionId != null">position_id,</if>
......@@ -70,7 +71,7 @@
</trim>
</insert>
<!-- 根据pk,修改记录-->
<!-- 根据pk,修改记录-->
<update id="updateByPrimaryKey" parameterType="com.adc.da.znks.entity.Position">
update tb_position
set record_time = #{recordTime},
......@@ -84,13 +85,13 @@
update tb_position
<set>
<if test="recordTime != null">
record_time = #{recordTime},
record_time = #{recordTime},
</if>
<if test="positionName != null">
position_name = #{positionName},
position_name = #{positionName},
</if>
<if test="userId != null">
user_id = #{userId},
user_id = #{userId},
</if>
</set>
where position_id = #{positionId}
......@@ -103,7 +104,7 @@
<include refid="Base_Column_List"/>
from tb_position
where position_id = #{value}
</select>
<!-- 删除记录 -->
......@@ -114,7 +115,7 @@
</delete>
<!-- tb_position 列表总数-->
<select id="queryByCount" resultType="java.lang.Integer" parameterType="com.adc.da.base.page.BasePage">
select count(1) from tb_position
......@@ -128,7 +129,7 @@
from tb_position
<include refid="Base_Where_Clause"/>
<if test="pager.orderCondition != null and pager.orderCondition != ''">
${pager.orderCondition}
${pager.orderCondition}
</if>
limit ${pager.pageOffset},${pageSize}
</select>
......@@ -140,8 +141,33 @@
from tb_position
<include refid="Base_Where_Clause"/>
<if test="pager.orderCondition != null and pager.orderCondition != ''">
${pager.orderCondition}
${pager.orderCondition}
</if>
</select>
<resultMap id="PositionVOMap" type="com.adc.da.znks.vo.PositionVO">
<id column="position_id" property="positionId"/>
<result column="record_time" property="recordTime"/>
<result column="position_name" property="positionName"/>
<result column="user_id" property="userId"/>
<result column="temphone" property="telphone"/>
</resultMap>
<sql id="Position_VO_Column">
p.position_id,p.record_time, p.position_name, p.user_id,u.temphone
</sql>
<select id="listPositionByPage" parameterType="object" resultMap="PositionVOMap">
select
<include refid="Position_VO_Column"/>
from tb_position p INNER JOIN tb_user u ON p.user_id = u.id
<where>
<if test="telphone!=null and telphone!=''">
<bind name="telphoneLike" value="'%'+telphone+'%'"/>
u.temphone LIKE #{telphoneLike}
</if>
</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