package jp.dip.arimodoki.blogic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jp.dip.arimodoki.mapper.UserMapper;
import jp.dip.arimodoki.model.PromenadeFormIf;
import jp.dip.arimodoki.model.dto.UserIf;
@Scope("prototype")
@Service
public class BlUser implements BlUserIf {
@Autowired
private UserMapper usrMapper;
private PromenadeFormIf formPromenade;
public void setForm(PromenadeFormIf form) {
this.formPromenade = form;
}
public void dbProc() throws Exception {
int dbcommandType = this.formPromenade.getDbcommandType();
UserIf user = this.formPromenade.getUser();
String[] checkVals = this.formPromenade.getCheckVals();
if(checkVals != null && checkVals.length > 0) user.setCheckVal(checkVals[0]);
switch(dbcommandType) {
case 1:
this.getUser();
break;
case 2:
this.insertUser();
break;
case 3:
this.updateUser();
break;
case 4:
this.deleteUser();
break;
default:
new Exception("dbcommandTypeが不正です");
}
}
@Transactional(readOnly=true)
public void getUser() throws Exception {
int userid = this.formPromenade.getUser().getUserid();
if(userid == 0) {
new Exception("useridが未指定です");
}
UserIf user = usrMapper.getUser(userid);
if(user == null) return;
this.formPromenade.setUser(user);
String checkVal = user.getCheckVal();
this.formPromenade.setFavorite(checkVal);
String checkVals[] = new String[1];
checkVals[0] = checkVal;
this.formPromenade.setCheckVals(checkVals);
}
@Transactional(rollbackFor = Exception.class)
public void insertUser() throws Exception {
UserIf user = this.formPromenade.getUser();
usrMapper.insertNewUser(user);
}
@Transactional(rollbackFor = Exception.class)
public void updateUser() throws Exception {
UserIf user = this.formPromenade.getUser();
if(user.getUserid() == 0) {
new Exception("useridが未指定です");
}
usrMapper.updateUser(user);
}
@Transactional(rollbackFor = Exception.class)
public void deleteUser() throws Exception {
int userid = this.formPromenade.getUser().getUserid();
if(userid == 0) {
new Exception("useridが未指定です");
}
usrMapper.deleteUser(userid);
}
}
|