Browse Source

更新

master
sunyuchao 4 years ago
parent
commit
958c8c8af9
  1. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  2. 10
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java
  3. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java
  4. 54
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java
  5. 23
      epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

4
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -121,8 +121,8 @@ public class IcResiUserController {
* @Description 党建互联平台--修改居民信息
**/
@PostMapping("edit")
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody IcResiUserFormDTO formDTO) {
icResiUserService.edit(formDTO);
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
icResiUserService.edit(tokenDto, formDTO);
return new Result();
}

10
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java

@ -33,5 +33,15 @@ import java.util.Map;
@Mapper
public interface IcResiUserDao extends BaseDao<IcResiUserEntity> {
/**
* @Author sun
* @Description 居民信息各表新增数据
**/
void add(@Param("tableName") String tableName, @Param("map") Map<String, String> map);
/**
* @Author sun
* @Description 更新或新增居民信息各表数据
**/
void upTable(@Param("tableName") String tableName, @Param("id") String id, @Param("map") Map<String, String> map);
}

2
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java

@ -105,5 +105,5 @@ public interface IcResiUserService extends BaseService<IcResiUserEntity> {
* @Author sun
* @Description 党建互联平台--修改居民信息
**/
void edit(IcResiUserFormDTO formDTO);
void edit(TokenDto tokenDto, List<IcResiUserFormDTO> formDTO);
}

54
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
@ -34,6 +35,7 @@ import com.epmet.entity.IcResiUserEntity;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.redis.IcResiUserRedis;
import com.epmet.service.IcResiUserService;
import oracle.sql.NUMBER;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -41,10 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
* 用户基础信息
@ -163,7 +162,52 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
* @Description 党建互联平台--修改居民信息
**/
@Override
public void edit(IcResiUserFormDTO formDTO) {
public void edit(TokenDto tokenDto, List<IcResiUserFormDTO> formDTO) {
//1.校验主表数据是否存在
String resiUserId = "";
Map<String, String> map = new HashMap<>();
for (IcResiUserFormDTO d : formDTO) {
if ("ic_resi_user".equals(d.getTableName())) {
map = d.getList().get(0);
if (!map.containsKey("ID")) {
throw new RenException(String.format("居民信息修改-居民信息表主键值为空"));
}
resiUserId = map.get("ID");
}
}
if (null == map) {
throw new RenException(String.format("居民信息修改,参数错误,未传入基础信息Id"));
}
IcResiUserEntity entity = baseDao.selectById(resiUserId);
if (null == entity) {
throw new RenException(String.format("居民信息修改,获取基础信息失败,基础信息Id->", resiUserId));
}
//2.更新主表数据
if (map.size() > NumConstant.ONE) {
map.put("updated_by", tokenDto.getUserId());
baseDao.upTable("ic_resi_user", resiUserId, map);
}
//3.循环更新或新增字表数据
String finalResiUserId = resiUserId;
formDTO.forEach(d -> {
if (!"ic_resi_user".equals(d.getTableName())) {
d.getList().forEach(hash -> {
hash.put("updated_by", tokenDto.getUserId());
if (!hash.containsKey("ID")) {
hash.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
hash.put("ic_resi_user", finalResiUserId);
hash.put("customer_id", tokenDto.getCustomerId());
hash.put("created_by", tokenDto.getUserId());
//字表新增数据
baseDao.add(d.getTableName(), hash);
} else {
//字表更新数据
baseDao.upTable(d.getTableName(), hash.get("ID"), hash);
}
});
}
});
}

23
epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

@ -15,15 +15,24 @@
,UPDATED_TIME
) values
(
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
#{value}
</foreach>
,'0'
,'0'
,NOW()
,NOW()
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
#{value}
</foreach>
,'0'
,'0'
,NOW()
,NOW()
)
</insert>
<update id="upTable">
UPDATE ${tableName}
SET
<foreach collection="map.entrySet()" index="key" item="value" separator=",">
${key} = #{value}
</foreach>
,UPDATED_TIME = NOW()
WHERE id = #{id}
</update>
</mapper>
Loading…
Cancel
Save