定时入住人数修改
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.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class ShopApplication {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
|
|
@ -57,4 +57,6 @@ public class BuildController {
|
|||
public Result<List<Housetype>> getHousetype() {
|
||||
return buildService.getHousetype();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.zyh.system.mapper;
|
|||
import com.zyh.common.domain.Building;
|
||||
import com.zyh.common.domain.Households;
|
||||
import com.zyh.common.domain.Housetype;
|
||||
import com.zyh.common.domain.dto.PersonNum;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -25,4 +26,8 @@ public interface BuildMapper {
|
|||
Integer updateHouse(Households households);
|
||||
|
||||
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.Households;
|
||||
import com.zyh.common.domain.Housetype;
|
||||
import com.zyh.common.domain.dto.PersonNum;
|
||||
import com.zyh.common.result.Result;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -20,4 +21,7 @@ public interface BuildService {
|
|||
|
||||
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.Households;
|
||||
import com.zyh.common.domain.Housetype;
|
||||
import com.zyh.common.domain.dto.PersonNum;
|
||||
import com.zyh.common.result.Result;
|
||||
import com.zyh.system.mapper.BuildMapper;
|
||||
import com.zyh.system.service.BuildService;
|
||||
|
@ -85,4 +86,15 @@ public class BuildServicempl implements BuildService {
|
|||
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}
|
||||
where id = #{id}
|
||||
</update>
|
||||
<update id="updateBuildPersonNum">
|
||||
update building set
|
||||
residents = #{personNum}
|
||||
where unit = #{unit}
|
||||
and build_id = #{buildId}
|
||||
</update>
|
||||
<delete id="deleteHouse">
|
||||
delete from households where id = #{id}
|
||||
</delete>
|
||||
|
@ -43,4 +49,10 @@
|
|||
<select id="getHousetype" resultType="com.zyh.common.domain.Housetype">
|
||||
select * from housetype
|
||||
</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>
|
||||
|
|
Loading…
Reference in New Issue