定时入住人数修改
parent
c23bd8328c
commit
8a8ff2e44e
|
@ -0,0 +1,12 @@
|
||||||
|
package com.zyh.common.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PersonNum {
|
||||||
|
private Integer id;
|
||||||
|
private String buildId;
|
||||||
|
private Integer unit;
|
||||||
|
private Integer personNum;
|
||||||
|
|
||||||
|
}
|
|
@ -4,8 +4,10 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
public class ShopApplication {
|
public class ShopApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
|
@ -57,4 +57,6 @@ public class BuildController {
|
||||||
public Result<List<Housetype>> getHousetype() {
|
public Result<List<Housetype>> getHousetype() {
|
||||||
return buildService.getHousetype();
|
return buildService.getHousetype();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.zyh.system.mapper;
|
||||||
import com.zyh.common.domain.Building;
|
import com.zyh.common.domain.Building;
|
||||||
import com.zyh.common.domain.Households;
|
import com.zyh.common.domain.Households;
|
||||||
import com.zyh.common.domain.Housetype;
|
import com.zyh.common.domain.Housetype;
|
||||||
|
import com.zyh.common.domain.dto.PersonNum;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -25,4 +26,8 @@ public interface BuildMapper {
|
||||||
Integer updateHouse(Households households);
|
Integer updateHouse(Households households);
|
||||||
|
|
||||||
List<Housetype> getHousetype();
|
List<Housetype> getHousetype();
|
||||||
|
|
||||||
|
List<PersonNum> getPersonNum();
|
||||||
|
|
||||||
|
void updateBuildPersonNum(@Param("personNum") Integer personNum,@Param("unit") Integer unit,@Param("buildId") String buildId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.zyh.system.service;
|
||||||
import com.zyh.common.domain.Building;
|
import com.zyh.common.domain.Building;
|
||||||
import com.zyh.common.domain.Households;
|
import com.zyh.common.domain.Households;
|
||||||
import com.zyh.common.domain.Housetype;
|
import com.zyh.common.domain.Housetype;
|
||||||
|
import com.zyh.common.domain.dto.PersonNum;
|
||||||
import com.zyh.common.result.Result;
|
import com.zyh.common.result.Result;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,4 +21,7 @@ public interface BuildService {
|
||||||
|
|
||||||
Result<List<Housetype>> getHousetype();
|
Result<List<Housetype>> getHousetype();
|
||||||
|
|
||||||
|
List<PersonNum> getPersonNum();
|
||||||
|
|
||||||
|
void updateBuildPersonNum(Integer personNum,Integer unit,String buildId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.zyh.system.service.impl;
|
||||||
import com.zyh.common.domain.Building;
|
import com.zyh.common.domain.Building;
|
||||||
import com.zyh.common.domain.Households;
|
import com.zyh.common.domain.Households;
|
||||||
import com.zyh.common.domain.Housetype;
|
import com.zyh.common.domain.Housetype;
|
||||||
|
import com.zyh.common.domain.dto.PersonNum;
|
||||||
import com.zyh.common.result.Result;
|
import com.zyh.common.result.Result;
|
||||||
import com.zyh.system.mapper.BuildMapper;
|
import com.zyh.system.mapper.BuildMapper;
|
||||||
import com.zyh.system.service.BuildService;
|
import com.zyh.system.service.BuildService;
|
||||||
|
@ -85,4 +86,15 @@ public class BuildServicempl implements BuildService {
|
||||||
return Result.success(housetypes);
|
return Result.success(housetypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PersonNum> getPersonNum() {
|
||||||
|
return buildMapper.getPersonNum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBuildPersonNum(Integer personNum,Integer unit,String buildId) {
|
||||||
|
buildMapper.updateBuildPersonNum(personNum, unit, buildId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.zyh.system.timer;
|
||||||
|
|
||||||
|
import com.zyh.common.domain.dto.PersonNum;
|
||||||
|
import com.zyh.system.service.BuildService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Timer {
|
||||||
|
@Autowired
|
||||||
|
BuildService buildService;
|
||||||
|
@Scheduled(cron = "0 * * * * ?") // 每分钟触发一次
|
||||||
|
public void myScheduledMethod() {
|
||||||
|
// 在这里编写定时任务要执行的业务逻辑
|
||||||
|
List<PersonNum> personNums = buildService.getPersonNum();
|
||||||
|
for (PersonNum personNum : personNums) {
|
||||||
|
//修改楼栋入住人数
|
||||||
|
buildService.updateBuildPersonNum(personNum.getPersonNum(),personNum.getUnit(),personNum.getBuildId());
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println("定时任务执行了");
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,12 @@
|
||||||
type = #{type}
|
type = #{type}
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateBuildPersonNum">
|
||||||
|
update building set
|
||||||
|
residents = #{personNum}
|
||||||
|
where unit = #{unit}
|
||||||
|
and build_id = #{buildId}
|
||||||
|
</update>
|
||||||
<delete id="deleteHouse">
|
<delete id="deleteHouse">
|
||||||
delete from households where id = #{id}
|
delete from households where id = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
@ -43,4 +49,10 @@
|
||||||
<select id="getHousetype" resultType="com.zyh.common.domain.Housetype">
|
<select id="getHousetype" resultType="com.zyh.common.domain.Housetype">
|
||||||
select * from housetype
|
select * from housetype
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getPersonNum" resultType="com.zyh.common.domain.dto.PersonNum">
|
||||||
|
SELECT id, build_id, unit, SUM(person_num) AS personNum
|
||||||
|
FROM households
|
||||||
|
GROUP BY build_id, unit;
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue